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.

Files changed (44) hide show
  1. pyconvexity/__init__.py +241 -0
  2. pyconvexity/_version.py +1 -0
  3. pyconvexity/core/__init__.py +60 -0
  4. pyconvexity/core/database.py +485 -0
  5. pyconvexity/core/errors.py +106 -0
  6. pyconvexity/core/types.py +400 -0
  7. pyconvexity/dashboard.py +265 -0
  8. pyconvexity/data/README.md +101 -0
  9. pyconvexity/data/__init__.py +17 -0
  10. pyconvexity/data/loaders/__init__.py +3 -0
  11. pyconvexity/data/loaders/cache.py +213 -0
  12. pyconvexity/data/schema/01_core_schema.sql +420 -0
  13. pyconvexity/data/schema/02_data_metadata.sql +120 -0
  14. pyconvexity/data/schema/03_validation_data.sql +507 -0
  15. pyconvexity/data/sources/__init__.py +5 -0
  16. pyconvexity/data/sources/gem.py +442 -0
  17. pyconvexity/io/__init__.py +26 -0
  18. pyconvexity/io/excel_exporter.py +1226 -0
  19. pyconvexity/io/excel_importer.py +1381 -0
  20. pyconvexity/io/netcdf_exporter.py +191 -0
  21. pyconvexity/io/netcdf_importer.py +1802 -0
  22. pyconvexity/models/__init__.py +195 -0
  23. pyconvexity/models/attributes.py +730 -0
  24. pyconvexity/models/carriers.py +159 -0
  25. pyconvexity/models/components.py +611 -0
  26. pyconvexity/models/network.py +503 -0
  27. pyconvexity/models/results.py +148 -0
  28. pyconvexity/models/scenarios.py +234 -0
  29. pyconvexity/solvers/__init__.py +29 -0
  30. pyconvexity/solvers/pypsa/__init__.py +30 -0
  31. pyconvexity/solvers/pypsa/api.py +446 -0
  32. pyconvexity/solvers/pypsa/batch_loader.py +296 -0
  33. pyconvexity/solvers/pypsa/builder.py +655 -0
  34. pyconvexity/solvers/pypsa/clearing_price.py +678 -0
  35. pyconvexity/solvers/pypsa/constraints.py +405 -0
  36. pyconvexity/solvers/pypsa/solver.py +1442 -0
  37. pyconvexity/solvers/pypsa/storage.py +2096 -0
  38. pyconvexity/timeseries.py +330 -0
  39. pyconvexity/validation/__init__.py +25 -0
  40. pyconvexity/validation/rules.py +312 -0
  41. pyconvexity-0.4.8.dist-info/METADATA +148 -0
  42. pyconvexity-0.4.8.dist-info/RECORD +44 -0
  43. pyconvexity-0.4.8.dist-info/WHEEL +5 -0
  44. pyconvexity-0.4.8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,159 @@
1
+ """
2
+ Carrier management operations for PyConvexity.
3
+
4
+ Provides operations for querying carriers and their properties.
5
+ """
6
+
7
+ import sqlite3
8
+ import logging
9
+ from typing import Dict, List, Optional
10
+ from dataclasses import dataclass
11
+
12
+ from pyconvexity.core.errors import ValidationError
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ @dataclass
18
+ class Carrier:
19
+ """Represents an energy carrier in the network (single network per database)."""
20
+
21
+ id: int
22
+ name: str
23
+ co2_emissions: float
24
+ color: Optional[str]
25
+ nice_name: Optional[str]
26
+
27
+
28
+ def list_carriers(conn: sqlite3.Connection) -> List[Carrier]:
29
+ """
30
+ List all carriers for the network (single network per database).
31
+
32
+ Args:
33
+ conn: Database connection
34
+
35
+ Returns:
36
+ List of Carrier objects ordered by name
37
+ """
38
+ cursor = conn.execute(
39
+ """
40
+ SELECT id, name, co2_emissions, color, nice_name
41
+ FROM carriers
42
+ ORDER BY name
43
+ """
44
+ )
45
+
46
+ carriers = []
47
+ for row in cursor.fetchall():
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
+
58
+ return carriers
59
+
60
+
61
+ def get_carrier_by_name(conn: sqlite3.Connection, name: str) -> Carrier:
62
+ """
63
+ Get a carrier by name (single network per database).
64
+
65
+ Args:
66
+ conn: Database connection
67
+ name: Carrier name
68
+
69
+ Returns:
70
+ Carrier object
71
+
72
+ Raises:
73
+ ValidationError: If carrier doesn't exist
74
+ """
75
+ cursor = conn.execute(
76
+ """
77
+ SELECT id, name, co2_emissions, color, nice_name
78
+ FROM carriers
79
+ WHERE name = ?
80
+ """,
81
+ (name,),
82
+ )
83
+
84
+ row = cursor.fetchone()
85
+ if not row:
86
+ raise ValidationError(f"Carrier '{name}' not found")
87
+
88
+ return Carrier(
89
+ id=row[0],
90
+ name=row[1],
91
+ co2_emissions=row[2] or 0.0,
92
+ color=row[3],
93
+ nice_name=row[4],
94
+ )
95
+
96
+
97
+ def get_carrier_by_id(conn: sqlite3.Connection, carrier_id: int) -> Carrier:
98
+ """
99
+ Get a carrier by ID (single network per database).
100
+
101
+ Args:
102
+ conn: Database connection
103
+ carrier_id: Carrier ID
104
+
105
+ Returns:
106
+ Carrier object
107
+
108
+ Raises:
109
+ ValidationError: If carrier doesn't exist
110
+ """
111
+ cursor = conn.execute(
112
+ """
113
+ SELECT id, name, co2_emissions, color, nice_name
114
+ FROM carriers
115
+ WHERE id = ?
116
+ """,
117
+ (carrier_id,),
118
+ )
119
+
120
+ row = cursor.fetchone()
121
+ if not row:
122
+ raise ValidationError(f"Carrier with ID {carrier_id} not found")
123
+
124
+ return Carrier(
125
+ id=row[0],
126
+ name=row[1],
127
+ co2_emissions=row[2] or 0.0,
128
+ color=row[3],
129
+ nice_name=row[4],
130
+ )
131
+
132
+
133
+ def get_carrier_colors(conn: sqlite3.Connection) -> Dict[str, str]:
134
+ """
135
+ Get carrier colors for visualization (single network per database).
136
+
137
+ Args:
138
+ conn: Database connection
139
+
140
+ Returns:
141
+ Dictionary mapping carrier names to color strings
142
+ """
143
+ cursor = conn.execute(
144
+ """
145
+ SELECT name, color
146
+ FROM carriers
147
+ """
148
+ )
149
+
150
+ colors = {}
151
+ for row in cursor.fetchall():
152
+ if row[1]: # Only include if color is defined
153
+ colors[row[0]] = row[1]
154
+
155
+ # Add default color for Unmet Load if not present
156
+ if "Unmet Load" not in colors:
157
+ colors["Unmet Load"] = "#FF0000"
158
+
159
+ return colors