Skip to content
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

Bugfix/misc #111

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions stormevents/nhc/storms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@ def nhc_storms(year: int = None) -> pandas.DataFrame:
url,
header=0,
names=columns,
parse_dates=["start_date", "end_date"],
date_parser=lambda x: (
pandas.to_datetime(x.strip(), format="%Y%m%d%H")
if x.strip() != "9999999999"
else numpy.nan
),
)
for i in ["start_date", "end_date"]:
storms[i] = pandas.to_datetime(storms[i], errors="coerce", format="%Y%m%d%H")

storms = storms.astype(
{"start_date": "datetime64[s]", "end_date": "datetime64[s]"},
Expand Down Expand Up @@ -107,7 +103,9 @@ def nhc_storms(year: int = None) -> pandas.DataFrame:
)
if len(gis_archive_storms) > 0:
gis_archive_storms[["start_date", "end_date"]] = pandas.to_datetime(numpy.nan)
storms = pandas.concat([storms, gis_archive_storms[storms.columns]])
storms = pandas.concat(
[storms, gis_archive_storms[storms.columns].astype(storms.dtypes.to_dict())]
)

for string_column in ["name", "class", "source"]:
storms.loc[storms[string_column].str.len() == 0, string_column] = pandas.NA
Expand Down Expand Up @@ -211,7 +209,7 @@ def nhc_storms_gis_archive(year: int = None) -> pandas.DataFrame:
year = list(range(NHC_GIS_ARCHIVE_START_YEAR, datetime.today().year + 1))

