-
Notifications
You must be signed in to change notification settings - Fork 12
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
Variable window length #48
Conversation
Thanks Kris! I'll look at them next week 😉 |
OK, no hurry. |
Kris, can you move the radiated energy problem to a separate issue? |
OK! |
I will come back to this PR, once we fix #49 😉 |
2f19378
to
3ac919b
Compare
Claudio, |
Kris, you're probably having problems pushing to the branch because I rebased and force-pushed it. I also slightly modified some commits. You can try "force pull" or backup your local branch and recreate it from the remote. Otherwise, I'll take care of adding this commit 😉 |
Claudio, Thanks, it worked with force pull. |
4c2eac0
to
45548ff
Compare
Thanks! Force-pushed again after some slight modification: I prefer to use |
Going to test (and hopefully merge 😉) this afternoon! |
45548ff
to
833a553
Compare
sourcespec/ssp_process_traces.py
Outdated
noise_pre_time = config.noise_pre_time or win_length | ||
t1 = max( | ||
trace.stats.starttime, | ||
p_arrival_time - noise_pre_time - config.signal_pre_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Kris, coming back to the analysis of this PR (sorry for the delay).
I don't understand this extra - config.signal_pre_time
. In fact, because of it, I get different results from the previous version, when using a fixed window length.
If I remove this extra term, then the results are identical to the previous version, when using a fixed window length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claudio,
This is to ensure that the noise window ends at the start of the P window (which is equal to p_arrival_time - config.signal_pre_time
) in the case that config.signal_pre_time
is set to zero or None and hence defaults to the length of the signal window (but note that this is in the subsequent commit).
It may indeed give different results to before (I hope only slightly different), but in the previous version there was this note:
# Note: maybe we should also take into account signal_pre_time here
I think the noise and signal windows are consistent this way.
Alternatively, we could leave it as before, and modify the next commit as follows:
if config.noise_pre_time == 0:
noise_pre_time = win_length - signal_pre_time
This will give the same result when window length is variable, and should not change anything when it is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Kris, sorry again for late reaction.
Does the last commit I (force) pushed make sense to you? I tried to implement your idea (except that there should be a +
and not a -
in the formula 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claudio, I'm in Germany for a meeting at the moment, so it's not so easy to look at your commit. But you are right, it should be +
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, everyone is busy! We'll find the time to merge this PR next week 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claudio, I had a look at your commit and I also tested it. Everything looks fine, so I hope it can be merged now!
t2 = t1 + win_length | ||
if t2 > (p_arrival_time - config.signal_pre_time): | ||
logger.warning(f'{trace.id}: noise window ends after P-window start') | ||
t2 = p_arrival_time - config.signal_pre_time | ||
t1 = min(t1, t2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an old line, but it's maybe worth discussing here: it implies that t1
can be equal to t2
and that the noise window length is zero. Is this acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but otherwise t2 might be < t1.
There is already a warning that the noise window ends after the start of the P window. Maybe we can add another test for the length of the noise window and warn if it is zero (or shorter than some threshold value)?
Great! Let me rebase on current main and force-push it. I will then ask you one last check, since I added two fixes (normally unrelated to this PR) in the current main. |
Ensure noise window has same length as signal (P or S) window.
…define_signal_and_noise_windows function.
- Added variable_win_length_factor configuration parameter in configspec.conf - Updated `ssp_process_traces._define_signal_and_noise_windows()` to take into account variable_window_length_factor - Fixed `ssp_plot_traces._trim_traces()` to trim plotted trace to real start of noise window and real end of S window (plus some margin).
If Er could not be computed, which may result in obscure matplotlib error.
Also: improved warning message
But only in case when the noise window length is not specified. This ensures backward compatibility with the old behavior.
e6a6b39
to
8a6d760
Compare
Ok, done. One last test please 🙏 |
I'm not sure if I will manage. I run in 2 problems now:
I need to check how to resolve this. Unless you know? |
The first one seems odd, since there is no The second error seems related to the first one. Maybe try a |
It's probably because I just switched to the |
OK, I managed to get back to the |
Great! One last request: a CHANGELOG entry referring to this PR 🙏 |
Only in the |
b9f699c
to
8741749
Compare
8741749
to
f6a233b
Compare
Great! Added a missing link at the end of the CHANGELOG. All is green for merging! |
Claudio,
Here is a first implementation of variable window length as a function of travel time (or equivalently distance).
It contains the following modifications:
signal_pre_time
for definition of noise window (there was a note that this should probably be done)noise_pre_time
to noise window length if it is not specified or zero (so it can be different for each record if variable window lengths are used)variable_win_length_factor
configuration parameter and use it to calculate window length from travel time of considered phase, while keepingwin_length
as the minimum valueThere are also 2 commits that are not directly related to variable window length, but they address issues I ran into while testing:
fmax
parameter (default None). In cases where the noise spectrum lies above the signal spectrum at the highest frequencies,noise_integral
becomes quickly higher thansignal_integral
. I fixed this by setting fmax fromspectral_snratio_fmax
(available in the header of the signal spectrum) when fmax is not specified or zero. I can document this problem with a plot and manual calculations ofnoise_integral
for different fmax values. I can include this in a next post or open a separate issue if you like.Finally, I also considered your suggestion to pad the windows to the same length for all records. However, that is not so easy to do as it requires knowing the available lengths beforehand. I'm not sure this is really necessary, because there is already the
spectral_win_length
configuration parameter, which can be set to ensure padding/trimming of all windows to the same length.I tested this variable window length for a case where I only have long-distance records (> 400 km). Using different fixed window lengths, the magnitude starts stabilizing for window lengths between 40 and 50 s, which more or less corresponds to using a
variable_win_length_factor
of 0.4 (for the S wave). Obviously, this would be much too long if I would include short-distance records and use a fixed window length.Can you have a look at these modifications and let me know what you think?
Kris