gimli-org / gimli

Geophysical Inversion and Modeling Library :earth_africa:
https://www.pygimli.org
Other
348 stars 131 forks source link

error in calling fatray in traveltime manager. #564

Closed makeabhishek closed 9 months ago

makeabhishek commented 10 months ago

Problem description

I am trying to call fatray in traveltime manager. But its giving me error. Is it not available?

Your environment

Please provide the output of print(pygimli.Report()) here. If that does not work, please give provide some additional information on your:

Operating system: Linux pyGIMLi version: 1.4.1` *

Steps to reproduce

I tried both ways but it didn't work

import pygimli as pg
from pygimli.physics import TravelTimeManager
import pygimli.physics.traveltime as tt

mgr = tt.TravelTimeManager(data)
mgr = tt.TravelTimeManager(data,fatray=True)
...

Expected behavior

Tell us what should happen or what you want to achieve.

Actual behavior

-```

TypeError Traceback (most recent call last) Cell In[12], line 7 4 data = pg.load(filename) 5 # intitializing the traveltime manager. Choose fatray=False or True fatray=False 6 # mgr = tt.TravelTimeManager(data) ----> 7 mgr = tt.TravelTimeManager(fatray=True) 9 # visualise data 10 #tt.showVA(data, usePos=True) 11 ax, cbar = mgr.showData()

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/TravelTimeManager.py:34, in TravelTimeManager.init(self, data, kwargs) 31 self._useFMM = kwargs.pop("fatray", False) 32 self.secNodes = 2 # default number of secondary nodes for inversion ---> 34 super().init(data=data, kwargs) 36 self.inv.dataTrans = pg.trans.Trans()

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:709, in MeshMethodManager.init(self, kwargs) 700 def init(self, kwargs): 701 """Initialize by calling super methods. 702 703 Attribute (...) 707 You can overwrite it with invert(mesh=mesh). 708 """ --> 709 super(MeshMethodManager, self).init(**kwargs) 710 self.mesh = None

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:128, in MethodManager.init(self, fop, fw, data, kwargs) 124 self._initInversionFramework(verbose=self._verbose, 125 debug=self._debug) 127 # The forward operator is stored in self._fw --> 128 self._initForwardOperator(verbose=self._verbose, kwargs) 130 self._data = None 132 if data is not None:

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:206, in MethodManager._initForwardOperator(self, kwargs) 204 fop = self._fop 205 else: --> 206 fop = self.createForwardOperator(kwargs) 208 if fop is None: 209 pg.critical("It seems that createForwardOperator method " 210 "does not return a valid forward operator.")

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/TravelTimeManager.py:51, in TravelTimeManager.createForwardOperator(self, kwargs) 45 """Create default forward operator for Traveltime modelling. 46 47 Your want your Manager use a special forward operator you can add them 48 here on default Dijkstra is used. 49 """ 50 if self._useFMM: ---> 51 fop = FatrayDijkstraModelling(kwargs) 52 else: 53 fop = TravelTimeDijkstraModelling(**kwargs)

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/modelling.py:140, in FatrayDijkstraModellingInterpolate.init(self, frequency, verbose) 139 def init(self, frequency=100., verbose=False): --> 140 super().init(verbose) 141 self.frequency = frequency 142 self.iMat = pg.matrix.SparseMapMatrix()

TypeError: TravelTimeDijkstraModelling.init() takes 1 positional argument but 2 were given

Paste output here.



> If possible, please add one or more labels to your issue, e.g. if you expect that your issue is rather a question than a problem with the code, please add the label "question".
halbmy commented 10 months ago

The fatray option is obviously not working now. I will fix this next week. Thank you for reporting.

halbmy commented 10 months ago

I fixed the fatray option and created a notebook for it: https://github.com/gimli-org/notebooks/blob/main/traveltime/fatray.ipynb

makeabhishek commented 10 months ago

Do I have to update #pygimli? What could be the fastest way for Ubuntu?

halbmy commented 10 months ago

There is no release yet. The only way is to use the current git version. See https://www.pygimli.org/installation.html#staying-up-to-date for details.

makeabhishek commented 10 months ago

I updated the pygimli as follows

(pg) teamacoustics@teamacoutics:~/Documents/pygimli$ git clone https://github.com/gimli-org/gimli
Cloning into 'gimli'...
remote: Enumerating objects: 43026, done.
remote: Counting objects: 100% (1740/1740), done.
remote: Compressing objects: 100% (551/551), done.
remote: Total 43026 (delta 1207), reused 1705 (delta 1189), pack-reused 41286
Receiving objects: 100% (43026/43026), 31.50 MiB | 8.29 MiB/s, done.
Resolving deltas: 100% (33300/33300), done.
(pg) teamacoustics@teamacoutics:~/Documents/pygimli$ cd gimli/
(pg) teamacoustics@teamacoutics:~/Documents/pygimli/gimli$ conda develop .
added /home/teamacoustics/Documents/pygimli/gimli
completed operation for: /home/teamacoustics/Documents/pygimli/gimli

