pyconvexity 0.4.0__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 -663
- 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/schema/04_scenario_schema.sql +0 -122
- pyconvexity/data/schema/migrate_add_geometries.sql +0 -73
- pyconvexity-0.4.0.dist-info/METADATA +0 -138
- pyconvexity-0.4.0.dist-info/RECORD +0 -44
- {pyconvexity-0.4.0.dist-info → pyconvexity-0.4.1.dist-info}/WHEEL +0 -0
- {pyconvexity-0.4.0.dist-info → pyconvexity-0.4.1.dist-info}/top_level.txt +0 -0
pyconvexity/models/__init__.py
CHANGED
|
@@ -5,120 +5,170 @@ Contains high-level operations for networks, components, and attributes.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from pyconvexity.models.components import (
|
|
8
|
-
get_component_type,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,
|
|
12
22
|
)
|
|
13
23
|
|
|
14
24
|
from pyconvexity.models.attributes import (
|
|
15
|
-
set_static_attribute,
|
|
16
|
-
|
|
25
|
+
set_static_attribute,
|
|
26
|
+
set_timeseries_attribute,
|
|
27
|
+
get_attribute,
|
|
28
|
+
delete_attribute,
|
|
29
|
+
get_timeseries,
|
|
30
|
+
get_timeseries_metadata,
|
|
17
31
|
)
|
|
18
32
|
|
|
19
33
|
from pyconvexity.models.network import (
|
|
20
|
-
create_network,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
create_network,
|
|
35
|
+
get_network_info,
|
|
36
|
+
get_network_time_periods,
|
|
37
|
+
list_networks,
|
|
38
|
+
create_carrier,
|
|
39
|
+
get_network_config,
|
|
40
|
+
set_network_config,
|
|
41
|
+
get_component_counts,
|
|
42
|
+
get_first_network,
|
|
43
|
+
get_network_by_name,
|
|
24
44
|
)
|
|
25
45
|
|
|
26
46
|
# Import from new modules
|
|
27
47
|
from pyconvexity.models.scenarios import (
|
|
28
48
|
list_scenarios,
|
|
29
|
-
get_scenario_by_name,
|
|
30
|
-
|
|
49
|
+
get_scenario_by_name,
|
|
50
|
+
get_scenario_by_id,
|
|
51
|
+
Scenario,
|
|
31
52
|
)
|
|
32
53
|
|
|
33
54
|
from pyconvexity.models.results import (
|
|
34
|
-
get_solve_results,
|
|
35
|
-
|
|
55
|
+
get_solve_results,
|
|
56
|
+
get_yearly_results,
|
|
57
|
+
SolveResults,
|
|
58
|
+
YearlyResults,
|
|
36
59
|
)
|
|
37
60
|
|
|
38
61
|
from pyconvexity.models.carriers import (
|
|
39
62
|
list_carriers,
|
|
40
|
-
get_carrier_by_name,
|
|
41
|
-
|
|
63
|
+
get_carrier_by_name,
|
|
64
|
+
get_carrier_by_id,
|
|
65
|
+
get_carrier_colors,
|
|
66
|
+
Carrier,
|
|
42
67
|
)
|
|
43
68
|
|
|
69
|
+
|
|
44
70
|
# Backward compatibility aliases
|
|
45
71
|
def get_scenario(conn, scenario_id):
|
|
46
72
|
"""Backward compatible alias for get_scenario_by_id."""
|
|
47
73
|
return get_scenario_by_id(conn, scenario_id)
|
|
48
74
|
|
|
49
|
-
|
|
75
|
+
|
|
76
|
+
def create_scenario(conn, name, description=None, probability=None):
|
|
50
77
|
"""
|
|
51
|
-
Create a new scenario.
|
|
52
|
-
|
|
78
|
+
Create a new scenario (single network per database).
|
|
79
|
+
|
|
53
80
|
Args:
|
|
54
81
|
conn: Database connection
|
|
55
|
-
network_id: Network ID
|
|
56
82
|
name: Scenario name
|
|
57
83
|
description: Optional description
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
probability: Optional probability for stochastic optimization
|
|
85
|
+
|
|
60
86
|
Returns:
|
|
61
87
|
Scenario ID
|
|
62
88
|
"""
|
|
63
|
-
cursor = conn.execute(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
cursor = conn.execute(
|
|
90
|
+
"""
|
|
91
|
+
INSERT INTO scenarios (name, description, probability)
|
|
92
|
+
VALUES (?, ?, ?)
|
|
93
|
+
""",
|
|
94
|
+
(name, description, probability),
|
|
95
|
+
)
|
|
96
|
+
|
|
68
97
|
scenario_id = cursor.lastrowid
|
|
69
98
|
return scenario_id
|
|
70
99
|
|
|
100
|
+
|
|
71
101
|
def delete_scenario(conn, scenario_id):
|
|
72
102
|
"""
|
|
73
|
-
Delete a scenario
|
|
74
|
-
|
|
103
|
+
Delete a scenario.
|
|
104
|
+
|
|
75
105
|
Args:
|
|
76
106
|
conn: Database connection
|
|
77
107
|
scenario_id: Scenario ID to delete
|
|
78
|
-
|
|
108
|
+
|
|
79
109
|
Raises:
|
|
80
|
-
ValidationError: If
|
|
110
|
+
ValidationError: If scenario doesn't exist
|
|
81
111
|
"""
|
|
82
112
|
from pyconvexity.core.errors import ValidationError
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
scenario = get_scenario_by_id(conn, scenario_id)
|
|
86
|
-
if scenario.is_master:
|
|
87
|
-
raise ValidationError("Cannot delete master scenario")
|
|
88
|
-
|
|
89
|
-
# Delete the scenario
|
|
113
|
+
|
|
114
|
+
# Delete the scenario (cascade will delete related data)
|
|
90
115
|
cursor = conn.execute("DELETE FROM scenarios WHERE id = ?", (scenario_id,))
|
|
91
|
-
|
|
116
|
+
|
|
92
117
|
if cursor.rowcount == 0:
|
|
93
118
|
raise ValidationError(f"Scenario with ID {scenario_id} not found")
|
|
94
119
|
|
|
120
|
+
|
|
95
121
|
__all__ = [
|
|
96
122
|
# Component operations
|
|
97
|
-
"get_component_type",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
|
|
123
|
+
"get_component_type",
|
|
124
|
+
"get_component",
|
|
125
|
+
"list_components_by_type",
|
|
126
|
+
"insert_component",
|
|
127
|
+
"create_component",
|
|
128
|
+
"update_component",
|
|
129
|
+
"delete_component",
|
|
130
|
+
"list_component_attributes",
|
|
131
|
+
"get_default_carrier_id",
|
|
132
|
+
"get_bus_name_to_id_map",
|
|
133
|
+
"get_component_by_name",
|
|
134
|
+
"get_component_id",
|
|
135
|
+
"component_exists",
|
|
136
|
+
"get_component_carrier_map",
|
|
102
137
|
# Attribute operations
|
|
103
|
-
"set_static_attribute",
|
|
104
|
-
"
|
|
105
|
-
|
|
138
|
+
"set_static_attribute",
|
|
139
|
+
"set_timeseries_attribute",
|
|
140
|
+
"get_attribute",
|
|
141
|
+
"delete_attribute",
|
|
142
|
+
"get_timeseries",
|
|
143
|
+
"get_timeseries_metadata",
|
|
106
144
|
# Network operations
|
|
107
|
-
"create_network",
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
|
|
145
|
+
"create_network",
|
|
146
|
+
"get_network_info",
|
|
147
|
+
"get_network_time_periods",
|
|
148
|
+
"list_networks",
|
|
149
|
+
"create_carrier",
|
|
150
|
+
"list_carriers",
|
|
151
|
+
"get_network_config",
|
|
152
|
+
"set_network_config",
|
|
153
|
+
"get_component_counts",
|
|
154
|
+
"get_first_network",
|
|
155
|
+
"get_network_by_name",
|
|
112
156
|
# Scenario operations (backward compatible)
|
|
113
|
-
"create_scenario",
|
|
114
|
-
"
|
|
157
|
+
"create_scenario",
|
|
158
|
+
"list_scenarios",
|
|
159
|
+
"get_scenario",
|
|
160
|
+
"delete_scenario",
|
|
161
|
+
"get_scenario_by_name",
|
|
162
|
+
"get_scenario_by_id",
|
|
115
163
|
"Scenario",
|
|
116
|
-
|
|
117
164
|
# Results operations
|
|
118
|
-
"get_solve_results",
|
|
119
|
-
"
|
|
120
|
-
|
|
165
|
+
"get_solve_results",
|
|
166
|
+
"get_yearly_results",
|
|
167
|
+
"SolveResults",
|
|
168
|
+
"YearlyResults",
|
|
121
169
|
# Carrier operations
|
|
122
|
-
"get_carrier_by_name",
|
|
170
|
+
"get_carrier_by_name",
|
|
171
|
+
"get_carrier_by_id",
|
|
172
|
+
"get_carrier_colors",
|
|
123
173
|
"Carrier",
|
|
124
174
|
]
|