From 8a1338c1389ccfc7fee73f5b5fddbc34580aad78 Mon Sep 17 00:00:00 2001 From: "Soroosh.Mani" Date: Mon, 24 Feb 2025 11:05:13 -0600 Subject: [PATCH 1/4] Fix selection of first landfall date for multi landfall storms --- stormworkflow/prep/hurricane_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stormworkflow/prep/hurricane_data.py b/stormworkflow/prep/hurricane_data.py index faf729e..05f063b 100644 --- a/stormworkflow/prep/hurricane_data.py +++ b/stormworkflow/prep/hurricane_data.py @@ -63,7 +63,7 @@ def trackstart_from_file( storm_all_times = leadtime_table.loc[[nhc_code.lower()]].dropna() if len(storm_all_times) > 1: - storm_all_times = storm_all_times.iloc[0] + storm_all_times = storm_all_times.iloc[[0]] if leadtime not in storm_all_times: return None From 630a1e69d8698496b858fcf165ccacb132164680 Mon Sep 17 00:00:00 2001 From: "Soroosh.Mani" Date: Wed, 23 Apr 2025 06:45:13 -0500 Subject: [PATCH 2/4] Fix landfall time order --- stormworkflow/prep/hurricane_data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stormworkflow/prep/hurricane_data.py b/stormworkflow/prep/hurricane_data.py index 05f063b..14ecf26 100644 --- a/stormworkflow/prep/hurricane_data.py +++ b/stormworkflow/prep/hurricane_data.py @@ -50,13 +50,14 @@ def trackstart_from_file( return None leadtime_dict = pd.read_json(leadtime_file, orient='index') + # Sort table by landfall time leadtime_table = leadtime_dict.drop(columns='leadtime').merge( leadtime_dict.leadtime.apply( lambda x: pd.Series({v: k for k, v in x.items()}) ).apply(pd.to_datetime, format='%Y%m%d%H'), left_index=True, right_index=True - ).set_index('ALnumber') + ).set_index('ALnumber').sort_values([0]) if nhc_code.lower() not in leadtime_table.index: return None From f2a87e2aa6b542eed361a8b525476bfcc8e203d6 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Mon, 19 May 2025 17:53:27 +0000 Subject: [PATCH 3/4] Test for leadtime selection --- tests/conftest.py | 4 +++ tests/data/refs/leadtime.json | 62 +++++++++++++++++++++++++++++++++++ tests/test_prep_funcs.py | 18 ++++++++++ 3 files changed, 84 insertions(+) create mode 100644 tests/data/refs/leadtime.json create mode 100644 tests/test_prep_funcs.py diff --git a/tests/conftest.py b/tests/conftest.py index e62a5af..3f39bd3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -46,3 +46,7 @@ def conf_v0_0_5(): @pytest.fixture def conf_latest(): return read_conf(input_latest) + +@pytest.fixture +def leadtime_file(): + return test_refs.joinpath('leadtime.json') diff --git a/tests/data/refs/leadtime.json b/tests/data/refs/leadtime.json new file mode 100644 index 0000000..e35bbc0 --- /dev/null +++ b/tests/data/refs/leadtime.json @@ -0,0 +1,62 @@ +{ + "A": { + "ALnumber": "al062048", + "leadtime": { + "2048090112": 0, + "2048083118": 12, + "2048083100": 24, + "2048083012": 36, + "2048082918": 48, + "2048082900": 60, + "2048082812": 72 + } + }, + "B1": { + "ALnumber": "al082049", + "leadtime": { + "2049100518": 0, + "2049100500": 12, + "2049100412": 24, + "2049100318": 36, + "2049100306": 48, + "2049100212": 60, + "2049100200": 72 + } + }, + "B2": { + "ALnumber": "al082049", + "leadtime": { + "2049100718": 0, + "2049100700": 12, + "2049100612": 24, + "2049100518": 36, + "2049100506": 48, + "2049100412": 60, + "2049100400": 72 + } + }, + "C2": { + "ALnumber": "al142050", + "leadtime": { + "2050100112": 0, + "2050093018": 12, + "2050093000": 24, + "2050092912": 36, + "2050092818": 48, + "2050092800": 60, + "2050092712": 72 + } + }, + "C1": { + "ALnumber": "al142050", + "leadtime": { + "2050092912": 0, + "2050092818": 12, + "2050092800": 24, + "2050092712": 36, + "2050092618": 48, + "2050092600": 60, + "2050092512": 72 + } + }, +} diff --git a/tests/test_prep_funcs.py b/tests/test_prep_funcs.py new file mode 100644 index 0000000..21f29ea --- /dev/null +++ b/tests/test_prep_funcs.py @@ -0,0 +1,18 @@ +from datetime import datetime + +import pytest + +from stormworkflow.prep.hurricane_data import trackstart_from_file + +def test_leadtime_pick(leadtime_file): + + # Always picks first + assert datetime(2049, 10, 3, 6) == trackstart_from_file( + leadtime_file=leadtime_file, + nhc_code="al082049", + leadtime=48) + + assert datetime(2050, 9, 28, 0) == trackstart_from_file( + leadtime_file=leadtime_file, + nhc_code="al142050", + leadtime=24) From bb5760450caff87236f9015f5ba2fefd1612b4a7 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Tue, 20 May 2025 10:36:15 +0000 Subject: [PATCH 4/4] Pin pip version for pyyaml spdx error --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index eadd32f..c2c8637 100644 --- a/environment.yml +++ b/environment.yml @@ -25,7 +25,7 @@ dependencies: - numba - ocsmesh==1.5.3 - pandas - - pip + - pip<=25.0.1 # Fix installation issue due yo PyYaml SPDX error - proj - pyarrow - pyproj