SeismicSource / sourcespec

Earthquake source parameters from P- and S-wave displacement spectra
https://sourcespec.seismicsource.org
Other
49 stars 12 forks source link

Problem with vp_source, vs_source #47

Closed krisvanneste closed 5 months ago

krisvanneste commented 5 months ago

@claudiodsf ,

Before working on the variable window length issue, I need to update my code to run sourcespec. I managed to catch up with most of your recent changes, but I run into a problem when I try to set the VP and VS of the event hypocenter:

  File "E:\Home\_kris\Python\seismo\robspy\sourcespec.py", line 113, in prepare_for_sourcespec
    ssp_read_traces._hypo_vel(event.hypocenter, config)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_read_traces.py", line 261, in _hypo_vel
    vp_string = medium_properties.to_string('vp_source', hypo.vp)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_util.py", line 247, in to_string
    if value.is_integer():

AttributeError: 'numpy.float32' object has no attribute 'is_integer'

I don't know how to solve this. The vp_source and vs_source properties of the config object passed to _hypo_vel are lists of floats, but apparently they should be objects having an is_integer method. However, I couldn't find any class definition with an is_integer method in sourcespec. When I comment out the offending lines in the to_string method of MediumProperties, everything seems to work. However, I notice that there are at least 2 other places where this is_integer method is called in sourcespec, so I'm probably doing something wrong. I hope you can tell me.

Kris

claudiodsf commented 5 months ago

Hi Kris, surprised by this error.

The method MediumProperties().get() called here should always return a number (float or integer).

What does it return in your case?

claudiodsf commented 5 months ago

Ah, ok, I understood: you have a numpy.float32 and not a regular python float!

Let me fix that!

krisvanneste commented 5 months ago

Claudio,

Indeed, it is a numpy float.

claudiodsf commented 5 months ago

Hopefully fixed by 165e20ff4c7f8547e32ad30fc9ecdd1bf84135c2.

Can you check?

claudiodsf commented 5 months ago

You probably have an old NumPy version, since is_integer() was added to NumPy in version 1.22.0: https://numpy.org/doc/stable/release/1.22.0-notes.html

krisvanneste commented 5 months ago

Claudio, The fix is working! Indeed, an older numpy version (although it is composed of the same digits: 1.20.2). I was not aware of this is_integer method for python and numpy floats. Kris

claudiodsf commented 5 months ago

Just made commit 6e8df95da56818b82107e42c0d5c6112c0302b99 to fix this everywhere.

It's indeed just a (hackish?) solution to pretty print pure integers 😉

krisvanneste commented 5 months ago

Thanks!