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.
Files changed (43) hide show
  1. pyconvexity/__init__.py +87 -46
  2. pyconvexity/_version.py +1 -1
  3. pyconvexity/core/__init__.py +3 -5
  4. pyconvexity/core/database.py +111 -103
  5. pyconvexity/core/errors.py +16 -10
  6. pyconvexity/core/types.py +61 -54
  7. pyconvexity/data/__init__.py +0 -1
  8. pyconvexity/data/loaders/cache.py +65 -64
  9. pyconvexity/data/schema/01_core_schema.sql +134 -234
  10. pyconvexity/data/schema/02_data_metadata.sql +38 -168
  11. pyconvexity/data/schema/03_validation_data.sql +327 -264
  12. pyconvexity/data/sources/gem.py +169 -139
  13. pyconvexity/io/__init__.py +4 -10
  14. pyconvexity/io/excel_exporter.py +694 -480
  15. pyconvexity/io/excel_importer.py +817 -545
  16. pyconvexity/io/netcdf_exporter.py +66 -61
  17. pyconvexity/io/netcdf_importer.py +850 -619
  18. pyconvexity/models/__init__.py +109 -59
  19. pyconvexity/models/attributes.py +197 -178
  20. pyconvexity/models/carriers.py +70 -67
  21. pyconvexity/models/components.py +260 -236
  22. pyconvexity/models/network.py +202 -284
  23. pyconvexity/models/results.py +65 -55
  24. pyconvexity/models/scenarios.py +58 -88
  25. pyconvexity/solvers/__init__.py +5 -5
  26. pyconvexity/solvers/pypsa/__init__.py +3 -3
  27. pyconvexity/solvers/pypsa/api.py +150 -134
  28. pyconvexity/solvers/pypsa/batch_loader.py +165 -162
  29. pyconvexity/solvers/pypsa/builder.py +390 -291
  30. pyconvexity/solvers/pypsa/constraints.py +184 -162
  31. pyconvexity/solvers/pypsa/solver.py +968 -663
  32. pyconvexity/solvers/pypsa/storage.py +1377 -671
  33. pyconvexity/timeseries.py +63 -60
  34. pyconvexity/validation/__init__.py +14 -6
  35. pyconvexity/validation/rules.py +95 -84
  36. pyconvexity-0.4.1.dist-info/METADATA +46 -0
  37. pyconvexity-0.4.1.dist-info/RECORD +42 -0
  38. pyconvexity/data/schema/04_scenario_schema.sql +0 -122
  39. pyconvexity/data/schema/migrate_add_geometries.sql +0 -73
  40. pyconvexity-0.4.0.dist-info/METADATA +0 -138
  41. pyconvexity-0.4.0.dist-info/RECORD +0 -44
  42. {pyconvexity-0.4.0.dist-info → pyconvexity-0.4.1.dist-info}/WHEEL +0 -0
  43. {pyconvexity-0.4.0.dist-info → pyconvexity-0.4.1.dist-info}/top_level.txt +0 -0
@@ -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, network_id: int) -> List[Carrier]:
28
+ def list_carriers(conn: sqlite3.Connection) -> List[Carrier]:
29
29
  """
30
- List all carriers for a network.
31
-
30
+ List all carriers for the network (single network per database).
31
+
32
32
  Args:
33
33
  conn: Database connection
34
- network_id: Network ID
35
-
34
+
36
35
  Returns:
37
36
  List of Carrier objects ordered by name
38
37
  """
39
- cursor = conn.execute("""
40
- SELECT id, network_id, name, co2_emissions, color, nice_name
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
- """, (network_id,))
45
-
43
+ """
44
+ )
45
+
46
46
  carriers = []
47
47
  for row in cursor.fetchall():
48
- carriers.append(Carrier(
49
- id=row[0],
50
- network_id=row[1],
51
- name=row[2],
52
- co2_emissions=row[3] or 0.0,
53
- color=row[4],
54
- nice_name=row[5]
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, network_id: int, name: str) -> Carrier:
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
- SELECT id, network_id, name, co2_emissions, color, nice_name
75
+ cursor = conn.execute(
76
+ """
77
+ SELECT id, name, co2_emissions, color, nice_name
77
78
  FROM carriers
78
- WHERE network_id = ? AND name = ?
79
- """, (network_id, name))
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 for network {network_id}")
84
-
86
+ raise ValidationError(f"Carrier '{name}' not found")
87
+
85
88
  return Carrier(
86
89
  id=row[0],
87
- network_id=row[1],
88
- name=row[2],
89
- co2_emissions=row[3] or 0.0,
90
- color=row[4],
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
- SELECT id, network_id, name, co2_emissions, color, nice_name
111
+ cursor = conn.execute(
112
+ """
113
+ SELECT id, name, co2_emissions, color, nice_name
111
114
  FROM carriers
112
115
  WHERE id = ?
113
- """, (carrier_id,))
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
- network_id=row[1],
122
- name=row[2],
123
- co2_emissions=row[3] or 0.0,
124
- color=row[4],
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, network_id: int) -> Dict[str, str]:
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
- network_id: Network ID
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
- WHERE network_id = ?
144
- """, (network_id,))
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 'Unmet Load' not in colors:
153
- colors['Unmet Load'] = '#FF0000'
154
-
155
- return colors
156
+ if "Unmet Load" not in colors:
157
+ colors["Unmet Load"] = "#FF0000"
156
158
 
159
+ return colors