zen-garden 2.8.13__py3-none-any.whl → 2.9.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.
- zen_garden/__init__.py +1 -0
- zen_garden/cli/zen_garden_cli.py +21 -13
- zen_garden/cli/zen_operation_cli.py +89 -0
- zen_garden/default_config.py +1 -4
- zen_garden/optimization_setup.py +40 -176
- zen_garden/postprocess/postprocess.py +4 -34
- zen_garden/postprocess/results/results.py +11 -13
- zen_garden/postprocess/results/solution_loader.py +68 -36
- zen_garden/preprocess/unit_handling.py +393 -100
- zen_garden/runner.py +28 -34
- zen_garden/wrapper/__init__.py +0 -0
- zen_garden/wrapper/operation_scenarios.py +248 -0
- zen_garden/wrapper/utils.py +438 -0
- {zen_garden-2.8.13.dist-info → zen_garden-2.9.1.dist-info}/METADATA +2 -2
- {zen_garden-2.8.13.dist-info → zen_garden-2.9.1.dist-info}/RECORD +18 -14
- {zen_garden-2.8.13.dist-info → zen_garden-2.9.1.dist-info}/entry_points.txt +1 -0
- {zen_garden-2.8.13.dist-info → zen_garden-2.9.1.dist-info}/WHEEL +0 -0
- {zen_garden-2.8.13.dist-info → zen_garden-2.9.1.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -129,7 +129,7 @@ class Scenario():
|
|
|
129
129
|
folder.
|
|
130
130
|
"""
|
|
131
131
|
|
|
132
|
-
def __init__(self, path: str, name: str, base_scenario: str
|
|
132
|
+
def __init__(self, path: str, name: str, base_scenario: str) -> None:
|
|
133
133
|
self.name = name
|
|
134
134
|
self.base_name = base_scenario
|
|
135
135
|
self._exists = True
|
|
@@ -138,8 +138,9 @@ class Scenario():
|
|
|
138
138
|
self._system: System = self._read_system()
|
|
139
139
|
self._solver: Solver = self._read_solver()
|
|
140
140
|
self._benchmarking: dict[str,Any] = self._read_benchmarking()
|
|
141
|
-
self.
|
|
142
|
-
self._components: dict[str, Component] =
|
|
141
|
+
self._component_types: dict[str, list[str]] = None
|
|
142
|
+
self._components: dict[str, Component] = None
|
|
143
|
+
self._read_components()
|
|
143
144
|
|
|
144
145
|
def _read_analysis(self) -> Analysis:
|
|
145
146
|
analysis_path = os.path.join(self.path, "analysis.json")
|
|
@@ -177,8 +178,12 @@ class Scenario():
|
|
|
177
178
|
else:
|
|
178
179
|
return {}
|
|
179
180
|
|
|
180
|
-
def _read_ureg(self
|
|
181
|
-
|
|
181
|
+
def _read_ureg(self) -> pint.UnitRegistry:
|
|
182
|
+
|
|
183
|
+
# suppress pint output about redefining units
|
|
184
|
+
logging.getLogger('pint').setLevel(logging.ERROR)
|
|
185
|
+
# load ureg
|
|
186
|
+
ureg = copy.copy(pint.UnitRegistry())
|
|
182
187
|
unit_path = os.path.join(self.path, "unit_definitions.txt")
|
|
183
188
|
if os.path.exists(unit_path):
|
|
184
189
|
ureg.load_definitions(unit_path)
|
|
@@ -216,7 +221,7 @@ class Scenario():
|
|
|
216
221
|
raise KeyError(f"Year {year} not in optimized years {all_years}.")
|
|
217
222
|
return ts
|
|
218
223
|
|
|
219
|
-
def _read_components(self) -> dict[str,
|
|
224
|
+
def _read_components(self) -> dict[str, list[str]]:
|
|
220
225
|
"""
|
|
221
226
|
Create the component instances.
|
|
222
227
|
|
|
@@ -224,8 +229,12 @@ class Scenario():
|
|
|
224
229
|
the component. Furthermore, the timestep name and type are derived by checking
|
|
225
230
|
if any of the defined time steps name is in the index of the dataframe.
|
|
226
231
|
"""
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
component_types: dict[str,list[str]] = {t: [] for t in ComponentType.get_component_type_names()}
|
|
233
|
+
components:dict[str,dict] = {}
|
|
234
|
+
|
|
235
|
+
if not self._exists:
|
|
236
|
+
return component_types
|
|
237
|
+
|
|
229
238
|
if self.has_rh:
|
|
230
239
|
mf_name = [i for i in os.listdir(self.path) if "MF_" in i][0]
|
|
231
240
|
component_folder = os.path.join(self.path, mf_name)
|
|
@@ -237,36 +246,22 @@ class Scenario():
|
|
|
237
246
|
|
|
238
247
|
if not os.path.exists(file_path):
|
|
239
248
|
continue
|
|
240
|
-
|
|
249
|
+
|
|
241
250
|
h5_file = h5py.File(file_path)
|
|
242
|
-
|
|
243
|
-
for
|
|
244
|
-
index_names = get_index_names(h5_file,component_name,version)
|
|
245
|
-
time_index = set(index_names).intersection(set(TimestepType.get_time_steps_names()))
|
|
246
|
-
timestep_name = time_index.pop() if len(time_index) > 0 else None
|
|
247
|
-
timestep_type = TimestepType.get_time_step_type(timestep_name)
|
|
248
|
-
|
|
249
|
-
doc = get_doc(h5_file,component_name,version)
|
|
250
|
-
|
|
251
|
-
has_units = get_has_units(h5_file,component_name,version)
|
|
252
|
-
|
|
253
|
-
ans[component_name] = Component(
|
|
254
|
-
component_name,
|
|
255
|
-
component_type,
|
|
256
|
-
index_names,
|
|
257
|
-
timestep_type,
|
|
258
|
-
timestep_name,
|
|
259
|
-
file_name,
|
|
260
|
-
doc,
|
|
261
|
-
has_units
|
|
262
|
-
)
|
|
251
|
+
component_types[component_type.value] = list(h5_file.keys())
|
|
252
|
+
components.update({cn: {"component_type": component_type, "file_name": file_name, "file_path": file_path} for cn in h5_file.keys()})
|
|
263
253
|
|
|
264
|
-
|
|
254
|
+
self._component_types = component_types
|
|
255
|
+
self._components = components
|
|
265
256
|
|
|
266
257
|
@property
|
|
267
|
-
def components(self) -> dict[str,
|
|
258
|
+
def components(self) -> dict[str, dict]:
|
|
268
259
|
return self._components
|
|
269
260
|
|
|
261
|
+
@property
|
|
262
|
+
def component_types(self) -> dict[str, list[str]]:
|
|
263
|
+
return self._component_types
|
|
264
|
+
|
|
270
265
|
@property
|
|
271
266
|
def analysis(self) -> Analysis:
|
|
272
267
|
return self._analysis
|
|
@@ -293,11 +288,48 @@ class Scenario():
|
|
|
293
288
|
|
|
294
289
|
@property
|
|
295
290
|
def ureg(self) -> pint.UnitRegistry:
|
|
296
|
-
return self.
|
|
291
|
+
return self._read_ureg()
|
|
297
292
|
|
|
298
293
|
@property
|
|
299
294
|
def exists(self) -> bool:
|
|
300
295
|
return self._exists
|
|
296
|
+
|
|
297
|
+
def get_component(self, component_name: str) -> Component:
|
|
298
|
+
"""
|
|
299
|
+
Method that returns a component given its name.
|
|
300
|
+
:param component_name: The name of the component.
|
|
301
|
+
:return: The component.
|
|
302
|
+
"""
|
|
303
|
+
if component_name not in self.components:
|
|
304
|
+
raise KeyError(f"Component {component_name} not found in scenario {self.name}. Available components: {list(self.components.keys())}")
|
|
305
|
+
|
|
306
|
+
component_info = self.components[component_name]
|
|
307
|
+
component_type = component_info["component_type"]
|
|
308
|
+
file_name = component_info["file_name"]
|
|
309
|
+
|
|
310
|
+
h5_file = h5py.File(component_info["file_path"])
|
|
311
|
+
version = get_solution_version(self)
|
|
312
|
+
index_names = get_index_names(h5_file,component_name,version)
|
|
313
|
+
time_index = set(index_names).intersection(set(TimestepType.get_time_steps_names()))
|
|
314
|
+
timestep_name = time_index.pop() if len(time_index) > 0 else None
|
|
315
|
+
timestep_type = TimestepType.get_time_step_type(timestep_name)
|
|
316
|
+
|
|
317
|
+
doc = get_doc(h5_file,component_name,version)
|
|
318
|
+
|
|
319
|
+
has_units = get_has_units(h5_file,component_name,version)
|
|
320
|
+
|
|
321
|
+
ans = Component(
|
|
322
|
+
component_name,
|
|
323
|
+
component_type,
|
|
324
|
+
index_names,
|
|
325
|
+
timestep_type,
|
|
326
|
+
timestep_name,
|
|
327
|
+
file_name,
|
|
328
|
+
doc,
|
|
329
|
+
has_units
|
|
330
|
+
)
|
|
331
|
+
return ans
|
|
332
|
+
|
|
301
333
|
|
|
302
334
|
class SolutionLoader():
|
|
303
335
|
"""
|
|
@@ -308,6 +340,7 @@ class SolutionLoader():
|
|
|
308
340
|
self.path = path
|
|
309
341
|
assert len(os.listdir(path)) > 0, f"Path {path} is empty."
|
|
310
342
|
self._scenarios: dict[str, Scenario] = self._read_scenarios()
|
|
343
|
+
self._ureg = get_first_scenario(self._scenarios).ureg
|
|
311
344
|
self._series_cache: dict[str, "pd.Series[Any]"] = {}
|
|
312
345
|
self.enable_cache = enable_cache
|
|
313
346
|
|
|
@@ -463,14 +496,13 @@ class SolutionLoader():
|
|
|
463
496
|
"""
|
|
464
497
|
scenarios_json_path = os.path.join(self.path, "scenarios.json")
|
|
465
498
|
ans: dict[str, Scenario] = {}
|
|
466
|
-
default_ureg = pint.UnitRegistry()
|
|
467
499
|
with open(scenarios_json_path, "r") as f:
|
|
468
500
|
scenario_configs = json.load(f)
|
|
469
501
|
|
|
470
502
|
if len(scenario_configs) == 1:
|
|
471
503
|
scenario_name = "none"
|
|
472
504
|
scenario_path = self.path
|
|
473
|
-
ans[scenario_name] = Scenario(scenario_path, scenario_name, ""
|
|
505
|
+
ans[scenario_name] = Scenario(scenario_path, scenario_name, "")
|
|
474
506
|
else:
|
|
475
507
|
for scenario_id, scenario_config in scenario_configs.items():
|
|
476
508
|
scenario_name = f"scenario_{scenario_id}"
|
|
@@ -490,7 +522,7 @@ class SolutionLoader():
|
|
|
490
522
|
)
|
|
491
523
|
|
|
492
524
|
scenario = Scenario(
|
|
493
|
-
scenario_path, scenario_name, base_scenario
|
|
525
|
+
scenario_path, scenario_name, base_scenario
|
|
494
526
|
)
|
|
495
527
|
|
|
496
528
|
if scenario.exists:
|