Commit 3a3f6b84 authored by Henrik Grythe's avatar Henrik Grythe
Browse files

Version shown MilDir Fri Nov 20th. Version working and emitting reasonable...

Version shown MilDir Fri Nov 20th. Version working and emitting reasonable amounts of CO2 CH4 and FC, but do not properly have N2O yet
parent 221e1608
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
function Emission_Factor_Model_group_HBEFA() function Emission_Factor_Model_group_HBEFA()
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% The model classes have a static Emission Factor for each driving
% condition. This means that
% 22.10.2020 -Henrik Grythe % 22.10.2020 -Henrik Grythe
% Kjeller NILU % Kjeller NILU
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
...@@ -35,6 +36,8 @@ fprintf('--- \n%s \n',input.files.SSB_Vehicle_dist) ...@@ -35,6 +36,8 @@ fprintf('--- \n%s \n',input.files.SSB_Vehicle_dist)
T = readtable(input.files.SSB_Vehicle_dist,'Sheet','HBEFA778toMODEL'); T = readtable(input.files.SSB_Vehicle_dist,'Sheet','HBEFA778toMODEL');
Tm = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL'); Tm = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
fprintf('read Sheet : %s and Sheet %s\n','HBEFA778toMODEL','MODEL') fprintf('read Sheet : %s and Sheet %s\n','HBEFA778toMODEL','MODEL')
fprintf('Using weight %s \n',Vehicle_weight)
% ModelNumber HBEFA_Weight Uniform_Weight % ModelNumber HBEFA_Weight Uniform_Weight
modelN = unique(T.ModelNumber); modelN = unique(T.ModelNumber);
...@@ -49,16 +52,16 @@ for com =1:length(comps) ...@@ -49,16 +52,16 @@ for com =1:length(comps)
if (~input.options.do_preProcessing_HBEFA && input.options.use_temporary_files && exist(oEFfile)) if (~input.options.do_preProcessing_HBEFA && input.options.use_temporary_files && exist(oEFfile))
fprintf('Using saved %s EFA_Table_MODEL file\n',char(comps(com))) fprintf('Using saved %s EFA_Table_MODEL file\n',char(comps(com)))
load(oEFfile)
else else
fprintf('Calculating New EFA_Table_MODEL_%s file\n',char(comps(com)))
load(iEFfile); load(iEFfile);
D = size(EF_AVG); D = size(EF_AVG);
fprintf('EF_AVG -- Dimensions\n') fprintf('EF_AVG -- Dimensions\n')
for i=1:length(D) for i=1:length(D)
fprintf('EF_AVG D%i : %i\n',i,D(i)); fprintf(' D%i:%-3i ',i,D(i));
end end
fprintf('\n')
% Tables are slow to work with and requires a lot of memory, but given % Tables are slow to work with and requires a lot of memory, but given
% the state of HBEFA, they offer good control of emission factors and % the state of HBEFA, they offer good control of emission factors and
...@@ -66,14 +69,14 @@ for com =1:length(comps) ...@@ -66,14 +69,14 @@ for com =1:length(comps)
TFout = table; TFout = table;
% Loop all model vehicles % Loop all model vehicles
for mod = 1:length(modelN) for mod = 1:length(modelN)
% Make the subset of emissions/weights needed to calculate a model % Make the subset of emissions/weights needed to calculate a model
% vehicle group. % vehicle group.
Tsub = T(T.ModelNumber==modelN(mod),:); Tsub = T(T.ModelNumber==modelN(mod),:);
% Make vehicles with HBEFA weight % Make vehicles with HBEFA weight
EFsub = EF_AVG(Tsub.HBEFA_Num,:,:,:,:,:); EFsub = EF_AVG(Tsub.HBEFA_Num,:,:,:,:,:);
% Check how many non-nan EF there are in each Vehicle. % Check how many non-nan EF there are in each Vehicle. Missing
% EF should be as nan and so this filter them out.
Nef=[]; Nef=[];
for i =1:size(EFsub,1) for i =1:size(EFsub,1)
Nef(i) = length(find(~isnan(EFsub(i,:,:,:,:,:,:)))); Nef(i) = length(find(~isnan(EFsub(i,:,:,:,:,:,:))));
...@@ -82,7 +85,7 @@ for com =1:length(comps) ...@@ -82,7 +85,7 @@ for com =1:length(comps)
% If there are only one amount (1440) of Emission factors % If there are only one amount (1440) of Emission factors
if length(uef) == 1 if length(uef) == 1
fprintf('MODEL Vehicle: %3i %-42s Found #%i EF',modelN(mod),char(Tm.Name(modelN(mod))),uef) fprintf('MODEL Vehicle: %3i %-42s Found #%i EF\n',modelN(mod),char(Tm.Name(modelN(mod))),uef)
Tout = table; Tout = table;
k = 1; k = 1;
for roa = 1:size(EF_AVG,2) for roa = 1:size(EF_AVG,2)
...@@ -111,8 +114,16 @@ for com =1:length(comps) ...@@ -111,8 +114,16 @@ for com =1:length(comps)
EFac = nan(height(Tout),1); EFac = nan(height(Tout),1);
Wght = nan(height(Tout),1); Wght = nan(height(Tout),1);
for cond = 1:height(Tout) for veh = 1:height(Tsub)
for veh = 1:height(Tsub) switch Vehicle_weight
case 'Uniform'
fprintf('%i of %i %s Weight %3.2f %-30s of %3.2f ',veh,height(Tsub),Vehicle_weight,Tsub.NERVE_Weight(veh),char(Tsub.Name(veh)),sum(Tsub.Uniform_Weight))
case 'NERVE'
fprintf('%i of %i %s Weight %3.2f %-30s of %3.2f ',veh,height(Tsub),Vehicle_weight,Tsub.NERVE_Weight(veh),char(Tsub.Name(veh)),sum(Tsub.NERVE_Weight))
case 'HBEFA'
fprintf('%i of %i %s Weight %3.2f %-30s of %3.2f ',veh,height(Tsub),Vehicle_weight,Tsub.NERVE_Weight(veh),char(Tsub.Name(veh)),sum(Tsub.HBEFA_Weight))
end
for cond = 1:height(Tout)
if veh == 1 if veh == 1
switch Vehicle_weight switch Vehicle_weight
case 'Uniform' case 'Uniform'
...@@ -139,17 +150,20 @@ for com =1:length(comps) ...@@ -139,17 +150,20 @@ for com =1:length(comps)
end end
end end
end end
fprintf('\n')
end end
Tout.EFac = EFac./Wght;
pos = find(ismember(Tout.Properties.VariableNames,{'EFac'}));
Tout.Properties.VariableNames(pos) = Tm.Name(modelN(mod));
if debug_mode if debug_mode
sprintf('%s_%sWeight',char(comps(com)),Vehicle_Weight) fprintf('%s_%s_weight',char(comps(com)),Vehicle_weight)
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(EFac./Wght),max(EFac./Wght),min(EFac./Wght)) fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) ',mean(EFac./Wght),max(EFac./Wght),min(EFac./Wght))
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(Wght),max(Wght),min(Wght)) fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(Wght),max(Wght),min(Wght))
else else
fprintf('\n') fprintf('\n')
end end
Tout.EFac = EFac./Wght;
Tout.Properties.VariableNames(find(ismember(Tout.Properties.VariableNames,{'EFac'}))) = Tm.Name(modelN(mod));
else else
% if this is the case, there are NaNs in the emission factor % if this is the case, there are NaNs in the emission factor
% and we will get wrong results. % and we will get wrong results.
...@@ -177,65 +191,14 @@ for com =1:length(comps) ...@@ -177,65 +191,14 @@ for com =1:length(comps)
end end
EFrdCond = table2array(TFout(:,8:end)); EFrdCond = table2array(TFout(:,8:end));
save(oEFfile,'TFout','roads','EFrdCond') save(oEFfile,'TFout','roads','EFrdCond')
fprintf('Saved an excel-file for Emission Factors Model:\n%s\n',oEFfile) fprintf('Saved an temp .mat -file for Emission Factors Model:\n%s\n',oEFfile)
writetable(TFout,ofile,'Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight))
fprintf('Saved an excel-file for Emission Factors Model:\n%s\n',ofile) % writetable(TFout,ofile,'Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight))
% fprintf('Saved an excel-file for Emission Factors Model:\n%s\n',ofile)
end
switch char(comps(com))
case 'FC'
MunicpalHBEFA_RoadsEF_FC = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_FC','roads','-append');
case 'FC_MJ'
MunicpalHBEFA_RoadsEF_FC_MJ = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_FC_MJ','roads','-append');
case 'CH4'
MunicpalHBEFA_RoadsEF_CH4 = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_CH4','roads','-append');
case 'BC'
MunicpalHBEFA_RoadsEF_BC = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_BC','roads','-append');
case 'PM'
MunicpalHBEFA_RoadsEF_PM = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_PM','roads','-append');
case 'HC'
MunicpalHBEFA_RoadsEF_HC = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_HC','roads','-append');
case 'CO'
MunicpalHBEFA_RoadsEF_CO = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_CO','roads','-append');
case 'NOx'
MunicpalHBEFA_RoadsEF_NOx = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NOx','roads','-append');
case 'Be'
MunicpalHBEFA_RoadsEF_Be = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_Be','roads','-append');
case 'NMHC'
MunicpalHBEFA_RoadsEF_NMHC = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NMHC','roads','-append');
case 'NO2'
MunicpalHBEFA_RoadsEF_NO2 = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NO2','roads','-append');
case 'NO'
MunicpalHBEFA_RoadsEF_NO = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NO','roads','-append');
case 'PN'
MunicpalHBEFA_RoadsEF_PN = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_PN','roads','-append');
case 'CO2'
MunicpalHBEFA_RoadsEF_CO2 = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_CO2','roads','-append');
case 'N2O'
MunicpalHBEFA_RoadsEF_N2O = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_N2O','roads','-append');
case 'NH3'
MunicpalHBEFA_RoadsEF_NH3 = TFout;
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NH3','roads','-append');
end end
end end
end end
...@@ -16,32 +16,29 @@ ...@@ -16,32 +16,29 @@
function Emission_Factor_Process_HBEFA_Matrix_Raw() function Emission_Factor_Process_HBEFA_Matrix_Raw()
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% Script for reading and processing HBEFA .csv file of subsegments. % Script for reading and processing HBEFA .csv file of subsegments.
% Basically taken from NERVE, but includes some updates for the format of % Basically taken from HEDGE, but includes some updates for the format of
% HBEFA4.1. Makes a 6-D matix of the emissions factor, convenient for speedy % HBEFA4.1. Makes a 6-D matix of the emissions factor, convenient for speedy
% processing. % processing.
% 22.10.2020 -Henrik Grythe % 22.10.2020 -Henrik Grythe
% Kjeller NILU % Kjeller NILU
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% % Path to emissions
% HBEFA_path = '/storage/nilu/Inby/Emission_Group/Emission_Factors/Traffic/HBEFA_Raw_data/HOT_HBEFA_41/';
% % List the avalable species SLA have downloaded Emission factors for
% comps = [{'NOx'},{'CO2'},{'BC'},{'Be'},{'CO'},{'HC'},{'NMHC'},{'NO2'},{'PM'},{'PN'},{'NH3'},{'N2O'},{'CH4'},{'FC'},{'FC_MJ'}];
global do_preProcessing_HBEFA debug_mode global do_preProcessing_HBEFA debug_mode
global HBEFA_path tfold comps global HBEFA_path tfold comps
fprintf('\tEmission_Factor_Process_HBEFA_Matrix_Raw *\n') fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factor_Process_HBEFA_Matrix_Raw *\n')
fprintf('---------------------------------------------------------------\n')
if ~do_preProcessing_HBEFA if ~do_preProcessing_HBEFA
fprintf('We Already Have Necessary HBEFA Emission Factors \n') fprintf('We Already Have Necessary HBEFA Emission Factors \n')
fprintf('... Continuing Without new HBEFA calculations \n ... \n') fprintf('... Continuing Without new HBEFA EFA_Matrix41_RAW calculations \n ... \n')
return return
else else
fprintf('Remaking HBEFA COMBINED files for Use in HEDGE \n') fprintf('Remaking HBEFA RAW_MATRIX files for Use in model \n')
fprintf('Combine the "HGV" EF file with the "others" files\n')
end end
% The download from HBEFA has some variation in what is enterpreted as
% numbers. Therefor need to define numeric and non numeric columns to be
% able to combine them.
% cell fields: % cell fields:
SfldList = [{'Case'},{'VehCat'},{'Component'},{'TrafficSit'},{'Gradient'},{'Subsegment'},{'Technology'},{'SizeClasse'},{'EmConcept'},{'x_OfSubsegment'}]; SfldList = [{'Case'},{'VehCat'},{'Component'},{'TrafficSit'},{'Gradient'},{'Subsegment'},{'Technology'},{'SizeClasse'},{'EmConcept'},{'x_OfSubsegment'}];
% Numerical fields: % Numerical fields:
...@@ -49,21 +46,22 @@ NfldList = [{'Year'},{'TrafficScenario'},{'RoadCat'},{'IDSubsegment'},{'KM'},{'x ...@@ -49,21 +46,22 @@ NfldList = [{'Year'},{'TrafficScenario'},{'RoadCat'},{'IDSubsegment'},{'KM'},{'x
{'EFA'},{'EFA_0_'},{'EFA_100_'},{'V_weighted'},{'V_weighted_0_'},{'V_weighted_100_'},{'EFA_weighted'},{'EFA_weighted_0_'},... {'EFA'},{'EFA_0_'},{'EFA_100_'},{'V_weighted'},{'V_weighted_0_'},{'V_weighted_100_'},{'EFA_weighted'},{'EFA_weighted_0_'},...
{'EFA_weighted_100_'},{'EFA_WTT'},{'EFA_WTT_0_'},{'EFA_WTT_100_'},{'EFA_WTW'},{'EFA_WTW_0_'},{'EFA_WTW_100_'},{'AmbientCondPattern'}]; {'EFA_weighted_100_'},{'EFA_WTT'},{'EFA_WTT_0_'},{'EFA_WTT_100_'},{'EFA_WTW'},{'EFA_WTW_0_'},{'EFA_WTW_100_'},{'AmbientCondPattern'}];
% Loop over all compounds in comps list. % Loop over all compounds in comps list.
redo = 1; redo = 0;
for com = 1:length(comps) for com = 1:length(comps)
fprintf('Remaking HBEFA COMBINED files for Use in matrix Calculations \n')
fprintf('Combine the "HGV" EF file with the "others" files\n')
% assumed a naming convention % assumed a naming convention
ifile1 = sprintf('%sEFA_HOT_Subsegm_%s.csv',HBEFA_path,char(comps(com))); ifile1 = sprintf('%sEFA_HOT_Subsegm_%s.csv',HBEFA_path,char(comps(com)));
ifile2 = sprintf('%sHGV/EFA_HOT_Subsegm_%s_hgv.csv',HBEFA_path,char(comps(com))); ifile2 = sprintf('%sHGV/EFA_HOT_Subsegm_%s_hgv.csv',HBEFA_path,char(comps(com)));
% avoid doing process repeatedly (save a combined file) % avoid doing process repeatedly (save a combined file)
ifile3 = sprintf('%sCOMBINED_EFA_HOT_Subsegm_%s.csv',HBEFA_path,char(comps(com))); ifile3 = sprintf('%sCOMBINED_EFA_HOT_Subsegm_%s.csv',HBEFA_path,char(comps(com)));
if ~exist(ifile3) || redo ==1 if ~exist(ifile3) || redo ==1
fprintf('COMBINIG TWO VERY LARGE FILES! \n')
fprintf('ifile1: %s\n',ifile1) fprintf('ifile1: %s\n',ifile1)
Tn1 = readtable(ifile1); Tn1 = readtable(ifile1);
fprintf('ifile2: %s\n',ifile2) fprintf('ifile2: %s\n',ifile2)
Tn2 = readtable(ifile2); Tn2 = readtable(ifile2);
...@@ -133,12 +131,12 @@ for com = 1:length(comps) ...@@ -133,12 +131,12 @@ for com = 1:length(comps)
fprintf('ifile3: %s\n',ifile3) fprintf('ifile3: %s\n',ifile3)
Tn = readtable(ifile3); Tn = readtable(ifile3);
end end
%%%%%% FINISHED PAIRING HGV with Others %------ END PAIRING HGV and Others
%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find the unique subsegments % Find the unique subsegments
expected_veh = 778; % for HBEFA4.1 expected_veh = 778; % for HBEFA4.1
sub = unique(Tn.Subsegment); sub = unique(Tn.Subsegment);
fprintf('Number of subsegments in %s %i\n',char(comps(com)), length(sub)) fprintf('Number of subsegments in %s %i\n',char(comps(com)), length(sub))
if length(sub) ~= expected_veh if length(sub) ~= expected_veh
warning('May have flawed input data!') warning('May have flawed input data!')
...@@ -387,7 +385,7 @@ for com = 1:length(comps) ...@@ -387,7 +385,7 @@ for com = 1:length(comps)
DriveOrig(v) = sum(~isnan(Tt.EFA_AVG)); DriveOrig(v) = sum(~isnan(Tt.EFA_AVG));
if debug_mode if debug_mode
fprintf('%03i %36s %i / %i :::: ',v, char(roads.Vehicles(v)),sum(count),height(Tt)) fprintf('%03i_%-46s %i / %i :::: ',v, char(roads.Vehicles(v)),sum(count),height(Tt))
fprintf('Numeric EF %i / %i\n',Driving(v),sum(~isnan(Tt.EFA_AVG))) fprintf('Numeric EF %i / %i\n',Driving(v),sum(~isnan(Tt.EFA_AVG)))
end end
end end
...@@ -395,7 +393,7 @@ for com = 1:length(comps) ...@@ -395,7 +393,7 @@ for com = 1:length(comps)
% save(sprintf('EFA_matrix_RAW_%s',char(comps(com))),'roads','EF_AVG','EF_000','EF_100') % save(sprintf('EFA_matrix_RAW_%s',char(comps(com))),'roads','EF_AVG','EF_000','EF_100')
oEFfile = sprintf('%s/EFA_matrix41_RAW_%s',tfold,char(comps(com))); oEFfile = sprintf('%s/EFA_matrix41_RAW_%s',tfold,char(comps(com)));
save(oEFfile,'roads','EF_AVG','EF_000','EF_100','traffCon'); save(oEFfile,'roads','EF_AVG','EF_000','EF_100','traffCon');
fprintf('Saved temporary file\n%s\n',oEFfile) fprintf('Saved temporary file: \n%s\n',oEFfile)
clear Gradient Tn T RTID roads EF_* clear Gradient Tn T RTID roads EF_*
end end
......
...@@ -17,16 +17,14 @@ function Emission_Factors_OnRoadAllCond() ...@@ -17,16 +17,14 @@ function Emission_Factors_OnRoadAllCond()
% Function for Road link calculations computes for each municipality an % Function for Road link calculations computes for each municipality an
% emission factor (EF) for Light, Heavy and Buses. % emission factor (EF) for Light, Heavy and Buses.
% This needs to be run for each component and each year. % This needs to be run for each component and each year.
global tfold Tyear SSB_Vehicle_dist comps Vehicle_dist Vehicle_weight global tfold Tyear SSB_Vehicle_dist comps Vehicle_dist
global debug_mode ofiles use_temporary_files input global debug_mode ofiles use_temporary_files input
fprintf('---------------------------------------------------------------\n') fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factors_OnRoadAllCond *\n') fprintf('in Emission_Factors_OnRoadAllCond *\n')
fprintf('---------------------------------------------------------------\n') fprintf('---------------------------------------------------------------\n')
TM = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2; LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4; BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4;
HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7; HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
...@@ -34,12 +32,10 @@ VD = Vehicle_dist.Vdist; ...@@ -34,12 +32,10 @@ VD = Vehicle_dist.Vdist;
% Loop all components to be calculated: % Loop all components to be calculated:
for com = 1:length(comps) for com = 1:length(comps)
fprintf('<--- %s\n',char(comps(com))) fprintf('<--- %s\n',char(comps(com)))
ofile = sprintf('OnRoadEF_RoadClasses_%s.xlsx',char(comps(com)));
osheet = sprintf('%s_%i',char(comps(com)),Tyear);
tmpfile = sprintf('%sEF_On_AllRoadCond_Municipality_%i_%s.mat',tfold,Tyear,char(comps(com))); tmpfile = sprintf('%sEF_On_AllRoadCond_Municipality_%i_%s.mat',tfold,Tyear,char(comps(com)));
if use_temporary_files && exist(tmpfile) if use_temporary_files && exist(tmpfile)
fprintf('Has all necessary EF files for :%s \n',char(comps(com))) fprintf('Has all necessary EF files for :%s \n',char(comps(com)))
else else
oEFfile = sprintf('%sEFA_Table_MODEL_%s.mat',tfold,char(comps(com))); oEFfile = sprintf('%sEFA_Table_MODEL_%s.mat',tfold,char(comps(com)));
...@@ -101,6 +97,8 @@ for com = 1:length(comps) ...@@ -101,6 +97,8 @@ for com = 1:length(comps)
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Buses'))) = {sprintf('EF_Buses_%04i',Vehicle_dist.D1_KommNr(komm))}; Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Buses'))) = {sprintf('EF_Buses_%04i',Vehicle_dist.D1_KommNr(komm))};
end end
% These are the on road emission factors used for road link
% calculations in each municipality.
K_EF.distNames = Trout.Properties.VariableNames; K_EF.distNames = Trout.Properties.VariableNames;
K_EF.traffSit = Trout.Name; K_EF.traffSit = Trout.Name;
K_EF.TraffSitID = Trout(:,2:7); K_EF.TraffSitID = Trout(:,2:7);
...@@ -113,67 +111,69 @@ for com = 1:length(comps) ...@@ -113,67 +111,69 @@ for com = 1:length(comps)
K_EF.kommNamesL = Trout.Properties.VariableNames(idl); K_EF.kommNamesL = Trout.Properties.VariableNames(idl);
K_EF.kommNamesH = Trout.Properties.VariableNames(idh); K_EF.kommNamesH = Trout.Properties.VariableNames(idh);
K_EF.kommNamesB = Trout.Properties.VariableNames(idb); K_EF.kommNamesB = Trout.Properties.VariableNames(idb);
save(tmpfile,'K_EF') save(tmpfile,'K_EF','Trout')
fprintf('saved a tmp file \n%s\n',tmpfile) fprintf('saved a tmp file \n%s\n',tmpfile)
writetable(Trout,ofile,'Sheet',osheet) % ofile = sprintf('OnRoadEF_RoadClasses_%s.xlsx',char(comps(com)));
fprintf('Wrote Sheet: %s \n to file; %s\n',osheet,ofile) % osheet = sprintf('%s_%i',char(comps(com)),Tyear);
% writetable(Trout,ofile,'Sheet',osheet)
% fprintf('Wrote Sheet: %s \n to file; %s\n',osheet,ofile)
fprintf('%s--- >\n',char(comps(com))) fprintf('%s--- >\n',char(comps(com)))
% Use a switch for string as MatLab do not love variable names changes % Use a switch for string as MatLab do not love variable names changes
% inside loops... % inside loops...
switch char(comps(com)) % switch char(comps(com))
case 'FC' % case 'FC'
OnRoadEF_RoadClasses_FC = Trout; % OnRoadEF_RoadClasses_FC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append');
case 'FC_MJ' % case 'FC_MJ'
OnRoadEF_RoadClasses_FC_MJ = Trout; % OnRoadEF_RoadClasses_FC_MJ = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append');
case 'CH4' % case 'CH4'
OnRoadEF_RoadClasses_CH4 = Trout; % OnRoadEF_RoadClasses_CH4 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append');
case 'BC' % case 'BC'
OnRoadEF_RoadClasses_BC = Trout; % OnRoadEF_RoadClasses_BC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append');
case 'PM' % case 'PM'
OnRoadEF_RoadClasses_PM = Trout; % OnRoadEF_RoadClasses_PM = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append');
case 'HC' % case 'HC'
OnRoadEF_RoadClasses_HC = Trout; % OnRoadEF_RoadClasses_HC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append');
case 'CO' % case 'CO'
OnRoadEF_RoadClasses_CO = Trout; % OnRoadEF_RoadClasses_CO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append');
case 'NOx' % case 'NOx'
OnRoadEF_RoadClasses_NOx = Trout; % OnRoadEF_RoadClasses_NOx = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append');
case 'Be' % case 'Be'
OnRoadEF_RoadClasses_Be = Trout; % OnRoadEF_RoadClasses_Be = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append');
case 'NMHC' % case 'NMHC'
OnRoadEF_RoadClasses_NMHC = Trout; % OnRoadEF_RoadClasses_NMHC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append');
case 'NO2' % case 'NO2'
OnRoadEF_RoadClasses_NO2 = Trout; % OnRoadEF_RoadClasses_NO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append');
case 'NO' % case 'NO'
OnRoadEF_RoadClasses_NO = Trout; % OnRoadEF_RoadClasses_NO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO','-append');
case 'PN' % case 'PN'
OnRoadEF_RoadClasses_PN = Trout; % OnRoadEF_RoadClasses_PN = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PN','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PN','-append');
case 'CO2' % case 'CO2'
OnRoadEF_RoadClasses_CO2 = Trout; % OnRoadEF_RoadClasses_CO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO2','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO2','-append');
case 'N2O' % case 'N2O'
OnRoadEF_RoadClasses_N2O = Trout; % OnRoadEF_RoadClasses_N2O = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_N2O','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_N2O','-append');
case 'NH3' % case 'NH3'
OnRoadEF_RoadClasses_NH3 = Trout; % OnRoadEF_RoadClasses_NH3 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NH3','-append'); % save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NH3','-append');
end % end
end end
end end
......
...@@ -19,24 +19,21 @@ function Emission_Factors_Road_DrivingDistance_IN_Municipalities() ...@@ -19,24 +19,21 @@ function Emission_Factors_Road_DrivingDistance_IN_Municipalities()
global RLinks tfold Tyear Vehicle_dist debug_mode SSB_Vehicle_dist ofiles global RLinks tfold Tyear Vehicle_dist debug_mode SSB_Vehicle_dist ofiles
global tfiles global tfiles input
fprintf('---------------------------------------------------------------\n') fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factors_Road_DrivingDistance_IN_Municipalities *\n') fprintf('in Emission_Factors_Road_DrivingDistance_IN_Municipalities *\n')
fprintf('---------------------------------------------------------------\n') fprintf('---------------------------------------------------------------\n')
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL'); TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2; LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4; BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4;
HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7; HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
T = readtable('modelHBEFA.xlsx','Sheet','Roads');