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

Relax noise window requirements #18

Merged
merged 10 commits into from
Jan 5, 2023

Conversation

krisvanneste
Copy link
Collaborator

Dear Claudio,

I would like to propose this branch for inclusion in sourcespec. It relaxes noise window requirements if noise weighting is not used. This is useful for older records or triggered records with noise windows that are short or even missing entirely.

Currently, traces with missing noise windows are skipped and for traces with noise windows shorter than win_length, the signal is (silently) truncated to the length of the noise window. In this branch:

  • the start time of the noise window is constrained to the start time of the trace
  • if noise RMS in time domain is zero, only raise an error if noise weighting is used, otherwise just log a warning
  • if noise weighting is used and signal window is truncated to the length of the noise window, a warning is logged
  • if noise weighting is not used and noise window is shorter than signal window, it is zero-padded to the length of the signal window
  • apply scale factor if noise window (minus zero pads) is shorter than signal window when calculating spectral SNR
  • if noise RMS in spectral domain is too low, only raise an error if noise weighting is used
  • avoid zero noise spectra to be plotted

In addition, I made two further improvements in ssp_process_traces._add_hypo_dist_and_arrivals function:

  • generate error if signal window is incomplete (P- or S-arrival before the start time of the trace)
  • constrain signal_pre_time for S-phase to half the S-P interval (for short-distance records with short S-P interval)

If you have any questions or remarks, let me know.
Kris

@claudiodsf
Copy link
Member

Thanks Kris for this PR!

I'm currently quite busy and will look into it hopefully in the next weeks 😉

@krisvanneste
Copy link
Collaborator Author

OK, thank you Claudio!

@claudiodsf
Copy link
Member

Dear Kris, happy new year!

I went through the PR and made some comments. Let me know!

@krisvanneste
Copy link
Collaborator Author

Hello Claudio,
My best wishes for 2023!
I will try to answer your questions today.

@claudiodsf
Copy link
Member

Great! Everything looks fine now.

Could you please just add a Changelog entry?

@krisvanneste
Copy link
Collaborator Author

OK, I will add a changelog entry.
I would also like to run the current version again on my test case and see if I obtain the same results.

@krisvanneste
Copy link
Collaborator Author

I added 2 entries in the changelog. I hope the way I did it is OK to you.

@krisvanneste
Copy link
Collaborator Author

I ran the new code on my test case. Unfortunately, it's impossible to obtain the same results because I have changed several instrument responses since the previous time. However, I get the same warnings and magnitudes for triggered accelerometric records where the noise window is lacking, so it seems to work as expected.

…noise weighting is used, otherwise just log a warning.

Improved _add_hypo_dist_and_arrivals function: raise error if signal window is incomplete (arrival earlier than start of trace), constrain signal_pre_time for S-phase to half the S-P interval, constrain start of signal and noise windows (including signal_pre_time) to start of trace.
…_signal_noise function: only truncate signal window if noise weighting is used and log warning, otherwise zero-pad noise window to length of signal window.

Added 'config' argument to _check_noise_level function, and apply scale factor to trace_noise_rms based on number of non-zero samples; if noise level is too low, only raise error if noise weighting is used, and made warning message more clear.
Improved checking for zero noise spectrum in _build_weight_from_noise function, and set data_raw property of weight to ones if noise spectrum is zero.
Pass 'config' argument to _check_noise_level in build_spectra function.
…The check for overlapping noise and S-windows is not needed as we already check for overlap with the P-window.
…_signal_noise function, and also simplified zero-padding.
@claudiodsf
Copy link
Member

claudiodsf commented Jan 5, 2023

Good. I just rebased and force-pushed. I will also somehow simplify the CHANGELOG entry

@claudiodsf
Copy link
Member

I modified the CHANGELOG and added a warning when (Ts-Tp)/2 is used.

Could you please force-pull and double-check?

@krisvanneste
Copy link
Collaborator Author

I pulled the relax_noise_window branch and ran the example again. The results are identical.

I suppose I better not push the relax_noise_window branch again? Maybe I did something wrong, but it contains a lot of changes that come from somewhere else.

By the way, there is a small error in ssp_sqlite_output.py in line 73. This should read:
ssp_exit(1)
Can you fix this in the main branch?

@claudiodsf
Copy link
Member

claudiodsf commented Jan 5, 2023

I think that the extra changes are the effects of the rebase.

Thanks for reporting the error in ssp_sqlite_output.py, I'll fix it.
(edit: fixed in dc4af75)

So I'm going ahead and merge this. Thank you again!

@claudiodsf claudiodsf merged commit 46ceb51 into SeismicSource:master Jan 5, 2023
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