Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# (b) thereby collect the weights which should be considered for each time series as well in a dictionary
timeSeriesData, weightDict = [], {}
for mdlName, mdl in self.componentModelingDict.items():
for compName, comp in mdl.componentsDict.items():
compTimeSeriesData, compWeightDict = comp.getDataForTimeSeriesAggregation()
if compTimeSeriesData is not None:
timeSeriesData.append(compTimeSeriesData), weightDict.update(compWeightDict)
timeSeriesData = pd.concat(timeSeriesData, axis=1)
# Note: Sets index for the time series data. The index is of no further relevance in the energy system model.
timeSeriesData.index = pd.date_range('2050-01-01 00:30:00', periods=len(self.totalTimeSteps),
freq=(str(self.hoursPerTimeStep) + 'H'), tz='Europe/Berlin')
# Cluster data with tsam package (the reindex call is here for reproducibility of TimeSeriesAggregation
# call)
timeSeriesData = timeSeriesData.reindex(sorted(timeSeriesData.columns), axis=1)
clusterClass = TimeSeriesAggregation(timeSeries=timeSeriesData, noTypicalPeriods=numberOfTypicalPeriods,
hoursPerPeriod=hoursPerPeriod,
clusterMethod=clusterMethod, sortValues=sortValues, weightDict=weightDict,
**kwargs)
# Convert the clustered data to a pandas DataFrame and store the respective clustered time series data in the
# associated components
data = pd.DataFrame.from_dict(clusterClass.clusterPeriodDict)
for mdlName, mdl in self.componentModelingDict.items():
for compName, comp in mdl.componentsDict.items():
comp.setAggregatedTimeSeriesData(data)
# Store time series aggregation parameters in class instance
if storeTSAinstance:
self.tsaInstance = clusterClass
self.typicalPeriods = clusterClass.clusterPeriodIdx
self.timeStepsPerPeriod = list(range(numberOfTimeStepsPerPeriod))