if isinstance(year, Iterable) and not isinstance(year, str):
years = sorted(pandas.unique(year))
years = sorted(pandas.unique(numpy.array(year)))
return pandas.concat(
[
nhc_storms_gis_archive(year)
Expand Down
5 changes: 2 additions & 3 deletions stormevents/nhc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ def atcf(self, advisory: ATCF_Advisory = None) -> DataFrame:
atcf["isotach_radius_for_NWQ"].astype("string").str.pad(5)
)

atcf["background_pressure"].fillna(method="ffill", inplace=True)
atcf["background_pressure"] = atcf["background_pressure"].astype(int)
atcf["background_pressure"] = atcf["background_pressure"].ffill().astype(int)
atcf["central_pressure"] = atcf["central_pressure"].astype(int)

press_cond_nobg = ~atcf["central_pressure"].isna() & (
Expand Down Expand Up @@ -1362,7 +1361,7 @@ def clamp(n, minn, maxn):
data={"forecast_hours": fcsthrs_12hr, "radius_of_maximum_winds": rmw_12hr},
index=dt_12hr,
)
rmw_rolling = df_temp.rolling(window="24.01 H", center=True, min_periods=1)[
rmw_rolling = df_temp.rolling(window="24.01 h", center=True, min_periods=1)[
"radius_of_maximum_winds"
].mean()
for valid_time, rmw in rmw_rolling.items():
Expand Down
11 changes: 3 additions & 8 deletions stormevents/usgs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def usgs_flood_storms(year: int = None) -> DataFrame:
storm_names = sorted(pandas.unique(storms["name"].str.strip()))
for storm_name in storm_names:
event_storms = events[
events["usgs_name"].str.contains(storm_name, flags=re.IGNORECASE)
events["usgs_name"].str.contains(f"\\b{storm_name}\\b", flags=re.IGNORECASE)
]
for _, event in event_storms.iterrows():
storms_matching = storms[
Expand All @@ -188,13 +188,8 @@ def usgs_flood_storms(year: int = None) -> DataFrame:
matching_event = events.loc[events["usgs_id"] == event["usgs_id"]].iloc[
0
]
if matching_event["nhc_code"] is None:
events.at[matching_event.name, "nhc_name"] = storm["name"]
events.at[matching_event.name, "nhc_code"] = storm.name
else:
matching_event["nhc_name"] = storm["name"]
matching_event["nhc_code"] = storm.name
events.loc[len(events)] = matching_event
events.at[matching_event.name, "nhc_name"] = storm["name"]
events.at[matching_event.name, "nhc_code"] = storm.name

events = events.loc[
~pandas.isna(events["nhc_code"]),
Expand Down
3 changes: 0 additions & 3 deletions tests/data/reference/test_usgs_flood_storms/storms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Hurricane Wilma was the most intense tropical cyclone ever recorded in the Atlan
AL092012,18,2012 Isaac,2012,ISAAC,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,36,[],2022-09-09 14:57:23.815290,2062.0,2012-08-27 04:00:00,2012-09-02 04:00:00
AL182005,19,2005 Rita,2005,RITA,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,515,[],2022-09-08 20:10:38.533682,1.0,2005-09-23 04:00:00,2005-09-25 04:00:00
AL092011,23,2011 Irene,2011,IRENE,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,36,[],2022-09-09 15:04:03.637296,2062.0,2011-08-26 04:00:00,2011-08-29 04:00:00
AL092011,23,2011 Irene,2011,IRENE,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,36,[],2022-09-09 15:04:03.637296,2062.0,2011-08-26 04:00:00,2011-08-29 04:00:00
AL182012,24,2012 Sandy,2012,SANDY,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,36,[],2022-09-09 15:04:13.715276,2062.0,2012-10-21 04:00:00,2012-10-30 04:00:00
AL072008,25,2008 Gustav,2008,GUSTAV,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,515,[],2022-09-09 15:04:24.293240,2062.0,2008-08-31 04:00:00,2008-09-03 04:00:00
AL092008,26,2008 Ike,2008,IKE,historical hurricane data loaded by the data archive team,HURRICANE,COMPLETED,515,[],2022-09-09 15:04:47.855383,2062.0,2008-09-11 04:00:00,2008-09-12 04:00:00
Expand All @@ -19,12 +18,10 @@ AL122017,190,2017 Jose,2017,JOSE,Tropical storm impacting the northeast us,HURRI
AL162017,196,2017 Nate,2017,NATE,TD16 will be developing into Nate. North Gulf deployment,HURRICANE,COMPLETED,36,[],2022-09-09 19:08:52.507058,2062.0,2017-10-05 04:00:00,2017-10-14 04:00:00
EP142018,281,2018 Lane,2018,LANE,Hurricane Lane in the central Pacific Ocean.,HURRICANE,ACTIVE,35,[],2022-09-09 19:33:46.421776,2062.0,2018-08-22 04:00:00,2018-09-15 04:00:00
AL072018,282,2018 Gordon,2018,GORDON,TS/Hurricane Gordon in Gulf of Mexico,HURRICANE,ACTIVE,35,[],2022-09-09 19:33:33.625101,2062.0,2018-09-04 04:00:00,2018-10-04 04:00:00
AL072018,282,2018 Gordon,2018,GORDON,TS/Hurricane Gordon in Gulf of Mexico,HURRICANE,ACTIVE,35,[],2022-09-09 19:33:33.625101,2062.0,2018-09-04 04:00:00,2018-10-04 04:00:00
AL062018,283,2018 Florence,2018,FLORENCE,,HURRICANE,ACTIVE,35,[],2022-09-09 19:33:14.016012,2062.0,2018-09-07 04:00:00,2018-10-07 04:00:00
AL092018,284,2018 Isaac,2018,ISAAC,,HURRICANE,COMPLETED,3,[],2022-09-09 19:33:02.531819,2062.0,2018-09-11 04:00:00,2018-09-18 04:00:00
AL142018,287,2018 Michael,2018,MICHAEL,storm hit the Mexico Beach area of the Florida panhandle,HURRICANE,COMPLETED,3,[],2022-09-09 19:32:14.235677,2062.0,2018-10-08 04:00:00,2018-10-15 04:00:00
AL052019,291,2019 Dorian,2019,DORIAN,,HURRICANE,ACTIVE,864,[],2022-09-09 19:31:39.126837,2062.0,2019-08-28 04:00:00,2019-09-20 04:00:00
AL052019,291,2019 Dorian,2019,DORIAN,,HURRICANE,ACTIVE,864,[],2022-09-09 19:31:39.126837,2062.0,2019-08-28 04:00:00,2019-09-20 04:00:00
AL092020,301,2020 Isaias,2020,ISAIAS,,HURRICANE,ACTIVE,1001,[],2022-09-09 19:29:43.878587,2062.0,2020-07-31 04:00:00,2020-08-07 04:00:00
AL132020,303,2020 Laura,2020,LAURA,,HURRICANE,ACTIVE,864,[],2022-09-09 19:29:38.331805,2062.0,2020-08-22 04:00:00,2020-08-30 04:00:00
AL192020,304,2020 Sally,2020,SALLY,,HURRICANE,ACTIVE,864,[],2022-09-09 19:29:25.785112,2062.0,2020-09-13 04:00:00,2020-09-20 04:00:00
Expand Down
4 changes: 2 additions & 2 deletions tests/test_stormevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ def test_storm_event_lookup():
assert henri2021.year == 2021
assert henri2021.nhc_code == "AL082021"
assert henri2021.usgs_id == 310
assert henri2021.start_date == datetime(2021, 8, 20, 18)
assert henri2021.start_date == datetime(2021, 8, 20, 4)
assert henri2021.end_date == datetime(2021, 8, 24, 18)

assert ida2021.name == "IDA"
assert ida2021.year == 2021
assert ida2021.nhc_code == "AL092021"
assert ida2021.usgs_id == 312
assert ida2021.start_date == datetime(2021, 8, 27, 18)
assert ida2021.start_date == datetime(2021, 8, 26, 12)
assert ida2021.end_date == datetime(2021, 9, 4, 18)

# Similar names are not swapped (like [B]ETA)
Expand Down