pyconvexity 0.4.8__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.
Potentially problematic release.
This version of pyconvexity might be problematic. Click here for more details.
- pyconvexity/__init__.py +241 -0
- pyconvexity/_version.py +1 -0
- pyconvexity/core/__init__.py +60 -0
- pyconvexity/core/database.py +485 -0
- pyconvexity/core/errors.py +106 -0
- pyconvexity/core/types.py +400 -0
- pyconvexity/dashboard.py +265 -0
- pyconvexity/data/README.md +101 -0
- pyconvexity/data/__init__.py +17 -0
- pyconvexity/data/loaders/__init__.py +3 -0
- pyconvexity/data/loaders/cache.py +213 -0
- pyconvexity/data/schema/01_core_schema.sql +420 -0
- pyconvexity/data/schema/02_data_metadata.sql +120 -0
- pyconvexity/data/schema/03_validation_data.sql +507 -0
- pyconvexity/data/sources/__init__.py +5 -0
- pyconvexity/data/sources/gem.py +442 -0
- pyconvexity/io/__init__.py +26 -0
- pyconvexity/io/excel_exporter.py +1226 -0
- pyconvexity/io/excel_importer.py +1381 -0
- pyconvexity/io/netcdf_exporter.py +191 -0
- pyconvexity/io/netcdf_importer.py +1802 -0
- pyconvexity/models/__init__.py +195 -0
- pyconvexity/models/attributes.py +730 -0
- pyconvexity/models/carriers.py +159 -0
- pyconvexity/models/components.py +611 -0
- pyconvexity/models/network.py +503 -0
- pyconvexity/models/results.py +148 -0
- pyconvexity/models/scenarios.py +234 -0
- pyconvexity/solvers/__init__.py +29 -0
- pyconvexity/solvers/pypsa/__init__.py +30 -0
- pyconvexity/solvers/pypsa/api.py +446 -0
- pyconvexity/solvers/pypsa/batch_loader.py +296 -0
- pyconvexity/solvers/pypsa/builder.py +655 -0
- pyconvexity/solvers/pypsa/clearing_price.py +678 -0
- pyconvexity/solvers/pypsa/constraints.py +405 -0
- pyconvexity/solvers/pypsa/solver.py +1442 -0
- pyconvexity/solvers/pypsa/storage.py +2096 -0
- pyconvexity/timeseries.py +330 -0
- pyconvexity/validation/__init__.py +25 -0
- pyconvexity/validation/rules.py +312 -0
- pyconvexity-0.4.8.dist-info/METADATA +148 -0
- pyconvexity-0.4.8.dist-info/RECORD +44 -0
- pyconvexity-0.4.8.dist-info/WHEEL +5 -0
- pyconvexity-0.4.8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Model management module for PyConvexity.
|
|
3
|
+
|
|
4
|
+
Contains high-level operations for networks, components, and attributes.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from pyconvexity.models.components import (
|
|
8
|
+
get_component_type,
|
|
9
|
+
get_component,
|
|
10
|
+
list_components_by_type,
|
|
11
|
+
insert_component,
|
|
12
|
+
create_component,
|
|
13
|
+
update_component,
|
|
14
|
+
delete_component,
|
|
15
|
+
list_component_attributes,
|
|
16
|
+
get_default_carrier_id,
|
|
17
|
+
get_bus_name_to_id_map,
|
|
18
|
+
get_component_by_name,
|
|
19
|
+
get_component_id,
|
|
20
|
+
component_exists,
|
|
21
|
+
get_component_carrier_map,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from pyconvexity.models.attributes import (
|
|
25
|
+
set_static_attribute,
|
|
26
|
+
set_timeseries_attribute,
|
|
27
|
+
get_attribute,
|
|
28
|
+
delete_attribute,
|
|
29
|
+
get_timeseries,
|
|
30
|
+
get_timeseries_metadata,
|
|
31
|
+
# Actual value functions
|
|
32
|
+
set_actual_static_value,
|
|
33
|
+
set_actual_timeseries_value,
|
|
34
|
+
get_actual_value,
|
|
35
|
+
clear_actual_value,
|
|
36
|
+
get_attribute_direct,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
from pyconvexity.models.network import (
|
|
40
|
+
create_network,
|
|
41
|
+
get_network_info,
|
|
42
|
+
get_network_time_periods,
|
|
43
|
+
list_networks,
|
|
44
|
+
create_carrier,
|
|
45
|
+
get_network_config,
|
|
46
|
+
set_network_config,
|
|
47
|
+
get_component_counts,
|
|
48
|
+
get_first_network,
|
|
49
|
+
get_network_by_name,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Import from new modules
|
|
53
|
+
from pyconvexity.models.scenarios import (
|
|
54
|
+
list_scenarios,
|
|
55
|
+
get_scenario_by_name,
|
|
56
|
+
get_scenario_by_id,
|
|
57
|
+
Scenario,
|
|
58
|
+
# Actual scenario functions
|
|
59
|
+
get_actual_scenario_id,
|
|
60
|
+
get_or_create_actual_scenario,
|
|
61
|
+
has_actual_value,
|
|
62
|
+
ACTUAL_SCENARIO_PURPOSE,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
from pyconvexity.models.results import (
|
|
66
|
+
get_solve_results,
|
|
67
|
+
get_yearly_results,
|
|
68
|
+
SolveResults,
|
|
69
|
+
YearlyResults,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
from pyconvexity.models.carriers import (
|
|
73
|
+
list_carriers,
|
|
74
|
+
get_carrier_by_name,
|
|
75
|
+
get_carrier_by_id,
|
|
76
|
+
get_carrier_colors,
|
|
77
|
+
Carrier,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Backward compatibility aliases
|
|
82
|
+
def get_scenario(conn, scenario_id):
|
|
83
|
+
"""Backward compatible alias for get_scenario_by_id."""
|
|
84
|
+
return get_scenario_by_id(conn, scenario_id)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def create_scenario(conn, name, description=None, probability=None):
|
|
88
|
+
"""
|
|
89
|
+
Create a new scenario (single network per database).
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
conn: Database connection
|
|
93
|
+
name: Scenario name
|
|
94
|
+
description: Optional description
|
|
95
|
+
probability: Optional probability for stochastic optimization
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Scenario ID
|
|
99
|
+
"""
|
|
100
|
+
cursor = conn.execute(
|
|
101
|
+
"""
|
|
102
|
+
INSERT INTO scenarios (name, description, probability)
|
|
103
|
+
VALUES (?, ?, ?)
|
|
104
|
+
""",
|
|
105
|
+
(name, description, probability),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
scenario_id = cursor.lastrowid
|
|
109
|
+
return scenario_id
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def delete_scenario(conn, scenario_id):
|
|
113
|
+
"""
|
|
114
|
+
Delete a scenario.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
conn: Database connection
|
|
118
|
+
scenario_id: Scenario ID to delete
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
ValidationError: If scenario doesn't exist
|
|
122
|
+
"""
|
|
123
|
+
from pyconvexity.core.errors import ValidationError
|
|
124
|
+
|
|
125
|
+
# Delete the scenario (cascade will delete related data)
|
|
126
|
+
cursor = conn.execute("DELETE FROM scenarios WHERE id = ?", (scenario_id,))
|
|
127
|
+
|
|
128
|
+
if cursor.rowcount == 0:
|
|
129
|
+
raise ValidationError(f"Scenario with ID {scenario_id} not found")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
__all__ = [
|
|
133
|
+
# Component operations
|
|
134
|
+
"get_component_type",
|
|
135
|
+
"get_component",
|
|
136
|
+
"list_components_by_type",
|
|
137
|
+
"insert_component",
|
|
138
|
+
"create_component",
|
|
139
|
+
"update_component",
|
|
140
|
+
"delete_component",
|
|
141
|
+
"list_component_attributes",
|
|
142
|
+
"get_default_carrier_id",
|
|
143
|
+
"get_bus_name_to_id_map",
|
|
144
|
+
"get_component_by_name",
|
|
145
|
+
"get_component_id",
|
|
146
|
+
"component_exists",
|
|
147
|
+
"get_component_carrier_map",
|
|
148
|
+
# Attribute operations
|
|
149
|
+
"set_static_attribute",
|
|
150
|
+
"set_timeseries_attribute",
|
|
151
|
+
"get_attribute",
|
|
152
|
+
"delete_attribute",
|
|
153
|
+
"get_timeseries",
|
|
154
|
+
"get_timeseries_metadata",
|
|
155
|
+
# Actual value operations
|
|
156
|
+
"set_actual_static_value",
|
|
157
|
+
"set_actual_timeseries_value",
|
|
158
|
+
"get_actual_value",
|
|
159
|
+
"clear_actual_value",
|
|
160
|
+
"get_attribute_direct",
|
|
161
|
+
"get_actual_scenario_id",
|
|
162
|
+
"get_or_create_actual_scenario",
|
|
163
|
+
"has_actual_value",
|
|
164
|
+
"ACTUAL_SCENARIO_PURPOSE",
|
|
165
|
+
# Network operations
|
|
166
|
+
"create_network",
|
|
167
|
+
"get_network_info",
|
|
168
|
+
"get_network_time_periods",
|
|
169
|
+
"list_networks",
|
|
170
|
+
"create_carrier",
|
|
171
|
+
"list_carriers",
|
|
172
|
+
"get_network_config",
|
|
173
|
+
"set_network_config",
|
|
174
|
+
"get_component_counts",
|
|
175
|
+
"get_first_network",
|
|
176
|
+
"get_network_by_name",
|
|
177
|
+
# Scenario operations (backward compatible)
|
|
178
|
+
"create_scenario",
|
|
179
|
+
"list_scenarios",
|
|
180
|
+
"get_scenario",
|
|
181
|
+
"delete_scenario",
|
|
182
|
+
"get_scenario_by_name",
|
|
183
|
+
"get_scenario_by_id",
|
|
184
|
+
"Scenario",
|
|
185
|
+
# Results operations
|
|
186
|
+
"get_solve_results",
|
|
187
|
+
"get_yearly_results",
|
|
188
|
+
"SolveResults",
|
|
189
|
+
"YearlyResults",
|
|
190
|
+
# Carrier operations
|
|
191
|
+
"get_carrier_by_name",
|
|
192
|
+
"get_carrier_by_id",
|
|
193
|
+
"get_carrier_colors",
|
|
194
|
+
"Carrier",
|
|
195
|
+
]
|