ewatercycle.base.model ====================== .. py:module:: ewatercycle.base.model .. autoapi-nested-parse:: Base classes for eWaterCycle models. Module Contents --------------- .. py:data:: logger .. py:data:: ISO_TIMEFMT :value: '%Y-%m-%dT%H:%M:%SZ' .. py:class:: eWaterCycleModel Bases: :py:obj:`pydantic.BaseModel`, :py:obj:`abc.ABC` Base functionality for eWaterCycle models. Children need to specify how to make their BMI instance: in a container or local python environment. .. py:attribute:: forcing :type: ewatercycle.base.forcing.DefaultForcing | None :value: None .. py:attribute:: parameter_set :type: ewatercycle.base.parameter_set.ParameterSet | None :value: None .. py:property:: version :type: str Version of the model. .. py:property:: parameters :type: collections.abc.ItemsView[str, Any] Display the model's parameters and their values. .. py:method:: setup(*, cfg_dir: str | None = None, **kwargs) -> tuple[str, str] Perform model setup. 1. Creates config file and config directory 2. Start bmi instance and store as self._bmi :param cfg_dir: Optionally specify path to use as config dir. Will be created if it doesn't exist yet. Behaviour follows PyMT documentation (https://pymt.readthedocs.io/en/latest/usage.html#model-setup). Only difference is that we don't create a temporary directory, but rather a time-stamped folder inside ewatercycle.CFG['output_dir']. :param \*args: Positional arguments. Sub class should specify each arg. :param \*\*kwargs: Named arguments. Sub class should specify each arg. :returns: Path to config file and path to config directory .. py:method:: initialize(config_file: str) -> None Initialize the model. :param config_file: Name of initialization file. .. py:method:: finalize() -> None Perform tear-down tasks for the model. After finalization, the model should not be used anymore. .. py:method:: update() -> None Advance model state by one time step. .. py:method:: get_value(name: str) -> numpy.ndarray Get a copy of values of the given variable. :param name: Name of variable .. py:method:: get_value_at_coords(name, lat: collections.abc.Iterable[float], lon: collections.abc.Iterable[float]) -> numpy.ndarray Get a copy of values of the given variable at lat/lon coordinates. :param name: Name of variable :param lat: Latitudinal value :param lon: Longitudinal value .. py:method:: set_value(name: str, value: numpy.ndarray) -> None Specify a new value for a model variable. :param name: Name of variable :param value: The new value for the specified variable. .. py:method:: set_value_at_coords(name: str, lat: collections.abc.Iterable[float], lon: collections.abc.Iterable[float], values: numpy.ndarray) -> None Specify a new value for a model variable at at lat/lon coordinates. :param name: Name of variable :param lat: Latitudinal value :param lon: Longitudinal value :param values: The new value for the specified variable. .. py:method:: get_value_as_xarray(name: str) -> xarray.DataArray Get a copy values of the given variable as xarray DataArray. The xarray object also contains time, coordinate information and additional attributes such as the units. :param name: Name of the variable :returns: Dataarray of the variable. .. py:property:: bmi :type: bmipy.Bmi Bmi class wrapped by the model. .. py:property:: start_time :type: float Start time of the model. .. py:property:: end_time :type: float End time of the model. .. py:property:: time :type: float Current time of the model. .. py:property:: time_units :type: str Time units of the model. Formatted using UDUNITS standard from Unidata. .. py:property:: time_step :type: float Current time step of the model. .. py:property:: output_var_names :type: collections.abc.Iterable[str] List of a model's output variables. .. py:property:: input_var_names :type: collections.abc.Iterable[str] List of a model's input variables. .. py:method:: var_units(name: str) -> str Return the given variable's units. .. py:property:: start_time_as_isostr :type: str Start time of the model. In UTC and ISO format string e.g. 'YYYY-MM-DDTHH:MM:SSZ'. .. py:property:: end_time_as_isostr :type: str End time of the model. In UTC and ISO format string e.g. 'YYYY-MM-DDTHH:MM:SSZ'. .. py:property:: time_as_isostr :type: str Current time of the model. In UTC and ISO format string e.g. 'YYYY-MM-DDTHH:MM:SSZ'. .. py:property:: start_time_as_datetime :type: datetime.datetime Start time of the model as a datetime object. .. py:property:: end_time_as_datetime :type: datetime.datetime End time of the model as a datetime object'. .. py:property:: time_as_datetime :type: datetime.datetime Current time of the model as a datetime object'. .. py:method:: get_latlon_grid(name) -> tuple[Any, Any, Any] Grid latitude, longitude and shape for variable. The default implementation takes Bmi's x as longitude and y as latitude. See bmi.readthedocs.io/en/stable/model_grids.html#structured-grids. Some models may deviate from this default. They can provide their own implementation or use a BMI wrapper as in the wflow and pcrglob examples. :param name: Name of the variable .. py:class:: LocalModel Bases: :py:obj:`eWaterCycleModel` eWaterCycle model running in a local Python environment. Mostly intended for development purposes. .. py:attribute:: bmi_class :type: type[bmipy.Bmi] .. py:property:: version :type: str Version of the model package. .. py:class:: ContainerizedModel Bases: :py:obj:`eWaterCycleModel` eWaterCycle model running inside a container. This is the recommended method for sharing eWaterCycle models. .. py:attribute:: bmi_image :type: Annotated[ewatercycle.container.ContainerImage, BeforeValidator(_parse_containerimage)] .. py:attribute:: protocol :type: Literal['grpc', 'openapi'] :value: 'grpc' .. py:attribute:: model_config .. py:property:: version :type: str Version of the container image. .. py:property:: logs :type: str Return the container logs.