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.
ImmutableDiskOnlyFileModel (DiskOnlyFileModel)
pydantic-model
¶
ImmutableDiskOnlyFileModel modifies the DiskOnlyFileModel to provide faux immutablitity.
This behaviour is required for the mappix properties, which should always have the same name and path and should not be modified by users.
RainfallRunoffModel (ParsableFileModel)
pydantic-model
¶
The RainfallRunoffModel contains all paths and sub-models related to the Rainfall Runoff model.
General layer¶
rainfall file¶
BuiModel (ParsableFileModel)
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/rr/meteo/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/rr/meteo/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)¶
Link (BaseModel)
pydantic-model
¶
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 (ParsableFileModel)
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 (ParsableFileModel)
pydantic-model
¶
Represents the file with the RR node topology data.
nodetypes_netter_to_rr
¶
Dictionary with nt
mapped against the expected mt
.
Some model types mt
do not have a related netter type; in that case the
dict key is a dummy value of -