|
| 1 | +# Parameters guide |
| 2 | + |
| 3 | +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`](graphfcns_guide.md) that uses it. Instead, to understand specific parameter purposes, you can view all available parameters at the [API](reference-parameters.md). |
| 4 | + |
| 5 | +## Using parameters |
| 6 | + |
| 7 | +Let's look at a [parameter group](reference-parameters.md#swmmanywhere.parameters.OutfallDerivation), which is a group of parameters related to identifying outfall locations. |
| 8 | + |
| 9 | +:::swmmanywhere.parameters.OutfallDerivation |
| 10 | + handler: python |
| 11 | + options: |
| 12 | + members: no |
| 13 | + show_root_heading: false |
| 14 | + show_bases: false |
| 15 | + show_source: true |
| 16 | + show_root_toc_entry: false |
| 17 | + show_docstring_attributes: false |
| 18 | + show_docstring_description: false |
| 19 | + show_docstring_examples: false |
| 20 | + show_docstring_parameters: false |
| 21 | + show_docstring_returns: false |
| 22 | + show_docstring_raises: false |
| 23 | + |
| 24 | +We can see here three related parameters and relevant metadata, grouped together in a [`pydantic.BaseModel`](https://docs.pydantic.dev/latest/api/base_model/) 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`](reference-graph-utilities.md#swmmanywhere.graphfcns.outfall_graphfcns.identify_outfalls), which needs these parameters. |
| 25 | + |
| 26 | +:::swmmanywhere.graphfcns.outfall_graphfcns.identify_outfalls |
| 27 | + handler: python |
| 28 | + options: |
| 29 | + members: no |
| 30 | + show_root_heading: false |
| 31 | + show_bases: false |
| 32 | + show_source: true |
| 33 | + show_root_toc_entry: false |
| 34 | + show_docstring_attributes: false |
| 35 | + show_docstring_description: false |
| 36 | + show_docstring_examples: false |
| 37 | + show_docstring_parameters: false |
| 38 | + show_docstring_returns: false |
| 39 | + show_docstring_raises: false |
| 40 | + |
| 41 | +When calling [`iterate_graphfcns`](reference-graph-utilities.md#swmmanywhere.graph_utilities.iterate_graphfcns), for more information see [here](graphfcns_guide.md#lists-of-graph-functions), SWMManywhere will automatically provide any parameters that have been registered to any graphfcn. |
| 42 | + |
| 43 | +## Registering parameters |
| 44 | + |
| 45 | +When you create a new parameter, it will need to belong to an existing or new parameter group. |
| 46 | + |
| 47 | +### Creating a new parameter group(s) |
| 48 | + |
| 49 | +You create a new module(s) that can contain multiple parameter groups. See below as a template of such amodule. |
| 50 | + |
| 51 | +```python |
| 52 | +{% |
| 53 | + include-markdown "../tests/test_data/custom_parameters.py" |
| 54 | + comments=false |
| 55 | +%} |
| 56 | +``` |
| 57 | + |
| 58 | +### Adjust config file |
| 59 | + |
| 60 | +We will add the required lines to the |
| 61 | +[minimum viable config](config_guide.md#minimum-viable-configuration) template. |
| 62 | + |
| 63 | +```yml |
| 64 | +{% |
| 65 | + include-markdown "snippets/minimum_viable_template.yml" |
| 66 | + comments=false |
| 67 | +%} |
| 68 | +custom_parameter_modules: |
| 69 | + - /path/to/custom_parameters.py |
| 70 | +``` |
| 71 | +
|
| 72 | +Now when we run our `config` file, these parameters will be registered and any [custom graphfcns](graphfcns_guide.md#add-a-new-graph-function) will have access to them. |
| 73 | + |
| 74 | +### Changing existing parameter groups |
| 75 | + |
| 76 | +There may be cases where you want to change existing parameter groups, such as introducing new weights to the [`calculate_weights`](reference-graph-utilities.md#swmmanywhere.graphfcns.topology_graphfcns.calculate_weights) step so that they are minimized during the shortest path optimization. In this example, we want the [`TopologyDerivation`](reference-parameters.md#swmmanywhere.parameters.TopologyDerviation) group to include some new parameters. We can do this in a similar way to [above](#creating-a-new-parameter-groups), but being mindful to inherit from `TopologyDerivation` rather than `BaseModel`: |
| 77 | + |
| 78 | +```python |
| 79 | +from swmmanywhere.parameters import register_parameter_group, TopologyDerivation, Field |
| 80 | +
|
| 81 | +@register_parameter_group("topology_derivation") |
| 82 | +class NewTopologyDerivation(TopologyDerivation): |
| 83 | + new_weight_scaling: float = Field( |
| 84 | + default=1, |
| 85 | + le=1, |
| 86 | + ge=0, |
| 87 | + ) |
| 88 | + new_weight_exponent: float = Field( |
| 89 | + default=1, |
| 90 | + le=2, |
| 91 | + ge=0, |
| 92 | + ) |
| 93 | +``` |
| 94 | + |
| 95 | +Now the `calculate_weights` function will have access to these new weighting parameters, as well as existing ones. |
| 96 | + |
| 97 | +Note, in this specific example of adding custom weights, you will also have to: |
| 98 | + |
| 99 | +- Update the `weights` parameter in your `config` file, for example: |
| 100 | + |
| 101 | +```yaml |
| 102 | +parameter_overrides: |
| 103 | + topology_derviation: |
| 104 | + weights: |
| 105 | + - new_weight |
| 106 | + - length |
| 107 | +``` |
| 108 | + |
| 109 | +- [Create and register a `graphfcn`](graphfcns_guide.md#add-a-new-graph-function) that adds the `new_weight` parameter to the graph. |
0 commit comments