pyconvexity 0.3.8.post7__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyconvexity/__init__.py +87 -46
- pyconvexity/_version.py +1 -1
- pyconvexity/core/__init__.py +3 -5
- pyconvexity/core/database.py +111 -103
- pyconvexity/core/errors.py +16 -10
- pyconvexity/core/types.py +61 -54
- pyconvexity/data/__init__.py +0 -1
- pyconvexity/data/loaders/cache.py +65 -64
- pyconvexity/data/schema/01_core_schema.sql +134 -234
- pyconvexity/data/schema/02_data_metadata.sql +38 -168
- pyconvexity/data/schema/03_validation_data.sql +327 -264
- pyconvexity/data/sources/gem.py +169 -139
- pyconvexity/io/__init__.py +4 -10
- pyconvexity/io/excel_exporter.py +694 -480
- pyconvexity/io/excel_importer.py +817 -545
- pyconvexity/io/netcdf_exporter.py +66 -61
- pyconvexity/io/netcdf_importer.py +850 -619
- pyconvexity/models/__init__.py +109 -59
- pyconvexity/models/attributes.py +197 -178
- pyconvexity/models/carriers.py +70 -67
- pyconvexity/models/components.py +260 -236
- pyconvexity/models/network.py +202 -284
- pyconvexity/models/results.py +65 -55
- pyconvexity/models/scenarios.py +58 -88
- pyconvexity/solvers/__init__.py +5 -5
- pyconvexity/solvers/pypsa/__init__.py +3 -3
- pyconvexity/solvers/pypsa/api.py +150 -134
- pyconvexity/solvers/pypsa/batch_loader.py +165 -162
- pyconvexity/solvers/pypsa/builder.py +390 -291
- pyconvexity/solvers/pypsa/constraints.py +184 -162
- pyconvexity/solvers/pypsa/solver.py +968 -666
- pyconvexity/solvers/pypsa/storage.py +1377 -671
- pyconvexity/timeseries.py +63 -60
- pyconvexity/validation/__init__.py +14 -6
- pyconvexity/validation/rules.py +95 -84
- pyconvexity-0.4.1.dist-info/METADATA +46 -0
- pyconvexity-0.4.1.dist-info/RECORD +42 -0
- pyconvexity/data/__pycache__/__init__.cpython-313.pyc +0 -0
- pyconvexity/data/loaders/__pycache__/__init__.cpython-313.pyc +0 -0
- pyconvexity/data/loaders/__pycache__/cache.cpython-313.pyc +0 -0
- pyconvexity/data/schema/04_scenario_schema.sql +0 -122
- pyconvexity/data/schema/migrate_add_geometries.sql +0 -73
- pyconvexity/data/sources/__pycache__/__init__.cpython-313.pyc +0 -0
- pyconvexity/data/sources/__pycache__/gem.cpython-313.pyc +0 -0
- pyconvexity-0.3.8.post7.dist-info/METADATA +0 -138
- pyconvexity-0.3.8.post7.dist-info/RECORD +0 -49
- {pyconvexity-0.3.8.post7.dist-info → pyconvexity-0.4.1.dist-info}/WHEEL +0 -0
- {pyconvexity-0.3.8.post7.dist-info → pyconvexity-0.4.1.dist-info}/top_level.txt +0 -0
pyconvexity/models/carriers.py
CHANGED
|
@@ -16,141 +16,144 @@ logger = logging.getLogger(__name__)
|
|
|
16
16
|
|
|
17
17
|
@dataclass
|
|
18
18
|
class Carrier:
|
|
19
|
-
"""Represents an energy carrier in the network."""
|
|
19
|
+
"""Represents an energy carrier in the network (single network per database)."""
|
|
20
|
+
|
|
20
21
|
id: int
|
|
21
|
-
network_id: int
|
|
22
22
|
name: str
|
|
23
23
|
co2_emissions: float
|
|
24
24
|
color: Optional[str]
|
|
25
25
|
nice_name: Optional[str]
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def list_carriers(conn: sqlite3.Connection
|
|
28
|
+
def list_carriers(conn: sqlite3.Connection) -> List[Carrier]:
|
|
29
29
|
"""
|
|
30
|
-
List all carriers for
|
|
31
|
-
|
|
30
|
+
List all carriers for the network (single network per database).
|
|
31
|
+
|
|
32
32
|
Args:
|
|
33
33
|
conn: Database connection
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
Returns:
|
|
37
36
|
List of Carrier objects ordered by name
|
|
38
37
|
"""
|
|
39
|
-
cursor = conn.execute(
|
|
40
|
-
|
|
38
|
+
cursor = conn.execute(
|
|
39
|
+
"""
|
|
40
|
+
SELECT id, name, co2_emissions, color, nice_name
|
|
41
41
|
FROM carriers
|
|
42
|
-
WHERE network_id = ?
|
|
43
42
|
ORDER BY name
|
|
44
|
-
"""
|
|
45
|
-
|
|
43
|
+
"""
|
|
44
|
+
)
|
|
45
|
+
|
|
46
46
|
carriers = []
|
|
47
47
|
for row in cursor.fetchall():
|
|
48
|
-
carriers.append(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
carriers.append(
|
|
49
|
+
Carrier(
|
|
50
|
+
id=row[0],
|
|
51
|
+
name=row[1],
|
|
52
|
+
co2_emissions=row[2] or 0.0,
|
|
53
|
+
color=row[3],
|
|
54
|
+
nice_name=row[4],
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
57
58
|
return carriers
|
|
58
59
|
|
|
59
60
|
|
|
60
|
-
def get_carrier_by_name(conn: sqlite3.Connection,
|
|
61
|
+
def get_carrier_by_name(conn: sqlite3.Connection, name: str) -> Carrier:
|
|
61
62
|
"""
|
|
62
|
-
Get a carrier by name.
|
|
63
|
-
|
|
63
|
+
Get a carrier by name (single network per database).
|
|
64
|
+
|
|
64
65
|
Args:
|
|
65
66
|
conn: Database connection
|
|
66
|
-
network_id: Network ID
|
|
67
67
|
name: Carrier name
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
Returns:
|
|
70
70
|
Carrier object
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
Raises:
|
|
73
73
|
ValidationError: If carrier doesn't exist
|
|
74
74
|
"""
|
|
75
|
-
cursor = conn.execute(
|
|
76
|
-
|
|
75
|
+
cursor = conn.execute(
|
|
76
|
+
"""
|
|
77
|
+
SELECT id, name, co2_emissions, color, nice_name
|
|
77
78
|
FROM carriers
|
|
78
|
-
WHERE
|
|
79
|
-
""",
|
|
80
|
-
|
|
79
|
+
WHERE name = ?
|
|
80
|
+
""",
|
|
81
|
+
(name,),
|
|
82
|
+
)
|
|
83
|
+
|
|
81
84
|
row = cursor.fetchone()
|
|
82
85
|
if not row:
|
|
83
|
-
raise ValidationError(f"Carrier '{name}' not found
|
|
84
|
-
|
|
86
|
+
raise ValidationError(f"Carrier '{name}' not found")
|
|
87
|
+
|
|
85
88
|
return Carrier(
|
|
86
89
|
id=row[0],
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
nice_name=row[5]
|
|
90
|
+
name=row[1],
|
|
91
|
+
co2_emissions=row[2] or 0.0,
|
|
92
|
+
color=row[3],
|
|
93
|
+
nice_name=row[4],
|
|
92
94
|
)
|
|
93
95
|
|
|
94
96
|
|
|
95
97
|
def get_carrier_by_id(conn: sqlite3.Connection, carrier_id: int) -> Carrier:
|
|
96
98
|
"""
|
|
97
|
-
Get a carrier by ID.
|
|
98
|
-
|
|
99
|
+
Get a carrier by ID (single network per database).
|
|
100
|
+
|
|
99
101
|
Args:
|
|
100
102
|
conn: Database connection
|
|
101
103
|
carrier_id: Carrier ID
|
|
102
|
-
|
|
104
|
+
|
|
103
105
|
Returns:
|
|
104
106
|
Carrier object
|
|
105
|
-
|
|
107
|
+
|
|
106
108
|
Raises:
|
|
107
109
|
ValidationError: If carrier doesn't exist
|
|
108
110
|
"""
|
|
109
|
-
cursor = conn.execute(
|
|
110
|
-
|
|
111
|
+
cursor = conn.execute(
|
|
112
|
+
"""
|
|
113
|
+
SELECT id, name, co2_emissions, color, nice_name
|
|
111
114
|
FROM carriers
|
|
112
115
|
WHERE id = ?
|
|
113
|
-
""",
|
|
114
|
-
|
|
116
|
+
""",
|
|
117
|
+
(carrier_id,),
|
|
118
|
+
)
|
|
119
|
+
|
|
115
120
|
row = cursor.fetchone()
|
|
116
121
|
if not row:
|
|
117
122
|
raise ValidationError(f"Carrier with ID {carrier_id} not found")
|
|
118
|
-
|
|
123
|
+
|
|
119
124
|
return Carrier(
|
|
120
125
|
id=row[0],
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
nice_name=row[5]
|
|
126
|
+
name=row[1],
|
|
127
|
+
co2_emissions=row[2] or 0.0,
|
|
128
|
+
color=row[3],
|
|
129
|
+
nice_name=row[4],
|
|
126
130
|
)
|
|
127
131
|
|
|
128
132
|
|
|
129
|
-
def get_carrier_colors(conn: sqlite3.Connection
|
|
133
|
+
def get_carrier_colors(conn: sqlite3.Connection) -> Dict[str, str]:
|
|
130
134
|
"""
|
|
131
|
-
Get carrier colors for visualization.
|
|
132
|
-
|
|
135
|
+
Get carrier colors for visualization (single network per database).
|
|
136
|
+
|
|
133
137
|
Args:
|
|
134
138
|
conn: Database connection
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
|
|
137
140
|
Returns:
|
|
138
141
|
Dictionary mapping carrier names to color strings
|
|
139
142
|
"""
|
|
140
|
-
cursor = conn.execute(
|
|
143
|
+
cursor = conn.execute(
|
|
144
|
+
"""
|
|
141
145
|
SELECT name, color
|
|
142
146
|
FROM carriers
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
"""
|
|
148
|
+
)
|
|
149
|
+
|
|
146
150
|
colors = {}
|
|
147
151
|
for row in cursor.fetchall():
|
|
148
152
|
if row[1]: # Only include if color is defined
|
|
149
153
|
colors[row[0]] = row[1]
|
|
150
|
-
|
|
154
|
+
|
|
151
155
|
# Add default color for Unmet Load if not present
|
|
152
|
-
if
|
|
153
|
-
colors[
|
|
154
|
-
|
|
155
|
-
return colors
|
|
156
|
+
if "Unmet Load" not in colors:
|
|
157
|
+
colors["Unmet Load"] = "#FF0000"
|
|
156
158
|
|
|
159
|
+
return colors
|