Skip to content
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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions stormworkflow/prep/hurricane_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ 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

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

Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
62 changes: 62 additions & 0 deletions tests/data/refs/leadtime.json
Original file line number Diff line number Diff line change
@@ -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
}
},
}
18 changes: 18 additions & 0 deletions tests/test_prep_funcs.py
Original file line number Diff line number Diff line change
@@ -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)