keurfonluu / evodcinv

Inversion of dispersion curves using Evolutionary Algorithms
BSD 3-Clause "New" or "Revised" License
69 stars 29 forks source link

model.invert: concatenation of run results #9

Closed wgajek closed 11 months ago

wgajek commented 1 year ago

That's a cool code! Thanks for posting. I found it very useful but also found some bugs.

BUG 1. When running model.invert for maxrun>1 with split_results=False (default value) TypeError is raised.

my example:

period=np.array([ 0.66666667, 1.        , 2.        ])
velocity=np.array([ 3.49215148, 3.5623525 , 2.74965395])
curves = [Curve(period, velocity, 0, "rayleigh", "phase")]
res = model.invert(curves, maxrun=2,split_results=False)

Full error message

Run 1  |████████████████████| 100% [0:00:01 / 0:00:00] - Misfit: 0.0529
Run 2  |████████████████████| 100% [0:00:01 / 0:00:00] - Misfit: 0.0528f
[?25hTraceback (most recent call last):

  File "/tmp/ipykernel_131271/491983976.py", line 1, in <module>
    res = model.invert(curves, maxrun=2,split_results=False)

  File "/home/wgajek/.local/lib/python3.9/site-packages/evodcinv/_model.py", line 304, in invert
    out += result

  File "/home/wgajek/.local/lib/python3.9/site-packages/evodcinv/_result.py", line 88, in __add__
    raise TypeError()

TypeError

BUG 2 What's more, prior to setting maxrun>1 running, i.e. using: res = model.invert(curves, split_results=False) with default maxrun, the code worked. Then I tried maxrun=2 (bug 1 reported above) and returned to maxrun=1. However, the code didn't work anymore, raising this error:

Run 1  |████████████████████| 100% [0:00:01 / 0:00:00] - Misfit: 0.0529
[?25hTraceback (most recent call last):

  File "/tmp/ipykernel_131271/824901905.py", line 1, in <module>
    res = model.invert(curves, split_results=False)

  File "/home/wgajek/.local/lib/python3.9/site-packages/evodcinv/_model.py", line 304, in invert
    out += result

  File "/home/wgajek/.local/lib/python3.9/site-packages/evodcinv/_result.py", line 88, in __add__
    raise TypeError()

TypeError

I tried redefining the model (model = EarthModel() etc as in tutorial) but it did not solve the problem. Restarting the kernel (I'm using spyder) solved the issue (till trying maxrun>1 again). Still, it seems solving bug 1 will also solve bug 2

System information

Side bug: when trying to plot the results afterwards by using res.plot_model('rho',show='all') (for 1 run) the colors of all the lines are same so I am not able to reproduce plots from the readme. Not sure if it is another problem or you need more than 1 run for it (I guess 1 run is enough to plot density of solutions correctly). The figure is plotted then, but all lines are yellow and following error message is given:

/home/wgajek/anaconda3/lib/python3.9/site-packages/matplotlib/colors.py:1254: RuntimeWarning: invalid value encountered in true_divide
  resdat /= (vmax - vmin)
/home/wgajek/anaconda3/lib/python3.9/site-packages/matplotlib/colors.py:1254: RuntimeWarning: invalid value encountered in true_divide
  resdat /= (vmax - vmin)
/home/wgajek/anaconda3/lib/python3.9/site-packages/matplotlib/colors.py:1254: RuntimeWarning: invalid value encountered in true_divide
  resdat /= (vmax - vmin)
/home/wgajek/anaconda3/lib/python3.9/site-packages/matplotlib/colors.py:1254: RuntimeWarning: invalid value encountered in true_divide
  resdat /= (vmax - vmin)
/home/wgajek/anaconda3/lib/python3.9/site-packages/matplotlib/colors.py:1254: RuntimeWarning: invalid value encountered in true_divide
  resdat /= (vmax - vmin)
keurfonluu commented 11 months ago

Looks like that something is wrong with your Python environment.