The Rainfall Runoff meteo layer¶
The meteo layer currently contains only support for the BUI file. The "bui" file contains the precipitation input data for Rainfall Runoff. It is represented by the classes below.
Model¶
BuiModel
¶
Bases: ParsableFileModel
Model that represents the file structure of a .bui file.
Source code in hydrolib/core/rr/meteo/models.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_station_events(station)
¶
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 |
Raises:
Type | Description |
---|---|
ValueError
|
If the station name does not exist in the BuiModel. |
Returns:
Type | Description |
---|---|
Dict[datetime, List[float]]
|
Dict[datetime, List[float]]: Dictionary with the start time and its precipitations. |
Source code in hydrolib/core/rr/meteo/models.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
BuiPrecipitationEvent
¶
Bases: BaseModel
Source code in hydrolib/core/rr/meteo/models.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
get_station_precipitations(station_idx)
¶
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 |
Raises:
Type | Description |
---|---|
ValueError
|
If the station index does not exist. |
Returns:
Type | Description |
---|---|
Tuple[datetime, List[float]]
|
Tuple[datetime, List[float]]: Tuple with the start time and its precipitations. |
Source code in hydrolib/core/rr/meteo/models.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
Parser¶
BuiEventListParser
¶
A parser for .bui events which are like this: StartTime (YYYY mm dd HH MM SS) TimeSeriesLength (dd HH MM SS) PrecipitationPerTimestep StartTime (YYYY mm dd HH MM SS) TimeSeriesLength (dd HH MM SS) PrecipitationPerTimestep Example given: 2021 12 20 0 0 0 1 0 4 20 4.2 4.2 4.2 2021 12 21 0 0 0 1 0 4 20 2.4 2.4 2.4
Source code in hydrolib/core/rr/meteo/parser.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
parse(raw_text, n_events, timestep)
staticmethod
¶
Parses a given raw text containing 0 to many text blocks representing a precipitation event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_text
|
str
|
Text blocks representing precipitation events. |
required |
n_events
|
int
|
Number of events contained in the text block. |
required |
timestep
|
int
|
Number of seconds conforming a timestep. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
List[Dict]: List containing all the events represented as dictionaries. |
Source code in hydrolib/core/rr/meteo/parser.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
BuiEventParser
¶
A parser for the precipitation event section within a .bui file. It resembles something like this: StartTime (YYYY mm dd HH MM SS) TimeSeriesLength (dd HH MM SS) PrecipitationPerTimestep Example given: 2021 12 20 0 0 0 1 0 4 20 4.2 2.4 4.2 2.4 4.2 2.4 (it should match the timeseries length based on the seconds per timstep.) Each column of the last three lines represents a station.
Source code in hydrolib/core/rr/meteo/parser.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
parse(raw_text)
staticmethod
¶
Given text representing a single BuiPrecipitationEvent parses it into a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_text
|
str
|
Text containing a single precipitation event. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
Mapped contents of the text. |
Source code in hydrolib/core/rr/meteo/parser.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
parse_event_time_reference(raw_text)
staticmethod
¶
Parses a single event time reference line containing both the start time and the timeseries length into a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_text
|
str
|
Line representing both start time and timeseries length. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
Resulting dictionary with keys start_time and timeseries_length. |
Source code in hydrolib/core/rr/meteo/parser.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
BuiParser
¶
A parser for .bui files which are like this: * comments Dataset type to use (always 1). * comments Number of stations. * comments Name of stations * comments Number of events Number of seconds per timestep. * comments First datetime reference. Precipitation per timestep per station.
Source code in hydrolib/core/rr/meteo/parser.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
parse(filepath)
staticmethod
¶
Parses a given file, in case valid, into a dictionary which can later be mapped to the BuiModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
Path
|
Path to file containing the data to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
Parsed values. |
Source code in hydrolib/core/rr/meteo/parser.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
Serializer¶
BuiEventSerializer
¶
Serializer class to transform a bui event into a text block.
Source code in hydrolib/core/rr/meteo/serializer.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
get_timedelta_fields(duration)
staticmethod
¶
Gets a dictionary containing the time delta in days, hours, minutes and seconds. This means that the seconds field does not contain the accumulative value of days hours and minutes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration
|
timedelta
|
Timedelta to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
Dictionary containing all fields. |
Source code in hydrolib/core/rr/meteo/serializer.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
serialize(event_data, config)
staticmethod
¶
Serializes a dictionary representing an event into a text block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_data
|
Dict
|
Dictionary representing precipitation event. |
required |
config
|
SerializerConfig
|
The serialization configuration. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted string. |
Source code in hydrolib/core/rr/meteo/serializer.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
serialize_precipitation_per_timestep(data_to_serialize, config)
staticmethod
¶
Serialized the data containing all the precipitations per timestep (and station) into a single string ready to be mapped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_serialize
|
List[List[str]]
|
Data to be mapped. |
required |
config
|
SerializerConfig
|
The serialization configuration. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Serialized string in .bui format. |
Source code in hydrolib/core/rr/meteo/serializer.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
serialize_start_time(data_to_serialize)
staticmethod
¶
Serializes a datetime into the expected .bui format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_serialize
|
datetime
|
Datetime representing reference time. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Converted datetime into string. |
Source code in hydrolib/core/rr/meteo/serializer.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
serialize_timeseries_length(data_to_serialize)
staticmethod
¶
Serializes a given timedelta into the .bui format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_serialize
|
timedelta
|
Reference timespan to serialize. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Converted timedelta in string. |
Source code in hydrolib/core/rr/meteo/serializer.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
BuiSerializer
¶
Serializer class to transform an object into a .bui file text format.
Source code in hydrolib/core/rr/meteo/serializer.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
serialize(bui_data, config)
staticmethod
¶
Formats the bui_template with the content of the given data. NOTE: It requires that caller injects file_path into bui_data prior to this call. Otherwise it will crash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bui_data
|
Dict
|
Data to serialize. |
required |
config
|
SerializerConfig
|
The serialization configuration. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The serialized data. |
Source code in hydrolib/core/rr/meteo/serializer.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
serialize_event_list(data_to_serialize, config)
staticmethod
¶
Serializes a event list dictionary into a single text block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_serialize
|
Dict
|
Dictionary containing list of events. |
required |
config
|
SerializerConfig
|
The serialization configuration. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Text block representing all precipitation events. |
Source code in hydrolib/core/rr/meteo/serializer.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
serialize_stations_ids(data_to_serialize)
staticmethod
¶
Serializes the stations ids into a single string as expected in a .bui file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_serialize
|
List[str]
|
List of station ids. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Serialized string. |
Source code in hydrolib/core/rr/meteo/serializer.py
208 209 210 211 212 213 214 215 216 217 218 219 |
|
write_bui_file(path, data, config, save_settings)
¶
Writes a .bui file in the given path based on the data given in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path where to output the text. |
required |
data
|
Dict
|
Data to serialize into the file. |
required |
config
|
SerializerConfig
|
The serialization configuration. |
required |
save_settings
|
ModelSaveSettings
|
The model save settings. |
required |
Source code in hydrolib/core/rr/meteo/serializer.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|