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
Geographic selection of inventory/network/station #2515
Conversation
31cf3bb
to
0c86979
Compare
Fixed a typo in documentation and force-pushed. |
would it make sense to put the location-based filtering in some generic util module to avoid the large copy/paste of identical codes ? |
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.
- please move
keep_empty
to old position - please add a changelog one-liner
- CircleCI fails are unrelated
Otherwise good to go, looks like (didn't check tests in detail).
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.
would it make sense to put the location-based filtering in some generic util module to avoid the large copy/paste of identical codes ?
I thought about it. Where would you put this generic code?
Yeah, not easy indeed, and the way you skip the channel is indeed not so easily "generalizable"... maybe something like this: def _filter_object_geographically(object, min_latitude, max_latitude, ...):
if minlatitude is not None:
if obj.latitude is None or obj.latitude < minlatitude:
return False
if maxlatitude is not None:
if obj.latitude is None or obj.latitude > maxlatitude:
return False
if minlongitude is not None:
if obj.longitude is None or obj.longitude < minlongitude:
return False
if maxlongitude is not None:
if obj.longitude is None or obj.longitude > maxlongitude:
return False
if all([l is not None for l in
(latitude, longitude, obj.latitude, obj.longitude)]):
distance = locations2degrees(latitude, longitude,
obj.latitude, obj.longitude)
if minradius is not None and distance < minradius:
return False
if maxradius is not None and distance > maxradius:
return False
return True and then in your calls: for cha in self.channels:
if _filter_object_geographically(cha, min_latitude, max_latitude, ...):
channels.append(cha) and for sta in self.stations:
if not _filter_object_geographically(sta, min_latitude, max_latitude, ...):
continue |
avoiding code duplication is always good 👍 |
Ok, should I put then this common code in |
I guess it could be useful for events/catalog as well? Then it should go into |
actually, I think it could be in |
Yes, agree. If it causes a circular import we see it in CI |
It might be a good idea to add a test that this works across hemispheres - e.g. in New Zealand we have stations both sides of 180W and have run into issues in the past with simple |
We had some issue with wrapping around longitude +-180° at some point, I was pretty sure, but I can't find it now.. |
@claudiodsf while you are at it, maybe think about making the selection inclusive or not( > or >= etc.) ? |
6998bf7
to
97145b8
Compare
Finally found some time to work on this. Let me know what do you think. |
Not sure whether this is essential: geographic coordinates are never that precise to require strict equality. And that would make the code and the function interface more complex. Edit: also equality of floating numbers makes little sense to me. |
Not sure which kind of errors the docs builds reports... |
Also, feel free to propose a better name for |
Possible alternative names:
Other ideas? |
|
@megies what do you think? |
Works for me |
@claudiodsf please make the name change and I'll pass for another (hopefully last) review of the code. |
ee26cd9
to
860ed8d
Compare
@ThomasLecocq Done! Let's wait on CI tests, then please review! |
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.
small stuff, nothing major
Made some final changes, will merge when CI is green, CC @claudiodsf |
Utility function to check whether an object is within a given latitude and/or longitude range, or within a given distance range from a reference geographic point.
Add geographic options to [Inventory,Network,Station].select(), following the same syntax of Client.get_stations(). Also add documentation to "sampling_rate" parameter.
8dcd747
to
ca022a9
Compare
@megies @ThomasLecocq Thanks for taking care of this: I have been sick and unable to work during the last few days. |
What does this PR do?
Add geographic options to
[Inventory,Network,Station].select()
, followingthe same syntax of
Client.get_stations()
.Also add documentation to "sampling_rate" parameter.
Why was it initiated? Any relevant Issues?
Sometimes datacenter provides preassembled datasets with data and metadata for all the stations in the network (ex.: http://cnt.rm.ingv.it/event/23558121 --> Download). This PR adds possibility of filtering metadata based on geographic parameters, following the same syntax of
Client.get_stations()
.Not covered by this PR is the possibility of selecting data in stream based on the inventory content (next time ;-)
PR Checklist
master
for new features,maintenance_...
for bug fixesJust remove the space in the following string after the + sign: "+DOCS"
(e.g.
clients.fdsn,clients.arclink
) after the colon in the following magic string: "+TESTS:"(you can also add "ALL" to just simply run all tests across all modules)
CHANGELOG.txt
.