CLIMADA-project / climada_python

Python (3.8+) version of CLIMADA
GNU General Public License v3.0
300 stars 118 forks source link

Subsetting a hazard by geographical bounding box #314

Open ChrisFairless opened 2 years ago

ChrisFairless commented 2 years ago

I’m trying to subset a Hazard object to a subset of its centroids given by a bounding box. It feels like there should be a method to do this, since all the ingredients are there in the code.

I suggest adding a new extent parameter to the Hazard.select method that mirrors the functionality of the same parameter in Centroids.select. This will only be a few extra lines of code, since Hazard.select already subsets by centroids when it gets a reg_id parameter.

I'm happy to implement this.

tovogt commented 2 years ago

Yes, sounds like a good idea, but make sure not to produce redundant code. Maybe add a helper function mask_from_extent (maybe as a method of Centroids) that implements the following lines: https://github.com/CLIMADA-project/climada_python/blob/1ec4ecfcc936f4628f8190db8698d078d0d3213e/climada/hazard/centroids/centr.py#L967-L974 Then use the sel_cen mask both in Centroids.select and in Hazard.select.