keurfonluu / evodcinv

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

Example not working #8

Closed dylanmikesell closed 1 year ago

dylanmikesell commented 2 years ago

Description of the problem

I tried to run your example on the github page by directly copying and running. There is no "period" variable and hence the call to Curve() fails. Can you please provide a working example so I can see how your code is running? I would like to try your method with my own data, but there is no working example on your site.

Full code that generated the error

from evodcinv import EarthModel, Layer, Curve

# Initialize model
model = EarthModel()

# Build model search boundaries from top to bottom
# First argument is the bounds of layer's thickness [km]
# Second argument is the bounds of layer's S-wave velocity [km/s]
model.add(Layer([0.001, 0.1], [0.1, 3.0]))
model.add(Layer([0.001, 0.1], [0.1, 3.0]))

# Configure model
model.configure(
    optimizer="cpso",  # Evolutionary algorithm
    misfit="rmse",  # Misfit function type
    optimizer_args={
        "popsize": 10,  # Population size
        "maxiter": 100,  # Number of iterations
        "workers": -1,  # Number of cores
        "seed": 0,
    },
)

# Define the dispersion curves to invert
# period and velocity are assumed to be data arrays
curves = [Curve(period, velocity, 0, "rayleigh", "phase")]

# Run inversion
res = model.invert(curves)
print(res)

Full error message

Traceback (most recent call last):
  File "/home/dmi/PROJECT/Kumamoto/evo_example.py", line 26, in <module>
    curves = [Curve(period, velocity, 0, "rayleigh", "phase")]
NameError: name 'period' is not defined

System information

keurfonluu commented 2 years ago

The error is pretty straightforward, you need to define the arrays period and velocity first before calling

curves = [Curve(period, velocity, 0, "rayleigh", "phase")]

These arrays correspond to one measured dispersion curve you want to invert.

For a working example, refer to the script .github/sample.py.