def Elec_ImportExport(individual, pathX): # Extract Electricity needs buildList = sFn.extractList(pathX.pathRaw + "/Total.csv") allElec = np.zeros((8760,1)) for build in buildList: buildFileRaw = pathX.pathRaw + "/" + build + ".csv" builddf = pd.read_csv(buildFileRaw, usecols = ["Ealf", "Eauxf", "Ecaf", "Edataf", "Epf"]) buildarray = np.array(builddf) for i in range(8760): allElec[i,0] += np.sum(buildarray[i,:])*1000 print sum(allElec) # Extract electricity produced form solar configKey = "".join(str(e)[0:4] for e in individual) PPactivationFile = pathX.pathSlaveRes + '/' + configKey + 'PPActivationPattern.csv' ESolardf = pd.read_csv(PPactivationFile, usecols = ['ESolarProducedPVandPVT']) EsolarArray = np.array(ESolardf) # Compute Import / Export imp = 0 exp = 0 for i in range(8760): delta = allElec[i,0] - EsolarArray[i,0] if delta > 0: imp += delta else: exp += delta return imp,exp
def sensAnalysis(pathX, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, gen): gV = glob.globalVariables() step = gV.sensibilityStep bandwidth = sensBandwidth() os.chdir(pathX.pathMasterRes) pop, eps, testedPop = sFn.readCheckPoint(pathX, gen, 0) toolbox = base.Toolbox() os.chdir(pathX.pathRaw) buildList = sFn.extractList("Total.csv") ParetoResults = np.zeros( len(pop) ) FactorResults = np.zeros((step + 1, bandwidth.nFactors * 2)) def sensOneFactor(obj, factor_name, mini, maxi, colNumber): iniValue = getattr(obj, factor_name) index = 0 for delta in np.arange(mini, maxi + 1E-5, (maxi-mini)/step): FactorResults[index][colNumber + 0] = delta if abs(delta) > 1E-10: setattr(obj, factor_name, iniValue * (1+delta)) newpop = [] for ind in pop: newInd = toolbox.clone(ind) newpop.append(newInd) (costs, CO2, prim) = eI.evalInd(newInd, buildList, pathX, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, obj) newInd.fitness.values = (costs, CO2, prim) selection = sel.selectPareto(newpop) for i in range(len(newpop)): if newpop[i] in selection: ParetoResults[i] += 1 FactorResults[index][colNumber + 1] = len(newpop) - len(selection) index += 1 setattr(obj, factor_name, iniValue) sensOneFactor(gV, 'ELEC_PRICE', bandwidth.minElec, bandwidth.maxElec, 0) sensOneFactor(gV, 'NG_PRICE', bandwidth.minNG, bandwidth.maxNG, 2) sensOneFactor(gV, 'BG_PRICE', bandwidth.minBG, bandwidth.maxBG, 4) indexSensible = FactorResults.argmax()%(2*bandwidth.nFactors) if indexSensible == 1: mostSensitive = 'Electricity price' elif indexSensible == 3: mostSensitive = 'NG price' else: mostSensitive = 'BG price' return ParetoResults, FactorResults, mostSensitive
def GHPCheck(individual, pathRaw, Qnom, gv): """ Computes the geothermal availability and modifies the individual to comply with it Parameters ---------- individual : list pathRaw : float Qnom : float Nominal installed capacity in the district heating plant """ areaArray = np.array( pd.read_csv(pathRaw + "/Geothermal.csv", usecols=["Area_geo"])) buildArray = np.array( pd.read_csv(pathRaw + "/Geothermal.csv", usecols=["Name"])) buildList = sFn.extractList(pathRaw + "/Total.csv") indCombi = sFn.readCombi(individual) Qallowed = 0 for index, buildName in zip(indCombi, buildList): if index == "1": areaAvail = areaArray[np.where(buildArray == buildName)[0][0]][0] Qallowed += np.ceil( areaAvail / gv.GHP_A) * gv.GHP_HmaxSize #[W_th] print Qallowed, "Qallowed" if Qallowed < individual[11] * Qnom: print "GHP share modified !" if Qallowed < 1E-3: oldValue = individual[11] shareLoss = individual[11] individual[10] = 0 individual[11] = 0 else: oldValue = individual[11] shareLoss = oldValue - Qallowed / Qnom individual[11] = Qallowed / Qnom # Adapt the other shares nPlant = 0 for i in range(gv.nHeat - 1): if individual[2 * i] > 0: nPlant += 1 individual[2 * i + 1] += individual[2 * i + 1] * shareLoss / (1 - oldValue) if nPlant == 0: # there was only the GHP --> replaced by only NG Boiler individual[2] = 1 individual[3] = 1 - individual[11]
def GHPCheck(individual, pathRaw, Qnom, gv): """ Computes the geothermal availability and modifies the individual to comply with it Parameters ---------- individual : list pathRaw : float Qnom : float Nominal installed capacity in the district heating plant """ areaArray = np.array( pd.read_csv( pathRaw + "/Geothermal.csv", usecols=["Area_geo"] ) ) buildArray = np.array( pd.read_csv( pathRaw + "/Geothermal.csv", usecols=["Name"] ) ) buildList = sFn.extractList(pathRaw + "/Total.csv") indCombi = sFn.readCombi(individual) Qallowed = 0 for index, buildName in zip(indCombi, buildList): if index == "1": areaAvail = areaArray[ np.where(buildArray == buildName)[0][0] ][0] Qallowed += np.ceil(areaAvail/gv.GHP_A) * gv.GHP_HmaxSize #[W_th] print Qallowed, "Qallowed" if Qallowed < individual[11] * Qnom: print "GHP share modified !" if Qallowed < 1E-3: oldValue = individual[11] shareLoss = individual[11] individual[10] =0 individual[11] =0 else: oldValue = individual[11] shareLoss = oldValue - Qallowed / Qnom individual[11] = Qallowed / Qnom # Adapt the other shares nPlant = 0 for i in range(gv.nHeat - 1): if individual[2*i] > 0: nPlant += 1 individual[2*i+1] += individual[2*i+1] * shareLoss / (1-oldValue) if nPlant == 0: # there was only the GHP --> replaced by only NG Boiler individual[2] = 1 individual[3] = 1-individual[11]
def decentralizeCosts(individual, pathX, gV): indCombi = sFn.readCombi(individual, gV) buildList = sFn.extractList(pathX.pathRaw + "/Total.csv") costsDisc = 0 for i in range(len(indCombi)): if indCombi[i] == "0": # Decentralized building buildName = buildList[i] DecentFile = pathX.pathDiscRes + "/DiscOp_" + buildName + "_result.csv" df = pd.read_csv(DecentFile) dfBest = df[df["Best configuration"] == 1] costsDisc += dfBest["Annualized Investment Costs [CHF]"].iloc[0] print costsDisc, "costsDisc" return costsDisc
def sensAnalysis(pathX, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, gen): gV = glob.globalVariables() step = gV.sensibilityStep bandwidth = sensBandwidth() os.chdir(pathX.pathMasterRes) pop, eps, testedPop = sFn.readCheckPoint(pathX, gen, 0) toolbox = base.Toolbox() os.chdir(pathX.pathRaw) buildList = sFn.extractList("Total.csv") ParetoResults = np.zeros(len(pop)) FactorResults = np.zeros((step + 1, bandwidth.nFactors * 2)) def sensOneFactor(obj, factor_name, mini, maxi, colNumber): iniValue = getattr(obj, factor_name) index = 0 for delta in np.arange(mini, maxi + 1E-5, (maxi - mini) / step): FactorResults[index][colNumber + 0] = delta if abs(delta) > 1E-10: setattr(obj, factor_name, iniValue * (1 + delta)) newpop = [] for ind in pop: newInd = toolbox.clone(ind) newpop.append(newInd) (costs, CO2, prim) = eI.evalInd(newInd, buildList, pathX, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, obj) newInd.fitness.values = (costs, CO2, prim) selection = sel.selectPareto(newpop) for i in range(len(newpop)): if newpop[i] in selection: ParetoResults[i] += 1 FactorResults[index][colNumber + 1] = len(newpop) - len(selection) index += 1 setattr(obj, factor_name, iniValue) sensOneFactor(gV, 'ELEC_PRICE', bandwidth.minElec, bandwidth.maxElec, 0) sensOneFactor(gV, 'NG_PRICE', bandwidth.minNG, bandwidth.maxNG, 2) sensOneFactor(gV, 'BG_PRICE', bandwidth.minBG, bandwidth.maxBG, 4) indexSensible = FactorResults.argmax() % (2 * bandwidth.nFactors) if indexSensible == 1: mostSensitive = 'Electricity price' elif indexSensible == 3: mostSensitive = 'NG price' else: mostSensitive = 'BG price' return ParetoResults, FactorResults, mostSensitive
def mcda_indicators(individual, pathX, plot = 0): """ Computes the specific operational costs and the share of local resources """ configKey = "".join(str(e)[0:4] for e in individual) print configKey buildList = sFn.extractList(pathX.pathRaw + "/Total.csv") gV = glob.globalVariables() # Recover data from the PP activation file resourcesFile = pathX.pathSlaveRes + "/" + configKey + "PPActivationPattern.csv" resourcesdf = pd.read_csv(resourcesFile, usecols=["ESolarProducedPVandPVT", "Q_AddBoiler", "Q_BoilerBase", "Q_BoilerPeak", "Q_CC", "Q_GHP", \ "Q_HPLake", "Q_HPSew", "Q_primaryAddBackupSum", "Q_uncontrollable"]) Electricity_Solar = resourcesdf.ESolarProducedPVandPVT.sum() Q_AddBoiler = resourcesdf.Q_AddBoiler.sum() Q_BoilerBase = resourcesdf.Q_BoilerBase.sum() Q_BoilerPeak = resourcesdf.Q_BoilerPeak.sum() Q_CC = resourcesdf.Q_CC.sum() Q_GHP = resourcesdf.Q_GHP.sum() Q_HPLake = resourcesdf.Q_HPLake.sum() Q_HPSew = resourcesdf.Q_HPSew.sum() Q_storage_missmatch = resourcesdf.Q_primaryAddBackupSum.sum() Q_uncontrollable = resourcesdf.Q_uncontrollable.sum() # Recover data from the Storage Operation file resourcesFile = pathX.pathSlaveRes + "/" + configKey + "StorageOperationData.csv" resourcesdf = pd.read_csv(resourcesFile, usecols=["Q_SCandPVT_coldstream"]) Q_fromSolar = resourcesdf.Q_SCandPVT_coldstream.sum() # Recover heating needs for decentralized buildings indCombi = sFn.readCombi(individual, gV) QfromNG = 0 QfromBG = 0 QfromGHP = 0 for i in range(len(indCombi)): if indCombi[i] == "0": # Decentralized building buildName = buildList[i] DescentFile = pathX.pathDiscRes + "/DiscOp_" + buildName + "_result.csv" df = pd.read_csv(DescentFile) dfBest = df[ df["Best configuration"] == 1 ] QfromNG += dfBest["QfromNG"].iloc[0] QfromBG += dfBest["QfromBG"].iloc[0] QfromGHP += dfBest["QfromGHP"].iloc[0] # Recover electricity and cooling needs totalFile = pathX.pathRaw + "/Total.csv" df = pd.read_csv(totalFile, usecols=["Ealf", "Eauxf", "Ecaf", "Edataf", "Epf"]) arrayTotal = np.array(df) totalElec = np.sum(arrayTotal) * 1E6 # [Wh] df = pd.read_csv(totalFile, usecols=["Qcdataf", "Qcicef", "Qcpf", "Qcsf"]) arrayTotal = np.array(df) if individual[12] == 0: totalCool = ( np.sum((arrayTotal)[:,:-1]) + np.sum((arrayTotal)[:,-1:]) * (1+gV.DCNetworkLoss) ) * 1E6 # [Wh] else: totalCool = ( np.sum((arrayTotal)[:,1:-1]) + np.sum((arrayTotal)[:,-1:]) * (1+gV.DCNetworkLoss) ) * 1E6 # [Wh] # Computes the specific operational costs totalEnergy = Q_AddBoiler + Q_BoilerBase + Q_BoilerPeak + Q_CC + Q_GHP + Q_HPLake + \ Q_HPSew + Q_uncontrollable + totalElec + totalCool + \ QfromNG + QfromBG + QfromGHP# + Q_storage_missmatch shareCC_NG = individual[0] % 2 * Q_CC / totalEnergy shareCC_BG = ( individual[0] + 1 ) % 2 * Q_CC / totalEnergy shareBB_NG = individual[2] % 2 * Q_BoilerBase / totalEnergy shareBB_BG = ( individual[2] + 1 ) % 2 * Q_BoilerBase / totalEnergy shareBP_NG = individual[4] % 2 * Q_BoilerPeak / totalEnergy shareBP_BG = ( individual[4] + 1 ) % 2 * Q_BoilerPeak / totalEnergy shareHPLake = Q_HPLake / totalEnergy shareHPSew = Q_HPSew / totalEnergy shareGHP = Q_GHP / totalEnergy shareExtraNG = (Q_AddBoiler + Q_storage_missmatch) / totalEnergy shareHR = (Q_uncontrollable - Q_fromSolar) / totalEnergy shareHeatSolar = Q_fromSolar / totalEnergy shareDecentralizedNG = QfromNG / totalEnergy shareDecentralizedBG = QfromBG / totalEnergy shareDecentralizedGHP = QfromGHP / totalEnergy shareElecGrid = (totalElec - Electricity_Solar) / totalEnergy shareElecSolar = Electricity_Solar / totalEnergy shareCoolLake = totalCool / totalEnergy printout = 1 if printout: print 'CC_NG', individual[0] % 2 * Q_CC print 'CC_BG', ( individual[0] + 1 ) % 2 * Q_CC print 'BB_NG', individual[2] % 2 * Q_BoilerBase print 'BB_BG', ( individual[2] + 1 ) % 2 * Q_BoilerBase print 'BP_NG', individual[4] % 2 * Q_BoilerPeak print 'BP_BG', ( individual[4] + 1 ) % 2 * Q_BoilerPeak print 'HPLake', Q_HPLake print 'HPSew', Q_HPSew print 'GHP', Q_GHP print 'ExtraNG', (Q_AddBoiler + Q_storage_missmatch) print 'HR', (Q_uncontrollable - Q_fromSolar) print 'HeatSolar', Q_fromSolar print 'DecentralizedNG', QfromNG print 'DecentralizedBG', QfromBG print 'DecentralizedGHP', QfromGHP print 'ElecGrid', (totalElec - Electricity_Solar) print 'ElecSolar', Electricity_Solar print 'CoolLake', totalCool print 'shareCC_NG', shareCC_NG*100 print 'shareCC_BG', shareCC_BG*100 print 'shareBB_NG', shareBB_NG*100 print 'shareBB_BG', shareBB_BG*100 print 'shareBP_NG', shareBP_NG*100 print 'shareBP_BG', shareBP_BG*100 print 'shareHPLake', shareHPLake*100 print 'shareHPSew', shareHPSew*100 print 'shareGHP', shareGHP*100 print 'shareExtraNG', shareExtraNG*100 print 'shareHR', shareHR*100 print 'shareHeatSolar', shareHeatSolar*100 print 'shareDecentralizedNG', shareDecentralizedNG*100 print 'shareDecentralizedBG', shareDecentralizedBG*100 print 'shareDecentralizedGHP', shareDecentralizedGHP*100 print 'shareElecGrid' ,shareElecGrid*100 print 'shareElecSolar', shareElecSolar*100 print 'shareCoolLake', shareCoolLake*100 specificCosts = gV.ELEC_PRICE * shareElecGrid + \ gV.NG_PRICE * (shareCC_NG + shareBB_NG + shareBP_NG + shareExtraNG + shareDecentralizedNG) + \ gV.BG_PRICE * (shareCC_BG + shareBB_BG + shareBP_BG + shareDecentralizedBG) # Computes the share of local resources shareLocal = shareHPLake + shareHPSew + shareGHP + shareHR + shareHeatSolar + shareDecentralizedGHP + shareElecSolar + shareCoolLake # Plots the pie chart for energy resources use if plot == 1: fig = plt.figure() subplot = fig.add_subplot(111, adjustable = 'box', aspect = 1, title = 'Energy mix') labels = ['Lake', 'Solar', 'HR', 'Ground', 'Gas', 'Grid'] shareLake = shareHPLake + shareCoolLake shareSolar = shareHeatSolar + shareElecSolar shareHRAll = shareHPSew + shareHR shareGround = shareGHP + shareDecentralizedGHP shareGas = 1 - shareLake - shareSolar - shareHRAll - shareGround - shareElecGrid fracs = [ shareLake, shareSolar, shareHRAll, shareGround, shareGas, shareElecGrid ] colors = ['RoyalBlue', 'Gold', 'LightGreen', 'SandyBrown', 'OrangeRed', 'Gray'] zipper = [ (l,f,c) for (l,f,c) in zip(labels,fracs,colors) if f > 0.001 ] labelsPlot, fracsPlot, colorsPlot = map( list, zip(*zipper) ) subplot.pie(fracsPlot, labels = labelsPlot, colors = colorsPlot, startangle = 90, autopct='%1.1f%%', pctdistance = 0.65) plt.show() return specificCosts, shareLocal