SeismicSource / sourcespec

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

Noise windows are shifted #21

Closed claudiodsf closed 1 year ago

claudiodsf commented 1 year ago

Hi @krisvanneste,

the changes introduced with #18 are causing a small but significant problem in my case: the noise window is shifted and a trace is rejected.

This is due to this line:

t1 = max(trace.stats.starttime, p_arrival_time - config.noise_pre_time)

which used to be:

t1 = p_arrival_time - config.noise_pre_time

Attached two figures showing the old and the new behaviour.

Could you explain why this change is important for you use case? Any idea for a workaround?

fr2022kgxxrg traces

fr2022kgxxrg traces-2

krisvanneste commented 1 year ago

Hi Claudio,

I made this change to make sure that the start of the noise window is not before the start of the trace. Without that constraint, the obspy trim operation (in the _cut_signal_noise function) just fills the missing part with zeros. So, the noise window was never considered too short, even if it was absent.

I'm not sure why the noise window is shifted in your case, but it is possible that a trace that was not rejected before is now rejected. The filling in of the missing part with zeros (old behavior) would result in a higher SNR (which is not real).

Could you check if the amount of time before the P arrival with respect to your noise_pre_time for the rejected record?

krisvanneste commented 1 year ago

I also think the plot may be misleading. In my case, in the previous behavior, it shows noise windows (flat lines), where there is no data in my trace. Have a look at the image: stations MASA, STWA and CLHA are late triggered (part of the P window is even missing in STWA), but yet a noise window is drawn.

1306 traces 00

With the new version, a flat line is still drawn (the trace is not actually as long as shown!), but a noise window is not plotted when it's absent. 1306 traces 00

claudiodsf commented 1 year ago

Ok, I think I should change the way traces are plotted (or are trimmed?) to avoid this impression of having signal, when it is not there.

Ideally, your plot for, e.g., BE.CLHA should not show any signal before a few seconds before S arrival.

claudiodsf commented 1 year ago

I'll prepare a pull request and I will ask you to test it, if you don't mind.

krisvanneste commented 1 year ago

OK, could you also check if the noise windows are drawn for each trace separately or if it the same box is used for each trace?

claudiodsf commented 1 year ago

You mean each of the three components, for a given station?

krisvanneste commented 1 year ago

Yes.

claudiodsf commented 1 year ago

Probably it is the same box. I'll try and fix that.

claudiodsf commented 1 year ago

Looks like the fix is quite easy: could you please comment out line 380 in ssp_plot_traces.py:

_trim_traces(config, st_sel)

And see what happens in your case?

krisvanneste commented 1 year ago

It's a big difference! Missing data are no longer plotted, but the traces are much longer, making it more difficult to see the selected windows.

1306 traces 00

claudiodsf commented 1 year ago

Ok, can you try changing line 311:

trace.trim(starttime=t1, endtime=t2, pad=True, fill_value=0)

with

trace.trim(starttime=t1, endtime=t2)

Of course, remove the comment from line 380 😉

claudiodsf commented 1 year ago

The idea in _trim_traces() is to plot a time window which is three times the length of the analysis window.

krisvanneste commented 1 year ago

This looks much better!

1306 traces 00

claudiodsf commented 1 year ago

Great! Looking at the code, noise windows should be plotted separately for each component. Do you have an example where they're not there same, to check that?

krisvanneste commented 1 year ago

Not straightaway. I trimmed all records in my archive to the same start time. I thought maybe in your example, the station FR.PLOF.00 could have different start times for the different components? If not, I will see if I can test it by cutting 1 component before sending it to sourcespec.

claudiodsf commented 1 year ago

The only problem I see is that noise and signal windows are plotted as vertical spans, so they always cover the full plot in vertical.

This can be improved by plotting rectangular patches of 1/3rd of the plot height... looking into that.

krisvanneste commented 1 year ago

I was going to say that it also depends on the selected wave_type (e.g. for P-wave only Z component is used), but I think in ssp_process_traces all components are processed separately. So, the noise windows could still be different.

claudiodsf commented 1 year ago

Ok, I modified the code to plot the patches separately.

I made a test randomising the noise and signal windows, just to see the effect: is that fine for you?

fr2022kgxxrg traces

Note: the code is not yet pushed to the repository.

krisvanneste commented 1 year ago

That looks fine!

claudiodsf commented 1 year ago

Sorry, I had to force-push https://github.com/SeismicSource/sourcespec/commit/92ddf7a1f3a6e8eb1d8e6e0388cdca195d2e757c

krisvanneste commented 1 year ago

I switched back to master and it works!