Skip to content

Commit 6e497ac

Browse files
rename enum class
1 parent 6056e6b commit 6e497ac

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

climada/hazard/tc_tracks.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
dataset using STORM. Scientific Data 7(1): 40."""
196196

197197

198-
class Basin(Enum):
198+
class Basin_bounds_storm(Enum):
199199
"""
200200
Store tropical cyclones basin geographical extent.
201201
The boundaries of the basin are represented as a polygon (using the `shapely` Polygon object)
@@ -415,6 +415,18 @@ def subset(self, filterdict):
415415

416416
return out
417417

418+
BASINS_GDF = gpd.GeoDataFrame(
419+
{"basin": b, "geometry": b.value} for b in Basin_bounds_storm
420+
)
421+
422+
def get_basins(
423+
track,
424+
): # this is the method I had in mind for 1. and I'd guess it could be a performance boost
425+
track_coordinates = gpd.GeoDataFrame(
426+
geometry=gpd.points_from_xy(track.lon, track.lat)
427+
)
428+
return track_coordinates.sjoin(BASINS_GDF, how="left", predicate="within").basin
429+
418430
def subset_by_basin(self):
419431
"""Subset all tropical cyclones tracks by basin.
420432
@@ -439,7 +451,7 @@ def subset_by_basin(self):
439451
Example:
440452
--------
441453
>>> tc = TCTracks.from_ibtracks("")
442-
>>> tc_basins = tc.split_by_basin()
454+
>>> tc_basins = tc.subset_by_basin()
443455
>>> tc_basins["NA"] # to access tracks in the North Atlantic
444456
445457
"""
@@ -454,7 +466,7 @@ def subset_by_basin(self):
454466
point_in_basin = False
455467

456468
# Find the basin that contains the point
457-
for basin in Basin:
469+
for basin in Basin_bounds_storm:
458470
if basin.value.contains(origin_point):
459471
basins_dict[basin.name].append(track)
460472
point_in_basin = True

0 commit comments

Comments
 (0)