Module classes¶
CompositeParameteriser
¶
Bases: HypercubeParameteriser
A parameteriser defined as the concatenation of several parameterisers
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
append(p)
¶
Append a parameteriser to this composite parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p |
HypercubeParameteriser
|
hypercube to append to this |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
concatenate(*args, strategy='')
staticmethod
¶
Concatenates some hypercubes to a single parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy |
str
|
The strategy to contatenate. Defaults to "", equivalent to "composite", the only available. May have other options in the future. |
''
|
Returns:
Name | Type | Description |
---|---|---|
CompositeParameteriser |
CompositeParameteriser
|
A concatenated parameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
empty_composite()
staticmethod
¶
Creates an empty parameteriser to be populated with other parameterisers
Returns:
Name | Type | Description |
---|---|---|
CompositeParameteriser |
CompositeParameteriser
|
composite parameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
EnsembleSimulation
¶
Bases: DeletableCffiNativeHandle
A simulation designed to facilitate model runs over ensemble of inputs
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_simulation_span()
¶
Gets the span of the simulation: start, end, time step
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: simulation span |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
record(variable_id)
¶
Records a state variable of the simualtion
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_id |
str
|
state variable identifier |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
record_ensemble_state(var_ids=CATCHMENT_FLOWRATE_VARID, recording_provider=None, data_ids=None)
¶
Records one or more state values from an ensemble simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_ids |
VecStr
|
Model variable identierfier(s). Defaults to CATCHMENT_FLOWRATE_VARID. |
CATCHMENT_FLOWRATE_VARID
|
recording_provider |
Optional[TimeSeriesLibrary]
|
An optional time series library to record to. Defaults to None. |
None
|
data_ids |
Optional[VecStr]
|
Data identifier(s). Defaults to None. |
None
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
setup(forecast_start, ensemble_size, forecast_horizon_length)
¶
Sets up this ensemble simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecast_start |
datetime
|
Start date for the simulation |
required |
ensemble_size |
int
|
size of the ensemble |
required |
forecast_horizon_length |
int
|
length of the simulation in numbers of time steps. |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
HypercubeParameteriser
¶
Bases: Parameteriser
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
|
__repr__()
¶
__str__()
¶
add_parameter_to_hypercube(name, value, min, max)
¶
Add a parameter to a hypercube. Must be a type of object that is expandable, otherwise may raise an exception
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
add_to_hypercube(specs)
¶
Add entries to a hypercube. Must be a type of object that is expandable, otherwise may raise an exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
specs |
pd.DataFrame
|
An optional data frame description of the parameter set, with at least columns Name, Min, Max, Value. |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
as_dataframe()
¶
Convert this hypercube parameteriser to a pandas data frame representation
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: pandas data frame |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
backtransform()
¶
Get the parameteriser values in the untransformed space
Get the parameteriser values in the untransformed space, i.e. remove any
transform added via [HypercubeParameteriser.wrap_transform
][HypercubeParameteriser.wrap_transform].
This allows to transform back e.g. from a virtual parameter log_X
to the underlying model (or even virtual/meta) parameter X.
Returns:
Name | Type | Description |
---|---|---|
HypercubeParameteriser |
HypercubeParameteriser
|
The parameters definitions without the transforms (if there are any) |
Examples:
>>> ref_area = 250
>>> time_span = 3600
>>> ptrans = sdh.define_gr4j_scaled_parameter(ref_area, time_span)
>>> ptrans
Name Value Min Max
0 log_x4 0.305422 0.000000 2.380211
1 log_x1 0.506690 0.000000 3.778151
2 log_x3 0.315425 0.000000 3.000000
3 asinh_x2 2.637752 -3.989327 3.989327
>>> ptrans.backtransform()
Name Value Min Max
0 x2 6.95511 -27.0 27.0
1 x3 2.06740 1.0 1000.0
2 x4 2.02033 1.0 240.0
3 x1 3.21137 1.0 6000.0
>>>
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
create_parameter_sampler(seed=0, type='urs')
¶
Creates a sampler for this parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed |
int
|
a seed for the sampler. Defaults to 0. |
0
|
type |
str
|
the type of sampler. Defaults to "urs". Only option supported as of 2023-01. |
'urs'
|
Returns:
Name | Type | Description |
---|---|---|
CandidateFactorySeed |
CandidateFactorySeed
|
a sampler, aka candidate factory |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
filtered_parameters()
¶
Wrap a parameteriser in a filter that can hide some parameters
from_dataframe(type='Generic subareas', definition=None)
staticmethod
¶
Create a parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
A string identifying the type of parameteriser to use. Recognised types are (case insensitive) 'log-likelihood', 'generic', 'subareas', 'links', 'nodes' and 'muskingum'. Defaults to "Generic subareas". |
'Generic subareas'
|
specs |
pd.DataFrame
|
An optional data frame description of the parameter set, with at least columns Name, Min, Max, Value. Defaults to None. |
required |
Returns:
Name | Type | Description |
---|---|---|
HypercubeParameteriser |
HypercubeParameteriser
|
new parameteriser |
Examples:
>>> d = pd.DataFrame(
... dict(
... Name=c("alpha", "inverse_velocity"),
... Value=c(1, 1),
... Min=c(1e-3, 1e-3),
... Max=c(1e2, 1e2),
... )
... )
meteriser.from_dataframe("Generic links", d)
p
>>> p = HypercubeParameteriser.from_dataframe("Generic links", d)
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
hide_parameters(patterns, regex=False, starts_with=False, strict=False)
¶
Hide some parameters (from the outside e.g. optimisers) in a filter parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patterns |
[type]
|
character, one or more pattern to match and hide matching parameters. Match according to other parameters. |
required |
regex |
bool
|
logical, defaults False, should the patterns be used as regular expressions.. Defaults to False. |
False
|
starts_with |
bool
|
logical, defaults False. Ignored if regex is True. Should the patterns be used as starting strings in the parameter names.. Defaults to False. |
False
|
strict |
bool
|
logical, default False. Used only if regex and starts_with are False. If True, raises an error if one of the "patterns" has no exact match in the parameters.. Defaults to False. |
False
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
make_state_init_parameteriser()
¶
Create a parameteriser used for model state initialisation
This allows to define tied parameters where, for instance, pval = a * modelStateVal. A more concrete use case is to define an initial soil moisture store 'S0', as a fraction of the model store capacity 'Smax'. The model state to initialise is 'S'
Note
See also swift2.classes.ScalingParameteriser for typical joint usage.
Returns:
Name | Type | Description |
---|---|---|
StateInitParameteriser |
StateInitParameteriser
|
state initialisation parameteriser |
Examples:
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
num_free_parameters()
¶
Number of free parameters in this hypercube parameteriser
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of free parameters |
set_hypercube(specs)
¶
Set the properties of a hypercube parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
specs |
pd.DataFrame
|
An optional data frame description of the parameter set, with at least columns Name, Min, Max, Value. |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_max_parameter_value(variable_name, value)
¶
Sets the value(s) of the upper bound of one or more parameter(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_name |
VecStr
|
one or more parameter name(s) |
required |
value |
VecScalars
|
one or more parameter value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_min_parameter_value(variable_name, value)
¶
Sets the value(s) of the lower bound of one or more parameter(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_name |
VecStr
|
one or more parameter name(s) |
required |
value |
VecScalars
|
one or more parameter value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_parameter_definition(variable_name, min, max, value)
¶
Sets the feasible range and value for a parameter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_name |
str
|
parameter name |
required |
min |
float
|
min |
required |
max |
float
|
max |
required |
value |
float
|
value |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_parameter_value(variable_name, value)
¶
Sets the value(s) of one or more parameter(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_name |
VecStr
|
one or more parameter name(s) |
required |
value |
VecScalars
|
one or more parameter value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
show_parameters(patterns, regex=False, starts_with=False)
¶
Show some parameters (from the outside e.g. optimisers) in a filter parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patterns |
[type]
|
character, one or more pattern to match and show matching parameters. Match according to other parameters |
required |
regex |
bool
|
should the patterns be used as regular expressions. Defaults to False. |
False
|
starts_with |
bool
|
should the patterns be used as starting strings in the parameter names. Defaults to False. |
False
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
wrap_transform()
¶
Create a parameteriser for which parameter transformations can be defined.
This allows to define e.g. a virtual parameter log_X instead of calibrating on the parameter X.
Returns:
Name | Type | Description |
---|---|---|
TransformParameteriser |
TransformParameteriser
|
A new parameteriser (TransformParameteriser) which has methods to define parameter transforms |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
ObjectiveEvaluator
¶
Bases: DeletableCffiNativeHandle
Objective Evaluator
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 |
|
create_composite_objective(objectives, weights, names)
staticmethod
¶
Creates a composite objective, weighted average of several objectives
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objectives |
Sequence["ObjectiveEvaluator"]
|
objective evaluators, for instance measures at several points in the catchment |
required |
weights |
Sequence[float]
|
Weights to use to average the objectives. This may not add to one, but must not sum to zero |
required |
names |
Sequence[str]
|
Names of individual objectives |
required |
Returns:
Name | Type | Description |
---|---|---|
ObjectiveEvaluator |
ObjectiveEvaluator
|
An objective evaluator that can be use by an optimiser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
create_sce_optim_swift(termination_criterion=None, sce_params=None, population_initialiser=None)
¶
Creates a shuffled complex optimiser for this objective
Parameters:
Name | Type | Description | Default |
---|---|---|---|
termination_criterion |
Optional["SceTerminationCondition"]
|
A termination criterion for the optimiser. Defaults to None, in which case an arbitrary "relative standard deviation" is set up. |
None
|
sce_params |
Optional[Dict[str, float]]
|
hyperparameters controlling SCE. Defaults to None, in which case |
None
|
population_initialiser |
Optional["CandidateFactorySeed"]
|
A candidate factory to initialise the population of parameters the optimiser starts from, or a hypercube. In the latter case, uniform random sampling is used. Defaults to None, which leads to an error (for legacy reasons). |
None
|
Returns:
Name | Type | Description |
---|---|---|
Optimiser |
Optimiser
|
SCE optimiser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_score(p_set)
¶
Evaluate this objective for a given parameterisation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p_set |
HypercubeParameteriser
|
parameteriser |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str,Any]: score(s), and a data frame representation of the input parameters. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_scores(p_set)
¶
Evaluate this objective for a given parameterisation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p_set |
HypercubeParameteriser
|
parameteriser |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
Dict[str,float]: score(s) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
Parameteriser
¶
Bases: DeletableCffiNativeHandle
Wrapper around a native parameteriser.
Note
This is a parent class for more common types such as swift2.classes.HypercubeParameteriser
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
apply_sys_config(simulation)
¶
Apply a model configuration to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
simulation |
required |
score_for_objective(objective)
¶
Computes the value of an objective for this given set of parameters
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
subcatchment_parameteriser(subcatchment)
¶
Create a parameteriser that gets applied to a subset of a whole catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subcatchment |
Simulation
|
the subcatchment, subset of a whole catchment, identifying which elements (subareas, nodes, links) will be parameterised by the new parameteriser. Other catchment elements are untouched. |
required |
Returns:
Name | Type | Description |
---|---|---|
HypercubeParameteriser |
New parameteriser whose application is limited to the subcatchment. |
Examples:
>>> sub_cats = simulation.split_to_subcatchments(["node.node_7", "node.node_10"])
>>> sc = sub_cats["node.node_7"]
>>> p = sp.create_parameteriser('generic subarea')
>>> p.add_parameter_to_hypercube("x1", 32, 1, 6e3)
>>> sp = p.subcatchment_parameteriser(sc)
>>> sp.apply_sys_config(simulation)
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
supports_thread_safe_cloning()
¶
Is this parameteriser clonable as a deep copy, safe for multi-threading?
ScalingParameteriser
¶
Bases: TransformParameteriser
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 |
|
linear_parameteriser(param_name, state_name, scaling_var_name, min_p_val, max_p_val, value, selector_type='subareas', intercept=0.0)
staticmethod
¶
Create a scaled linear parameteriser, tying by a linear transformation a (resp several) model state to a (resp several) parameter values
This allows to define tied parameters where pval = a * modelStateVal + intercept. The intent in particular is to define virtual model parameters such as initial store value as a fraction of the maximum storage capacity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_name |
VecStr
|
the name of the meta-parameter. Note that it can be the same value as inner_param_name without interference, though this may be confusing a choice. |
required |
state_name |
VecStr
|
the name of the model state to modify, based on the value of the meta-parameter and the state found in 'scalingVarName' |
required |
scaling_var_name |
VecStr
|
the name of the parameter for each subarea model, to which to apply the area scaled value. |
required |
min_p_val |
VecNum
|
minimum value allowed for the meta-parameter |
required |
max_p_val |
VecNum
|
minimum value allowed for the meta-parameter |
required |
value |
VecNum
|
value for the meta parameter. |
required |
selector_type |
str
|
an identifier to define to which catchment element(s) the parameteriser will be applied. Defaults to "subareas". |
'subareas'
|
intercept |
VecNum
|
[description]. Defaults to 0.0. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
ScalingParameteriser |
new ScalingParameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
linear_parameteriser_from(data_frame, selector_type='subareas')
staticmethod
¶
Create a scaled linear parameteriser, tying by a linear transformation a (resp several) model state to a (resp several) parameter values This allows to define tied parameters where pval = a * modelStateVal + intercept. The intent in particular is to define virtual model parameters such as initial store value as a fraction of the maximum storage capacity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_frame |
pd.DataFrame
|
data frame with columns "param_name", "state_name", "scaling_var_name", "min_value", "max_value", "value", "intercept", |
required |
selector_type |
str
|
[description]. Defaults to "subareas". |
'subareas'
|
Returns:
Name | Type | Description |
---|---|---|
ScalingParameteriser |
ScalingParameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
Simulation
¶
Bases: DeletableCffiNativeHandle
, SimulationMixin
Wrapper around single dimension simulation objects
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
|
__str__()
¶
string representation
add_state_initialiser(state_initialiser)
¶
Adds a state initialiser to any prior list of state initialisers
apply_recording_function(recording_func, var_ids, recording_provider, data_ids)
¶
DRAFT Advanced/technical. Record states to a record provider using a callable function.
Likely not for end users. This is used by methods such as
EnsembleSimulation.record_ensemble_state
.
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
check_simulation()
¶
Checks whether a simulation is configured to a state where it is executable
clone()
¶
Clone this simulation (deep copy)
Returns:
Name | Type | Description |
---|---|---|
Simulation |
Simulation
|
A new simulation object |
cookie_cut_dendritic_catchment(bottom_element_id, top_element_ids)
¶
cookie cut a dendritic catchment (without confluences)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bottom_element_id |
str
|
identifier of the most downstream element to keep |
required |
top_element_ids |
str
|
identifier(s) of the most upstream element(s) to keep |
required |
Returns:
Name | Type | Description |
---|---|---|
Simulation |
a subcatchment simulation, cookie cut from the base simulation. Deep clone of objects. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
create_ensemble_forecast_simulation(data_library, start, end, input_map, lead_time, ensemble_size, n_time_steps_between_forecasts)
¶
Create an ensemble forecast simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_library |
Any
|
external pointer type ENSEMBLE_DATA_SET_PTR, or a Python class wrapper around it |
required |
start |
ConvertibleToTimestamp
|
the start date of the simulation. The time zone will be forced to UTC. |
required |
end |
ConvertibleToTimestamp
|
the end date of the simulation. The time zone will be forced to UTC. |
required |
input_map |
dict
|
a named list were names are the data library data identifiers, and values are character vectors with model state identifiers. |
required |
lead_time |
int
|
integer, the length in time steps of the forecasts. |
required |
ensemble_size |
int
|
ensemble size |
required |
n_time_steps_between_forecasts |
int
|
nTimeStepsBetweenForecasts |
required |
Returns:
Type | Description |
---|---|
EnsembleForecastSimulation
|
An external pointer |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
create_multisite_objective(statspec, observations, weights)
¶
Creates an objective that combines multiple statistics. Used for joined, "whole of catchment" calibration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statspec |
pd.DataFrame
|
dataframe defining the objectives used. See function |
required |
observations |
Sequence[TimeSeriesLike]
|
A list of (time series) observations to calculated the statistics. Must be of same length as the number of rows of statspec. |
required |
weights |
Dict[str, float]
|
numeric vector of weights to ponderate each objective. |
required |
Returns:
Name | Type | Description |
---|---|---|
ObjectiveEvaluator |
ObjectiveEvaluator
|
an objective evaluator |
Examples:
>>> _, ms = sdh.create_test_catchment_structure()
>>> from swift2.utils import mk_full_data_id
>>>
>>> nodeids = ['node.n2', 'node.n4']
>>> mvids = mk_full_data_id(nodeids, 'OutflowRate')
>>>
>>> sdh.configure_test_simulation(
... ms,
... data_id='MMH',
... simul_start='1990-01-01',
... simul_end='2005-12-31',
... tstep='daily',
... varname_rain='P',
... varname_pet='E',
... varname_data_rain='rain',
... varname_data_pet='evap',
... )
>>>
>>> w = dict(zip(mvids, [1.0, 2.0]))
>>> w
{'node.n2.OutflowRate': 1.0, 'node.n4.OutflowRate': 2.0}
>>> span = ms.get_simulation_span()
>>>
>>> from swift2.utils import rep
>>> statspec = sst.multi_statistic_definition(mvids, rep('nse', 2), mvids, mvids, rep(span['start'], 2), rep(span['end'], 2) )
>>>
>>> statspec
ModelVarId StatisticId ObjectiveId ObjectiveName Start End
0 node.n2.OutflowRate nse node.n2.OutflowRate node.n2.OutflowRate 1990-01-01 2005-12-31
1 node.n4.OutflowRate nse node.n4.OutflowRate node.n4.OutflowRate 1990-01-01 2005-12-31
>>>
>>> # Create synthetic observations
>>> observations = [
... modFlows.sel(variable_identifiers=mvids[0]) * 0.33,
... modFlows.sel(variable_identifiers=mvids[1]) * 0.77
... ]
>>>
>>> obj = ms.create_multisite_objective(statspec, observations, w)
>>>
>>> dummy = sp.create_parameteriser()
>>> obj.get_scores(dummy)
{'node.n2.OutflowRate': -4.152338377267432, 'node.n4.OutflowRate': 0.8884789439301954}
>>>
>>> obj.get_score(dummy)
{'scores': {'MultisiteObjectives': 0.7917934964690136}, 'sysconfig': Empty DataFrame
Columns: [Name, Value, Min, Max]
Index: []}
>>>
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
|
create_objective(state_name, observation, statistic, start_date, end_date)
¶
Creates an objective calculator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_name |
str
|
The name identifying the model state variable to calibrate against the observation |
required |
observation |
TimeSeriesLike
|
an xts |
required |
statistic |
str
|
statistic identifier, e.g. "NSE" |
required |
start_date |
ConvertibleToTimestamp
|
start date of the period to calculate statistics on |
required |
end_date |
ConvertibleToTimestamp
|
end date of the period to calculate statistics on |
required |
Returns:
Name | Type | Description |
---|---|---|
ObjectiveEvaluator |
ObjectiveEvaluator
|
single objective evaluator |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
describe(verbosity=None)
¶
Describe the catchment model structure using simple python representations
ensemble_simulation(ensemble_size)
¶
Create an ensemble simulation templated from this simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ensemble_size |
int
|
The size of the ensemble dimension |
required |
Returns:
Name | Type | Description |
---|---|---|
EnsembleSimulation |
EnsembleSimulation
|
Ensemble simulation (ensemble simulation runner) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
erris_ensemble_simulation(warmup_start, warmup_end, observed_ts, error_model_element_id)
¶
Creates an ensemble simulation templated on this simulation, with an ERRIS model on one of the network element
Parameters:
Name | Type | Description | Default |
---|---|---|---|
warmup_start |
ConvertibleToTimestamp
|
start time stamp for the warmup period |
required |
warmup_end |
ConvertibleToTimestamp
|
end time stamp for the warmup period |
required |
observed_ts |
TimeSeriesLike
|
Time series of observations to correct prediction against |
required |
error_model_element_id |
str
|
model element identifier where to set up an ERRIS correction model |
required |
Returns:
Name | Type | Description |
---|---|---|
EnsembleSimulation |
EnsembleSimulation
|
Ensemble simulation (ensemble simulation runner) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_all_played()
¶
Gets all the time series of models variables into which input time sereis is/are played
get_all_recorded()
¶
get_catchment_structure()
¶
Gets the essential connective structure of a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
base catchment simulation |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A nested dictionary describing the catchment connectivity of subareas, links, and nodes |
Examples:
>>> _, simulation = sdh.create_test_catchment_structure()
>>> simulation.get_catchment_structure()
{'Node': Id Name
0 n1 n1_name
1 n2 n2_name
2 n3 n3_name
3 n4 n4_name
4 n5 n5_name
5 n6 n6_name, 'Link': Id Name LengthMetres f ManningsN Slope
0 lnk1 lnk1_name 0.0 0.0 0.0 0.0
1 lnk2 lnk2_name 0.0 0.0 0.0 0.0
2 lnk3 lnk3_name 0.0 0.0 0.0 0.0
3 lnk4 lnk4_name 0.0 0.0 0.0 0.0
4 lnk5 lnk5_name 0.0 0.0 0.0 0.0, 'Subarea': Id Name AreaKm2
0 lnk1 lnk1_name 1.1
1 lnk2 lnk2_name 2.2
2 lnk3 lnk3_name 3.3
3 lnk4 lnk4_name 4.4
4 lnk5 lnk5_name 5.5, 'NodeLink': DownstreamId UpstreamId LinkId
0 n6 n2 lnk1
1 n2 n5 lnk2
2 n2 n4 lnk3
3 n4 n3 lnk4
4 n4 n1 lnk5, 'SubareaLink': LinkId SubareaId
0 lnk1 lnk1
1 lnk2 lnk2
2 lnk3 lnk3
3 lnk4 lnk4
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_link_ids()
¶
get_link_names()
¶
get_node_ids()
¶
get_node_names()
¶
get_played(var_ids=None, start_time=None, end_time=None)
¶
Retrieves one or more played (input) time series from a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_ids |
optional str or sequence of str
|
name(s) of the model variable(s) into which a time series is played as input. e.g. 'Catchment.StreamflowRate'. If missing, a multivariate time series of all played states is returned; this may be a large amount of data. |
None
|
start_time |
datetime like
|
An optional parameter, the start of a period to subset the time series |
None
|
end_time |
datetime like
|
An optional parameter, the end of a period to subset the time series |
None
|
Returns:
Type | Description |
---|---|
xr.DataArray
|
xr.DataArray: a time series, possibly multivariate. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_played_varnames()
¶
Gets all the names of model states fed an input time series
get_recorded(var_ids=None, start_time=None, end_time=None)
¶
Retrieves a recorded time series from a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_ids |
optional str or sequence of str
|
name(s) of the model variable(s) recorded to a time series. e.g. 'Catchment.StreamflowRate'. If missing, a multivariate time series of all played states is returned; this may be a large amount of data. |
None
|
start_time |
datetime like
|
An optional parameter, the start of a period to subset the time series |
None
|
end_time |
datetime like
|
An optional parameter, the end of a period to subset the time series |
None
|
Returns:
Type | Description |
---|---|
xr.DataArray
|
xr.DataArray: a time series, possibly multivariate. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_simulation_span()
¶
Gets the simulation span of this simulation
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str,Any]: information on start, end, time step |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_state_value(var_id)
¶
Gets the value(s) of a model state(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_id |
VecStr
|
string or sequence of str, model variable state identifier(s) |
required |
Returns:
Type | Description |
---|---|
Union[Dict[str, float], float]
|
value(s) of the requested model states |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_subarea_ids()
¶
get_subarea_names()
¶
get_variable_ids(element_id=None, full_id=True)
¶
Gets all the names of the variables of an element (link, node, subarea) within a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
Optional[str]
|
a character, identifier of the element within the catchment |
None
|
full_id |
bool
|
boolean, if TRUE return the full hierarchical identifier |
True
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
is_variable_id(var_id)
¶
Are one or more model state identifier(s) valid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_id |
VecStr
|
model identifier(s) |
required |
Returns:
Type | Description |
---|---|
Union[Dict[str, bool], bool]
|
Union[Dict[str, bool], bool]: whether the identifier(s) are valid. A dictionary is returned if the input is vectorised rather than scalar. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
muskingum_param_constraints(inner_parameters, delta_t=1.0, param_name_k='K', param_name_x='X')
¶
Create a parameteriser with Muskingum-type constraints.
Given an existing parameteriser, create a wrapper that adds constraints on two of its parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inner_parameters |
HypercubeParameteriser
|
A SWIFT parameteriser object that contains two Muskingum-type attenuation and delay parameters. |
required |
delta_t |
int
|
the simulation time step in HOURS. Defaults to 1. |
1.0
|
param_name_k |
str
|
the variable identifier to use for the delay parameter of the Muskingum routing. Defaults to "K". |
'K'
|
param_name_x |
str
|
the variable identifier to use for the attenuation parameter of the Muskingum routing. Defaults to "X". |
'X'
|
Returns:
Name | Type | Description |
---|---|---|
ConstraintParameteriser |
ConstraintParameteriser
|
A parameteriser with constraints on the feasibility of the attenuation / delay parameters |
Examples:
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
play_input(input_ts, var_ids=None)
¶
Sets one or more time series as input(s) to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ts |
TimeSeriesLike
|
univariate time series. If an xts time series column names must be valid model variable identifiers, unless explicitely provided via varIds |
required |
var_ids |
optional str or sequence of str
|
optional character, the variable identifiers to use, overriding the column names of the inputTs. If not NULL, must be of length equal to the number of columns in inputTs |
None
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
play_inputs(data_library, model_var_id, data_id, resample='')
¶
Assign input time series from a time series library to a model simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_library |
TimeSeriesLibrary
|
external pointer type ENSEMBLE_DATA_SET_PTR, or a Python class wrapper around it |
required |
model_var_id |
str or sequence of str
|
model state variable unique identifier(s) |
required |
data_id |
str or sequence of str
|
identifier(s) for data in the data_library. If length is not the same as model_var_id, the elements of data_id are reused to match it |
required |
resample |
str or sequence of str
|
identifier(s) for how the series is resampled (aggregated or disaggregated). If length is not the same as model_var_id, the elements of resample are reused to match it |
''
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
play_subarea_input(input, subarea_name, input_name)
¶
Sets time series as input to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
TimeSeriesLike
|
univariate time series. |
required |
subarea_name |
str
|
a valid name of the subarea |
required |
input_name |
str
|
the name of the input variable to the model (i.e. 'P' for the precip of GR5H) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
prepare_dual_pass_forecasting(observation, error_model_element_id, warmup_start, warmup_end, required_windows_percentage)
¶
Create an ensemble simulation for forecasting with the Dual Pass error correction method
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation |
TimeSeriesLike
|
Time series of observations to correct prediction against |
required |
error_model_element_id |
str
|
model element identifier where to set up an ERRIS correction model |
required |
warmup_start |
ConvertibleToTimestamp
|
start time stamp for the warmup period |
required |
warmup_end |
ConvertibleToTimestamp
|
end time stamp for the warmup period |
required |
required_windows_percentage |
float
|
required_windows_percentage |
required |
Returns:
Name | Type | Description |
---|---|---|
EnsembleSimulation |
EnsembleSimulation
|
Ensemble simulation (ensemble simulation runner) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
prepare_erris_forecasting(observation, error_model_element_id, warmup_start, warmup_end)
¶
Create an ensemble simulation for forecasting with ERRIS
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation |
TimeSeriesLike
|
Time series of observations to correct prediction against |
required |
error_model_element_id |
str
|
model element identifier where to set up an ERRIS correction model |
required |
warmup_start |
ConvertibleToTimestamp
|
start time stamp for the warmup period |
required |
warmup_end |
ConvertibleToTimestamp
|
end time stamp for the warmup period |
required |
Returns:
Name | Type | Description |
---|---|---|
EnsembleSimulation |
EnsembleSimulation
|
Ensemble simulation (ensemble simulation runner) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
record_singular_state(var_ids=CATCHMENT_FLOWRATE_VARID, recording_provider=None, data_ids=None)
¶
DRAFT Advanced/technical. Record states to a record provider.
Likely not for end users.
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
remove_state_initialisers()
¶
reset_model_states()
¶
Reset the model states of a simulation, and apply one or more state initialers if the simulation is configured with any.
set_error_correction_model(model_id, element_id, length=1, seed=0)
¶
Add an error correction model to an element in a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
str
|
the identifier of the new model to use, e.g. 'ERRIS' |
required |
element_id |
str
|
the identifier of the catchment element (node, link, subcatchment) whose outflow rate is corrected. |
required |
length |
int
|
other parameters to pass to the creation of the error correction model. Currently length of the AR model only supported. |
1
|
seed |
int
|
other parameters to pass to the creation of the error correction model. Currently length of the AR model only supported. |
0
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_reservoir_geometry(element_id, level, storage, area)
¶
Sets the geometry of a reservoir
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
str
|
Element with a suitable reservoir supporting a geometry description |
required |
level |
np.ndarray
|
array of water surface levels, in S.I. units (m) TO BE CONFIRMED |
required |
storage |
np.ndarray
|
array of volume storages, in S.I. units (m3) TO BE CONFIRMED |
required |
area |
np.ndarray
|
array of surfce areas, in S.I. units (m2) TO BE CONFIRMED |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_reservoir_max_discharge(element_id, level, discharge)
¶
Sets a reservoir operating curve, maximum release for a given level
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
str
|
Element with a suitable reservoir supporting a geometry description |
required |
level |
np.ndarray
|
array of levels (m) |
required |
discharge |
np.ndarray
|
array of maximum discharges (m3/s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_reservoir_min_discharge(element_id, level, discharge)
¶
Sets a reservoir operating curve, minimum release for a given level
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
str
|
Element with a suitable reservoir supporting a geometry description |
required |
level |
np.ndarray
|
array of levels (m) |
required |
discharge |
np.ndarray
|
array of minimum discharges (m3/s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_reservoir_model(new_model_id, element_id)
¶
Sets a new reservoir model on an element
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_model_id |
str
|
Currently one of: "ControlledReleaseReservoir", "LevelVolumeAreaReservoir", "FarmDamReservoir"; |
required |
element_id |
str
|
description |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_simulation_span(start, end)
¶
Sets the simulation span
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
ConvertibleToTimestamp
|
the start date of the simulation. The time zone will be forced to UTC. |
required |
end |
ConvertibleToTimestamp
|
the end date of the simulation. The time zone will be forced to UTC. |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_simulation_time_step(name)
¶
Sets the time step of this simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
a time step identifier, currently 'daily' or 'hourly' are supported. The identifier is made lower case in the function. |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_state_value(var_id, value=None)
¶
Sets the value of a model state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_id |
Any
|
character, model variable state identifier(s) |
required |
value |
Any
|
numeric value(s) |
None
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
set_states(states)
¶
Apply memory states to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states |
MemoryStates
|
memory states |
required |
snapshot_state()
¶
Take a snapshot of the memory states of a simulation
Returns:
Name | Type | Description |
---|---|---|
MemoryStates |
MemoryStates
|
memory states, that can be stored and reapplied |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
sort_by_execution_order(split_element_ids, sorting_option='')
¶
Sort the specified element ids according to the execution order of the simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split_element_ids |
Sequence[str]
|
a character vector with element identifiers such as 'node.n1', 'link.linkId_2' |
required |
sorting_option |
str
|
a character - for future options. Ignored for now. |
''
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: values in split_element_ids sorted by simulation execution order |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
split_to_subcatchments(split_element_ids, include_upstream=None)
¶
Split a catchment in subcatchments, given a list of node/link element identifiers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split_element_ids |
str
|
element identifiers such as 'node.n1', 'link.linkId_2' |
required |
include_upstream |
bool
|
indicates whether for each element in split_element_ids it should be including in the upstream portion of the subcatchment. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
OrderedDict |
OrderedDict[str, Simulation]
|
list of subcatchments resulting from the split |
Examples:
>>> _, simulation = sdh.create_test_catchment_structure()
>>> e_ids = ['node.n2', 'node.n4']
>>> sub_sims = simulation.split_to_subcatchments(e_ids)
>>> for k in sub_sims:
>>> print(k)
>>> print(sub_sims[k].get_node_ids())
>>> print(sub_sims[k].get_node_names())
node.n4
['n4', 'n3', 'n1']
['n4_name', 'n3_name', 'n1_name']
node.n2
['n2', 'n5']
['n2_name', 'n5_name']
remainder
['n6']
['n6_name']
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
subset_catchment(element_id, action='keep_above')
¶
Subsets a catchment, keeping only a portion above or below a node, link or subarea.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
str
|
id of the element to cut at. |
required |
action |
str
|
how to cut; currently limited to 'keep_above' |
'keep_above'
|
Returns:
Name | Type | Description |
---|---|---|
Simulation |
a subcatchment simulation, cookie cut from the base simulation. Deep clone of objects. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
swap_model(model_id, what='runoff')
¶
Clone and change a simulation, using another model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
str
|
the identifier of the new model to use, e.g. 'GR4J' |
required |
what |
str
|
character identifying the type of structure replaced: 'runoff', 'channel_routing' |
'runoff'
|
Returns:
Name | Type | Description |
---|---|---|
Simulation |
Simulation
|
A SWIFT simulation object, clone of the simulation but with a new model type in use. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
use_state_initialises(state_initialiser)
¶
Sets the state initialiser to use for a simulation. This forces the removal of any prior state initialiser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_initialiser |
StateInitialiser
|
the new state initialiser to use |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
SimulationMixin
¶
A parent class for simulation objects. Most users are unlikely to explicitly use it.
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
exec_simulation(reset_initial_states=True)
¶
Execute a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reset_initial_states |
bool
|
logical, should the states of the model be reinitialized before the first time step. |
True
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_played_varnames()
¶
Gets all the names of states fed an input time series
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The names of the state variables fed over the simulation with values from a time series |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
get_recorded_varnames()
¶
Gets all the names of the recorded states
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The names of the state variables being recorded into time series |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
record_state(var_ids=CATCHMENT_FLOWRATE_VARID, recording_provider=None, data_ids=None)
¶
Record a time series of one of the state of the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_ids |
VecStr
|
identifier(s) of the output variable recorded to a time series, e.g. 'Catchment|StreamflowRate' or 'subcatchment.Subarea.runoff'. Defaults to CATCHMENT_FLOWRATE_VARID. |
CATCHMENT_FLOWRATE_VARID
|
recording_provider |
TimeSeriesLibrary
|
description. Defaults to None. |
None
|
data_ids |
VecStr
|
description. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
description |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
TransformParameteriser
¶
Bases: HypercubeParameteriser
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
add_transform(param_name, inner_param_name, transform_id, a=1.0, b=0.0)
¶
Create a parameteriser for which parameter transformations can be defined
This allows to define e.g. a virtual parameter log_X instead of calibrating on the parameter X.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_name |
str
|
the name of the meta-parameter. Note that it can be the same value as inner_param_name, but this is NOT recommended. |
required |
inner_param_name |
str
|
the name of the parameter being transformed |
required |
transform_id |
str
|
identifier for a known bijective univariate function |
required |
a |
float
|
parameter in Y = F(ax+b). Defaults to 1.0. |
1.0
|
b |
float
|
parameter in Y = F(ax+b). Defaults to 0.0. |
0.0
|