common.py
Cross-cutting network helpers: load clipping and resource meta-data attachment.
attach_resources_to_network_meta(n, snakemake)
Attach resource tables to the network meta before the netCDF export.
Embeds energy_totals and co2_totals CSV data directly into
n.meta["resources"] so that downstream evaluation rules can access
sectoral energy demand and CO₂ totals without relying on a separate
post-processing step or extra input files.
The network name is also updated to a human-readable string that includes the planning horizon year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
pypsa.Network
|
The solved network whose metadata will be updated in place. |
required |
snakemake
|
snakemake.script.Snakemake
|
The Snakemake workflow object providing inputs, params, config, and wildcards. |
required |
Raises:
| Type | Description |
|---|---|
MissingInputException
|
If the required inputs ( |
Returns:
| Type | Description |
|---|---|
None
|
Updates |
Source code in mods/network/common.py
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 | |
clip_negative_loads_for_edge_cases(n, snakemake)
Clip negative Loads for selected edge cases.
This is neccessary, because some electricity demands are calculated
from heuristics. For example, heat for electricity from
energy_totals and population share is deducted from
regional base load. This can lead to negative Loads if
heuristics yield larger values than input data sets. However,
there are many examples where this may happen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
pypsa.Network
|
The network before solve step. |
required |
snakemake
|
snakemake.script.Snakemake
|
The Snakemake workflow object providing inputs, params, config, and outputs. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates network in place. |
Raises:
| Type | Description |
|---|---|
RunTimeError
|
If expected edge cases could not be found. |
Source code in mods/network/common.py
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 | |
modify_prenetwork(n, snakemake)
Apply all PyPSA-AT specific modifications to the pre-network.
This is the single entry point for all AT-specific modifications during
the modify_prenetwork Snakemake step. It orchestrates the individual
modification functions and encapsulates the conditional logic for when
each modification applies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
pypsa.Network
|
The pre-network to be modified in place. |
required |
snakemake
|
snakemake.script.Snakemake
|
The Snakemake workflow object providing inputs, params, config, and wildcards. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the :class: |
Source code in mods/network/common.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
prepare_sector_network(n, snakemake, nodes, costs, spatial)
Apply all PyPSA-AT specific modifications during prepare_sector_network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
The pre-network to be modified in place. |
required | |
snakemake
|
The Snakemake workflow object providing inputs, params, and config. |
required | |
costs
|
Processed cost DataFrame for the current planning horizon. |
required | |
nodes
|
Clustered node index ( |
required | |
spatial
|
Spatial namespace produced by |
required |
Returns:
| Type | Description |
|---|---|
|
Modifies the network in place. |
Source code in mods/network/common.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |