Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
803d680
Update core.py to work with another dimension
FBumann Mar 30, 2025
a83f2b1
Add scenarios to TimeSeries
FBumann Mar 30, 2025
8b06454
Update TimeSeriesCollection
FBumann Mar 30, 2025
74c18c2
Update get_numeric_stats() to return values per scenario
FBumann Mar 30, 2025
3927e29
Update repr and str
FBumann Mar 30, 2025
132c119
Improve stats
FBumann Mar 30, 2025
89eaa4e
Add utility methods to analyze data
FBumann Mar 30, 2025
b2aba8f
Move test insto class
FBumann Mar 30, 2025
7993df7
Improve DataConverter
FBumann Mar 30, 2025
ccaac59
Improve DataConverter
FBumann Mar 30, 2025
91a1bb8
Improve conversion and copying
FBumann Mar 30, 2025
108afd3
Improve conversion and copying
FBumann Mar 30, 2025
a1ce245
Update tests
FBumann Mar 30, 2025
7ae3814
Update test
FBumann Mar 30, 2025
23e5088
Bugfix stats
FBumann Mar 30, 2025
d734a58
Bugfix stored_data.setter
FBumann Mar 30, 2025
0de5015
Improve __str__ of TimeSeries
FBumann Mar 30, 2025
f827d91
Bugfixes
FBumann Mar 30, 2025
63e59b2
Add tests
FBumann Mar 30, 2025
fc339d8
Temp
FBumann Mar 30, 2025
2bfa397
Simplify the TImeSeriesCollection
FBumann Mar 30, 2025
d7acaf0
Simplify the TImeSeriesCollection
FBumann Mar 30, 2025
70808d1
Add test script
FBumann Mar 30, 2025
d21dd50
Improve TImeSeriesAllocator
FBumann Mar 30, 2025
5dc3c78
Update TimeSeries
FBumann Mar 31, 2025
6edc87d
Update TimeSeries
FBumann Mar 31, 2025
168aa39
Update selection
FBumann Mar 31, 2025
3cc2b41
Renaming
FBumann Mar 31, 2025
e69631b
Update TimeSeriesAllocator
FBumann Mar 31, 2025
6988e2a
Update TimeSeriesAllocator
FBumann Mar 31, 2025
acf869c
Update TimeSeriesAllocator
FBumann Mar 31, 2025
c3f5b00
Update TimeSeriesAllocator
FBumann Mar 31, 2025
84715c3
Update selection
FBumann Mar 31, 2025
f9d3840
Improve selection
FBumann Mar 31, 2025
8c9a859
Improve validation of Timesteps
FBumann Mar 31, 2025
580e99a
Improve TimeSeries
FBumann Mar 31, 2025
9a93e92
Improve TimeSeriesAllocator
FBumann Mar 31, 2025
14b4f58
Update calculation and FlowSystem
FBumann Mar 31, 2025
0d3fc2e
rename active_data to selected_data
FBumann Mar 31, 2025
fb281df
Add property
FBumann Mar 31, 2025
30994d5
Improve type hints
FBumann Mar 31, 2025
af697fe
Improve type hints
FBumann Mar 31, 2025
f240268
Add options to get data without extra timestep
FBumann Mar 31, 2025
054d0fc
Rename
FBumann Mar 31, 2025
1b320b0
Update tests
FBumann Mar 31, 2025
f96a815
Bugfix for TImeSeriesData to work
FBumann Mar 31, 2025
8c7b986
Update calculation.py
FBumann Mar 31, 2025
57cf231
Bugfix
FBumann Mar 31, 2025
5857773
Improve as_dataset to improve aggregation
FBumann Mar 31, 2025
0376fca
Bugfix
FBumann Mar 31, 2025
28fac88
Update test
FBumann Mar 31, 2025
6e2d7bf
Remove test script
FBumann Mar 31, 2025
28b8199
ruff check
FBumann Mar 31, 2025
02f57f0
Revert some renaming
FBumann Mar 31, 2025
9c66de5
Bugfix in test
FBumann Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions flixopt/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def solve(self, solver: _Solver, log_file: Optional[pathlib.Path] = None, log_ma

def _activate_time_series(self):
self.flow_system.transform_data()
self.flow_system.time_series_collection.activate_timesteps(
active_timesteps=self.active_timesteps,
self.flow_system.time_series_collection.set_selection(
timesteps=self.active_timesteps
)


Expand Down Expand Up @@ -217,6 +217,8 @@ def __init__(
list with indices, which should be used for calculation. If None, then all timesteps are used.
folder: folder where results should be saved. If None, then the current working directory is used.
"""
if flow_system.time_series_collection.scenarios is not None:
raise ValueError('Aggregation is not supported for scenarios yet. Please use FullCalculation instead.')
super().__init__(name, flow_system, active_timesteps, folder=folder)
self.aggregation_parameters = aggregation_parameters
self.components_to_clusterize = components_to_clusterize
Expand Down Expand Up @@ -272,9 +274,9 @@ def _perform_aggregation(self):

# Aggregation - creation of aggregated timeseries:
self.aggregation = Aggregation(
original_data=self.flow_system.time_series_collection.to_dataframe(
include_extra_timestep=False
), # Exclude last row (NaN)
original_data=self.flow_system.time_series_collection.as_dataset(
with_extra_timestep=False, with_constants=False
).to_dataframe(),
hours_per_time_step=float(dt_min),
hours_per_period=self.aggregation_parameters.hours_per_period,
nr_of_periods=self.aggregation_parameters.nr_of_periods,
Expand All @@ -286,9 +288,11 @@ def _perform_aggregation(self):
self.aggregation.cluster()
self.aggregation.plot(show=True, save=self.folder / 'aggregation.html')
if self.aggregation_parameters.aggregate_data_and_fix_non_binary_vars:
self.flow_system.time_series_collection.insert_new_data(
self.aggregation.aggregated_data, include_extra_timestep=False
)
for col in self.aggregation.aggregated_data.columns:
data = self.aggregation.aggregated_data[col].values
if col in self.flow_system.time_series_collection._has_extra_timestep:
data = np.append(data, data[-1])
self.flow_system.time_series_collection.update_time_series(col, data)
self.durations['aggregation'] = round(timeit.default_timer() - t_start_agg, 2)


Expand Down Expand Up @@ -327,8 +331,8 @@ def __init__(
self.nr_of_previous_values = nr_of_previous_values
self.sub_calculations: List[FullCalculation] = []

self.all_timesteps = self.flow_system.time_series_collection.all_timesteps
self.all_timesteps_extra = self.flow_system.time_series_collection.all_timesteps_extra
self.all_timesteps = self.flow_system.time_series_collection._full_timesteps
self.all_timesteps_extra = self.flow_system.time_series_collection._full_timesteps_extra

self.segment_names = [
f'Segment_{i + 1}' for i in range(math.ceil(len(self.all_timesteps) / self.timesteps_per_segment))
Expand Down
24 changes: 12 additions & 12 deletions flixopt/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ def transform_data(self, flow_system: 'FlowSystem') -> None:
self.relative_minimum_charge_state = flow_system.create_time_series(
f'{self.label_full}|relative_minimum_charge_state',
self.relative_minimum_charge_state,
needs_extra_timestep=True,
has_extra_timestep=True,
)
self.relative_maximum_charge_state = flow_system.create_time_series(
f'{self.label_full}|relative_maximum_charge_state',
self.relative_maximum_charge_state,
needs_extra_timestep=True,
has_extra_timestep=True,
)
self.eta_charge = flow_system.create_time_series(f'{self.label_full}|eta_charge', self.eta_charge)
self.eta_discharge = flow_system.create_time_series(f'{self.label_full}|eta_discharge', self.eta_discharge)
Expand Down Expand Up @@ -342,7 +342,7 @@ def __init__(self, model: SystemModel, element: Transmission):
def do_modeling(self):
"""Initiates all FlowModels"""
# Force On Variable if absolute losses are present
if (self.element.absolute_losses is not None) and np.any(self.element.absolute_losses.active_data != 0):
if (self.element.absolute_losses is not None) and np.any(self.element.absolute_losses.selected_data != 0):
for flow in self.element.inputs + self.element.outputs:
if flow.on_off_parameters is None:
flow.on_off_parameters = OnOffParameters()
Expand Down Expand Up @@ -379,14 +379,14 @@ def create_transmission_equation(self, name: str, in_flow: Flow, out_flow: Flow)
# eq: out(t) + on(t)*loss_abs(t) = in(t)*(1 - loss_rel(t))
con_transmission = self.add(
self._model.add_constraints(
out_flow.model.flow_rate == -in_flow.model.flow_rate * (self.element.relative_losses.active_data - 1),
out_flow.model.flow_rate == -in_flow.model.flow_rate * (self.element.relative_losses.selected_data - 1),
name=f'{self.label_full}|{name}',
),
name,
)

if self.element.absolute_losses is not None:
con_transmission.lhs += in_flow.model.on_off.on * self.element.absolute_losses.active_data
con_transmission.lhs += in_flow.model.on_off.on * self.element.absolute_losses.selected_data

return con_transmission

Expand All @@ -413,8 +413,8 @@ def do_modeling(self):

self.add(
self._model.add_constraints(
sum([flow.model.flow_rate * conv_factors[flow.label].active_data for flow in used_inputs])
== sum([flow.model.flow_rate * conv_factors[flow.label].active_data for flow in used_outputs]),
sum([flow.model.flow_rate * conv_factors[flow.label].selected_data for flow in used_inputs])
== sum([flow.model.flow_rate * conv_factors[flow.label].selected_data for flow in used_outputs]),
name=f'{self.label_full}|conversion_{i}',
)
)
Expand Down Expand Up @@ -474,12 +474,12 @@ def do_modeling(self):
)

charge_state = self.charge_state
rel_loss = self.element.relative_loss_per_hour.active_data
rel_loss = self.element.relative_loss_per_hour.selected_data
hours_per_step = self._model.hours_per_step
charge_rate = self.element.charging.model.flow_rate
discharge_rate = self.element.discharging.model.flow_rate
eff_charge = self.element.eta_charge.active_data
eff_discharge = self.element.eta_discharge.active_data
eff_charge = self.element.eta_charge.selected_data
eff_discharge = self.element.eta_discharge.selected_data

self.add(
self._model.add_constraints(
Expand Down Expand Up @@ -565,8 +565,8 @@ def absolute_charge_state_bounds(self) -> Tuple[NumericData, NumericData]:
@property
def relative_charge_state_bounds(self) -> Tuple[NumericData, NumericData]:
return (
self.element.relative_minimum_charge_state.active_data,
self.element.relative_maximum_charge_state.active_data,
self.element.relative_minimum_charge_state.selected_data,
self.element.relative_maximum_charge_state.selected_data,
)


Expand Down
Loading