gimli-org / gimli

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

3D TravelTime inversion: the starting gradient is created along the Y axis #627

Closed GregBievre closed 5 months ago

GregBievre commented 6 months ago

Problem description

Hi pyGIMLi team, When running the TravelTime inversion in 3D, the velocity gradient for the starting model is created along the Y axis instead of the Z axis.

Your environment

OS : Windows CPU(s) : 4 Machine : AMD64 Architecture : 64bit RAM : 15.9 GiB Environment : IPython

Python 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)]

pygimli : 1.4.5 pgcore : 1.4.0 numpy : 1.24.3 matplotlib : 3.7.1 scipy : 1.11.2 IPython : 8.18.0 pyvista : 0.42.3

I specify that I have the same issue when running from other OS such as Linux.

Steps to reproduce

import numpy as np
import pygimli as pg
import pygimli.meshtools as mt
import pyvista
from pygimli.viewer.pv import drawSensors

datafile = 'test.sgt' # hyperlink to the file at the bottom of the message
data = pg.physics.traveltime.load(datafile)
sensors=data.sensorPositions()

mgr = pg.physics.traveltime.TravelTimeManager(data)
data['err'] = mgr.estimateError(data['t'], errLevel=0.03, absError=1e-3)

Coarse mesh for testing purpose:

plc = mt.createParaMeshPLC3D(data, surfaceMeshQuality=34, surfaceMeshArea=2000)
mesh = mt.createMesh(plc)
mesh = mesh.createSubMesh(mesh.cells(mesh.cellMarkers()==2))

Inversion with creation of a starting model:

vest = mgr.invert(data, mesh=mesh, secNodes=1,
                 useGradient=True, vTop=100, vBottom=3000,
                 maxIter=0, # to check starting model
                 verbose=1)

label = pg.utils.unit("vel")
pl, _ = pg.show(mesh, vest, cMap='jet', showMesh=True, label=label, hold=True)
drawSensors(pl, sensors, diam=1, color='white')
pl.show()

Expected behavior

When invoking mgr.invert, I specifiy some parameters (useGradient, vTop and vBottom) to create a starting model and I expect the velocity gradient to be vertical.

Actual behavior

The velocity gradient for the starting model is oriented along the Y axis: StartingModel01 Furthermore, when I do not specify the abovementioned parameters (useGradient, vTop, vBottom), a gradient is eventually created and has the same shape, i.e. oriented along the Y axis: StartingModel02 I am probably missing something but I have no clue where. Could it originate from an ambiguity between coordinates Y and Z, since I know it is better to use Y to name the elevation variable in 2D inversion?

Paste your script output here.

No issue with the output, the inversion eventually converges when setting maxIter to higher values. Any help much appreciated. Best regards, Greg

The datafile (I have the same issue with other data, including synthetics): test.zip

halbmy commented 6 months ago

Dear Greg, great to see you in the pyGIMLi community again. This was indeed a bug (seems like not many are doing 3D refraction yet), thank you for pointing this out. We corrected this by 297bc848 image

GregBievre commented 6 months ago

Many thanks for your efficiency Thomas. Does that mean I can copy the new file "utils.py" to my local environment and just wait for the next update on conda-forge?

While you are around, I have another question: is there a way to set velocity bounds for the inversion process (seismics, resistivity, IP and others), such as cMin and cMax in BERT?

Regards, greg

halbmy commented 6 months ago

Better just use pyGIMLi directly from git as described here: https://www.pygimli.org/installation.html#staying-up-to-date (i.e. cloning and updating with git and conda develop)

GregBievre commented 6 months ago

Many thanks. I have some issues, notably a "ModuleNotFoundError: No module named 'pgcore'" despite the installation seemed to go well. I guess it is a problem dealing with PATH/PYTHONPATH. I'll have a look tomorrow. Cheers, Greg

halbmy commented 6 months ago

No, the pgcore package should be installed via conda. In the above report you specified

pgcore : 1.4.0

Are you using the same environment?

GregBievre commented 6 months ago

It seemed it was a PATH issue, which I solved using conda develop PATH=$PATH:c/Users/MyName/gimli Capture However, I am not quite sure I understood what I did since the path to the environment is C:\ProgramData\anaconda3\envs\pgcore Hopefully one day I'll understand Python. Anyway, many thanks again for your time. Greg

halbmy commented 6 months ago

Seems like your env is called pgcore and there is the pgcore package installed?

conda develop c:\Users\MyData\gimli (that should be the path where you checked out gimli) installs the source code to behave like a conda package (just redirecting), i.e. it is done only for this environment and therefore more sober than messing up the PYTHONPATH variable which would be for all environments.

Oh no: conda develop PATH=$PATH:c/Users/MyName/gimli does something strange!

conda develop c/Users/MyName/gimli installs the git repository as a

GregBievre commented 5 months ago

I did not see there was a dot after conda develop Everything runs fine when typing conda develop . Thanks again for your help.