Skip to content

Commit

Permalink
Update and improve version check
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Sep 5, 2024
1 parent 3111110 commit 21e8f9b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 22 deletions.
51 changes: 31 additions & 20 deletions stormworkflow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,32 @@

_logger = logging.getLogger(__file__)

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


def _handle_input_v0_0_1_to_v0_0_2(inout_conf):
def _input_version(prev, curr):
def decorator(handler):
def wrapper(inout_conf):
ver = Version(inout_conf['input_version'])

ver = Version(inout_conf['input_version'])
# Only update config if specified version matches the
# assumed one
if ver != Version(prev):
return ver

# Only update config if specified version matches the assumed one
if ver != Version('0.0.1'):
return ver
# TODO: Need return values?
handler(inout_conf)

return Version(curr)
global VER_UPDATE_FUNCS
VER_UPDATE_FUNCS.append(wrapper)
return wrapper
return decorator


@_input_version('0.0.1', '0.0.2')
def _handle_input_v0_0_1_to_v0_0_2(inout_conf):

_logger.info(
"Adding perturbation variables for persistent RMW perturbation"
Expand All @@ -40,24 +55,23 @@ def _handle_input_v0_0_1_to_v0_0_2(inout_conf):
'max_sustained_wind_speed',
]

return Version('0.0.2')


@_input_version('0.0.2', '0.0.3')
def _handle_input_v0_0_2_to_v0_0_3(inout_conf):

ver = Version(inout_conf['input_version'])

# Only update config if specified version matches the assumed one
if ver != Version('0.0.2'):
return ver


_logger.info(
"Adding RMW fill method default to persistent"
)
inout_conf['rmw_fill_method'] = 'persistent'

return Version('0.0.3')

@_input_version('0.0.3', '0.0.4')
def _handle_input_v0_0_3_to_v0_0_4(inout_conf):

_logger.info(
"Path to observations"
)
inout_conf['NHC_OBS'] = ''


def handle_input_version(inout_conf):
Expand All @@ -77,10 +91,7 @@ def handle_input_version(inout_conf):
f"Input version not supported! Max version supported is {CUR_INPUT_VER}"
)

for fn in [
_handle_input_v0_0_1_to_v0_0_2,
_handle_input_v0_0_2_to_v0_0_3,
]:
for fn in VER_UPDATE_FUNCS:
ver = fn(inout_conf)
inout_conf['input_version'] = str(ver)

Expand Down
2 changes: 1 addition & 1 deletion stormworkflow/refs/input.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
input_version: 0.0.3
input_version: 0.0.4

storm: "florence"
year: 2018
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@


refs = files('stormworkflow.refs')
test_refs = files('tests.data.refs')
test_refs = files('data.refs')
input_v0_0_1 = test_refs.joinpath('input_v0.0.1.yaml')
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_latest = refs.joinpath('input.yaml')


Expand All @@ -33,6 +34,9 @@ def conf_v0_0_2():
def conf_v0_0_3():
return read_conf(input_v0_0_3)

@pytest.fixture
def conf_v0_0_4():
return read_conf(input_v0_0_4)

@pytest.fixture
def conf_latest():
Expand Down
49 changes: 49 additions & 0 deletions tests/data/refs/input_v0.0.4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
input_version: 0.0.4

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"

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 @@ -45,3 +45,8 @@ def test_v0_0_2_to_latest(conf_v0_0_2, conf_latest):
def test_v0_0_3_to_latest(conf_v0_0_3, conf_latest):
handle_input_version(conf_v0_0_3)
assert conf_latest == conf_v0_0_3


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

0 comments on commit 21e8f9b

Please sign in to comment.