DataManager
DataManager
Provide functionality for handling data processings and workflows.
Source code in pySWATPlus/data_manager.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 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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
hru_stats_from_daily_simulation(sim_file: str | pathlib.Path, has_units: bool, gis_id: int, sim_col: str, output_dir: typing.Optional[str | pathlib.Path] = None) -> dict[str, pandas.DataFrame]
Compute monthly and yearly statistical summaries for a Hydrological Response Unit (HRU) from daily simulation time series data.
The method returns a dictionary containing two keys, monthly and yearly, whose values are DataFrame objects.
Each DataFrame includes the following columns:
- `date`: The first day of the corresponding month or year.
- `min`: Minimum simulated value within the time window.
- `max`: Maximum simulated value within the time window.
- `mean`: Mean simulated value within the time window.
- `std`: Standard deviation of simulated values within the time window.
The statistics are computed using daily values between the first and last dates (both inclusive)
of each month or year. The date column represents the first day of the corresponding period
(e.g., 01-Jan-2012, 01-Feb-2012 for monthly; 01-Jan-2012 for yearly).
If the first or last record in the input file does not align exactly with the start or end
of a month or year, the statistics are computed for the available portion of that period.
In such cases, the date column represents the first available date for that partial period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_file
|
str | Path
|
Path to the input file containing time series data generated by
the method |
required |
has_units
|
bool
|
If |
required |
gis_id
|
int
|
Unique identifier for the Hydrological Response Unit (HRU) found in the |
required |
sim_col
|
str
|
Name of the column containing simulated values. |
required |
output_dir
|
str | Path
|
Directory path to save the computed results as two following JSON files.
If |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary with two keys:
|
Source code in pySWATPlus/data_manager.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
read_sensitive_dfs(sensim_file: str | pathlib.Path, df_name: str, add_problem: bool = False, add_sample: bool = False) -> dict[str, typing.Any]
Read sensitivity simulation data generated by the method
simulation_by_sample_parameters,
and return a dictionary mapping each scenario integer to its corresponding DataFrame.
The returned dictionary may include the following keys:
- scenario (default): A mapping between each scenario integer and its corresponding DataFrame.
- problem (optional): The problem definition.
- sample (optional): The sample list used in the sensitivity simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensim_file
|
str | Path
|
Path to the |
required |
df_name
|
str
|
Name of the |
required |
add_problem
|
bool
|
If |
False
|
add_sample
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary with the following keys:
|
Source code in pySWATPlus/data_manager.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
simulated_timeseries_df(sim_file: str | pathlib.Path, has_units: bool, begin_date: typing.Optional[str] = None, end_date: typing.Optional[str] = None, ref_day: typing.Optional[int] = None, ref_month: typing.Optional[int] = None, apply_filter: typing.Optional[dict[str, list[typing.Any]]] = None, usecols: typing.Optional[list[str]] = None, json_file: typing.Optional[str | pathlib.Path] = None) -> pandas.DataFrame
Extract data from a simulation output file and return a time series DataFrame.
A new date column is constructed using datetime.date objects from the yr, mon, and day columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_file
|
str | Path
|
Path to the input file containing time series data generated by
the method |
required |
has_units
|
bool
|
If |
required |
begin_date
|
str
|
Start date in |
None
|
end_date
|
str
|
End date in |
None
|
ref_day
|
int
|
Reference day for monthly and yearly time series after filtering by |
None
|
ref_month
|
int
|
Reference month for yearly time series after filtering by |
None
|
apply_filter
|
dict[str, list[Any]]
|
Dictionary mapping column names to lists of values for row filtering.
If |
None
|
usecols
|
list[str]
|
Column names to include in the output. If |
None
|
json_file
|
str | Path
|
Path to save the output |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Time series |
Source code in pySWATPlus/data_manager.py
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 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 189 190 | |