MESQUAL Network Lines Data¶
NetworkLineFlowsData
¶
Wrapper for bidirectional flow data of network transmission lines.
This class encapsulates energy or power flow data for lines in both directions, accounting for transmission losses. It provides a standardized interface for handling complex flow patterns in electrical network analysis.
Flow Direction Conventions
- sent_up: Flow entering line at node_from (towards node_to)
- received_up: Flow leaving line at node_from after losses (coming from node_to)
- sent_down: Flow entering line at node_to (towards node_from)
- received_down: Flow leaving line at node_to after losses (coming from node_from)
The distinction between 'sent' and 'received' allows for modeling transmission losses, where received_flow = sent_flow * (1 - loss_rate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sent_up
|
DataFrame
|
DataFrame with flow data entering at node_from |
required |
received_up
|
DataFrame
|
DataFrame with flow data received at node_from after losses |
required |
sent_down
|
DataFrame
|
DataFrame with flow data entering at node_to |
required |
received_down
|
DataFrame
|
DataFrame with flow data received at node_to after losses |
required |
granularity
|
None | float | Series
|
Time granularity of the data (None, float in minutes, or Series) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If indices or columns of the four DataFrames don't match |
Example:
>>> import pandas as pd
>>> index = pd.date_range('2024-01-01', periods=24, freq='1H')
>>> columns = ['Line_A_B', 'Line_B_C']
>>> flows_up = pd.DataFrame(100, index=index, columns=columns)
>>> flows_down = pd.DataFrame(50, index=index, columns=columns)
>>> line_data = NetworkLineFlowsData.from_up_and_down_flow_without_losses(
... flows_up, flows_down)
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 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 | |
__init__
¶
__init__(sent_up: DataFrame, received_up: DataFrame, sent_down: DataFrame, received_down: DataFrame, granularity: None | float | Series = None)
Initialize NetworkLineFlowsData with flow data in both directions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sent_up
|
DataFrame
|
Flow data sent in up direction (node_from -> node_to) |
required |
received_up
|
DataFrame
|
Flow data received in up direction after losses |
required |
sent_down
|
DataFrame
|
Flow data sent in down direction (node_to -> node_from) |
required |
received_down
|
DataFrame
|
Flow data received in down direction after losses |
required |
granularity
|
None | float | Series
|
Time granularity information for the data |
None
|
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
__post_init__
¶
__post_init__()
Validate that all DataFrames have matching indices and columns.
Raises:
| Type | Description |
|---|---|
ValueError
|
If any DataFrame has mismatched indices or columns. |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
66 67 68 69 70 71 72 73 74 75 76 77 78 | |
from_mw_to_mwh
¶
from_mw_to_mwh() -> NetworkLineFlowsData
Convert flow data from MW (power) to MWh (energy).
This conversion requires granularity information to properly scale the values.
Returns:
| Type | Description |
|---|---|
NetworkLineFlowsData
|
New NetworkLineFlowsData instance with energy values |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Method not yet implemented |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
from_mwh_to_mw
¶
from_mwh_to_mw() -> NetworkLineFlowsData
Convert flow data from MWh (energy) to MW (power).
This conversion requires granularity information to properly scale the values.
Returns:
| Type | Description |
|---|---|
NetworkLineFlowsData
|
New NetworkLineFlowsData instance with power values |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Method not yet implemented |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
94 95 96 97 98 99 100 101 102 103 104 105 106 | |
from_net_flow_without_losses
classmethod
¶
from_net_flow_without_losses(net_flow: DataFrame) -> NetworkLineFlowsData
Create NetworkLineFlowsData from net flow data assuming no transmission losses.
Converts net flow data (where positive values indicate flow in up direction and negative values indicate flow in down direction) into the bidirectional flow representation used by this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net_flow
|
DataFrame
|
DataFrame with net flow values. Positive = up direction, negative = down direction |
required |
Returns:
| Type | Description |
|---|---|
NetworkLineFlowsData
|
NetworkLineFlowsData instance with flows split into up/down directions |
Example:
>>> import pandas as pd
>>> net_flows = pd.DataFrame({
... 'Line_A_B': [100, -50, 75],
... 'Line_B_C': [200, 150, -100]
... })
>>> line_data = NetworkLineFlowsData.from_net_flow_without_losses(net_flows)
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
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 | |
from_up_and_down_flow_without_losses
classmethod
¶
from_up_and_down_flow_without_losses(flow_up: DataFrame, flow_down: DataFrame) -> NetworkLineFlowsData
Create NetworkLineFlowsData from separate up and down flow data without losses.
This constructor assumes that there are no transmission losses, so sent and received flows are identical in each direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_up
|
DataFrame
|
DataFrame with flow data in up direction (node_from -> node_to) |
required |
flow_down
|
DataFrame
|
DataFrame with flow data in down direction (node_to -> node_from) |
required |
Returns:
| Type | Description |
|---|---|
NetworkLineFlowsData
|
NetworkLineFlowsData instance where sent and received flows are equal |
Example:
>>> import pandas as pd
>>> up_flows = pd.DataFrame({'Line_A_B': [100, 80, 120]})
>>> down_flows = pd.DataFrame({'Line_A_B': [50, 60, 40]})
>>> line_data = NetworkLineFlowsData.from_up_and_down_flow_without_losses(
... up_flows, down_flows)
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
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 | |
NetworkLineCapacitiesData
dataclass
¶
Wrapper for bidirectional capacity data of network transmission lines.
This dataclass encapsulates transmission capacity limits for network lines in both directions. Capacities can be asymmetric to reflect real-world transmission constraints or operational limits.
Capacity Direction Conventions
- capacities_up: Maximum transmission capacity from node_from to node_to
- capacities_down: Maximum transmission capacity from node_to to node_from
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capacities_up
|
DataFrame
|
DataFrame with capacity limits in up direction |
required |
capacities_down
|
DataFrame
|
DataFrame with capacity limits in down direction |
required |
granularity
|
None | float | Series
|
Time granularity of capacity data (None, float in minutes, or Series) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If indices or columns of the two DataFrames don't match |
Example:
>>> import pandas as pd
>>> index = pd.date_range('2024-01-01', periods=24, freq='1H')
>>> columns = ['Line_A_B', 'Line_B_C']
>>> caps = pd.DataFrame(1000, index=index, columns=columns)
>>> capacity_data = NetworkLineCapacitiesData.from_symmetric_capacities(caps)
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
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 | |
__post_init__
¶
__post_init__()
Validate that both capacity DataFrames have matching indices and columns.
Raises:
| Type | Description |
|---|---|
ValueError
|
If DataFrames have mismatched indices or columns. |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
208 209 210 211 212 213 214 215 216 217 | |
from_mw_to_mwh
¶
from_mw_to_mwh() -> NetworkLineCapacitiesData
Convert capacity data from MW (power) to MWh (energy).
This conversion requires granularity information to properly scale the values.
Returns:
| Type | Description |
|---|---|
NetworkLineCapacitiesData
|
New NetworkLineCapacitiesData instance with energy capacity values |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Method not yet implemented |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
219 220 221 222 223 224 225 226 227 228 229 230 231 | |
from_mwh_to_mw
¶
from_mwh_to_mw() -> NetworkLineCapacitiesData
Convert capacity data from MWh (energy) to MW (power).
This conversion requires granularity information to properly scale the values.
Returns:
| Type | Description |
|---|---|
NetworkLineCapacitiesData
|
New NetworkLineCapacitiesData instance with power capacity values |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Method not yet implemented |
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
233 234 235 236 237 238 239 240 241 242 243 244 245 | |
from_symmetric_capacities
classmethod
¶
from_symmetric_capacities(capacities: DataFrame) -> NetworkLineCapacitiesData
Create NetworkLineCapacitiesData with identical capacities in both directions.
This is a convenience constructor for cases where transmission lines have the same capacity limit in both directions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capacities
|
DataFrame
|
DataFrame with capacity values to use for both directions |
required |
Returns:
| Type | Description |
|---|---|
NetworkLineCapacitiesData
|
NetworkLineCapacitiesData instance with symmetric capacities |
Example:
>>> import pandas as pd
>>> caps = pd.DataFrame({
... 'Line_A_B': [1000, 1200, 800],
... 'Line_B_C': [1500, 1500, 1000]
... })
>>> capacity_data = NetworkLineCapacitiesData.from_symmetric_capacities(caps)
Source code in submodules/mesqual/mesqual/energy_data_handling/network_lines_data.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |