Parameters guide
SWMManywhere is a deliberately highly parameterised workflow, with the goal of enabling users to create a diverse range of UDMs. This guide is to explain the logic of the implemented parameters and how to customise them, as what each parameter does is highly specific to the graphfcn
that uses it. Instead, to understand specific parameter purposes, you can view all available parameters at the API.
Using parameters
Let's look at a parameter group, which is a group of parameters related to identifying outfall locations.
Source code in swmmanywhere/parameters.py
We can see here three related parameters and relevant metadata, grouped together in a pydantic.BaseModel
object. Parameters in SWMManywhere are grouped together because graphfcns
that need one of them tend to need the others. Let's look at identify_outfalls
, which needs these parameters.
Source code in swmmanywhere/graphfcns/outfall_graphfcns.py
When calling iterate_graphfcns
, for more information see here, SWMManywhere will automatically provide any parameters that have been registered to any graphfcn.
Registering parameters
When you create a new parameter, it will need to belong to an existing or new parameter group.
Creating a new parameter group(s)
You create a new module(s) that can contain multiple parameter groups. See below as a template of such amodule.
from __future__ import annotations
from swmmanywhere import parameters
@parameters.register_parameter_group(name="new_params")
class new_params(parameters.BaseModel):
"""New parameters."""
new_param: int = parameters.Field(
default=1,
ge=0,
le=10,
unit="-",
description="A new parameter.",
)
Adjust config file
We will add the required lines to the minimum viable config template.
base_dir: /path/to/base/directory
project: my_first_swmm
bbox: [1.52740,42.50524,1.54273,42.51259]
custom_parameter_modules:
- /path/to/custom_parameters.py
Now when we run our config
file, these parameters will be registered and any custom graphfcns will have access to them.
Changing existing parameter groups
There may be cases where you want to change existing parameter groups, such as introducing new weights to the calculate_weights
step so that they are minimized during the shortest path optimization. In this example, we want the TopologyDerivation
group to include some new parameters. We can do this in a similar way to above, but being mindful to inherit from TopologyDerivation
rather than BaseModel
:
from swmmanywhere.parameters import register_parameter_group, TopologyDerivation, Field
@register_parameter_group("topology_derivation")
class NewTopologyDerivation(TopologyDerivation):
new_weight_scaling: float = Field(
default=1,
le=1,
ge=0,
)
new_weight_exponent: float = Field(
default=1,
le=2,
ge=0,
)
Now the calculate_weights
function will have access to these new weighting parameters, as well as existing ones.
Note, in this specific example of adding custom weights, you will also have to:
- Update the
weights
parameter in yourconfig
file, for example:
- Create and register a
graphfcn
that adds thenew_weight
parameter to the graph.