-
Notifications
You must be signed in to change notification settings - Fork 530
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
Stream.rotate: enable rotating multiple groups of traces simultaneously #3155
Conversation
I am unsure here. The grouping will not work e.g. for multiple event waveforms at the same station which is very common for receiver function processing. Should we not better rely on the user sorting the stream correctly and mention this in the docs (if not already done). We could even state a sort expression working in most cases. (I think By using sets the current implementation may change the order of the groups. Edit: Adding to that, we could simply warn if the seed ids of the traces in one rotation do not fit together, similar as an error is raised if times do not match. |
Hmm.. might need to think about this more. I still think this might be the better approach and it can be done cleanly (I havent looked into the CI fails yet xD). Maybe similar to |
Yes, that would be more convenient if working correctly. Please also use the updated test case from the other PR. Using trim_common_channels would also loosen the very restrictive time span condition. |
@trichter the problem with this was just that the order of traces changed in some cases. I added a I think this recursion approach is cleaner, you OK with this change? |
obspy/core/tests/test_stream.py
Outdated
@@ -2011,18 +2011,22 @@ def test_rotate(self): | |||
st = read() | |||
st += st.copy() | |||
st[3:].normalize() | |||
for tr in st[3:]: | |||
tr.stats.location = '01' |
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.
I think you are cheating here ;)
IMHO this test should pass without these lines.
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.
Tbh, I think it's a weird test case, why would you process a fully duplicated exact same waveform set of 2x the same three Traces?
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.
Yes, that is completely nonsense. For me, it conceptually represents the rotation of waveforms of two different events (with different baz) registered at the same station. Changing the starttime instead of the location code would be more in line with this idea. I do not know if this was the original intention.
I agree the recursion approach is better. But I think we should still handle streams of more than 3 traces in one seed id group (see inline comment). More than a single event at the same station inside one stream is a perfectly valid use case. I think the sorting is not really necessary? Why not use a dictionary instead of a set which keeps the order?
|
I'm not sure why the sort would hurt, tbh. Any code that is strictly relying on the order of traces in a stream mixed with multiple stations, channels and even same stations for different times and expecting to pick some trace by an index number like With proper automatic selecting/grouping traces out of an arbitrary mix of traces in a stream, order of traces fortunately becomes irrelevant, so ordering in output should not matter either, I would argue. In any case, maybe bump this to
I already do in e.g. Anyway @trichter, I think I'll bump this to 1.4.0 or even 1.4.1 even. 1.3.1 is months overdue with lots of important fixes that break installations with new versions, so it can't be held up any further. |
Yea, you are correct, but then why sort inside rotate at all?
I pushed some more commits. Order of the seed id groups is now preserved. And I added the fix from #3124. If tests pass, this can be merged in 1.3.1 IMHO. Would this be OK with you? |
Mainly, I did not like the notion of order of traces coming out in a different order after changing internal implementation. So I thought, might be good to just sort everything, so that on future implementation changes the order would not change anymore. But I don't really care, can stay without sort for all I care.
If baz/inc is specified in the rotate call, it doesn't make sense to mix multiple stations anyway. If a global baz/inc is valid for all or it instead is attached to each Aaaaaanyway, I'll have a look at the changes now ;) |
Ah, I think I didn't ever understand what your PR was doing, to be honest, the commit message in this one helped. Sorry about the confusion.. 🙈 I also wasn't aware that dictionaries keep order of items stored in them these days.. |
For ->ZNE, different stations have different rotations this is caught by the seed id grouping, for ->LQT different events have different rotations, this is not caught by the seed id grouping
:) |
by just recursively calling the existing rotation routine on each group of channels
..to ensure order of traces stays reproducible in the future even if internal implementation changes
792e57b
to
30aed91
Compare
Ah, yeah, good point. I just didn't latch on to the fact that the code just used to grab baz/inc from first trace no matter what 🤦 |
Had to rebase n force push |
What does this PR do?
Fix Stream.rotate() with multiple-station Streams
Why was it initiated? Any relevant Issues?
Fixes #2623 with an alternative approach to #3124
PR Checklist
master
for new features,maintenance_...
for bug fixesJust add the "build_docs" tag to this PR.
Docs will be served at docs.obspy.org/pr/{branch_name} (do not use master branch).
Please post a link to the relevant piece of documentation.
clients.fdsn
) should be tested for the PR,just add the "test_network" tag to this PR.
CHANGELOG.txt
.CONTRIBUTORS.txt
.from all the CI builds look correct. Add the "upload_plots" tag so that plotting
outputs are attached as artifacts.