Skip to content

Commit 74e9d92

Browse files
Merge pull request #94 from oceanmodeling/bugfix/leadtime_multilandfall
Bugfix/leadtime multilandfall - pick the first landfall consistently
2 parents 1648dd7 + bb57604 commit 74e9d92

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- numba
2626
- ocsmesh==1.5.3
2727
- pandas
28-
- pip
28+
- pip<=25.0.1 # Fix installation issue due yo PyYaml SPDX error
2929
- proj
3030
- pyarrow
3131
- pyproj

stormworkflow/prep/hurricane_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ def trackstart_from_file(
5050
return None
5151

5252
leadtime_dict = pd.read_json(leadtime_file, orient='index')
53+
# Sort table by landfall time
5354
leadtime_table = leadtime_dict.drop(columns='leadtime').merge(
5455
leadtime_dict.leadtime.apply(
5556
lambda x: pd.Series({v: k for k, v in x.items()})
5657
).apply(pd.to_datetime, format='%Y%m%d%H'),
5758
left_index=True,
5859
right_index=True
59-
).set_index('ALnumber')
60+
).set_index('ALnumber').sort_values([0])
6061

6162
if nhc_code.lower() not in leadtime_table.index:
6263
return None
6364

6465
storm_all_times = leadtime_table.loc[[nhc_code.lower()]].dropna()
6566
if len(storm_all_times) > 1:
66-
storm_all_times = storm_all_times.iloc[0]
67+
storm_all_times = storm_all_times.iloc[[0]]
6768
if leadtime not in storm_all_times:
6869
return None
6970

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ def conf_v0_0_5():
4646
@pytest.fixture
4747
def conf_latest():
4848
return read_conf(input_latest)
49+
50+
@pytest.fixture
51+
def leadtime_file():
52+
return test_refs.joinpath('leadtime.json')

tests/data/refs/leadtime.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"A": {
3+
"ALnumber": "al062048",
4+
"leadtime": {
5+
"2048090112": 0,
6+
"2048083118": 12,
7+
"2048083100": 24,
8+
"2048083012": 36,
9+
"2048082918": 48,
10+
"2048082900": 60,
11+
"2048082812": 72
12+
}
13+
},
14+
"B1": {
15+
"ALnumber": "al082049",
16+
"leadtime": {
17+
"2049100518": 0,
18+
"2049100500": 12,
19+
"2049100412": 24,
20+
"2049100318": 36,
21+
"2049100306": 48,
22+
"2049100212": 60,
23+
"2049100200": 72
24+
}
25+
},
26+
"B2": {
27+
"ALnumber": "al082049",
28+
"leadtime": {
29+
"2049100718": 0,
30+
"2049100700": 12,
31+
"2049100612": 24,
32+
"2049100518": 36,
33+
"2049100506": 48,
34+
"2049100412": 60,
35+
"2049100400": 72
36+
}
37+
},
38+
"C2": {
39+
"ALnumber": "al142050",
40+
"leadtime": {
41+
"2050100112": 0,
42+
"2050093018": 12,
43+
"2050093000": 24,
44+
"2050092912": 36,
45+
"2050092818": 48,
46+
"2050092800": 60,
47+
"2050092712": 72
48+
}
49+
},
50+
"C1": {
51+
"ALnumber": "al142050",
52+
"leadtime": {
53+
"2050092912": 0,
54+
"2050092818": 12,
55+
"2050092800": 24,
56+
"2050092712": 36,
57+
"2050092618": 48,
58+
"2050092600": 60,
59+
"2050092512": 72
60+
}
61+
},
62+
}

tests/test_prep_funcs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from datetime import datetime
2+
3+
import pytest
4+
5+
from stormworkflow.prep.hurricane_data import trackstart_from_file
6+
7+
def test_leadtime_pick(leadtime_file):
8+
9+
# Always picks first
10+
assert datetime(2049, 10, 3, 6) == trackstart_from_file(
11+
leadtime_file=leadtime_file,
12+
nhc_code="al082049",
13+
leadtime=48)
14+
15+
assert datetime(2050, 9, 28, 0) == trackstart_from_file(
16+
leadtime_file=leadtime_file,
17+
nhc_code="al142050",
18+
leadtime=24)

0 commit comments

Comments
 (0)