diff --git a/PyStemmusScope/bmi/docker_process.py b/PyStemmusScope/bmi/docker_process.py index 06362673..7e0cc220 100644 --- a/PyStemmusScope/bmi/docker_process.py +++ b/PyStemmusScope/bmi/docker_process.py @@ -83,7 +83,7 @@ class StemmusScopeDocker: """Communicate with a STEMMUS_SCOPE Docker container.""" # Default image, can be overridden with config: - compatible_tags = ("1.5.0",) + compatible_tags = ("1.6.0",) _process_ready_phrase = b"Select BMI mode:" _process_finalized_phrase = b"Finished clean up." diff --git a/PyStemmusScope/bmi/implementation.py b/PyStemmusScope/bmi/implementation.py index c64ca575..17af3bb2 100644 --- a/PyStemmusScope/bmi/implementation.py +++ b/PyStemmusScope/bmi/implementation.py @@ -9,7 +9,7 @@ from bmipy.bmi import Bmi from PyStemmusScope.bmi.utils import InapplicableBmiMethods from PyStemmusScope.bmi.utils import nested_set -from PyStemmusScope.bmi.variable_reference import VARIABLES +from PyStemmusScope.bmi.variable_reference import VARIABLES, BmiVariable from PyStemmusScope.config_io import read_config @@ -21,6 +21,8 @@ var.name for var in VARIABLES if var.output ) +MODEL_VARS: dict[str, BmiVariable] = {var.name: var for var in VARIABLES} + MODEL_VARNAMES: tuple[str, ...] = tuple(var.name for var in VARIABLES) VARNAME_UNITS: dict[str, str] = {var.name: var.units for var in VARIABLES} @@ -29,7 +31,7 @@ VARNAME_GRID: dict[str, int] = {var.name: var.grid for var in VARIABLES} -VARNAME_LOC: dict[str, list[str]] = {var.name: var.loc for var in VARIABLES} +VARNAME_LOC: dict[str, list[str]] = {var.name: var.keys for var in VARIABLES} NO_STATE_MSG = ( "The model state is not available. Please run `.update()` before requesting " @@ -78,13 +80,11 @@ def get_variable( for _loc in VARNAME_LOC[varname]: _s = _s.get(_loc) - if VARNAME_GRID[varname] == 0: + if MODEL_VARS[varname].all_timesteps: + return _s[0].astype(VARNAME_DTYPE[varname])[[int(state["KT"][0])]] + else: return _s[0].astype(VARNAME_DTYPE[varname]) - # something's gone wrong: - msg = "Varname is missing in get_variable! Contact devs." - raise ValueError(msg) - def set_variable( state: h5py.File, diff --git a/PyStemmusScope/bmi/variable_reference.py b/PyStemmusScope/bmi/variable_reference.py index 123050c2..fc7ed14d 100644 --- a/PyStemmusScope/bmi/variable_reference.py +++ b/PyStemmusScope/bmi/variable_reference.py @@ -12,7 +12,8 @@ class BmiVariable: output: bool units: str grid: int - loc: list[str] + keys: list[str] + all_timesteps: bool = False VARIABLES: tuple[BmiVariable, ...] = ( @@ -24,7 +25,7 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["fluxes", "Resp"], + keys=["fluxes", "Resp"], ), BmiVariable( name="evaporation_total", @@ -33,7 +34,8 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["EVAP"], + keys=["EVAP"], + all_timesteps=True, ), # soil vars: BmiVariable( @@ -43,7 +45,7 @@ class BmiVariable: output=True, units="degC", grid=1, - loc=["TT"], + keys=["TT"], ), BmiVariable( name="soil_moisture", @@ -52,7 +54,7 @@ class BmiVariable: output=True, units="m3 m-3", grid=1, - loc=["SoilVariables", "Theta_U"], + keys=["SoilVariables", "Theta_U"], ), BmiVariable( name="soil_root_water_uptake", @@ -61,7 +63,7 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["RWUs"], + keys=["RWUs"], ), # surface runoff BmiVariable( @@ -71,7 +73,7 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["RS"], + keys=["RS"], ), BmiVariable( name="surface_runoff_hortonian", @@ -80,7 +82,8 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["ForcingData", "R_Dunn"], + keys=["ForcingData", "R_Dunn"], + all_timesteps=True, ), BmiVariable( name="surface_runoff_dunnian", @@ -89,7 +92,8 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["ForcingData", "R_Hort"], + keys=["ForcingData", "R_Hort"], + all_timesteps=True, ), # groundwater vars (STEMMUS_SCOPE) BmiVariable( @@ -99,7 +103,7 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["RWUg"], + keys=["RWUg"], ), BmiVariable( name="groundwater_recharge", @@ -108,7 +112,7 @@ class BmiVariable: output=True, units="cm s-1", grid=0, - loc=["gwfluxes", "recharge"], + keys=["gwfluxes", "recharge"], ), # groundwater (coupling) vars BmiVariable( @@ -118,7 +122,7 @@ class BmiVariable: output=False, units="-", grid=0, - loc=["GroundwaterSettings", "GroundwaterCoupling"], + keys=["GroundwaterSettings", "GroundwaterCoupling"], ), BmiVariable( name="groundwater_head_bottom_layer", @@ -127,7 +131,7 @@ class BmiVariable: output=False, units="cm", grid=0, - loc=["GroundwaterSettings", "headBotmLayer"], + keys=["GroundwaterSettings", "headBotmLayer"], ), BmiVariable( name="groundwater_temperature", @@ -136,7 +140,7 @@ class BmiVariable: output=False, units="degC", grid=0, - loc=["GroundwaterSettings", "tempBotm"], + keys=["GroundwaterSettings", "tempBotm"], ), BmiVariable( name="groundwater_elevation_top_aquifer", @@ -145,6 +149,6 @@ class BmiVariable: output=False, units="cm", grid=0, - loc=["GroundwaterSettings", "toplevel"], + keys=["GroundwaterSettings", "topLevel"], ), )