Git Product home page Git Product logo

fteikpy's Introduction

fteikpy

License Stars Pyversions Version Downloads Code style: black Codacy Badge Codecov Build Docs DOI

fteikpy is a Python library that computes accurate first arrival traveltimes in 2D and 3D heterogeneous isotropic velocity models. The algorithm handles properly the curvature of wavefronts close to the source which can be placed without any problem between grid points.

The code is based on FTeik implemented in Python and compiled just-in-time with numba.

sample-marmousi

Computation of traveltimes and ray-tracing on smoothed Marmousi velocity model.

Features

Forward modeling:

  • Compute traveltimes in 2D and 3D Cartesian grids with the possibility to use a different grid spacing in Z, X and Y directions,
  • Compute traveltime gradients at runtime or a posteriori,
  • A posteriori 2D and 3D ray-tracing.

Parallel:

  • Traveltime grids are seemlessly computed in parallel for different sources,
  • Raypaths from a given source to different locations are also evaluated in parallel.

Installation

The recommended way to install fteikpy and all its dependencies is through the Python Package Index:

pip install fteikpy --user

Otherwise, clone and extract the package, then run from the package location:

pip install . --user

To test the integrity of the installed package, check out this repository and run:

pytest

Documentation

Refer to the online documentation for detailed description of the API and examples.

Alternatively, the documentation can be built using Sphinx:

pip install -r doc/requirements.txt
sphinx-build -b html doc/source doc/build

Usage

The following example computes the traveltime grid in a 3D homogeneous velocity model:

import numpy as np
from fteikpy import Eikonal3D

# Velocity model
velocity_model = np.ones((8, 8, 8))
dz, dx, dy = 1.0, 1.0, 1.0

# Solve Eikonal at source
eik = Eikonal3D(velocity_model, gridsize=(dz, dx, dy))
tt = eik.solve((0.0, 0.0, 0.0))

# Get traveltime at specific grid point
t1 = tt[0, 1, 2]

# Or get traveltime at any point in the grid
t2 = tt(np.random.rand(3) * 7.0)

Contributing

Please refer to the Contributing Guidelines to see how you can help. This project is released with a Code of Conduct which you agree to abide by when contributing.

fteikpy's People

Contributors

keurfonluu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fteikpy's Issues

Can't change the position of source in the sample.py

Description of the problem

I can't set the poisition to (10.0,10.0) but to (10.0+1e-3,10.0+1e-3) or (10.5,10.5)

Full code that generated the error

My test code is in the attachment.

sample.zip

Full error message

Traceback (most recent call last):
  File "sample.py", line 37, in <module>
    trays = [tt(ray) for ray in rays]
  File "sample.py", line 37, in <listcomp>
    trays = [tt(ray) for ray in rays]
  File "C:\Users\xcq\AppData\Roaming\Python\Python38\site-packages\fteikpy\_grid.py", line 91, in __call__
    return vinterp2d(
ZeroDivisionError: division by zero

System information

  • Operating system:Winodws 10
  • Python install

ation (Anaconda, system, ETS):Anaconda

  • Version of Python:3.8
  • Version of this package:2.0

When I run the code to get traveltime at any grid point, the python kernel always died, why?

Description of the problem

When I run the example, the kernel will die at the last line (see the figure below);

Full code that generated the error
image

import numpy
from fteikpy import Eikonal3D

# Velocity model
velocity_model = numpy.ones((8, 8, 8))
dz, dx, dy = 1.0, 1.0, 1.0

# Solve Eikonal at source
eik = Eikonal3D(velocity_model, gridsize=(dz, dx, dy))
tt = eik.solve((0.0, 0.0, 0.0))

# Get traveltime at specific grid point
t1 = tt[0, 1, 2]

# Or get traveltime at any point in the grid
t2 = tt(numpy.random.rand(3) * 7.0)

Full error message

Kernel died, restarting

System information

  • Operating system: Windows 10
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of Python: 3.8.8
  • Version of this package: latest

When I run the code to get traveltime at some points,Some error like ZeroDivisionError: division by zero

Description of the problem
When I run the code to get traveltime at some points,Some error like ZeroDivisionError: division by zero.
I want to give a random array of positions within a circle to get traveltime.The source is in the center of the circular region.I tried different speed models and grid spacing sizes, which can pass when the array is linear, but may fail when the array becomes random.I wonder if this could have been avoided by code optimization or certain design principles?

Full code that generated the error

PASTE YOUR CODE HERE
import numpy as np
import pyvista
import random

from fteikpy import Eikonal3D, grid_to_meshio

pyvista.set_plot_theme("document")

def getRandomPointInCircle(num, radius, centerx, centery):
    
    # Polar coordinates generate a random array within a ring
    samplePoint = []
    for i in range(num):
        theta = random.random() * 2 * np.pi
        r = random.uniform(0, radius ** 2) 
        x = np.cos(theta) * (r ** 0.5) + centerx
        y = np.sin(theta) * (r ** 0.5) + centery
        samplePoint.append([x, y])

    return samplePoint
def main():
 
    # Observation system :Polar coordinates generate a random array within a ring
    num = 50
    radius = 12
    centerx,centery = 5, 5
    receiver = np.array(getRandomPointInCircle(num, radius, centerx, centery))

    # Velocity model
    velocity_model = np.ones((60, 200, 200))
    dz, dx, dy = 0.5, 0.5, 0.5
    velocity_model[:10]=velocity_model[:10]*500
    velocity_model[11:30]=velocity_model[11:30]*800
    velocity_model[31:60]=velocity_model[31:60]*1200

    # Solve Eikonal at source
    eik = Eikonal3D(velocity_model, gridsize=(dz, dx, dy),origin=(0,-50,-50))
    #eik.smooth(2.5)
    tt = eik.solve((0, 0, 0), nsweep=3, return_gradient=True)
    ttgrid = tt.grid.ravel()

    # Trace rays for 50 locations
    end_points = np.zeros((num, 3)) #z、x、y
    end_points[:,1] = receiver[:,0] 
    end_points[:,2] = receiver[:,1]
    rays = tt.raytrace(end_points)

    trays = [tt(ray) for ray in rays]

if __name__ == '__main__':
    main()

Full error message

PASTE ERROR MESSAGE HERE

image

System information

  • Operating system: Windows 10
  • Python installation (Anaconda, system, ETS):Anaconda
  • Version of Python:3.6.1
  • Version of this package:latest

Example code would be very nice

Description of the desired feature

It would be very helpful to have the code which generates the figure on the doc webpage, especially how the raytracing is done.

Some question about this pacakge

From the paper of Noble et al.2014.

The hybrid scheme has very good performance that combines a spherical approximation when close to the source and a plane
wave approximation when far away.

From _fteik2d.py I know there is some condition to choose plane wave or spherical wave.

I am not sure is the hybrid scheme applied in _fteik3d.py.

Do you know this ?

How to trace the ray inside a cylinderal volume?

Description of the desired feature
Hi, @keurfonluu
In the laboratory, the sample is a usually cylinder column. So, would you please add a feature to calculte the traveltime and trace the ray inside a cylinder area ? Thank you

Are you willing to help implement and maintain this feature? Yes/No
Yes

Interpretation of gradients

Hi Keurfon,

Thanks for your efforts of releasing/maintaining your code projects. fteikpy has been very useful to me so far.

From the documentation and the tests it is not entirely clear to me what the tt.gradient vector represents. Are these the gradients of the travel times with respect to the source location, for each receiver? If yes, that would be convenient for gradient-based hypocentre inversion :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.