Here is the pygimli system report

--------------------------------------------------------------------------------
  Date: Wed Aug 09 12:05:25 2023 

                OS : Linux
            CPU(s) : 40
           Machine : x86_64
      Architecture : 64bit
               RAM : 62.5 GiB
       Environment : Jupyter
       File system : ext4

  Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32)
  [GCC 12.3.0]

           pygimli : 1.4.3
            pgcore : 1.4.0
             numpy : 1.23.5
        matplotlib : 3.7.2
             scipy : 1.11.1
           IPython : 8.14.0
           pyvista : 0.41.1
--------------------------------------------------------------------------------

I tried the example, but its giving me error.

TypeError                                 Traceback (most recent call last)
Cell In[8], line 8
      4 data = pg.load(filename)
      5 # data["err"] = 0.001
      6 # intitializing the traveltime manager. Choose fatray=False or True fatray=False
      7 # mgr = tt.TravelTimeManager(data)
----> 8 mgr = tt.TravelTimeManager(data=data, secNodes=4)
      9 # mgr = tt.TravelTimeManager(fatray=True)
     10 
     11 # visualise data
     12 #tt.showVA(data, usePos=True)
     13 ax, cbar = mgr.showData()

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/TravelTimeManager.py:34, in TravelTimeManager.__init__(self, data, **kwargs)
     31 self._useFMM = kwargs.pop("fatray", False)
     32 self.secNodes = 2  # default number of secondary nodes for inversion
---> 34 super().__init__(data=data, **kwargs)
     36 self.inv.dataTrans = pg.trans.Trans()

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:709, in MeshMethodManager.__init__(self, **kwargs)
    700 def __init__(self, **kwargs):
    701     """Initialize by calling super methods.
    702 
    703     Attribute
   (...)
    707         You can overwrite it with invert(mesh=mesh).
    708     """
--> 709     super(MeshMethodManager, self).__init__(**kwargs)
    710     self.mesh = None

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:128, in MethodManager.__init__(self, fop, fw, data, **kwargs)
    124 self._initInversionFramework(verbose=self._verbose,
    125                              debug=self._debug)
    127 # The forward operator is stored in self._fw
--> 128 self._initForwardOperator(verbose=self._verbose, **kwargs)
    130 self._data = None
    132 if data is not None:

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/methodManager.py:206, in MethodManager._initForwardOperator(self, **kwargs)
    204     fop = self._fop
    205 else:
--> 206     fop = self.createForwardOperator(**kwargs)
    208 if fop is None:
    209     pg.critical("It seems that createForwardOperator method "
    210                 "does not return a valid forward operator.")

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/TravelTimeManager.py:53, in TravelTimeManager.createForwardOperator(self, **kwargs)
     51     fop = FatrayDijkstraModelling(**kwargs)
     52 else:
---> 53     fop = TravelTimeDijkstraModelling(**kwargs)
     54 return fop

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/physics/traveltime/modelling.py:19, in TravelTimeDijkstraModelling.__init__(self, **kwargs)
     17 def __init__(self, **kwargs):
---> 19     super(TravelTimeDijkstraModelling, self).__init__(**kwargs)
     21     self._core = pg.core.TravelTimeDijkstraModelling()
     22     self._core.setRegionManager(self.regionManagerRef())

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/modelling.py:556, in MeshModelling.__init__(self, **kwargs)
    555 def __init__(self, **kwargs):
--> 556     super().__init__(**kwargs)
    557     self._axs = None
    558     self._meshNeedsUpdate = True

File ~/anaconda3/envs/pg/lib/python3.10/site-packages/pygimli/frameworks/modelling.py:86, in Modelling.__init__(self, **kwargs)
     84 self.fop = kwargs.pop('fop', None)
     85 # super(Modelling, self).__init__(**kwargs)
---> 86 super().__init__(**kwargs)
     88 self._regionProperties = {}
     89 self._interRegionCouplings = []

TypeError: ModellingBaseMT__.__init__() got an unexpected keyword argument 'secNodes'
halbmy commented 10 months ago

you have to switch to the development branch (git checkout dev). Our automated code checking and merging into the master seems to be broken. Sorry about that.

makeabhishek commented 10 months ago

Apologies, may I request a detail steps to follow, as I'm not an expert for git. Thanks

halbmy commented 10 months ago

just go to the folder where you checked out gimli and then type the command, that's it

makeabhishek commented 10 months ago

I tried that and its giving me this message git checkout


(pg) teamacoustics@teamacoutics:~/Documents/pygimli/gimli$ git branch dev
fatal: A branch named 'dev' already exists.
halbmy commented 10 months ago

