obspy / obspy

ObsPy: A Python Toolbox for seismology/seismological observatories.
https://www.obspy.org
Other
1.15k stars 530 forks source link

Trace plot automatically applies calib & apply_calib not passed to _generic_reader #2935

Open ThomasLecocq opened 2 years ago

ThomasLecocq commented 2 years ago

While working on io.kinemetrics I noticed an issue (I think) with the apply_calib behaviour: (note apply_calib only applies to, I think: gse, knet, kinemetrics and maybe others, providing a tr.stats.calib!=1)

obspy.core.stream.read doesn't pass the apply_calib kwarg to the _generic_reader:

https://github.com/obspy/obspy/blob/2af06db830f99f41f2f4f0c43323b6ddd1e45905/obspy/core/stream.py#L195-L207

which results, if apply_calib=True (it's not passed):

then, the end of the generic read routine: https://github.com/obspy/obspy/blob/2af06db830f99f41f2f4f0c43323b6ddd1e45905/obspy/core/stream.py#L237-L239

applies the calibration to the data. So, at this point, I have what I wanted, but...

This case has a strong impact when plotting with Stream.plot, as the routine applies the tr.stats.calib automatically: https://github.com/obspy/obspy/blob/2af06db830f99f41f2f4f0c43323b6ddd1e45905/obspy/imaging/waveform.py#L690 which results in apparent (it's not in the data) very very small values!

First solution:

Passing the apply_calib to the modules.

When modifying the behaviour, such that apply_calib=True is passed to the _generic_reader:

Second solution:

Either: should this chunk of the read routine reset the Trace.stats.calib = 1

 if apply_calib: 
     for tr in st: 
         tr.data = tr.data * tr.stats.calib 
         tr.stats.calib = 1

Third solution

should the plotting routines not automatically apply calibration ? But in this case, what's the meaning/purpose of having the trace.stats.calib to be different from 1 as it as already been applied, to go back to raw counts ?

trichter commented 2 years ago

I am not into these data formats, but I think cleanest would be to apply calib in generic read according to stats and not passing apply_calib to underlying read routines. plotting routines should not automatically apply calib. But I think other suggested solutions are adequate, too.