Skip to content

Commit

Permalink
More hurricane info fixes + test script
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Apr 26, 2024
1 parent 2d0d8cb commit fd4d80b
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 3 deletions.
11 changes: 8 additions & 3 deletions singularity/info/files/hurricane_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def trackstart_from_file(
def get_perturb_timestamp_in_track(
track: VortexTrack,
time_col: 'str',
hr_before_landfall: datetime,
prescribed: Optional[datetime],
land_shapes: List[base.BaseGeometry],
) -> Optional[datetime]:
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_perturb_timestamp_in_track(
times_start_landfall = candidates[
candidates['timediff'] >= dt
][
'track_start_time', 'datetime'
['track_start_time', 'datetime']
].iloc[-1]
picked_track = track_data[
track_data.track_start_time == times_start_landfall.track_start_time]
Expand Down Expand Up @@ -164,13 +165,15 @@ def main(args):
df_dt = pd.DataFrame(columns=['date_time'])

# All preprocessed tracks are treated as OFCL
local_track_file = track_dir / f'a{nhc_code.lower()}.dat'
local_track_file = pathlib.Path()
if track_dir is not None:
local_track_file = track_dir / f'a{nhc_code.lower()}.dat'

if use_past_forecast or is_current_storm:
logger.info("Fetching a-deck track info...")

advisory = 'OFCL'
if not local_track_file.exists():
if not local_track_file.is_file():
# Find and pick a single advisory based on priority
temp_track = event.track(file_deck='a')
adv_avail = temp_track.unfiltered_data.advisory.unique()
Expand Down Expand Up @@ -218,6 +221,7 @@ def main(args):
forecast_start = get_perturb_timestamp_in_track(
track,
'track_start_time',
hr_before_landfall,
prescribed,
[shp_US, ne_low.unary_union],
)
Expand Down Expand Up @@ -272,6 +276,7 @@ def main(args):
perturb_start = get_perturb_timestamp_in_track(
track,
'datetime',
hr_before_landfall,
prescribed,
[shp_US, ne_low.unary_union],
)
Expand Down
102 changes: 102 additions & 0 deletions singularity/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

THIS_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $THIS_SCRIPT_DIR/input.conf

TEST_OUT=/nhc/Soroosh.Mani/runs/
SINGULARITY_ROOT=$L_SCRIPT_DIR/../

init () {
uuid=$(uuidgen)
tag=test_${2}_${3}_${uuid}

local run_dir=$1/$tag
mkdir $run_dir
echo $run_dir
}

test_hurricane_info () {
storm=florence
year=2018
hr_prelandfall=48

run_dir=$(init $TEST_OUT $storm $year)

this_test_out=$run_dir/info_w_leadjson_preptrack_$hr_prelandfall
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--past-forecast \
--hours-before-landfall "$hr_prelandfall" \
--lead-times "$L_LEADTIMES_DATASET" \
--preprocessed-tracks-dir "$L_TRACK_DIR" \
$storm $year

this_test_out=$run_dir/info_w_leadjson_$hr_prelandfall
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--past-forecast \
--hours-before-landfall "$hr_prelandfall" \
--lead-times "$L_LEADTIMES_DATASET" \
$storm $year

this_test_out=$run_dir/info_w_leadjson_24
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--past-forecast \
--hours-before-landfall 24 \
--lead-times "$L_LEADTIMES_DATASET" \
$storm $year

this_test_out=$run_dir/info_w_preptrack_$hr_prelandfall
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--past-forecast \
--hours-before-landfall "$hr_prelandfall" \
--preprocessed-tracks-dir "$L_TRACK_DIR" \
$storm $year

this_test_out=$run_dir/info_w_leadjson_besttrack_$hr_prelandfall
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--hours-before-landfall "$hr_prelandfall" \
--lead-times "$L_LEADTIMES_DATASET" \
$storm $year

this_test_out=$run_dir/info_w_besttrack_$hr_prelandfall
mkdir $this_test_out
python $SINGULARITY_ROOT/info/files/hurricane_data.py \
--date-range-outpath $this_test_out/dates.csv \
--track-outpath $this_test_out/hurricane-track.dat \
--swath-outpath $this_test_out/windswath \
--station-data-outpath $this_test_out/stations.nc \
--station-location-outpath $this_test_out/stations.csv \
--hours-before-landfall "$hr_prelandfall" \
$storm $year
}

$1

0 comments on commit fd4d80b

Please sign in to comment.