Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Geographic selection of inventory/network/station #2515
What does this PR do?
Add geographic options to
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
claudiodsf left a comment
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)
for sta in self.stations: if not _filter_object_geographically(sta, min_latitude, max_latitude, ...): continue
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
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.
Add geographic options to [Inventory,Network,Station].select(), following the same syntax of Client.get_stations(). Also add documentation to "sampling_rate" parameter.