swift2 code documentation¶
placeholder
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
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/classes.py
module common¶
module const¶
module doc_helper¶
configure_hourly_gr4j(simulation)
¶
Configure a simulation with GR4J models for hourly time step modelling
Configure a simulation with GR4J models for hourly time step modelling
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
create_gr4jh_parameters()
¶
Get a parameter set that configures GR4J for hourly operations
Get a parameter set that configures GR4J for hourly operations
Returns:
Name | Type | Description |
---|---|---|
HyperCubeParameteriser |
a parameter set that can be applied to SWIFT systems with GR4J |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
define_gr4j_scaled_parameter(ref_area=250, time_span=3600, pspec_gr4j=None)
¶
define a scaled and transformed parameterizer for GR4J
define a scaled and transformed parameterizer for GR4J
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_area |
float
|
the reference area in square kilometres |
250
|
time_span |
int
|
the time span of the simulation intented for this model, in seconds |
3600
|
pspec_gr4j |
pd.DataFrame
|
optional - data frame specifying the feasible parameter space for parameters x1 to x2 of GR4J |
None
|
Returns:
Name | Type | Description |
---|---|---|
TransformParameteriser |
a parameterizer for GR4J, combining time and area scaling and superimposed with log10 transforms for x1, x3, x4 and arc-sinh for x2 |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
get_catchment_dot_graph(simulation)
¶
Gets a catchment representation in Graphviz DOT format
Gets a catchment representation in Graphviz DOT format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
a string in a notation usable by the DiagrammeR package. |
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
get_free_params(model_id)
¶
Get a default parameter set for models
Get a default parameter set for models, as a data frame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
Any
|
an identifier for the model, e.g. 'GR5H' |
required |
Returns:
Type | Description |
---|---|
a data frame with Min, Max, Value, Name |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
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 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
gr4j_scaled_parameteriser(reference_area=240, t_step_seconds=3600)
¶
Get a time step and area scaled parameterizer for the GR4 model structure
Get a time step and area scaled parameterizer for the GR4 model structure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_area |
Any
|
The reference area in km^2 for the parameter x4 |
240
|
t_step_seconds |
Any
|
The simulation time step in seconds. |
3600
|
Returns:
Type | Description |
---|---|
A SWIFT catchment parameterizer for GR4 model structures |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
inspect(simulation, element='link', id='1', full_names=False)
¶
Inspect an element of a catchment model
Inspect the current state values of an element of a catchment model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
element |
Any
|
type of top level element, within c('link','node','subarea') |
'link'
|
id |
Any
|
SWIFT simulation |
'1'
|
full_names |
Any
|
if TRUE returns the full names of state variable ids (e.g. link.link_1.OutlfowRate) |
False
|
Returns:
Type | Description |
---|---|
named numeric vector, the current state values of the catchment model element |
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
sample_catchment_model(site_id='South_Esk', config_id='catchment')
¶
Deserialize a basic catchment structure from the package sample data
Deserialize a basic catchment structure from the package sample data. This function is mostly for documentation purposes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_id |
Any
|
a site identifier |
'South_Esk'
|
config_id |
Any
|
a variable identifier for a model structure valid for the given site_id |
'catchment'
|
Returns:
Type | Description |
---|---|
a model simulation |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
sample_series(site_id='MMH', var_name='rain')
¶
Deserialize information to a UTC time series
Deserialize information to a UTC time series. This function is overcoming some behaviors in saving/loading xts series to/from binary RData format. Usage is not intended for most users.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_id |
Any
|
a site identifier |
'MMH'
|
var_name |
Any
|
a variable identifier valid for the given site_id |
'rain'
|
Returns:
Type | Description |
---|---|
an xts time series with UTC time indexing |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
sce_parameter(nparams, nshuffle=40)
¶
Create SCE parameters suited for a given number of parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nparams |
int
|
number of free model parameters |
required |
nshuffle |
int
|
maximum number of shuffles to do, if no other termination criterion. Defaults to 40. |
40
|
Returns:
Type | Description |
---|---|
Dict[str, float]
|
Dict[str,float]: SCE hyperparameters |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
set_loglik_param_keys(a='a', b='b', m='m', s='s', maxobs='maxobs', ct='ct', censopt='CensOpt')
¶
Specify the global parameter names to use in the log-likelihood calculation
Specify the global parameter names to use in the log-likelihood calculation. Consequence of prehistoric legacy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
str
|
the name of the a parameter |
'a'
|
b |
str
|
the name of the b parameter |
'b'
|
m |
str
|
the name of the m parameter |
'm'
|
s |
str
|
the name of the s parameter |
's'
|
maxobs |
str
|
the name of the maxobs parameter |
'maxobs'
|
ct |
str
|
the name of the ct parameter |
'ct'
|
censopt |
str
|
the name of the censopt parameter |
'CensOpt'
|
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
set_sample_data(model_sim, site_id='MMH', rain_data_var='rain', evap_data_var='evap', rain_model_var='P', evap_model_var='E', t_step='daily')
¶
Sets sample input data into a model simulation
Sets input data from the included sample data into a model simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_sim |
Any
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "MODEL_SIMULATION_PTR" |
required |
site_id |
Any
|
sample data site identifier |
'MMH'
|
rain_data_var |
Any
|
time series ID for the rainfall in the sample data |
'rain'
|
evap_data_var |
Any
|
time series ID for the evaporation in the sample data |
'evap'
|
rain_model_var |
Any
|
sub-area runoff model state identifier for the rainfall, e.g. 'P' |
'P'
|
evap_model_var |
Any
|
sub-area runoff model state identifier for the evaporation, e.g. 'E' |
'E'
|
t_step |
Any
|
identifier for the time step to set the simulation to. |
'daily'
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
short_var_id(var_ids)
¶
Shorten long model variable identifiers to the short model variable name
Shorten long model variable identifiers to the short model variable name. This is useful for instance to prepare time series names for multi-plot displays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_ids |
Any
|
character vector |
required |
Returns:
Type | Description |
---|---|
VecStr
|
the short model variable identifiers |
Examples:
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/doc_helper.py
module helpers¶
module internal¶
simplify_time_series(input_ts)
¶
simplify a 1D time series object to a representation suitable for portable serialisation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ts |
TimeSeriesLike
|
time series |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str,Any]: dictionary with keys "tsgeom" for the time series geometry, and "tsvalues" for its values. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/internal.py
to_interop_univariate_series(ts, from_date=None, to_date=None)
¶
Convert an univariate python time series to a representation suitable for interoperability with a C API
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ts |
TimeSeriesLike
|
Python native time series |
required |
from_date |
ConvertibleToTimestamp
|
start timestamp of the time series to subset to. Defaults to None. |
None
|
to_date |
ConvertibleToTimestamp
|
end timestamp of the time series to subset to. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, TimeSeriesGeometryNative]
|
Tuple[np.ndarray, TimeSeriesGeometryNative]: univeriate data and time series geometry for interop. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/internal.py
module model_definitions¶
cookie_cut_dendritic_catchment(simulation, bottom_element_id, top_element_ids)
¶
cookie cut a dendritic catchment (without confluences)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
base catchment simulation |
required |
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 |
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/model_definitions.py
get_catchment_structure(simulation)
¶
Gets the essential connective structure of a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
base catchment simulation |
required |
Returns:
Type | Description |
---|---|
Dict
|
|
Examples:
>>> _, simulation = sdh.create_test_catchment_structure()
>>> smd.get_catchment_structure(simulation)
{'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/model_definitions.py
split_to_subcatchments(simulation, split_element_ids, include_upstream=None)
¶
Split a catchment in subcatchments, given a list of node/link element identifiers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
base catchment simulation |
required |
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 = smd.split_to_subcatchments(simulation, 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/model_definitions.py
subset_catchment(simulation, 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 |
---|---|---|---|
simulation |
Simulation
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "MODEL_SIMULATION_PTR" |
required |
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 |
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/model_definitions.py
module parameteriser¶
MhData
¶
Data log from metaheuristic calibration processes
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 |
|
data
property
¶
The inner data of this data log
bound_fitness(obj_lims=None)
¶
Return a copy of the log data with the fitness measure bound by min/max limits
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_lims |
Sequence[float]
|
min/max limits, length 2. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: log data with bound fitness |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
rename_columns(colnames_map)
¶
Rename the columns of the data log according to a mapping.
This is handy for instance to change fully qualified parameter names such as 'subarea.Wolf_Creek.x1' to just 'x1' to produce more legible plots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colnames_map |
Dict[str, str]
|
mapping |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
subset_by_message(pattern='Initial.*|Reflec.*|Contrac.*|Add.*')
¶
Subset the log by filtering the 'Message' column by a regexp pattern
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
str
|
regexp pattern, filter definition |
'Initial.*|Reflec.*|Contrac.*|Add.*'
|
Returns:
Name | Type | Description |
---|---|---|
Any |
MhData
|
New MhData object with subset data |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
subset_by_pattern(colname, pattern)
¶
Subset the log by filtering an attribute by a regexp pattern
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colname |
str
|
column name to filter on |
required |
pattern |
str
|
regexp pattern, filter definition |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
MhData
|
New MhData object with subset data |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
add_to_hypercube(parameteriser, specs)
¶
Add entries to a hypercube
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
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/parameteriser.py
add_transform(parameteriser, 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 |
---|---|---|---|
parameteriser |
TransformParameteriser
|
A TransformParameteriser wrapper, or a type inheriting from it |
required |
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
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
apply_sys_config(parameteriser, simulation)
¶
Apply a model configuration to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
simulation |
Simulation
|
simulation |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
as_py_structure(x)
¶
Try to convert an external pointer to a native python representation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Any
|
object, presumably wrapper around an Xptr, to convert to a 'pure' python representation |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
backtransform(parameteriser)
¶
Get the parameteriser values in the untransformed space
Get the parameteriser values in the untransformed space, i.e. remove any transform added via wrapTransform. This allows to transform back e.g. from a virtual parameter log_X to the underlying model (or even virtual/meta) parameter X.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
Returns:
Type | Description |
---|---|
[HypercubeParameteriser]: The parameters definitions without the transforms (if there are any) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
bound_values_df(x, colname, lim=None)
¶
min/max bound a column in a data frame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
[type]
|
a data frame |
required |
colname |
[type]
|
a character vector, name of the column to bound |
required |
lim |
[type]
|
a num vector of the min/max limits to apply, for instance c(0, 1). Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
concatenate_parameterisers(*args, strategy='')
¶
Concatenate 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/parameteriser.py
create_multisite_obj_parameteriser(func_parameterisers, func_identifiers, prefixes=None, mix_func_parameteriser=None, hydro_parameteriser=None)
¶
Builds a parameteriser usable with a multisite multiobjective calculator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func_parameterisers |
[type]
|
list of external pointers, parameterisers for each function of a multiobjective calculation. |
required |
func_identifiers |
[type]
|
character, identifiers for each of the objectives defined in an multisite objective definition. |
required |
prefixes |
[type]
|
Optional prefixes to use to disambiguate short parameter names used in each function of a multiobjective calculator.. Defaults to None. |
None
|
mix_func_parameteriser |
[type]
|
parameteriser, default None. (FUTURE) Optional parameteriser used in mixing the multiple objectives.. Defaults to None. |
None
|
hydro_parameteriser |
[type]
|
parameteriser, default None. Optional parameteriser applied to the simulation model.. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
create_muskingum_param_constraints(inner_parameters, delta_t=1, param_name_k='K', param_name_x='X', simulation=None)
¶
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. |
required |
delta_t |
int
|
the simulation time step in HOURS. Defaults to 1. |
1
|
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'
|
simulation |
[Simulation]
|
the model simulation from which link properties are inspected to define constraints. The links' parameters must already be set.. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
[description] |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
create_parameter_sampler(seed, parameteriser, type)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed |
[type]
|
seed integer, the seed to use for the sampler |
required |
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
type |
str
|
identifying a method such as 'urs' for uniform random sampling. |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
create_parameteriser(type='Generic subareas', specs=None)
¶
Create a SWIFT parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
A string identifying the (likely SWIFT-specific) 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. |
None
|
Returns:
Type | Description |
---|---|
[HypercubeParameteriser]: new parameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
create_sce_optim_swift(objective, termination_criterion, sce_params, population_initialiser)
¶
Build an SCE optimiser for a SWIFT model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objective |
ObjectiveEvaluator
|
an objective calculator |
required |
termination_criterion |
SceTerminationCondition
|
An object that can be passed to SCE for testing the completion of the algorithm. |
required |
sce_params |
dict
|
optional; parameters controlling the behavior of the SCE optimisers. |
required |
population_initialiser |
CandidateFactorySeed
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type HYPERCUBE_PTR or coercible to it, or a type of object that can seed a sampler i.e. coercible to a type CANDIDATE_FACTORY_SEED_WILA_PTR. If the argument is a hypercube, a uniform random sampler is created. |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
create_sce_termination_wila(type, arguments)
¶
Create a type of termination criteria suitable for the SCE algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
A type of termination criterion; currently at least "relative standard deviation" and "maximum evaluations" are valid options |
required |
arguments |
Sequence[str]
|
Arguments, in string forms even for numeric values, options for the selected type. |
required |
Returns:
Name | Type | Description |
---|---|---|
SceTerminationCondition |
SceTerminationCondition
|
[description] |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
evaluate_score_for_parameters(objective, parameteriser)
¶
Computes the value of an objective for a given set of parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objective |
[type]
|
an objective calculator |
required |
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
example_parameteriser(type, strict=False)
¶
Get examples of typical parameterisers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
identifier for a type of parameteriser including 'log-likelihood' |
required |
strict |
bool
|
If True an error is raised if the type is not found, otherwise a dummy empty parameteriser is returned.. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
execute_optimisation(optimiser)
¶
Launch an optimization task, as defined by the object passed as an argument
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimiser |
Optimiser
|
the instance of the optimiser that has been created for the optimisation task about to be launched. |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
feasible_muskingum_bounds(simulation, delta_t_hours=1)
¶
[summary]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
[description] |
required |
delta_t_hours |
int
|
[description]. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
filtered_parameters(parameteriser)
¶
Wrap a parameteriser in a filter that can hide some parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it. A deep copy of the input is taken. |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_best_score(scores_population, score_name='NSE', convert_to_py=False)
¶
Gets the best score in a population for a given objective
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scores_population |
[type]
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type VEC_OBJECTIVE_SCORES_PTR |
required |
score_name |
str
|
name of the objective to use for sorting. Defaults to "NSE". |
'NSE'
|
convert_to_py |
bool
|
should the returned score be converted to an R representation. Default False. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_default_sce_parameters()
¶
[summary]
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_logger_content(optimiser, add_numbering=False)
¶
Gets logger content on an optimiser, recorded detail of the optimisation process for post-optimisation analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimiser |
[type]
|
the instance of the optimiser that has been created for the optimisation task about to be launched. |
required |
add_numbering |
bool
|
Add an explicit column for numbering the lines of the log. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The data log of the optimiser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_marginal_termination(tolerance=1e-06, cutoff_no_improvement=10, max_hours=0.05)
¶
Create an termination criterion based on the rate of marginal fitness improvement
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolerance |
[type]
|
the increment in the objective below which the improvement is considered negligible. Defaults to 1e-06. |
1e-06
|
cutoff_no_improvement |
int
|
the maximum number of successive times the algorithm fails to improve the objective function.. Defaults to 10. |
10
|
max_hours |
float
|
the maximum wall time runtime for the optimisation. Defaults to 0.05. |
0.05
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_max_iteration_termination(max_iterations=1000)
¶
Create an termination criterion based on the number of objective evaluations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_iterations |
int
|
number of iterations, which, if less than total count of optim objective evaluations, defines optim termination.. Defaults to 1000. |
1000
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_max_runtime_termination(max_hours=0.05)
¶
Create an termination criterion based on the wall clock runtime
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_hours |
float
|
the maximum wall time runtime in hours for the optimisation. Defaults to 0.05. |
0.05
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
get_score_at_index(scores_population, index)
¶
Get an objective scores in a vector thereof
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scores_population |
[type]
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type VEC_OBJECTIVE_SCORES_PTR |
required |
index |
int
|
one-based index in the population |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
hide_parameters(parameteriser, 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 |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
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/parameteriser.py
is_hypercube(p_set)
¶
Is the object a native parameteriser that can be cast as a hypercube?
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p_set |
CffiNativeHandle
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
is_sampler_seeding(obj)
¶
Is the argument a native object that is a seeded candidate parameteriser factory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
CffiNativeHandle
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
is_score(x)
¶
OBJECTIVE_SCORES_WILA_PTR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
[type]
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
is_set_of_scores(x)
¶
VEC_OBJECTIVE_SCORES_PTR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
[type]
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
linear_parameteriser(param_name, state_name, scaling_var_name, min_p_val, max_p_val, value, selector_type='subareas', intercept=0.0)
¶
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
|
intercepts in the linear relationship(s). Defaults to 0.0. |
0.0
|
Returns:
Type | Description |
---|---|
[ScalingParameteriser]: new ScalingParameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
linear_parameteriser_from(data_frame, selector_type='subareas')
¶
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:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
make_state_init_parameteriser(parameteriser)
¶
[summary]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
Returns:
Type | Description |
---|---|
[StateInitParameteriser]: new state initialisation parameteriser |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
parameteriser_as_dataframe(parameteriser)
¶
Convert an external object hypercube parameteriser to a pandas data frame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
Returns:
Type | Description |
---|---|
[type]: [a data frame] |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
parameteriser_for_score(score)
¶
Gets the parameteriser for a score
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score |
[type]
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
scores_as_dataframe(scores_population)
¶
Convert objective scores to a pandas data frame representation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scores_population |
[type]
|
[description] |
required |
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
set_calibration_logger(optimiser, type='')
¶
Sets logging on an optimiser, so as to record a detail of the optimisation process for post-optimisation analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimiser |
[type]
|
[description] |
required |
type |
str
|
[description]. Defaults to "". |
''
|
Returns:
Type | Description |
---|---|
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
set_hypercube(parameteriser, specs)
¶
Set the properties of a hypercube parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
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/parameteriser.py
set_max_parameter_value(parameteriser, variable_name, value)
¶
Sets the maximum value of a model parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
variable_name |
str or iterable of str
|
model variable state identifier(s) |
required |
value |
numeric or iterable of numeric
|
value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
set_min_parameter_value(parameteriser, variable_name, value)
¶
Sets the minimum value of a model parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
variable_name |
str or iterable of str
|
model variable state identifier(s) |
required |
value |
numeric or iterable of numeric
|
value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
set_parameter_value(parameteriser, variable_name, value)
¶
Sets the value of a model parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
variable_name |
str or iterable of str
|
model variable state identifier(s) |
required |
value |
numeric or iterable of numeric
|
value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
show_parameters(parameteriser, patterns, regex=False, starts_with=False)
¶
Show some parameters (from the outside e.g. optimisers) in a filter parameteriser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
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/parameteriser.py
sort_by_score(scores_population, score_name='NSE')
¶
Sort objective scores according to one of the objective values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scores_population |
[type]
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type VEC_OBJECTIVE_SCORES_PTR |
required |
score_name |
str
|
name of the objective to use for sorting. Defaults to "NSE". |
'NSE'
|
Returns:
Name | Type | Description |
---|---|---|
VectorObjectiveScores |
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type VEC_OBJECTIVE_SCORES_PTR |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
subcatchment_parameteriser(parameteriser, subcatchment)
¶
Create a parameteriser that gets applied to a subset of a whole catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
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:
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/parameteriser.py
wrap_transform(parameteriser)
¶
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 |
---|---|---|---|
parameteriser |
HypercubeParameteriser
|
A HypercubeParameteriser wrapper, or a type inheriting from it |
required |
Returns:
Name | Type | Description |
---|---|---|
TransformParameteriser |
A new parameteriser (TransformParameteriser) which has methods to define parameter transforms |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/parameteriser.py
module play_record¶
get_played(simulation, var_ids=None, start_time=None, end_time=None)
¶
Retrieves a played time series from a simulation
Retrieves a played time series from a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_ids |
Any
|
name of the output variable played to a time series. '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 |
Any
|
An optional parameter, the start of a period to subset the time series |
None
|
end_time |
Any
|
An optional parameter, the end of a period to subset the time series |
None
|
Returns:
Type | Description |
---|---|
an xts time series, possibly multivariate. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/play_record.py
get_played_varnames(simulation)
¶
Gets all the names of states fed an input time series
Gets all the names of states fed an input time series
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
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/play_record.py
get_recorded(simulation, var_ids=None, start_time=None, end_time=None)
¶
Retrieves a recorded time series from a simulation
Retrieves a recorded time series from a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_ids |
Any
|
name of the output variable recorded to a time series. 'Catchment|StreamflowRate'. If missing, a multivariate time series of all recorded states is returned; this may be a large amount of data. |
None
|
start_time |
Any
|
An optional parameter, the start of a period to subset the time series |
None
|
end_time |
Any
|
An optional parameter, the end of a period to subset the time series |
None
|
Returns:
Type | Description |
---|---|
an xts time series, possibly multivariate. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/play_record.py
get_recorded_ensemble_forecast(simulation, var_id, start_time=None, end_time=None)
¶
Retrieves a recorded time series from a simulation
Retrieves a recorded time series from a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_ids |
Any
|
name of the output variable recorded to a time series. 'Catchment|StreamflowRate'. If missing, a multivariate time series of all recorded states is returned; this may be a large amount of data. |
required |
start_time |
Any
|
NOT USED YET An optional parameter, the start of a period to subset the time series |
None
|
end_time |
Any
|
NOT USED YET An optional parameter, the end of a period to subset the time series |
None
|
Returns:
Type | Description |
---|---|
an xts time series, possibly multivariate. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/play_record.py
get_recorded_varnames(simulation)
¶
Gets all the names of the recorded states
Gets all the names of the recorded states
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The names of the state variables being recorded into time series |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/play_record.py
play_ensemble_forecast_input(simulation, input_ts, var_id)
¶
Sets time series as input to a simulation
Sets time series as input to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Any
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "ENSEMBLE_FORECAST_SIMULATION_PTR" |
required |
input_ts |
Any
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "ENSEMBLE_FORECAST_TIME_SERIES_PTR" |
required |
var_id |
Any
|
character of length one, the variable identifier to use |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/play_record.py
play_input(simulation, input_ts, var_ids=None)
¶
Sets time series as input to a simulation
Sets time series as input to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
input_ts |
Any
|
an xts time series, or an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "ENSEMBLE_FORECAST_TIME_SERIES_PTR". if an xts time series column names must be valid model variable identifiers, unless explicitely provided via varIds |
required |
var_ids |
Any
|
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/play_record.py
play_inputs(simulation, 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 |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
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/play_record.py
play_subarea_input(simulation, input, subarea_name, input_name)
¶
Sets time series as input to a simulation
Sets time series as input to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
input |
Any
|
an xts time series. |
required |
subarea_name |
Any
|
a valid name of the subarea |
required |
input_name |
Any
|
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/play_record.py
record_state(simulation, var_ids=CATCHMENT_FLOWRATE_VARID, recording_provider=None, data_ids=None)
¶
Record a time series of one of the state of the model
Record a time series of one of the state of the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Any
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "MODEL_SIMULATION_PTR", "ENSEMBLE_SIMULATION_PTR" or "ENSEMBLE_FORECAST_SIMULATION_PTR" |
required |
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/play_record.py
module proto¶
module prototypes¶
estimate_transformation_parameters(calib_obs, estimation_start, estimation_end, censor_threshold, exclusion, exclusion_start, exclusion_end, termination_condition=None)
¶
Estimate the transformation parameters for a log-likelihood for a series of observations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
calib_obs |
TimeSeriesLike
|
An timeseries of observed data |
required |
estimation_start |
datetime
|
Start of estimation period |
required |
estimation_end |
datetime
|
End of estimation period |
required |
censor_threshold |
float
|
The value below which observations are treated a censored data (Default=0.0) |
required |
exclusion |
bool
|
Start of period exclued from estimation |
required |
exclusion_start |
datetime
|
End of period exclued from estimation |
required |
exclusion_end |
datetime
|
Use the exclusion period (bool) |
required |
termination_condition |
SceTerminationCondition
|
A SWIFT termination condition used by the optimisation. Default max runtime of ~3 minutes if None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
HypercubeParameteriser |
HypercubeParameteriser
|
transformation parameters |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/prototypes.py
module simulation¶
check_simulation(simulation)
¶
Checks whether a simulation is configured to a state where it is executable
Checks whether a simulation is configured to a state where it is executable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
create_catchment(node_ids, node_names, link_ids, link_names, link_from_node, link_to_node, runoff_model_name='GR4J', areas_km2=None)
¶
Create a SWIFT catchment with a specified hydrologic model
Create a SWIFT catchment with a specified hydrologic model. This function is intended mostly for testing, not for usual modelling code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_ids |
Any
|
character, node unique identifiers |
required |
node_names |
Any
|
character, node display names |
required |
link_ids |
Any
|
character, links unique identifiers |
required |
link_names |
Any
|
character, links display names |
required |
link_from_node |
Any
|
character, identifier of the links' upstream node |
required |
link_to_node |
Any
|
character, identifier of the links' downstream node |
required |
runoff_model_name |
Any
|
A valid, known SWIFT model name (e.g. 'GR5H') |
'GR4J'
|
areas_km2 |
Any
|
The areas in square kilometres |
None
|
Returns:
Type | Description |
---|---|
A SWIFT simulation object (i.e. a model runner) |
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
create_ensemble_forecast_simulation(simulation, data_library, start, end, input_map, lead_time, ensemble_size, n_time_steps_between_forecasts)
¶
Create an ensemble forecast simulation
Create an ensemble forecast simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
data_library |
Any
|
external pointer type ENSEMBLE_DATA_SET_PTR, or a Python class wrapper around it |
required |
start |
Any
|
the start date of the simulation. The time zone will be forced to UTC. |
required |
end |
Any
|
the end date of the simulation. The time zone will be forced to UTC. |
required |
input_map |
Any
|
a named list were names are the data library data identifiers, and values are character vectors with model state identifiers. |
required |
lead_time |
Any
|
integer, the length in time steps of the forecasts. |
required |
ensemble_size |
Any
|
ensemble size |
required |
n_time_steps_between_forecasts |
Any
|
nTimeStepsBetweenForecasts |
required |
Returns:
Type | Description |
---|---|
An external pointer |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
create_subarea(model_name, area_km2)
¶
Create a SWIFT subarea with a specified hydrologic model
Create a SWIFT subarea with a specified hydrologic model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name |
Any
|
A valid, known SWIFT model name (e.g. 'GR5H') |
required |
area_km2 |
Any
|
The area in square kilometres |
required |
Returns:
Type | Description |
---|---|
A SWIFT simulation object (i.e. a model runner) |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
create_subarea_simulation(data_id='MMH', simul_start='1990-01-01', simul_end='2005-12-31', model_id='GR4J', tstep='daily', varname_rain='P', varname_pet='E')
¶
Creates a one sub-catchment simulation
Creates a one sub-catchment simulation. This function is intended for creating sample simulations, not for use in production.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataId |
Any
|
data identifier in swift_sample_data |
required |
simulStart |
Any
|
ISO string for the simulation start date time |
required |
simulEnd |
Any
|
ISO string for the simulation end date time |
required |
modelId |
Any
|
model identifier |
required |
tstep |
Any
|
character, 'daily' or 'hourly' |
'daily'
|
varNameRain |
Any
|
variable name to assign rainfall to |
required |
varNamePet |
Any
|
variable name to assign PET to |
required |
Returns:
Type | Description |
---|---|
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/simulation.py
exec_simulation(simulation, reset_initial_states=True)
¶
Execute a simulation
Execute a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
reset_initial_states |
Any
|
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/simulation.py
get_link_ids(simulation)
¶
Gets all the identifiers of the links in the catchment
Gets all the identifiers of the links in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The identifiers of the links in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_link_names(simulation)
¶
Gets all the names of the links in the catchment
Gets all the names of the links in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The names of the links in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_node_ids(simulation)
¶
Gets all the identifiers of the nodes in the catchment
Gets all the identifiers of the nodes in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The identifiers of the nodes in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_node_names(simulation)
¶
Gets all the names of the nodes in the catchment
Gets all the names of the nodes in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The names of the nodes in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_state_value(simulation, var_id)
¶
Gets the value(s) of a model state(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_id |
VecStr
|
string or sequence of str, model variable state identifier(s) |
required |
Returns:
Type | Description |
---|---|
numeric vector, value(s) of the requested model states |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_subarea_ids(simulation)
¶
Gets all the identifiers of the sub-areas in the catchment
Gets all the identifiers of the sub-areas in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The identifiers of the sub-areas in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_subarea_names(simulation)
¶
Gets all the names of the sub-areas in the catchment
Gets all the names of the sub-areas in the catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
Returns:
Type | Description |
---|---|
The names of the sub-areas in the catchment |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
get_variable_ids(simulation, element_id=None, full_id=True)
¶
Gets all the names of the variables of an element within a catchment
Gets all the names of the variables of an element (link, node, subarea) within a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
element_id |
Any
|
a character, identifier of the element within the catchment |
None
|
full_id |
Any
|
boolean, if TRUE return the full hierarchical identifier |
True
|
Returns:
Type | Description |
---|---|
character vector, names (identifiers) of model states in the element |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
is_variable_id(simulation, var_id)
¶
Is a variable identifier valid for a simulation
Is a variable identifier valid for a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_id |
Any
|
a character, identifier(s) of the variable(s) |
required |
Returns:
Type | Description |
---|---|
logical vector |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
reset_model_states(simulation)
¶
Reset the model states of a simulation, and apply one or more state initialers if the simulation is configured with any.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
simulation |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
set_error_correction_model(simulation, model_id, element_id, length=1, seed=0)
¶
Add an error correction model to an element in a catchment
Add an error correction model to an element in a catchment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
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/simulation.py
set_simulation_span(simulation, start, end)
¶
Sets simulation span
Sets the simulation span
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
start |
Any
|
the start date of the simulation. The time zone will be forced to UTC. |
required |
end |
Any
|
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/simulation.py
set_simulation_time_step(simulation, name)
¶
Sets the time step of a SWIFT simulation
Sets the time step of a SWIFT simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
name |
Any
|
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/simulation.py
set_state_value(simulation, var_id, value)
¶
Sets the value of a model state
Sets the value of a model state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
var_id |
(str, Sequence[str])
|
character, model variable state identifier(s) |
required |
value |
(float, int, bool, Sequence)
|
numeric value(s) |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
set_states(simulation, states)
¶
Apply memory states to a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
simulation |
required |
states |
MemoryStates
|
memory states |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
snapshot_state(simulation)
¶
Take a snapshot of the memory states of a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
model simulation |
required |
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/simulation.py
sort_by_execution_order(simulation, split_element_ids, sorting_option='')
¶
Sort the specified element ids according to the execution order of the simulation
Sort the specified element ids according to the execution order of the simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
split_element_ids |
Any
|
a character vector with element identifiers such as 'node.n1', 'link.linkId_2' |
required |
sorting_option |
Any
|
a character - for future options. Ignored for now. |
''
|
Returns:
Type | Description |
---|---|
values in split_element_ids sorted by simulation execution order |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/simulation.py
swap_model(simulation, model_id, what='runoff')
¶
Clone and change a simulation, using another runoff model
Clone and change a simulation, using another runoff model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A swift simulation object |
required |
model_id |
Any
|
the identifier of the new model to use, e.g. 'GR4J' |
required |
what |
Any
|
character identifying the type of structure: 'runoff', 'channel_routing' |
'runoff'
|
Returns:
Type | Description |
---|---|
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/simulation.py
module statistics¶
createCompositeObjective(simulation, state_name, observation, yamlstring_statistic, start_date, end_date)
¶
Creates a composite objective calculator
Creates a composite objective calculator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A SWIFT simulation object (i.e. a model runner) |
required |
state_name |
Any
|
The name identifying the model state variable to calibrate against the observation |
required |
observation |
Any
|
an xts |
required |
yamlstring_statistic |
Any
|
a yaml string representing objective functions and weights eg... |
required |
start_date |
Any
|
start date of the period to calculate statistics on |
required |
end_date |
Any
|
end date of the period to calculate statistics on |
required |
Returns:
Type | Description |
---|---|
objective evaluator |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/statistics.py
create_multisite_objective(simulation, statspec, observations, weights)
¶
Creates an objective that combines multiple statistics
Creates an objective that combines multiple statistics. Used for joined, "whole of catchment" calibration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A SWIFT simulation object (i.e. a model runner) |
required |
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 |
Examples |
|
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/statistics.py
create_objective(simulation, state_name, observation, statistic, start_date, end_date)
¶
Creates an objective calculator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation |
Simulation
|
A SWIFT simulation object (i.e. a model runner) |
required |
state_name |
Any
|
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 |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/statistics.py
get_score(objective_evaluator, p_set)
¶
Evaluate an objective for a given parameterisation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objective_evaluator |
ObjectiveEvaluator
|
objective evaluator |
required |
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/statistics.py
multi_statistic_definition(model_var_ids, statistic_ids, objective_ids, objective_names, starts, ends)
¶
Collate information for use in multisite multiobjective definition
Collate information for use in multisite multiobjective definition
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_var_ids |
Any
|
character vector, model state identifiers where statistics are calculated |
required |
statistic_ids |
Any
|
character vector, identifiers for bivariate statistics (e.g. nse, lognse, et.) |
required |
objective_ids |
Any
|
character vector, identifiers for the objectives. Can be the same as modelVarIds. |
required |
objective_names |
Any
|
character vector, display names for the objectives. Can be the same as modelVarIds. |
required |
starts |
Any
|
POSIXct vector of start dates for statistics |
required |
ends |
Any
|
POSIXct vector of end dates for statistics |
required |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/statistics.py
module system¶
get_last_swift_error()
¶
Retrieve the message for the last known error in SWIFT
Retrieve the message for the last known error in SWIFT. Error means here that an exception was thrown by the core SWIFT library. The SWIFT C API intercepts these messages to make them available to users for diagnosis.
Returns:
Type | Description |
---|---|
A character, the message for the last known error in SWIFT. |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/system.py
runoff_model_ids()
¶
Gets all the names of known runoff models
Gets all the names of known runoff models
Returns:
Type | Description |
---|---|
character vector, names (identifiers) of runoff models |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/system.py
runoff_model_var_ids(model_id)
¶
Gets all the names of the variables a runoff model exposes
Gets all the names of the variables a runoff model exposes for dynamic query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
Any
|
character; A recognized model identifier |
required |
Returns:
Type | Description |
---|---|
a character vector, the known model variable that can be set/gotten |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/system.py
set_default_max_parallelism_threads(n_threads=-1)
¶
Sets the level of thread parallelism to use by default for new objects such as optimisers. May be overwritten for each instance afterwards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_threads |
int
|
number of threads. Positive, or -1 to mean "as many as available" |
-1
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/system.py
set_maximum_threads(optimiser, n_threads=-1)
¶
Sets the maximum level of parallelism of an optimizer
Sets the maximum level of threading of an optimizer. NOTE: this also modifies a global default for further optimizers, which is a hack for ERRIS, acceptable but still likely to change in the future. It is VERY important to use this function prior to running calibrations on some systems such as clusters, as the default hardware detection may not be appropriate if the cluster node is not dedicated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
Any
|
an S4 object 'ExternalObjRef' [package "cinterop"] with external pointer type "OPTIMIZER_PTR" |
required |
n_threads |
Any
|
integer, maximum number of threads allowed. If -1, the system defaults to using all but one of the CPU cores detected on the hardware. |
-1
|
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/system.py
module utils¶
c(*args)
¶
Emulate the R c (concatenate) function, somewhat.
Returns:
Type | Description |
---|---|
np.ndarray
|
np.ndarray: [description] |
is_common_iterable(obj)
¶
True if an object is iterable but not a string (str)
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/utils.py
mk_full_data_id(*args)
¶
Create swift IDs (dot separated hierarchical naming scheme)
Create swift IDs (dot separated hierarchical naming scheme). Note that the behavior is different than 'paste' for empty characters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Any
|
one or more character vectors. |
()
|
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/utils.py
paste(*lists, sep=' ', collapse=None)
¶
Port of R paste function
paste0(*lists, collapse=None)
¶
paste_2(x, y, sep=' ')
¶
Port of R vectorised paste, for 2 elements
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/utils.py
sort_by(x, unsorted_reference, sorted_reference)
¶
Sort one vector according to the known reordering of another
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Any
|
values to sort |
required |
unsorted_reference |
Any
|
unique 'keys' corresponding to each element in x |
required |
sorted_reference |
Any
|
set of 'keys', identical as a set to unsorted_reference, but sorted |
required |
Returns:
Type | Description |
---|---|
the values in x reordered such that the same reordering of unsorted_reference matches sorted_reference |
Examples:
TODO
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/utils.py
vpaste(root, vars)
¶
vectorised paste for 2 elements; Port of R paste0 in spirit
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
VecScalars
|
left hand side(s) of the paste |
required |
vars |
VecScalars
|
right hand side(s) of the paste |
required |
Returns:
Type | Description |
---|---|
Union[str, Sequence[str]]
|
Union[str,Sequence[str]]: pasted scalars |
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/utils.py
module vis¶
OptimisationPlots
¶
Source code in /home/per202/src/swift/bindings/python/swift2/swift2/vis.py
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 |
|
shuffles(x, y, obj_lims=None)
¶
Facetted bi-parameter scatter plots of the value of a parameter along the optimisation process
Plot the value of a parameter along the optimisation process. The color scale is the objective score. Useful to check the behavior of the optimisation process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
str
|
the exact name of one of the model parameters |
required |
y |
str
|
the exact name of a second model parameter |
required |
obj_lims |
Sequence[float]
|
min/max limits to plot the fitness, for example min 0 for NSE. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Any
|
sns.FacetGrid: FacetGrid object |