Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for cases when components of the same instrument have different length #31

Merged
merged 8 commits into from Mar 31, 2023

Conversation

claudiodsf
Copy link
Member

I stumbled upon some corner case, where components of the same instrument have different length.

For that, I had to:

  1. Make sure that noise and signal windows have the same number of points for all the components
  2. Make sure that trace plots are correctly aligned

I also took the opportunity to add a fix which correctly plots signal and noise windows when the signal window is truncated to the noise length or when the noise window is padded to the signal length.

As always, I'm asking @krisvanneste to double-check, especially because this touches some of the changes he introduced. Thank you!

@claudiodsf claudiodsf force-pushed the fix_three_comps branch 3 times, most recently from 338e4d0 to 0e69088 Compare March 29, 2023 12:59
@krisvanneste
Copy link
Collaborator

Claudio,

I will test it before the end of the week.

@claudiodsf claudiodsf force-pushed the fix_three_comps branch 2 times, most recently from 9a7f730 to 14a751f Compare March 29, 2023 16:24
@krisvanneste
Copy link
Collaborator

Claudio,

I'm running into a problem that I think I have seen (and fixed) before. I will investigate.
Here is the output:

Running sourcespec, run_id: test_three_comps
Pre-restitution...
Preparing traces...
Preparing traces...
Processing traces...
BE.CLA..EHE shortp: S/N: 179.9
BE.CLA..EHN shortp: S/N: 548.3
BE.CLHA..HNE: noise window ends after P-wave arrival
BE.CLHA..HNE acc: empty noise window!
BE.CLHA..HNE acc: S/N: 0.0
BE.CLHA..HNN: noise window ends after P-wave arrival
BE.CLHA..HNN acc: empty noise window!
BE.CLHA..HNN acc: S/N: 0.0
BE.CTH..EHE shortp: S/N: 234.7
BE.CTH..EHN shortp: S/N: 1823.8
BE.DOU..EHE shortp: S/N: 4177.8
BE.DOU..EHN shortp: S/N: 6338.6
BE.GES..EHE shortp: S/N: 537.6
BE.GES..EHN shortp: S/N: 517.3
BE.KLB..EHE shortp: S/N: 930.9
BE.KLB..EHN shortp: S/N: 185.0
BE.LLVA..HNE: S-window incomplete: skipping trace
BE.LLVA..HNN: S-window incomplete: skipping trace
BE.MASA..HNE: noise window ends after P-wave arrival
BE.MASA..HNE acc: empty noise window!
BE.MASA..HNE acc: S/N: 0.0
BE.MASA..HNN: noise window ends after P-wave arrival
BE.MASA..HNN acc: empty noise window!
BE.MASA..HNN acc: S/N: 0.0
BE.MEMS..DHE shortp: S/N: 3106.3
BE.MEMS..DHN shortp: S/N: 1336.8
BE.SKQ..EHE shortp: S/N: 936.4
BE.SKQ..EHN shortp: S/N: 2199.3
BE.STWA..HNE: noise window ends after P-wave arrival
BE.STWA..HNE acc: empty noise window!
BE.STWA..HNE acc: S/N: 0.0
BE.STWA..HNN: noise window ends after P-wave arrival
BE.STWA..HNN acc: empty noise window!
BE.STWA..HNN acc: S/N: 0.0
BE.UCCS..HHE broadb: S/N: 304.6
BE.UCCS..HHN broadb: S/N: 355.6
BE.WLF..EHE shortp: S/N: 1976.4
BE.WLF..EHN shortp: S/N: 1942.1
NL.HGN..BHE: maximum frequency for bandpass filtering is larger or equal to Nyquist. Setting it to 19.98 Hz
NL.HGN..BHE broadb: S/N: 7299.9
NL.HGN..BHN: maximum frequency for bandpass filtering is larger or equal to Nyquist. Setting it to 19.98 Hz
NL.HGN..BHN broadb: S/N: 17706.3
Processing traces: done
Building spectra...
BE.CLHA..HN: zero-padding noise window to signal length
BE.CLHA..HN: zero-padding noise window to signal length
BE.MASA..HN: zero-padding noise window to signal length
BE.MASA..HN: zero-padding noise window to signal length
BE.STWA..HN: zero-padding noise window to signal length
BE.STWA..HN: zero-padding noise window to signal length
BE.CLA..EHR: Vs_hypo: 3.61 km/s, Vs_station: 2.98 km/s
BE.CLA..EHR: spectral S/N: 3663.76
BE.CLA..EHT: Vs_hypo: 3.61 km/s, Vs_station: 2.98 km/s
BE.CLA..EHT: spectral S/N: 4234.21
BE.CLHA..HNR: Vs_hypo: 3.61 km/s, Vs_station: 2.98 km/s
BE.CLHA..HN: No available noise window: a uniform weight will be applied
Traceback (most recent call last):

  File "C:\Users\kris\Documents\Python\seismo\projects\Belshake\kris\calc_mw_sourcespec.py", line 156, in <module>
    weighting='frequency',

  File "E:\Home\_kris\Python\seismo\hazard\belshakelib\db.py", line 2664, in calc_mw_sourcespec
    run_id=run_id, write_asdf=write_asdf, **kwargs)

  File "E:\Home\_kris\Python\seismo\robspy\sourcespec.py", line 637, in run_sourcespec
    spec_st, specnoise_st, weight_st = build_spectra(config, proc_st)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_build_spectra.py", line 633, in build_spectra
    _build_signal_and_noise_spectral_streams(config, signal_st, noise_st)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_build_spectra.py", line 596, in _build_signal_and_noise_spectral_streams
    _check_spectral_sn_ratio(config, spec, specnoise)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_build_spectra.py", line 521, in _check_spectral_sn_ratio
    idx = range(len(weight.data_raw))

