Skip to content

Commit

Permalink
Renamed TimeSeriesRaw to TImeSeriesData and .value to .data
Browse files Browse the repository at this point in the history
  • Loading branch information
FBumann committed Oct 21, 2024
1 parent 2ce5098 commit 3350a89
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions examples/Ex03_full_seg_agg/Model_and_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@
minimal_final_charge_state=137, maximal_final_charge_state=158,
eta_load=1, eta_unload=1, relative_loss_per_hour=0.001, prevent_simultaneous_charge_and_discharge=True)

TS_Q_th_Last = TimeSeriesRaw(Q_th_Last)
TS_Q_th_Last = TimeSeriesData(Q_th_Last)
aWaermeLast = Sink('Wärmelast', sink=Flow('Q_th_Last', bus=Fernwaerme, size=1, fixed_relative_value=TS_Q_th_Last))

# TS with explicit defined weight
TS_P_el_Last = TimeSeriesRaw(P_el_Last, agg_weight=0.7) # explicit defined weight
TS_P_el_Last = TimeSeriesData(P_el_Last, agg_weight=0.7) # explicit defined weight
aStromLast = Sink('Stromlast', sink=Flow('P_el_Last', bus=Strom, size=1, fixed_relative_value=TS_P_el_Last))

aKohleTarif = Source('Kohletarif',
Expand All @@ -171,8 +171,8 @@
aGasTarif = Source('Gastarif', source=Flow('Q_Gas', bus=Gas, size=1000, effects_per_flow_hour={costs: gP, CO2: 0.3}))

# 2 TS with same aggType (--> implicit defined weigth = 0.5)
p_feed_in = TimeSeriesRaw(-(p_el - 0.5), agg_group='p_el') # weight shared in group p_el
p_sell = TimeSeriesRaw(p_el + 0.5, agg_group='p_el')
p_feed_in = TimeSeriesData(-(p_el - 0.5), agg_group='p_el') # weight shared in group p_el
p_sell = TimeSeriesData(p_el + 0.5, agg_group='p_el')
# p_feed_in = p_feed_in.value # only value
# p_sell = p_sell.value # only value
aStromEinspeisung = Sink('Einspeisung', sink=Flow('P_el', bus=Strom, size=1000, effects_per_flow_hour=p_feed_in))
Expand Down
2 changes: 1 addition & 1 deletion flixOpt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
from flixOpt.calculation import FullCalculation, SegmentedCalculation, AggregatedCalculation
from flixOpt.interface import InvestParameters, OnOffParameters
from flixOpt.postprocessing import flix_results
from flixOpt.core import setup_logging, change_logging_level, TimeSeriesRaw
from flixOpt.core import setup_logging, change_logging_level, TimeSeriesData
setup_logging('INFO')
10 changes: 5 additions & 5 deletions flixOpt/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from flixOpt.elements import Flow
from flixOpt.flow_system import FlowSystem
from flixOpt.components import Storage
from flixOpt.core import TimeSeriesRaw
from flixOpt.core import TimeSeriesData
from flixOpt.structure import Element, SystemModel
from flixOpt.math_modeling import Equation, Variable

Expand Down Expand Up @@ -372,8 +372,8 @@ def addPeak_Min_labels(self):

def __init__(self,
time_series_list: List[TimeSeries],
addPeakMax_TSraw: Optional[List[TimeSeriesRaw]] = None,
addPeakMin_TSraw: Optional[List[TimeSeriesRaw]] = None):
addPeakMax_TSraw: Optional[List[TimeSeriesData]] = None,
addPeakMin_TSraw: Optional[List[TimeSeriesData]] = None):
self.time_series_list = time_series_list
self.addPeakMax_TSraw = addPeakMax_TSraw or []
self.addPeakMin_TSraw = addPeakMin_TSraw or []
Expand Down Expand Up @@ -444,8 +444,8 @@ def _getWeight(self, aTS: TimeSeries):
def _checkPeak_TSraw(self, aTSrawlist):
if aTSrawlist is not None:
for aTSraw in aTSrawlist:
if not isinstance(aTSraw, TimeSeriesRaw):
raise Exception('addPeak_max/min must be list of TimeSeriesRaw-objects!')
if not isinstance(aTSraw, TimeSeriesData):
raise Exception('addPeak_max/min must be list of TimeSeriesData-objects!')

