flixopt 3.0.1__py3-none-any.whl → 6.0.0rc7__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.
- flixopt/__init__.py +57 -49
- flixopt/carrier.py +159 -0
- flixopt/clustering/__init__.py +51 -0
- flixopt/clustering/base.py +1746 -0
- flixopt/clustering/intercluster_helpers.py +201 -0
- flixopt/color_processing.py +372 -0
- flixopt/comparison.py +819 -0
- flixopt/components.py +848 -270
- flixopt/config.py +853 -496
- flixopt/core.py +111 -98
- flixopt/effects.py +294 -284
- flixopt/elements.py +484 -223
- flixopt/features.py +220 -118
- flixopt/flow_system.py +2026 -389
- flixopt/interface.py +504 -286
- flixopt/io.py +1718 -55
- flixopt/linear_converters.py +291 -230
- flixopt/modeling.py +304 -181
- flixopt/network_app.py +2 -1
- flixopt/optimization.py +788 -0
- flixopt/optimize_accessor.py +373 -0
- flixopt/plot_result.py +143 -0
- flixopt/plotting.py +1177 -1034
- flixopt/results.py +1331 -372
- flixopt/solvers.py +12 -4
- flixopt/statistics_accessor.py +2412 -0
- flixopt/stats_accessor.py +75 -0
- flixopt/structure.py +954 -120
- flixopt/topology_accessor.py +676 -0
- flixopt/transform_accessor.py +2277 -0
- flixopt/types.py +120 -0
- flixopt-6.0.0rc7.dist-info/METADATA +290 -0
- flixopt-6.0.0rc7.dist-info/RECORD +36 -0
- {flixopt-3.0.1.dist-info → flixopt-6.0.0rc7.dist-info}/WHEEL +1 -1
- flixopt/aggregation.py +0 -382
- flixopt/calculation.py +0 -672
- flixopt/commons.py +0 -51
- flixopt/utils.py +0 -86
- flixopt-3.0.1.dist-info/METADATA +0 -209
- flixopt-3.0.1.dist-info/RECORD +0 -26
- {flixopt-3.0.1.dist-info → flixopt-6.0.0rc7.dist-info}/licenses/LICENSE +0 -0
- {flixopt-3.0.1.dist-info → flixopt-6.0.0rc7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Xarray accessor for statistics and transformations (``.fxstats``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import xarray as xr
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@xr.register_dataset_accessor('fxstats')
|
|
10
|
+
class DatasetStatsAccessor:
|
|
11
|
+
"""Statistics/transformation accessor for any xr.Dataset. Access via ``dataset.fxstats``.
|
|
12
|
+
|
|
13
|
+
Provides data transformation methods that return new datasets.
|
|
14
|
+
Chain with ``.plotly`` for visualization.
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
Duration curve::
|
|
18
|
+
|
|
19
|
+
ds.fxstats.to_duration_curve().plotly.line()
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, xarray_obj: xr.Dataset) -> None:
|
|
23
|
+
self._ds = xarray_obj
|
|
24
|
+
|
|
25
|
+
def to_duration_curve(self, *, normalize: bool = True) -> xr.Dataset:
|
|
26
|
+
"""Transform dataset to duration curve format (sorted values).
|
|
27
|
+
|
|
28
|
+
Values are sorted in descending order along the 'time' dimension.
|
|
29
|
+
The time coordinate is replaced with duration (percentage or index).
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
normalize: If True, x-axis shows percentage (0-100). If False, shows timestep index.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Transformed xr.Dataset with duration coordinate instead of time.
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
>>> ds.fxstats.to_duration_curve().plotly.line(title='Duration Curve')
|
|
39
|
+
"""
|
|
40
|
+
if 'time' not in self._ds.dims:
|
|
41
|
+
raise ValueError("Duration curve requires a 'time' dimension.")
|
|
42
|
+
|
|
43
|
+
# Sort each variable along time dimension (descending), preserving attributes
|
|
44
|
+
sorted_vars = {}
|
|
45
|
+
for var in self._ds.data_vars:
|
|
46
|
+
da = self._ds[var]
|
|
47
|
+
if 'time' not in da.dims:
|
|
48
|
+
# Keep variables without time dimension unchanged
|
|
49
|
+
sorted_vars[var] = da
|
|
50
|
+
continue
|
|
51
|
+
time_axis = da.dims.index('time')
|
|
52
|
+
sorted_values = np.flip(np.sort(da.values, axis=time_axis), axis=time_axis)
|
|
53
|
+
sorted_vars[var] = xr.DataArray(
|
|
54
|
+
sorted_values,
|
|
55
|
+
dims=da.dims,
|
|
56
|
+
coords={k: v for k, v in da.coords.items() if k != 'time'},
|
|
57
|
+
attrs=da.attrs,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Preserve non-time coordinates from the original dataset
|
|
61
|
+
non_time_coords = {k: v for k, v in self._ds.coords.items() if k != 'time'}
|
|
62
|
+
sorted_ds = xr.Dataset(sorted_vars, coords=non_time_coords, attrs=self._ds.attrs)
|
|
63
|
+
|
|
64
|
+
# Replace time coordinate with duration
|
|
65
|
+
n_timesteps = sorted_ds.sizes['time']
|
|
66
|
+
if normalize:
|
|
67
|
+
duration_coord = np.linspace(0, 100, n_timesteps)
|
|
68
|
+
sorted_ds = sorted_ds.assign_coords({'time': duration_coord})
|
|
69
|
+
sorted_ds = sorted_ds.rename({'time': 'duration_pct'})
|
|
70
|
+
else:
|
|
71
|
+
duration_coord = np.arange(n_timesteps)
|
|
72
|
+
sorted_ds = sorted_ds.assign_coords({'time': duration_coord})
|
|
73
|
+
sorted_ds = sorted_ds.rename({'time': 'duration'})
|
|
74
|
+
|
|
75
|
+
return sorted_ds
|