Skip to content

Commit

Permalink
Merge pull request #82 from oceanmodeling/feature/perturb_features
Browse files Browse the repository at this point in the history
Add option to enable disable perturbation feature
  • Loading branch information
SorooshMani-NOAA authored Oct 22, 2024
2 parents 2107bff + dbe85bb commit 6621fb9
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"cmocean",
"dask",
"dask-jobqueue",
"ensembleperturbation>=1.3.0", # rmax option
"ensembleperturbation>=1.3.4", # perturb feature
"fiona",
"geoalchemy2",
"geopandas",
Expand Down
11 changes: 10 additions & 1 deletion stormworkflow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

_logger = logging.getLogger(__file__)

CUR_INPUT_VER = Version('0.0.4')
CUR_INPUT_VER = Version('0.0.5')
VER_UPDATE_FUNCS = []


Expand Down Expand Up @@ -74,6 +74,15 @@ def _handle_input_v0_0_3_to_v0_0_4(inout_conf):
inout_conf['NHC_OBS'] = ''


@_input_version('0.0.4', '0.0.5')
def _handle_input_v0_0_4_to_v0_0_5(inout_conf):

_logger.info("Adding perturbation features")
inout_conf['perturb_features'] = [
'isotach_adjustment',
]


def handle_input_version(inout_conf):

if 'input_version' not in inout_conf:
Expand Down
7 changes: 6 additions & 1 deletion stormworkflow/prep/setup_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from coupledmodeldriver.generate import SCHISMRunConfiguration
from coupledmodeldriver.generate.schism.script import SchismEnsembleGenerationJob
from coupledmodeldriver.generate import generate_schism_configuration
from ensembleperturbation.perturbation.atcf import perturb_tracks
from ensembleperturbation.perturbation.atcf import perturb_tracks, PerturberFeatures
from pylib_essentials.schism_file import (
read_schism_hgrid_cached,
schism_bpfile,
Expand Down Expand Up @@ -137,6 +137,9 @@ def main(args):
use_wwm = args.use_wwm
with_hydrology = args.with_hydrology
pahm_model = args.pahm_model
setup_features = PerturberFeatures.NONE
for feat in args.perturb_features:
setup_features |= PerturberFeatures[feat.upper()]

workdir = out_dir
mesh_file = mesh_dir / 'mesh_w_bdry.grd'
Expand Down Expand Up @@ -208,6 +211,7 @@ def main(args):
overwrite=True,
file_deck=file_deck,
advisories=[advisory],
features=setup_features,
)

if perturb_start != model_start_time:
Expand Down Expand Up @@ -345,6 +349,7 @@ def parse_arguments():
argument_parser.add_argument('--use-wwm', action='store_true')
argument_parser.add_argument('--with-hydrology', action='store_true')
argument_parser.add_argument('--pahm-model', choices=['gahm', 'symmetric'], default='gahm')
argument_parser.add_argument('--perturb-features', nargs='+', type=str, default=[PerturberFeatures.ISOTACH_ADJUSTMENT.name])
argument_parser.add_argument('--variables', nargs='+', type=str)

argument_parser.add_argument('name', help='name of the storm', type=str)
Expand Down
4 changes: 3 additions & 1 deletion stormworkflow/refs/input.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
input_version: 0.0.4
input_version: 0.0.5

storm: "florence"
year: 2018
Expand All @@ -19,6 +19,8 @@ perturb_vars:
- "radius_of_maximum_winds_persistent"
- "max_sustained_wind_speed"
rmw_fill_method: "persistent"
perturb_features:
- "isotach_adjustment"

spinup_exec: "pschism_PAHM_TVD-VL"
hotstart_exec: "pschism_PAHM_TVD-VL"
Expand Down
6 changes: 3 additions & 3 deletions stormworkflow/scripts/workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ PREP_KWDS+=" --variables $perturb_vars"
if [ $use_wwm == 1 ]; then PREP_KWDS+=" --use-wwm"; fi
if [ $hydrology == 1 ]; then PREP_KWDS+=" --with-hydrology"; fi
PREP_KWDS+=" --pahm-model $pahm_model"
PREP_KWDS+=" --perturb-features $perturb_features"
export PREP_KWDS
# NOTE: We need to wait because run jobs depend on perturbation dirs!
setup_id=$(sbatch \
--output "${run_dir}/output/slurm-%j.setup.out" \
--wait \
--job-name=prep_$tag \
--parsable \
--export=ALL,PREP_KWDS,STORM=$storm,YEAR=$year,IMG="$L_IMG_DIR/prep.sif" \
--export=ALL,PREP_KWDS,STORM=$storm,YEAR=$year \
$run_dir/slurm/prep.sbatch \
)