AttributeError: 'Spectrum' object has no attribute 'data_raw'

@claudiodsf
Copy link
Member Author

weight.data_raw is used to compute spectral S/N ratio... working on a fix

@krisvanneste
Copy link
Collaborator

Yes, the problem is that it is only created in _build_weight_from_ratio, but not in the other _build_weight_from functions.

@claudiodsf
Copy link
Member Author

It needs to be created by the two functions called in _build_weight_from_noise(), namely: _build_weight_from_ratio() and _build_uniform_weight().

It should be fixed now 😉

@krisvanneste
Copy link
Collaborator

krisvanneste commented Mar 30, 2023

Now it runs, but another error occurs when saving the spectra:

Traceback (most recent call last):

  File "C:\Users\kris\Documents\Python\seismo\projects\Belshake\kris\calc_mw_sourcespec.py", line 156, in <module>
    weighting='frequency',

  File "E:\Home\_kris\Python\seismo\hazard\belshakelib\db.py", line 2664, in calc_mw_sourcespec
    run_id=run_id, write_asdf=write_asdf, **kwargs)

  File "E:\Home\_kris\Python\seismo\robspy\sourcespec.py", line 681, in run_sourcespec
    plot_spectra(config, spec_st, specnoise_st, plot_type='regular')

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_plot_spectra.py", line 676, in plot_spectra
    _plot_specid(config, plot_params, specid, spec_st, specnoise_st)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_plot_spectra.py", line 639, in _plot_specid
    _plot_spec(config, plot_params, spec, spec_noise)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_plot_spectra.py", line 565, in _plot_spec
    _snratio_text(spec, ax, color, path_effects)

  File "C:\Users\kris\Documents\Python\cloned_repos\sourcespec\sourcespec\ssp_plot_spectra.py", line 441, in _snratio_text
    snratio_text = f'S/N: {spec.stats.spectral_snratio:.1f}'

  File "C:\Miniconda3\envs\py3\lib\site-packages\obspy\core\util\attribdict.py", line 130, in __getattr__
    raise AttributeError(e.args[0])

AttributeError: spectral_snratio

I will resume testing tomorrow.

@claudiodsf
Copy link
Member Author

Thanks. It should be fixed now

@krisvanneste
Copy link
Collaborator

Claudio,

It runs without errors now and the results are similar to before.
So you can go ahead!

@claudiodsf claudiodsf merged commit d95d792 into master Mar 31, 2023
2 checks passed
@claudiodsf
Copy link
Member Author

Great! Merged!

One step closer to v1.7...

@claudiodsf claudiodsf deleted the fix_three_comps branch March 31, 2023 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants