Skip to content

Commit

Permalink
made collective analysis based on selective ranges instead of continu…
Browse files Browse the repository at this point in the history
…ous ranges
  • Loading branch information
ShahmBarmada committed Nov 4, 2021
1 parent ee96725 commit 98c1444
Show file tree
Hide file tree
Showing 6 changed files with 741 additions and 42 deletions.
116 changes: 98 additions & 18 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from CSV_Parser import csvParser
from Plotter import (PlotterSelective, PlotterCollective)
from UI_Main import Ui_MainWindow
from UI_RangeForm import Ui_RangeForm

dataList = {'Renewable Energy Sources [g]':'0100', 'Hydrolic Powers [g]':'0200', 'Solar Thermal Powers [g]':'0300', 'Combined Steam & Heat Production [g]':'0400', 'Geothermal Heat Production [g]':'0500', 'Power Plants Electricity Production [g]':'0600', 'Nuclear [g]':'0700', 'Pump Consumption [g]':'0800', 'Turbine Production [g]':'0900', 'Pump Storage [g]':'1000', 'Electrolyser Gr.2 [g]':'1100', 'Electrolyser Gr.3 [g]':'1200', 'EV & V2G (Transport) [g]':'1300', 'Nordpool Prices [g]':'1400', 'Market Prices [g]':'1500', 'Exports Payment [g]':'1600', 'Individual Heat 1 [g]':'1700', 'Individual Electricity [g]':'1800', 'Individual Heat 2 [g]':'1900', 'Transports Heat 2 [g]':'2000', 'District Cooling [g]':'2100', 'Desalination [g]':'2200', 'Gas Grid Demand & Balance [g]':'2300', 'Electr. Demand':'0001', 'Elec.dem Cooling':'0002', 'Fixed Exp/Imp':'0003', 'DH Demand':'0004', 'Wind Electr.':'0101', 'Offshore Electr.':'0102', 'PV Electr.':'0103', 'CSP Electr.':'0104', 'River Electr.':'0105', 'Wave Electr.':'0106', 'Tidal Electr.':'0107', 'CSP2 Electr.':'0108', 'CSP2 Storage':'0109', 'CSP2 loss':'0110', 'Hydro Electr.':'0201', 'Hydro pump':'0202', 'Hydro storage':'0203', 'Hydro Wat-Sup':'0204', 'Hydro Wat-Loss':'0205', 'Solar Heat':'0301', 'CSHP 1 Heat':'0401', 'Waste 1 Heat':'0402', 'Boiler 1 Heat':'0005', 'Solar 1 Heat':'0302', 'Sol1 Str Heat':'0303', 'CSHP 2 Heat':'0403', 'Waste 2 Heat':'0404', 'Geoth 2 Heat':'0501', 'Geoth 2 Steam':'0502', 'Geoth 2 Storage':'0503', 'CHP 2 Heat':'0006', 'HP 2 Heat':'0007', 'Boiler 2 Heat':'0008', 'EH 2 Heat':'0009', 'ELT 2 Heat':'0010', 'Solar2 Heat':'0304', 'Sol2 Str Heat':'0305', 'Storage2 Heat':'0011', 'Balance2 Heat':'0012', 'CSHP 3 Heat':'0405', 'Waste 3 Heat':'0406', 'Geoth 3 Heat':'0504', 'Geoth 3 Steam':'0505', 'Geoth 3 Storage':'0506', 'CHP 3 Heat':'0013', 'HP 3 Heat':'0014', 'Boiler 3 Heat':'0015', 'EH 3 Heat':'0016', 'ELT 3 Heat':'0017', 'Solar3 Heat':'0306', 'Sol3 Str Heat':'0307', 'Storage3 Heat':'0018', 'Balance3 Heat':'0019', 'Flexible Electr.':'0020', 'HP Electr.':'0021', 'CSHP Electr.':'0022', 'CHP Electr.':'0023', 'PP Electr.':'0601', 'PP2 Electr.':'0602', 'Nuclear Electr.':'0701', 'Geother. Electr.':'0702', 'Pump Electr.':'0801', 'Turbine Electr.':'0901', 'Pumped Storage':'1001', 'Pump2 Electr.':'0802', 'Turbine2 Electr.':'0902', 'Pumped2 Storage':'1002', 'Rock in Electr.':'0903', 'Rock out Steam':'0904', 'Rock str Storage':'0905', 'ELT 2 Electr.':'1101', 'ELT 2 H2 ELT 2':'1102', 'ELT 3 Electr.':'1201', 'ELT 3 H2 ELT 3':'1202', 'V2G Demand':'1301', 'V2G Charge':'1302', 'V2G Discha.':'1303', 'V2G Storage':'1304', 'H2 Electr.':'2001', 'H2 Storage':'2002', 'CO2Hydro Electr.':'2003', 'NH3Hydro Electr.':'2004', 'CO2Hydro liq.fuel':'2005', 'NH3Hydro Ammonia':'2006', 'HH-CHP Electr.':'1801', 'HH-HP Electr.':'1802', 'HH-HP/EB Electr.':'1803', 'HH-EB Electr.':'1804', 'HH-H2 Electr.':'1901', 'HH-H2 Storage':'1902', 'HH-H2 Prices':'1903', 'HH Dem. Heat':'1701', 'HH CHP+HP Heat':'1702', 'HH Boil. Heat':'1703', 'HH Solar Heat':'1704', 'HH Store Heat':'1705', 'HH Balan Heat':'1706', 'Stabil. LoadPercent':'0024', 'Import Electr.':'0025', 'Export Electr.':'0026', 'CEEP Electr.':'0027', 'EEEP Electr.':'0028', 'ExMarket Prices':'1401', 'ExMarket Prod':'1402', 'System Prices':'1501', 'InMarket Prices':'1502', 'Btl-neck Prices':'1503', 'Import Payment':'0029', 'Export Payment':'1601', 'Blt-neck Payment':'1602', 'Add-exp Payment':'0030', 'Boilers ':'2301', 'CHP2+3 ':'2302', 'PP CAES':'2303', 'Indi- vidual':'2304', 'Transp. ':'2305', 'Indust. Various':'2306', 'Demand Sum':'2307', 'Biogas ':'2308', 'Syngas ':'2309', 'CO2HyGas ':'2310', 'SynHyGas ':'2311', 'SynFuel ':'2312', 'Storage ':'2313', 'Storage Content':'2314', 'Sum ':'2315', 'Import Gas':'2316', 'Export Gas':'2317', 'FreshW Demand':'2201', 'FreshW Storage':'2202', 'SaltW Demand':'2203', 'Brine Prod.':'2204', 'Brine Storage':'2205', 'Desal.Pl Electr.':'2206', 'FWPump Electr.':'2207', 'Turbine Electr.':'2208', 'Pump Electr.':'2209', 'CoolGr1 Demand':'2101', 'CoolGr2 Demand':'2102', 'CoolGr3 Demand':'2103', 'Cool-El Demand':'2104', 'CoolGr1 Natural':'2105', 'CoolGr2 Natural':'2106', 'CoolGr3 Natural':'2107', 'Cooling DHgr1':'2108', 'Cooling DHgr2':'2109', 'Cooling DHgr3':'2110', 'Cooling Electr.':'2111'}

monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
figList, pltList, stdList = [], [], []
figList, pltList, stdList, xRangelist = [], [], [], []
figID, pltID, stdID = 1, 1, 1


class MainWindow(QMainWindow, Ui_MainWindow):

def __init__(self):
Expand All @@ -43,7 +45,7 @@ def SwitchHandelers(self):
self.lw_StdList.currentRowChanged.connect(self.UpdateStdSlct)
self.cb_TicksX.stateChanged.connect(self.UpdateTickStateX)
self.cb_TicksY.stateChanged.connect(self.UpdateTickStateY)
self.cb_Xdata.currentTextChanged.connect(self.UpdateRangeX)
self.cb_Xdata.currentTextChanged.connect(self.UpdateXdata)

def SelectiveAnalysis(self):
self.rb_HourlyVal.setEnabled(True)
Expand All @@ -52,6 +54,7 @@ def SelectiveAnalysis(self):
self.cb_StatMean.setEnabled(True)
self.cb_StatMedian.setEnabled(True)
self.rb_HourlyVal.setChecked(True)
self.btn_Xrange.setEnabled(False)
self.UpdateDataType()

def CollectiveAnalysis(self):
Expand All @@ -61,6 +64,7 @@ def CollectiveAnalysis(self):
self.cb_StatMean.setEnabled(False)
self.cb_StatMedian.setEnabled(False)
self.rb_AnnualVal.setChecked(True)
self.btn_Xrange.setEnabled(True)
self.UpdateDataType()

def UpdateDataType(self):
Expand Down Expand Up @@ -125,8 +129,8 @@ def UpdateDataType(self):
self.cb_Trace.setCurrentIndex(0)
self.rb_Xdata.setChecked(True)
self.rb_Xtime.setEnabled(False)
self.cb_Xstart.setEnabled(True)
self.cb_Xend.setEnabled(True)
self.cb_Xstart.setEnabled(False)
self.cb_Xend.setEnabled(False)
self.sb_Col.setEnabled(False)
self.sb_Row.setEnabled(False)
self.cb_Ydata.clear()
Expand Down Expand Up @@ -176,17 +180,10 @@ def UpdateTrace(self):
if self.rb_AnnualVal.isChecked():
self.cb_Xdata.clear()
self.cb_Xdata.addItems(['Energy Balance (per Index)', 'Installed Capacities (per Index)', 'Total Elect. Demand', 'Total Heat Demand'])
self.UpdateRangeX()

def UpdateRangeX(self):
self.cb_Xstart.clear()
self.cb_Xend.clear()
if self.cb_Xdata.currentText() == 'Energy Balance (per Index)':
self.cb_Xstart.addItems(['Coal', 'Oil', 'N.Gas', 'Biomass', 'Renewable'])
self.cb_Xend.addItems(['Coal', 'Oil', 'N.Gas', 'Biomass', 'Renewable'])
elif self.cb_Xdata.currentText() == 'Installed Capacities (per Index)':
self.cb_Xstart.addItems(['PP1', 'CHP2', 'CHP3', 'PP2', 'Nuclear', 'Geopower', 'Hydro', 'Res1', 'Res2', 'Res3', 'Res4', 'Res5', 'Res6', 'Res7', 'Heat Pump 2', 'Heat Pump 3', 'Electrolysers', 'Boiler 2', 'Boiler3 ', 'Boiler 2 Thermal', 'Boiler 3 Thermal', 'CHP2 Thermal', 'CHP3 Thermal'])
self.cb_Xend.addItems(['PP1', 'CHP2', 'CHP3', 'PP2', 'Nuclear', 'Geopower', 'Hydro', 'Res1', 'Res2', 'Res3', 'Res4', 'Res5', 'Res6', 'Res7', 'Heat Pump 2', 'Heat Pump 3', 'Electrolysers', 'Boiler 2', 'Boiler3 ', 'Boiler 2 Thermal', 'Boiler 3 Thermal', 'CHP2 Thermal', 'CHP3 Thermal'])

def UpdateXdata(self):
global xDataMode
xDataMode = self.cb_Xdata.currentText()

def UpdateTickStateX(self):
if self.cb_TicksX.isChecked():
Expand Down Expand Up @@ -240,6 +237,7 @@ def Connections(self):
self.btn_PltDlt.clicked.connect(self.RemovePlot)
self.btn_FigSave.clicked.connect(self.SaveFigure)
self.btn_FigView.clicked.connect(self.PreviewFigure)
self.btn_Xrange.clicked.connect(self.OpenRangeWindow)

def openAboutDialog(self):
QMessageBox.about(self, 'About', 'Hi, I\'m developer')
Expand Down Expand Up @@ -591,12 +589,11 @@ def PrepareFigure(self):

# get X data series:
xData = self.cb_Xdata.currentText()
xStart = self.cb_Xstart.currentText()
xEnd = self.cb_Xend.currentText()
xRange = xRangelist
traceStyle = self.cb_Style.currentText()

# process figure in plotter
figure = PlotterCollective(slctFig, slctStd, xData, xStart, xEnd, traceStyle)
figure = PlotterCollective(slctFig, slctStd, xData, xRange, traceStyle)

def SaveFigure(self):
try:
Expand Down Expand Up @@ -626,6 +623,10 @@ def PreviewFigure(self):
except:
pass

def OpenRangeWindow(self):
self.RangeDialog = RangeWindow(self)
self.RangeDialog.show()

class PreviewWindow(QMainWindow):
def __init__(self, parent= None):
super(PreviewWindow, self).__init__(parent)
Expand Down Expand Up @@ -656,6 +657,85 @@ def __init__(self, parent= None):
self.setCentralWidget(self.imageLable)
os.remove('./preview.jpg')

class RangeWindow(QMainWindow, Ui_RangeForm):
def __init__(self, parent= MainWindow):
super(RangeWindow, self).__init__(parent)
self.setupUi(self)
self.UpdateStack()
self.pushButton.clicked.connect(self.GenerateList)

def UpdateStack(self):
if xDataMode == 'Energy Balance (per Index)':
self.groupBox.setVisible(True)
self.groupBox_2.setVisible(False)
elif xDataMode == 'Installed Capacities (per Index)':
self.groupBox.setVisible(False)
self.groupBox_2.setVisible(True)

def GenerateList(self):

xRangelist.clear()
if self.groupBox.isVisible():
if self.checkBox_1.isChecked():
xRangelist.append(self.checkBox_1.text())
if self.checkBox_2.isChecked():
xRangelist.append(self.checkBox_2.text())
if self.checkBox_3.isChecked():
xRangelist.append(self.checkBox_3.text())
if self.checkBox_4.isChecked():
xRangelist.append(self.checkBox_4.text())
if self.checkBox_5.isChecked():
xRangelist.append(self.checkBox_5.text())

elif self.groupBox_2.isVisible():
if self.checkBox_6.isChecked():
xRangelist.append(self.checkBox_6.text())
if self.checkBox_7.isChecked():
xRangelist.append(self.checkBox_7.text())
if self.checkBox_8.isChecked():
xRangelist.append(self.checkBox_8.text())
if self.checkBox_9.isChecked():
xRangelist.append(self.checkBox_9.text())
if self.checkBox_10.isChecked():
xRangelist.append(self.checkBox_10.text())
if self.checkBox_11.isChecked():
xRangelist.append(self.checkBox_11.text())
if self.checkBox_12.isChecked():
xRangelist.append(self.checkBox_12.text())
if self.checkBox_13.isChecked():
xRangelist.append(self.checkBox_13.text())
if self.checkBox_14.isChecked():
xRangelist.append(self.checkBox_14.text())
if self.checkBox_15.isChecked():
xRangelist.append(self.checkBox_15.text())
if self.checkBox_16.isChecked():
xRangelist.append(self.checkBox_16.text())
if self.checkBox_17.isChecked():
xRangelist.append(self.checkBox_17.text())
if self.checkBox_18.isChecked():
xRangelist.append(self.checkBox_18.text())
if self.checkBox_19.isChecked():
xRangelist.append(self.checkBox_19.text())
if self.checkBox_20.isChecked():
xRangelist.append(self.checkBox_20.text())
if self.checkBox_21.isChecked():
xRangelist.append(self.checkBox_21.text())
if self.checkBox_22.isChecked():
xRangelist.append(self.checkBox_22.text())
if self.checkBox_23.isChecked():
xRangelist.append(self.checkBox_23.text())
if self.checkBox_24.isChecked():
xRangelist.append(self.checkBox_24.text())
if self.checkBox_26.isChecked():
xRangelist.append(self.checkBox_26.text())
if self.checkBox_27.isChecked():
xRangelist.append(self.checkBox_27.text())
if self.checkBox_29.isChecked():
xRangelist.append(self.checkBox_29.text())
if self.checkBox_31.isChecked():
xRangelist.append(self.checkBox_31.text())

self.close()

app = QApplication(sys.argv)
mainWindow = MainWindow()
Expand Down
52 changes: 31 additions & 21 deletions Plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,22 +504,22 @@ def PlotterSelective (srcFig= dict, srcPlt= list):

return figure

def PlotterCollective (srcFig= dict, srcStd= list, xDataSrc= str, xStart= str, xEnd= str, traceStyle= str):
def PlotterCollective (srcFig= dict, srcStd= list, xDataSrc= str, xRange= list, traceStyle= str):

if xDataSrc == 'Energy Balance (per Index)':

indexList = ['Coal', 'Oil', 'N.Gas', 'Biomass', 'Renewable']
indexList = indexList[indexList.index(xStart):indexList.index(xEnd)+1]
#indexList = indexList[indexList.index(xStart):indexList.index(xEnd)+1]

SumDF = pd.DataFrame(0, index= indexList, columns=['test'])

for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')

rangeStart = stdDF.index.get_loc('TotalAnnualCosts')
rangeStart = rangeStart + stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(xStart)
rangeStart = rangeStart + stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(indexList[0])

rangeEnd = stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(xEnd)
rangeEnd = stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(indexList[-1])
rangeEnd = rangeEnd + rangeStart +1

xData = stdDF.iloc[rangeStart:rangeEnd].index.values.tolist()
Expand All @@ -531,6 +531,11 @@ def PlotterCollective (srcFig= dict, srcStd= list, xDataSrc= str, xStart= str, x

SumDF.drop(['test'], axis= 1, inplace=True)

xRangeTarget = SumDF.index.values.tolist()
for j in range(len(xRangeTarget)):
if xRangeTarget[j] not in xRange:
SumDF.drop([xRangeTarget[j]], axis= 0, inplace=True)

figure = make_subplots()

if traceStyle == 'Whiskers & Points':
Expand Down Expand Up @@ -571,40 +576,45 @@ def PlotterCollective (srcFig= dict, srcStd= list, xDataSrc= str, xStart= str, x

list1 = ['InputCapPpEl', 'InputCapChp2El', 'InputCapChp3El', 'InputCapPp2El', 'InputNuclearCap', 'InputGeopowerCap', 'InputHydroCap', 'InputRes1Capacity', 'InputRes2Capacity', 'InputRes3Capacity', 'InputRes4Capacity', 'InputRes5Capacity', 'InputRes6Capacity', 'InputRes7Capacity', 'InputCapHp2El', 'InputCapHp3El', 'InputCapElttransEl', 'InputEh2', 'InputEh3', 'InputCapBoiler2Th', 'InputCapBoiler3Th', 'InputCapChp2Thermal', 'InputCapChp3Thermal']

list2 = ['PP1', 'CHP2', 'CHP3', 'PP2', 'Nuclear', 'Geopower', 'Hydro', 'Res1', 'Res2', 'Res3', 'Res4', 'Res5', 'Res6', 'Res7', 'Heat Pump 2', 'Heat Pump 3', 'Electrolysers', 'Boiler 2', 'Boiler3 ', 'Boiler 2 Thermal', 'Boiler 3 Thermal', 'CHP2 Thermal', 'CHP3 Thermal']
list2 = ['PP1', 'CHP2', 'CHP3', 'PP2', 'Nuclear', 'Geopower', 'Hydro', 'Res1', 'Res2', 'Res3', 'Res4', 'Res5', 'Res6', 'Res7', 'Heat Pump 2', 'Heat Pump 3', 'Electrolysers', 'Boiler 2', 'Boiler 3 ', 'Boiler 2 Thermal', 'Boiler 3 Thermal', 'CHP2 Thermal', 'CHP3 Thermal']

xStartIndex = list2.index(xStart)
xEndIndex = list2.index(xEnd)+1
#xStartIndex = list2.index(xStart)
#xEndIndex = list2.index(xEnd)+1

xStart = list1[xStartIndex]
try:
xEnd = list1[xEndIndex]
except:
xEnd = list1[-1]
#xStart = list1[xStartIndex]
#try:
# xEnd = list1[xEndIndex]
#except:
# xEnd = list1[-1]

list1 = list1[xStartIndex:xEndIndex]
list2 = list2[xStartIndex:xEndIndex]
#list1 = list1[xStartIndex:xEndIndex]
#list2 = list2[xStartIndex:xEndIndex]

SumDF = pd.DataFrame(0, index= list1, columns=['test'])

for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')

rangeStart = stdDF.index.get_loc(xStart)
rangeEnd = stdDF.index.get_loc(xEnd) +1

#xData = stdDF.iloc[rangeStart:rangeEnd].index.values.tolist()


rangeStart = stdDF.index.get_loc(list1[0])
rangeEnd = stdDF.index.get_loc(list1[-1]) +1

stdDF = stdDF.iloc[rangeStart:rangeEnd]
stdDF = stdDF.loc[:, 'g0-Data1']
stdDF = stdDF.astype(float)

SumDF.insert(0, 'std' + str(study), stdDF)

SumDF.drop(['test'], axis= 1, inplace=True)

SumDF.rename(index= dict(zip(list1, list2)), inplace= True)

xRangeTarget = SumDF.index.values.tolist()
for j in range(len(xRangeTarget)):
if xRangeTarget[j] not in xRange:
SumDF.drop([xRangeTarget[j]], axis= 0, inplace=True)

SumDF.sort_index(axis=0, inplace=True)

xData = SumDF.index.values.tolist()

figure = make_subplots()
Expand Down
15 changes: 14 additions & 1 deletion QtUI/ui_main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<enum>QFrame::Plain</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page_1">
<widget class="QLabel" name="label_pg1">
Expand Down Expand Up @@ -1066,6 +1066,19 @@
<string>Data Series</string>
</property>
</widget>
<widget class="QPushButton" name="btn_Xrange">
<property name="geometry">
<rect>
<x>290</x>
<y>40</y>
<width>50</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Select</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="gb_SeriesY">
<property name="geometry">
Expand Down
Loading

0 comments on commit 98c1444

Please sign in to comment.