def __str__(self) -> str:
result = f'{len(self.time_series_list)} TimeSeries used for aggregation:\n'
Expand Down
6 changes: 3 additions & 3 deletions flixOpt/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from flixOpt import utils
from flixOpt.aggregation import TimeSeriesCollection
from flixOpt.core import Skalar, Numeric, TimeSeriesRaw
from flixOpt.core import Skalar, Numeric, TimeSeriesData
from flixOpt.math_modeling import VariableTS
from flixOpt.structure import SystemModel
from flixOpt.flow_system import FlowSystem
Expand Down Expand Up @@ -195,10 +195,10 @@ def do_modeling(self, periodLengthInHours, nr_of_typical_periods, use_extreme_pe
useOriginalTimeSeries : boolean.
orginal or aggregated timeseries should
be chosen for the calculation. default is False.
addPeakMax : list of TimeSeriesRaw
addPeakMax : list of TimeSeriesData
list of data-timeseries. The period with the max-value are
chosen as a explicitly period.
addPeakMin : list of TimeSeriesRaw
addPeakMin : list of TimeSeriesData
list of data-timeseries. The period with the min-value are
chosen as a explicitly period.
Expand Down
26 changes: 13 additions & 13 deletions flixOpt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
# Datatype Numeric_TS:
# Skalar --> wird später dann in array ("Zeitreihe" mit length=nrOfTimeIndexe) übersetzt
# np.ndarray --> muss length=nrOfTimeIndexe haben ("Zeitreihe")
# TimeSeriesRaw --> wie obige aber zusätzliche Übergabe aggWeight (für Aggregation)
# TimeSeriesData --> wie obige aber zusätzliche Übergabe aggWeight (für Aggregation)


class TimeSeriesRaw:
class TimeSeriesData:
def __init__(self,
value: Union[int, float, np.ndarray],
data: Numeric,
agg_group: Optional[str] = None,
agg_weight: Optional[float] = None):
"""
Expand All @@ -34,18 +34,18 @@ def __init__(self,
EXAMPLE solar:
you have several solar timeseries. These should not be overweighted
compared to the remaining timeseries (i.g. heat load, price)!
fixed_relative_value_solar1 = TimeSeriesRaw(sol_array_1, type = 'solar')
fixed_relative_value_solar2 = TimeSeriesRaw(sol_array_2, type = 'solar')
fixed_relative_value_solar3 = TimeSeriesRaw(sol_array_3, type = 'solar')
fixed_relative_value_solar1 = TimeSeriesData(sol_array_1, type = 'solar')
fixed_relative_value_solar2 = TimeSeriesData(sol_array_2, type = 'solar')
fixed_relative_value_solar3 = TimeSeriesData(sol_array_3, type = 'solar')
--> this 3 series of same type share one weight, i.e. internally assigned each weight = 1/3
(instead of standard weight = 1)
Parameters
----------
value : Union[int, float, np.ndarray]
data : Union[int, float, np.ndarray]
The timeseries data, which can be a scalar, array, or numpy array.
agg_group : str, optional
The group this TimeSeriesRaw is a part of. agg_weight is split between members of a group. Default is None.
The group this TimeSeriesData is a part of. agg_weight is split between members of a group. Default is None.
agg_weight : float, optional
The weight for calculation_type 'aggregated', should be between 0 and 1. Default is None.
Expand All @@ -54,14 +54,14 @@ def __init__(self,
Exception
If both agg_group and agg_weight are set, an exception is raised.
"""
self.value = value
self.data = data
self.agg_group = agg_group
self.agg_weight = agg_weight
if (agg_group is not None) and (agg_weight is not None):
raise Exception('Either <agg_group> or explicit <agg_weigth> can be used. Not both!')

def __repr__(self):
return f"TimeSeriesRaw(value={self.value}, agg_group={self.agg_group}, agg_weight={self.agg_weight})"
return f"TimeSeriesData(value={self.data}, agg_group={self.agg_group}, agg_weight={self.agg_weight})"


class TimeSeries:
Expand All @@ -76,7 +76,7 @@ class TimeSeries:
----------
label : str
The label for the time series.
TSraw : Optional[TimeSeriesRaw]
TSraw : Optional[TimeSeriesData]
The raw time series data if provided as cTSraw.
data : Optional[Numeric]
The actual data for the time series. Can be None.
Expand All @@ -94,8 +94,8 @@ def __init__(self, label: str, data: Optional[Numeric_TS]):
self.explicit_active_data: Optional[Numeric] = None # Shortcut fneeded for aggregation. TODO: Improve this!
self.TSraw = None

if isinstance(data, TimeSeriesRaw):
self.data: Optional[Numeric] = self.make_scalar_if_possible(data.value)
if isinstance(data, TimeSeriesData):
self.data: Optional[Numeric] = self.make_scalar_if_possible(data.data)
self.TSraw = data
else:
self.data: Optional[Numeric] = self.make_scalar_if_possible(data)
Expand Down
10 changes: 5 additions & 5 deletions flixOpt/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self,
----------
label : str
name.
excess_penalty_per_flow_hour : none or scalar, array or TimeSeriesRaw
excess_penalty_per_flow_hour : none or scalar, array or TimeSeriesData
excess costs / penalty costs (bus balance compensation)
(none/ 0 -> no penalty). The default is 1e5.
(Take care: if you use a timeseries (no scalar), timeseries is aggregated if calculation_type = aggregated!)
Expand Down Expand Up @@ -187,9 +187,9 @@ def __init__(self,
name of flow
bus : Bus, optional
bus to which flow is linked
relative_minimum : scalar, array, TimeSeriesRaw, optional
relative_minimum : scalar, array, TimeSeriesData, optional
min value is relative_minimum multiplied by size
relative_maximum : scalar, array, TimeSeriesRaw, optional
relative_maximum : scalar, array, TimeSeriesData, optional
max value is relative_maximum multiplied by size. If size = max then relative_maximum=1
size : scalar. None if is a nominal value is a opt-variable, optional
nominal value/ invest size (linked to relative_minimum, relative_maximum and others).
Expand All @@ -202,7 +202,7 @@ def __init__(self,
def: :math:`load\_factor:= sumFlowHours/ (nominal\_val \cdot \Delta t_{tot})`
load_factor_max : scalar, optional
maximal load factor (see minimal load factor)
effects_per_flow_hour : scalar, array, TimeSeriesRaw, optional
effects_per_flow_hour : scalar, array, TimeSeriesData, optional
operational costs, costs per flow-"work"
can_be_off : OnOffParameters, optional
flow can be "off", i.e. be zero (only relevant if relative_minimum > 0)
Expand All @@ -214,7 +214,7 @@ def __init__(self,
flow_hours_total_min : TYPE, optional
minimum flow-hours ("flow-work")
(if size is not const, maybe load_factor_min fits better for you!)
fixed_relative_value : scalar, array, TimeSeriesRaw, optional
fixed_relative_value : scalar, array, TimeSeriesData, optional
fixed relative values for flow (if given).
val(t) := fixed_relative_value(t) * size(t)
With this value, the flow-value is no opt-variable anymore;
Expand Down
2 changes: 1 addition & 1 deletion flixOpt/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self,
(last off-time period of timeseries is not checked and can be shorter)
consecutive_off_hours_max : scalar, optional
max sum of non-operating hours in one piece
effects_per_switch_on : scalar, array, TimeSeriesRaw, optional
effects_per_switch_on : scalar, array, TimeSeriesData, optional
cost of one switch from off (var_on=0) to on (var_on=1),
unit i.g. in Euro
switch_on_total_max : integer, optional
Expand Down
8 changes: 4 additions & 4 deletions flixOpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
import math # für nan

from flixOpt.core import TimeSeriesRaw
from flixOpt.core import TimeSeriesData
from flixOpt.core import Numeric, Skalar

logger = logging.getLogger('flixOpt')
Expand Down Expand Up @@ -46,12 +46,12 @@ def as_vector(value: Union[int, float, np.ndarray, List], length: int) -> np.nda
return np.array(value)


def check_bounds(value: Union[int, float, np.ndarray, TimeSeriesRaw],
def check_bounds(value: Union[int, float, np.ndarray, TimeSeriesData],
label: str,
lower_bound: Numeric,
upper_bound: Numeric):
if isinstance(value, TimeSeriesRaw):
value = value.value
if isinstance(value, TimeSeriesData):
value = value.data
if np.any(value < lower_bound):
raise Exception(f'{label} is below its {lower_bound=}!')
if np.any(value >= upper_bound):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ def calculate(self, modeling_type: Literal["full", "segmented", "aggregated"]):
aKWK = CHP('BHKW2', eta_th=0.58, eta_el=0.22, effects_per_switch_on=24000, P_el=Flow('P_el', bus=Strom), Q_th=Flow('Q_th', bus=Fernwaerme), Q_fu=Flow('Q_fu', bus=Kohle, size=288, relative_minimum=87 / 288), on_values_before_begin=[0])
aSpeicher = Storage('Speicher', charging=Flow('Q_th_load', size=137, bus=Fernwaerme), discharging=Flow('Q_th_unload', size=158, bus=Fernwaerme), capacity_in_flow_hours=684, initial_charge_state=137, minimal_final_charge_state=137, maximal_final_charge_state=158, eta_load=1, eta_unload=1, relative_loss_per_hour=0.001, prevent_simultaneous_charge_and_discharge=True)

TS_Q_th_Last, TS_P_el_Last = TimeSeriesRaw(Q_th_Last), TimeSeriesRaw(P_el_Last, agg_weight=0.7)
TS_Q_th_Last, TS_P_el_Last = TimeSeriesData(Q_th_Last), TimeSeriesData(P_el_Last, agg_weight=0.7)
aWaermeLast, aStromLast = Sink('Wärmelast', sink=Flow('Q_th_Last', bus=Fernwaerme, size=1, fixed_relative_value=TS_Q_th_Last)), Sink('Stromlast', sink=Flow('P_el_Last', bus=Strom, size=1, fixed_relative_value=TS_P_el_Last))
aKohleTarif, aGasTarif = Source('Kohletarif', source=Flow('Q_Kohle', bus=Kohle, size=1000, effects_per_flow_hour={costs: 4.6, CO2: 0.3})), Source('Gastarif', source=Flow('Q_Gas', bus=Gas, size=1000, effects_per_flow_hour={costs: gP, CO2: 0.3}))

p_feed_in, p_sell = TimeSeriesRaw(-(p_el - 0.5), agg_group='p_el'), TimeSeriesRaw(p_el + 0.5, agg_group='p_el')
p_feed_in, p_sell = TimeSeriesData(-(p_el - 0.5), agg_group='p_el'), TimeSeriesData(p_el + 0.5, agg_group='p_el')
aStromEinspeisung, aStromTarif = Sink('Einspeisung', sink=Flow('P_el', bus=Strom, size=1000, effects_per_flow_hour=p_feed_in)), Source('Stromtarif', source=Flow('P_el', bus=Strom, size=1000, effects_per_flow_hour={costs: p_sell, CO2: 0.3}))

es = FlowSystem(aTimeSeries, last_time_step_hours=None)
Expand Down

0 comments on commit 3350a89

Please sign in to comment.