I wrote git checkout dev

makeabhishek commented 10 months ago

Ah, my bad. thanks. seems like working now. Appreciate your quick responses.

Is there a way to control the fatray width while performing inversion?

halbmy commented 10 months ago

The only thing you can control is the width of the fatray by the frequency argument.

makeabhishek commented 10 months ago

You mean while generating the data for a particular frequency or there is an argument in the fatray function. I can't find the description in pygimli documentation. Where can I find the details about the fatray function arguments? Or is it based on the velocity model?

halbmy commented 10 months ago

You're right, I just added the keyword to the manager (so you just have to git pull):

mgr = tt.TravelTimeManager(data=data, fatray=True, secNodes=3, frequency=500.)

I will also make a notebook on Fresnel zones and their dependency on frequency. Note that pygimli.org is only updated upon new versions.

makeabhishek commented 10 months ago

Thanks, Yeah that would be my next question on Fresnel zones and their dependency on frequency. Thanks again.

makeabhishek commented 10 months ago

It seems that below commands are giving same result for higher frequency?

pg.show(mgr.paraDomain, mgr.fop.J[7])
pg.show(mgr.paraDomain, mgr.fop.FresnelWeight[7])

May i also know the location of the fatray function, I want to take a look of it? Is there any reference available which is followed for this?

halbmy commented 10 months ago

The Jacobian (first command) contains the ray length in meters and the weight is a dimensionless function summing to 1 that is being used to weight the jacobian. So only the color scale is different.

The fatray is implemented in pygimli.physics.traveltime.modelling under the FatrayTraveltime operator. For the background I suggest the paper of Jordi et al. (2016) and references therein.

C. Jordi, C. Schmelzbach, and S. Greenhalgh, “Frequency-dependent traveltime tomography using fat rays: application to near-surface seismic imaging,” Journal of Applied Geophysics, vol. 131, pp. 202–213, Aug. 2016, doi: 10.1016/j.jappgeo.2016.06.002.

makeabhishek commented 10 months ago

Do you think generating synthetic data (forward modeling) using fat ray influence the travel times?

halbmy commented 10 months ago

No, it does not affect the forward response (first arrivals) but only the Jacobian.

halbmy commented 10 months ago

By the way, I've made a notebook for the Fresnel volume: https://github.com/gimli-org/notebooks/blob/main/traveltime/fresnelVolume.ipynb

benbpete commented 10 months ago

Ah, my bad. thanks. seems like working now. Appreciate your quick responses.

Edit: I just saw in discussions @halbmy is working on the secNodes. I apologize if this is just addressing that same issue that you are already working on.

Sorry to jump in here a little late. I've been trying what @makeabhishek has done to install the development version and am struggling.

I've followed the instructions on pyglimli.org, e.g. created a new environment 'pgcore', cloned the source code, used "git checkout dev" in the gimli folder (and confirmed this with the response of "Already on 'dev' Your branchs is up to date with 'origin/dev'", but I receive the same error with the secNodes @makeabhishek is receiving. Any thoughts on where I may be going wrong on the installation?

Thank you!

halbmy commented 10 months ago

Please specify what exactly you did and the error message along with the filled template about platform etc.

Did you install pgcore in this environment?

makeabhishek commented 10 months ago

By the way, I've made a notebook for the Fresnel volume: https://github.com/gimli-org/notebooks/blob/main/traveltime/fresnelVolume.ipynb

I was trying the script. What does the meaning of the quote "The first-arrival traveltime is computed by the ratio of the shot-receiver distance and the velocity."? Is this the first Fresnel volume which is defined in terms of traveltimes $|t{sx} + t{rx} -t_{sr}| \leq \frac{T}{2}$

Also, how does the weight assigned as per equation (5) i.e, $w = 1-2f\Delta t, 0 \leq \Delta t \leq 1/2f ; 0, 1/2f \leq\Delta t$ in Jordi paper (it looks different)? what does weight represent here?

Which numerical method is used to obtain traveltime fields. For example, in Jordi paper they used finite difference modelling of the Eikonal equation to obtain traveltime fields (fig 1a).

benbpete commented 10 months ago

Please specify what exactly you did and the error message along with the filled template about platform etc.

Did you install pgcore in this environment?

I did install pgcore. I am likely just installing something wrong. I will spend more time on it before I ask others for more help. Thanks again.

halbmy commented 10 months ago

The first-arrival traveltime is computed by the ratio of the shot-receiver distance and the velocity.

This is a very simple and trivial statement for a homogeneous halfspace, i.e. analytical traveltime computation. This has nothing to do with Fresnel volume. This goes only into the Jacobian matrix where the thin ray is spread into a whole distribution using the weighting function just as in Jordi et al. (2016).

For the numerical computation of first-arrival traveltimes, we use a shortest-path solver of the Eikonal equation, see references in traveltime examples.