def CalculateHDV(HDVID, Component, Speed, Grad, Load): """ Calculation of emissions from heavy duty vehicles UNITS: Speed km/h Gradient 6 is 6% Emission calculated is g/km CO2 calculated from Fuel consumption No maximum speed is given for each equation. """ Gradient=0.0 WarningText = [] if Grad <= -6 : Gradient = -6 WarningText.append("Used maximum gradient -6%") elif Grad > -6 and Grad <= -4: Gradient = -4 WarningText.append("Used standard gradient -4%") elif Grad > -4 and Grad <= -2 : Gradient = -2 WarningText.append("Used standard gradient -2%") elif Grad > -2 and Grad < 2 : Gradient = 0 WarningText.append("Used standard gradient 0%") elif Grad >= 12: Grad = 12 WarningText.append("Maximum grade 12 % is selected") #This limits us from using unrealistic grades CalculateCO2fromFC = False if Component == "CO2": Component = "FC" CalculateCO2fromFC = True CalculateEnergy = False if Component == "E": Component = "FC" CalculateEnergy = True if Component == "HC": Component = "THC" if Grad <0: key = str(HDVID) + "_" + Component + "_" + str(int(Gradient)) + "_" + str(int(Load)) data = S.H_HDV[key] ans=[] ans=extractAndCalc(data,Speed) Emission = ans[0] WarningText.append(ans[1]) else: X=[] Y=[] key = str(HDVID) + "_" + Component + "_" + str(int(0)) + "_" + str(int(Load)) data0 = S.H_HDV[key] X.append(0) Y.append(extractAndCalc(data0,Speed)[0]) key = str(HDVID) + "_" + Component + "_" + str(int(2)) + "_" + str(int(Load)) data2 = S.H_HDV[key] X.append(2) Y.append(extractAndCalc(data2,Speed)[0]) key = str(HDVID) + "_" + Component + "_" + str(int(4)) + "_" + str(int(Load)) data4 = S.H_HDV[key] X.append(4) Y.append(extractAndCalc(data4,Speed)[0]) key = str(HDVID) + "_" + Component + "_" + str(int(6)) + "_" + str(int(Load)) data6 = S.H_HDV[key] X.append(6) Y.append(extractAndCalc(data6,Speed)[0]) a,b,rr=S.linreg(X,Y) #print X #print Y #print a,b,rr Emission = a*Grad + b if CalculateCO2fromFC: Emission = Emission * 3.17 # http://www.klif.no/Tema/Klima-og-ozon/Klimagasser/--MENY/Sporsmal-og-svar/ WarningText.append("CO2 emissions calculated from fuel consumption") if CalculateEnergy: Emission = Emission * (S.EDensity_Diesel/1000.0) WarningText.append("Energy calculated from fuel consumption") if (len(WarningText) == 0): WarningText.append("No Warnings") return Emission, "g/km", WarningText
def CreateShip(): S.load_Ship() create_vehicle_list()
def CreateHDV(): S.load_HDV() create_vehicle_list()
def CreatePC(): S.load_PC() S.load_PCGradient() create_vehicle_list()
def CalculatePC(PCID, Component, Speed, Gradient, Engine, TrafficSituation): """ Calculation of emissions from private cars UNITS: Speed km/h Gradient 0.06 is 6% Emission calculated is g/km Fuel is calculated from CO2 emissions by factors from SFT, Norway Maximum speed is 125 km/h Engine size: PETROL small < 1.4 liters medium 1.4 -> 2.0 liters large >2.0 liters DIESEL medium <2.0 liters large >2.0 liters """ WarningText = [] CalculateFCfromCO2 = False #Finds the correct gradient Gradient = findGrade(Gradient, TrafficSituation) if Component == "FC": Component = "CO2" CalculateFCfromCO2 = True if not (Component == "C02" or Component == "FC"): Engine = 'all' if Speed >= 6: #Get Data from the PC dictionary key = str(PCID) + "_" + Component + "_" + Engine value = S.H_PC[key] data = value VehicleID = data[0] EmissionComponent = data[1] FuelType = data[2] EngineSize = data[3] EuroClass = data[4] EquationType = data[5] Order = data[6] a0 = float(data[7]) a1 = float(data[8]) a2 = float(data[9]) a3 = float(data[10]) a4 = float(data[11]) a5 = float(data[12]) Emission = -1 if EquationType == 'Polyn.': Emission = float(a0) + \ float(a1) * float(Speed) + \ float(a2) * pow(float(Speed), 2) + \ float(a3) * pow(float(Speed), 3) + \ float(a4) * pow(float(Speed), 4) + \ float(a5) * pow(float(Speed), 5) if EquationType == 'Power': Emission = a0 * pow(Speed, a1) if CalculateFCfromCO2: if FuelType == "DIESEL": Emission = Emission / 3.18 WarningText.append( "Fuel Calculated from CO2 emission factor 3.18") if FuelType == "PETROL": Emission = Emission / 3.13 WarningText.append( "Fuel Calculated from CO2 emission factor 3.13") #Her ligger feilsjekkingsrutiner if Speed > 125: WarningText.append("Emission Function used outside valid area") if (len(WarningText) == 0): WarningText.append("No Warnings") if Speed < 6: Emission = 0 WarningText.append("Speed Under 6kmh") #Here comes correction for gradient corrFactor = 0 GradeKey = EuroClass + "_" + TrafficSituation + "_" + str(Gradient) value = S.H_PCGrade[GradeKey] if FuelType == 'PETROL': if Component == 'CO': corrFactor = value[3] if Component == 'HC': corrFactor = value[4] if Component == 'NOx': corrFactor = value[5] if Component == 'FC': corrFactor = value[6] if Component == 'CO2': corrFactor = value[6] if Component == 'PM': corrFactor = 1 # ARTEMIS does not correct PM for gasoline for grades elif FuelType == 'DIESEL': if Component == 'CO': corrFactor = value[7] if Component == 'HC': corrFactor = value[8] if Component == 'NOx': corrFactor = value[9] if Component == 'PM': corrFactor = value[10] if Component == 'FC': corrFactor = value[11] if Component == 'CO2': corrFactor = value[11] CorrectedEmission = float(Emission) * float(corrFactor) egps = S.Convert_gpkm_to_gps(CorrectedEmission, Speed) return CorrectedEmission, "g/km", egps[0], egps[1], WarningText
def CreateLDV(): S.load_LDV() create_vehicle_list()
def CreateTrain(): S.load_Train()