echo "Launching runs"
SCHISM_SHARED_ENV=""
SCHISM_SHARED_ENV+="ALL"
SCHISM_SHARED_ENV+=",IMG=$L_IMG_DIR/solve.sif"
SCHISM_SHARED_ENV+=",MODULES=$L_SOLVE_MODULES"
spinup_id=$(sbatch \
--nodes $hpc_solver_nnodes --ntasks $hpc_solver_ntasks \
Expand Down Expand Up @@ -185,5 +185,5 @@ sbatch \
--output "${run_dir}/output/slurm-%j.post.out" \
--job-name=post_$tag \
-d afterok${joblist} \
--export=ALL,IMG="$L_IMG_DIR/prep.sif",ENSEMBLE_DIR="$run_dir/setup/ensemble.dir/" \
--export=ALL,ENSEMBLE_DIR="$run_dir/setup/ensemble.dir/" \
$run_dir/slurm/post.sbatch
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
input_v0_0_2 = test_refs.joinpath('input_v0.0.2.yaml')
input_v0_0_3 = test_refs.joinpath('input_v0.0.3.yaml')
input_v0_0_4 = test_refs.joinpath('input_v0.0.4.yaml')
input_v0_0_5 = test_refs.joinpath('input_v0.0.5.yaml')
input_latest = refs.joinpath('input.yaml')


Expand Down Expand Up @@ -38,6 +39,10 @@ def conf_v0_0_3():
def conf_v0_0_4():
return read_conf(input_v0_0_4)

@pytest.fixture
def conf_v0_0_5():
return read_conf(input_v0_0_5)

@pytest.fixture
def conf_latest():
return read_conf(input_latest)
51 changes: 51 additions & 0 deletions tests/data/refs/input_v0.0.5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
input_version: 0.0.5

storm: "florence"
year: 2018
suffix: ""
subset_mesh: 1
hr_prelandfall: -1
past_forecast: 1
hydrology: 0
use_wwm: 0
pahm_model: "gahm"
num_perturb: 2
sample_rule: "korobov"
perturb_vars:
- "cross_track"
- "along_track"
# - "radius_of_maximum_winds"
- "radius_of_maximum_winds_persistent"
- "max_sustained_wind_speed"
rmw_fill_method: "persistent"
perturb_features:
- "isotach_adjustment"

spinup_exec: "pschism_PAHM_TVD-VL"
hotstart_exec: "pschism_PAHM_TVD-VL"

hpc_solver_nnodes: 3
hpc_solver_ntasks: 108
hpc_account: ""
hpc_partition: ""

RUN_OUT: ""
L_NWM_DATASET: ""
L_TPXO_DATASET: ""
L_LEADTIMES_DATASET: ""
L_TRACK_DIR: ""
L_DEM_HI: ""
L_DEM_LO: ""
L_MESH_HI: ""
L_MESH_LO: ""
L_SHP_DIR: ""
NHC_OBS: ""

TMPDIR: "/tmp"
PATH_APPEND: ""

L_SOLVE_MODULES:
- "intel/2022.1.2"
- "impi/2022.1.2"
- "netcdf"
5 changes: 5 additions & 0 deletions tests/test_input_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ def test_v0_0_3_to_latest(conf_v0_0_3, conf_latest):
def test_v0_0_4_to_latest(conf_v0_0_4, conf_latest):
handle_input_version(conf_v0_0_4)
assert conf_latest == conf_v0_0_4


def test_v0_0_5_to_latest(conf_v0_0_5, conf_latest):
handle_input_version(conf_v0_0_5)
assert conf_latest == conf_v0_0_5

0 comments on commit 6621fb9

Please sign in to comment.