Skip to content

RainfallRunoff file models

The rr module provides the various file models for files that are input to the Rainfall Runoff kernel. Support is still basic, but growing. The input 'layers' listed below correspond with the input description in the SOBEK UM.

Main input (sobek_3b.fnm)

models.py defines the RainfallRunoffModel and supporting structures.

RainfallRunoffModel (FileModel) pydantic-model

The RainfallRunoffModel contains all paths and sub-models related to the Rainfall Runoff model.

General layer

rainfall file

BuiModel (FileModel) pydantic-model

Model that represents the file structure of a .bui file.

get_station_events(self, station: str) -> Dict[datetime.datetime, List[float]]

Returns all the events (start time and precipitations) related to a given station.

Parameters:

Name Type Description Default
station str

Name of the station to retrieve.

required

Exceptions:

Type Description
ValueError

If the station name does not exist in the BuiModel.

Returns:

Type Description
Dict[datetime, List[float]]

Dictionary with the start time and its precipitations.

Source code in hydrolib/core/io/bui/models.py
def get_station_events(self, station: str) -> Dict[datetime, List[float]]:
    """
    Returns all the events (start time and precipitations) related to a given station.

    Args:
        station (str): Name of the station to retrieve.

    Raises:
        ValueError: If the station name does not exist in the BuiModel.

    Returns:
        Dict[datetime, List[float]]: Dictionary with the start time and its precipitations.
    """
    if station not in self.name_of_stations:
        raise ValueError("Station {} not found BuiModel.".format(station))
    station_idx = self.name_of_stations.index(station)
    station_events = {}
    for event in self.precipitation_events:
        start_time, precipitations = event.get_station_precipitations(station_idx)
        station_events[start_time] = precipitations
    return station_events

BuiPrecipitationEvent (BaseModel) pydantic-model

get_station_precipitations(self, station_idx: int) -> Tuple[datetime.datetime, List[float]]

Returns all the precipitations related to the given station index (column).

Parameters:

Name Type Description Default
station_idx int

Index of the column which values need to be retrieved.

required

Exceptions:

Type Description
ValueError

If the station index does not exist.

Returns:

Type Description
Tuple[datetime, List[float]]

Tuple with the start time and its precipitations.

Source code in hydrolib/core/io/bui/models.py
def get_station_precipitations(
    self, station_idx: int
) -> Tuple[datetime, List[float]]:
    """
    Returns all the precipitations related to the given station index (column).

    Args:
        station_idx (int): Index of the column which values need to be retrieved.

    Raises:
        ValueError: If the station index does not exist.

    Returns:
        Tuple[datetime, List[float]]: Tuple with the start time and its precipitations.
    """
    number_of_stations = len(self.precipitation_per_timestep[0])
    if station_idx >= number_of_stations:
        raise ValueError(
            "Station index not found, number of stations: {}".format(
                number_of_stations
            )
        )
    return (
        self.start_time,
        [
            ts_precipitations[station_idx]
            for ts_precipitations in self.precipitation_per_timestep
        ],
    )

Topology layer ("Topography" in SOBEK UM)

Represents a link from the topology link file.

dict(self, *args, **kwargs)

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Source code in hydrolib/core/io/rr/topology/models.py
def dict(self, *args, **kwargs):
    kwargs["by_alias"] = True
    return super().dict(*args, **kwargs)

LinkFile (FileModel) pydantic-model

Represents the file with the RR link topology data.

Node (BaseModel) pydantic-model

Represents a node from the topology node file.

dict(self, *args, **kwargs)

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Source code in hydrolib/core/io/rr/topology/models.py
def dict(self, *args, **kwargs):
    kwargs["by_alias"] = True
    return super().dict(*args, **kwargs)

NodeFile (FileModel) pydantic-model

Represents the file with the RR node topology data.

(Other input layers foreseen in future releases)

Back to top