Skip to content

Commit

Permalink
Altered transport profile weighting
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzyWillow committed Jun 14, 2019
1 parent 88673cd commit 272adb5
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 18 deletions.
13 changes: 13 additions & 0 deletions GQF/Calcs3.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ def QF(areaCodes, timeStepEnd, timeStepDuration, annualEnergyUse, diurnalProfile
# Factor of 86400 to convert from J/m2/day to J/m2/s (W/m2)
dslSc = prop['diesel']
petSc = prop['petrol']
# print('Fuel cons density (kg/m2)', trans.getCar(areaCodes, 'petrol', timeStepEnd))
# print('HoC (J km -1)', petHoc)
# print('J m-2 day-1', petHoc * trans.getCar(areaCodes, 'petrol', timeStepEnd))
# print('J m-2 s-1', (petHoc * trans.getCar(areaCodes, 'petrol', timeStepEnd) /86400))
# issue with mean or sum division of transport profile could be coming out here
# comes as HoC * profile time * fuel proportion
# cardiur = diurnalTrans.getCar(timeStepEnd, timeStepDuration)[0]
# print('printing getCar Diurnal', type(cardiur))
# print('getCar Diurnal:', cardiur)
# print('HoC:', petHoc, dslHoc)
# print(areaCodes)
# print('FC:', trans.getCar(areaCodes, 'petrol', timeStepEnd))
# print('Sc:', petSc, dslSc)
WattHour.loc[areaCodes,columns[9]] = (petHoc * trans.getMotorcycle(areaCodes, 'petrol', timeStepEnd) * petSc +
dslHoc * trans.getMotorcycle(areaCodes, 'diesel', timeStepEnd) * dslSc) * \
diurnalTrans.getMotorcycle(timeStepEnd, timeStepDuration)[0]/86400.0 # motorcycles
Expand Down
4 changes: 4 additions & 0 deletions GQF/DataManagement/spatialHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def calculate_fuel_use(inputLayer, inputIdField,
QgsVectorLayerUtils.getDoubleValues(
inputLayer, vAADTFields[key], selectedOnly=True)[0]) # Populate and translate names at the same time
# aadtData[key] = np.array(QgsVectorLayerUtils.getDoubleValues(inputLayer,vAADTFields[key], selectedOnly=True)[0]) # Populate and translate names at the same time
# aadtData.to_csv('')

# Make use of the extra detail available to us
newValues[fieldMap['diesel']['car']].loc[ids] = aadtData['diesel_car'] * \
Expand Down Expand Up @@ -312,6 +313,9 @@ def calculate_fuel_use(inputLayer, inputIdField,
newValues['_FC_Dbus'].loc[ids] = 0
alreadyCalculated = ['car', 'lgv', 'bus']

# aadtData.to_pickle(f'/Users/suegrimmond/Documents/IQF/GQF-PYQGIS3/logfiles/small_london/AADT_data_{roadType}.pkl')
# lkm.to_pickle(f'/Users/suegrimmond/Documents/IQF/GQF-PYQGIS3/logfiles/small_london/lkm_{roadType}.pkl')
# print('AADT and lkm pickled!')
# The remaining vehicle types all get calculated in the same way so loop over fieldMap to save on code...
for fuelType in list(fieldMap.keys()):
for vehType in list(fieldMap[fuelType].keys()):
Expand Down
3 changes: 2 additions & 1 deletion GQF/Disaggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def disaggregate(qfDataSources, qfParams, outputFolder):
inputFieldId=ie['featureIds'],
weight_by=workpopattrib,
epsgCode=ie['epsgCode'])
(ds, attrib) = bldgEnergy.getIndustrialElecLayer(makeUTC(ie['startDate']))
# different for others, next two lines are in other order
outFile = os.path.join(outputFolder, 'IndElec_starting' + ie['startDate'].strftime('%Y-%m-%d') + '.shp')
(ds, attrib) = bldgEnergy.getIndustrialElecLayer(makeUTC(ie['startDate']))
saveLayerToFile(ds, outFile, bldgEnergy.getOutputLayer().crs(), 'ind elec gas downscaled')
returnDict['indElec'].append({'file':outFile, 'EPSG':ie['epsgCode'], 'startDate':ie['startDate'], 'attribute':attrib, 'featureIds':outFeatIds})

Expand Down
12 changes: 12 additions & 0 deletions GQF/FuelConsumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pass
import os
from .string_func import lower
import pickle
class FuelConsumption():
def __init__(self, filename):
''' Class to read in fuel consumption file with prescribed format in g/km,
Expand All @@ -14,6 +15,10 @@ def __init__(self, filename):
self.fuelTypes = ['diesel', 'petrol']
self.roadTypes = ['motorway', 'rural_single', 'rural_dual', 'urban']
self.dealWithFile(filename)
fuel_vehs = ['dieselcar', 'petrolcar', 'dieseltaxi', 'petroltaxi', 'dieselbus', 'petrolbus',
'diesellgv', 'petrollgv', 'dieselartic', 'petrolartic', 'dieselrigid', 'petrolrigid',
'dieselmotorcycle', 'petrolmotorcycle']
self.FC_record = {m: [] for m in fuel_vehs}

def dealWithFile(self, filename):
'''
Expand Down Expand Up @@ -82,5 +87,12 @@ def getFuelConsumption(self, date, vehicle, road, fuel):
timePick = self.data.index.levels[0].asof(date)

tidx = self.data.index.levels[0].asof(timePick)

fc_val = self.data.loc[tidx].loc[self.fuelMatch[fuel]].loc[self.vehicleMatch[vehicle]][self.roadMatch[road]]/1000.0
self.FC_record[fuel+vehicle].append(fc_val)
# pickle.dump(self.FC_record, open('/Users/suegrimmond/Documents/IQF/GQF-PYQGIS3/logfiles/FC_GQF.pkl', 'wb'))
# f_c_pkl.to_pickle(f'/Users/suegrimmond/Documents/IQF/GQF-PYQGIS3/logfiles/FC_{road}_{fuel}_{vehicle}.pkl')
# print('Saved FC pkl')
# print(self.data.loc[tidx].loc[self.fuelMatch[fuel]].loc[self.vehicleMatch[vehicle]][self.roadMatch[road]]/1000.0)
return self.data.loc[tidx].loc[self.fuelMatch[fuel]].loc[self.vehicleMatch[vehicle]][self.roadMatch[road]]/1000.0 # Convert to kg/km

2 changes: 1 addition & 1 deletion GQF/GreaterQF.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def mostcalcs(self):
[diurnalE.addIndElec(ie['profileFile']) for ie in self.ds.diurnIndElec]
[diurnalE.addIndGas(ig['profileFile']) for ig in self.ds.diurnIndGas]

# Diurnal traffic patterns
# Diurnal traffic patterns %%% for whole run as one var?
diurnalT = TransportProfiles(
self.parameters.city, use_uk_holidays=self.parameters.useUKholidays, customHolidays=self.parameters.customHolidays)
[diurnalT.addProfiles(tr['profileFile'])
Expand Down
15 changes: 11 additions & 4 deletions GQF/TransportProfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
except:
pass
import pytz
from copy import copy
from .DataManagement.LookupLogger import LookupLogger
from .DataManagement.TemporalProfileSampler import TemporalProfileSampler

Expand Down Expand Up @@ -115,7 +116,7 @@ def dealWithInputFile(self, file):
if len(matches) != len(list(dl.keys()))-1:
raise ValueError('Top row of transport diurnal profiles must contain each of: ' + str(expectedHeadings))

firstDataRow = 3
fDR = 3
# Expect certain keywords
if 'transporttype' not in dl.columns.tolist():
raise ValueError('First column of row 1 must be \'TransportType\' in ' + file)
Expand Down Expand Up @@ -149,10 +150,16 @@ def dealWithInputFile(self, file):

for transportType in expectedHeadings:
# Normalize each week series (over the whole week) so it's a weighting factor
# dl.loc[firstDataRow:,transportType] = dl.loc[firstDataRow:,transportType].astype('float')/dl.loc[firstDataRow:,transportType].astype('float').mean()
dl.loc[firstDataRow:,transportType] = dl.loc[firstDataRow:,transportType].astype('float')/dl.loc[firstDataRow:,transportType].astype('float').mean()
# Should it not be normalised by dividing by the sum instead of the mean? then sums to 1, instead of around 1
# dl.loc[fDR:,transportType] = dl.loc[fDR:,transportType].astype('float')/dl.loc[fDR:,transportType].astype('float').mean()
# NOrmalising the transpotr profile between 0 and 1 for each day by dividing by the sum
for i in range(int(dl.loc[fDR:, transportType].shape[0] / 48)):
dl.loc[fDR+(i*48):fDR+(i+1)*48, transportType] = \
dl.loc[fDR+(i*48):fDR+(i+1)*48, transportType].astype('float') / \
dl.loc[fDR+(i*48):fDR+(i+1)*48, transportType].astype('float').sum()
# Assign to the relevant element of this object
subObj = getattr(self, transportType.lower())
if subObj is None:
raise Exception('Programming error: The wrong transport type has been referenced')
subObj.addPeriod(startDate=sd, endDate=ed, dataSeries=dl.loc[firstDataRow:,transportType])
subObj.addPeriod(startDate=sd, endDate=ed, dataSeries=dl.loc[fDR:,transportType])
# dl.to_pickle('logfiles/meanedtransportProfile.pkl')
6 changes: 3 additions & 3 deletions GQF_Inputs/smalltestarea/DataSources.nml
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@

&fuelConsumption
! File containing fuel consumption performance data for each vehicle type as standards change over the years
profileFiles = './GQF_Inputs/smalltestarea/fuelConsumption.csv'
profileFiles = './GQF_Inputs_Izzy/fuelConsumption.csv'
/

! Temporal transport data
&diurnalTraffic
! Diurnal cycles of transport flow for different vehicle types
profileFiles = './GQF_Inputs/smalltestarea/Transport.csv'
profileFiles = './GQF_Inputs_Izzy/Transport.csv'
/

! Temporal metabolism data
&diurnalMetabolism
profileFiles = './GQF_Inputs/smalltestarea/Metabolism.csv'
profileFiles = './GQF_Inputs_Izzy/Metabolism.csv'
/
2 changes: 1 addition & 1 deletion QGIS3-Standalone-brew.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# print(QgsApplication.showSettings())

# set path to run GQF
path_GQF = Path('/Users/sunt05/Dropbox/6.Repos/GQF-PYQGIS3')
path_GQF = Path('/Users/sunt05/Dropbox/6.Repos/GQF-PYQGIS3') # /Users/suegrimmond/Documents/IQF/GQF-PYQGIS3
sys.path.append(path_GQF.as_posix())
os.chdir(path_GQF)
print(os.getcwd())
Expand Down
16 changes: 8 additions & 8 deletions RunGQF.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from pathlib import Path
# set path to run GQF
path_GQF = Path('/Users/sunt05/Dropbox/6.Repos/GQF-PYQGIS3')
path_GQF = Path('/Users/suegrimmond/Documents/IQF/GQF-PYQGIS3')
sys.path.append(path_GQF.as_posix())


Expand Down Expand Up @@ -32,27 +32,27 @@ def random_generator(size=6, chars=string.ascii_uppercase + string.digits):
b['sensible_qf'] = 1
b['latent_qf'] = 1
b['wastewater_qf'] = 0
b['start_dates'] = '2015-01-01'
b['end_dates'] = '2015-01-02'
b['start_dates'] = '2015-06-18'
b['end_dates'] = '2015-06-19'
config.loadFromDictionary(b)
# config.saveNamelist(f'./SampleRun/history-runs/{rand_file}.nml')

model = Model()

# model.setParameters('./GQF_Inputs/1/Parameters.nml')
model.setParameters('./GQF_Inputs/centralLondon/Parameters.nml')
model.setParameters('./GQF_Inputs_Izzy/Parameters.nml')

# model.setDataSources('./GQF_Inputs/1/DataSources.nml')
model.setDataSources('./GQF_Inputs/centralLondon/DataSources.nml')
model.setDataSources('./GQF_Inputs_Izzy/DataSources.nml')

model.setConfig(config)

model.setOutputDir(f'./SampleRun/{rand_file}/')

model.processInputData()
# model.setPreProcessedInputFolder(f'./SampleRun/88WPL5/DownscaledData/')
model.setPreProcessedInputFolder(f'./SampleRun/{rand_file}/DownscaledData/')

print("I'M HERE!")
model.run()



print('FINISHED!')

0 comments on commit 272adb5

Please sign in to comment.