Skip to content

Commit

Permalink
remove assign category
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasColombi committed Feb 5, 2025
1 parent d84f9ee commit cc79d57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 51 deletions.
44 changes: 4 additions & 40 deletions climada/hazard/tc_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,42 +1620,6 @@ def from_netcdf(cls, folder_name):
data.append(track)
return cls(data)

@staticmethod
def define_tc_category_FAST(max_sust_wind: np.array, units: str = "kn") -> int:
"""Define category of the tropical cyclone according to Saffir-Simpson scale.
Parameters:
----------
max_wind : str
Maximal sustained wind speed
units: str
Wind speed units, kn or m/s. Default: kn
Returns:
-------
category : int
-1: "Tropical Depression",
0: "Tropical Storm",
1: "Hurricane Cat. 1",
2: "Hurricane Cat. 2",
3: "Hurricane Cat. 3",
4: "Hurricane Cat. 4",
5: "Hurricane Cat. 5",
"""

max_sust_wind = max_sust_wind.astype(
float
) # avoid casting errors if max_sust_wind is int
max_sust_wind *= 1.943844 if units == "m/s" else 1

max_wind = np.nanmax(max_sust_wind)
category_test = np.full(len(SAFFIR_SIM_CAT), max_wind) < np.array(
SAFFIR_SIM_CAT
)
category = np.argmax(category_test) - 1

return category

@classmethod
def from_FAST(cls, folder_name: str):

Check warning on line 1624 in climada/hazard/tc_tracks.py

View check run for this annotation

Jenkins - WCR / Pylint

invalid-name

LOW: Method name "from_FAST" doesn't conform to '(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$' pattern
Raw output
Used when the name doesn't match the regular expression associated to its type(constant, variable, class...).

Check warning on line 1624 in climada/hazard/tc_tracks.py

View check run for this annotation

Jenkins - WCR / Pylint

too-many-locals

LOW: Too many local variables (16/15)
Raw output
Used when a function or method has too many local variables.
"""Create a new TCTracks object from NetCDF files generated by the FAST model, modifying
Expand Down Expand Up @@ -1707,13 +1671,13 @@ def from_FAST(cls, folder_name: str):
track.time.data, unit="s", origin=reference_time
).astype("datetime64[s]")
# Define variables
max_sustained_wind_knots = track.vmax_trks.data * 1.943844
max_wind_kn = track.vmax_trks.data * 1.943844
env_pressure = BASIN_ENV_PRESSURE[track.tc_basins.data.item()]
cen_pres = _estimate_pressure(
np.full(lat.shape, np.nan),
lat,
lon,
max_sustained_wind_knots,
max_wind_kn,
)

data.append(
Expand Down Expand Up @@ -1758,8 +1722,8 @@ def from_FAST(cls, folder_name: str):
"orig_event_flag": True,
"data_provider": "FAST",
"id_no": track.n_trk.item(),
"category": TCTracks.define_tc_category_FAST(
max_sustained_wind_knots
"category": set_category(
max_wind_kn, wind_unit="kn", saffir_scale=None
),
},
)
Expand Down
11 changes: 0 additions & 11 deletions climada/hazard/test/test_tc_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,6 @@ def test_from_simulations_storm(self):
tc_track = tc.TCTracks.from_simulations_storm(TEST_TRACK_STORM, years=[7])
self.assertEqual(len(tc_track.data), 0)

def test_define_tc_category_FAST(self):
"""test that the correct category is assigned to a TC from FAST model."""

max_wind = np.array([20, 72, 36, 50]) # knots
category1 = tc.TCTracks.define_tc_category_FAST(max_wind)
category2 = tc.TCTracks.define_tc_category_FAST(
max_sust_wind=max_wind, units="m/s"
)
self.assertEqual(category1, 1)
self.assertEqual(category2, 5)

def test_from_FAST(self):
"""test the correct import of netcdf files from FAST model and the conversion to a
different xr.array structure compatible with CLIMADA."""
Expand Down

0 comments on commit cc79d57

Please sign in to comment.