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 @@
%--------------------------------------------------------------------------
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
% Kjeller NILU
%--------------------------------------------------------------------------
......@@ -35,6 +36,8 @@ fprintf('--- \n%s \n',input.files.SSB_Vehicle_dist)
T = readtable(input.files.SSB_Vehicle_dist,'Sheet','HBEFA778toMODEL');
Tm = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
fprintf('read Sheet : %s and Sheet %s\n','HBEFA778toMODEL','MODEL')
fprintf('Using weight %s \n',Vehicle_weight)
% ModelNumber HBEFA_Weight Uniform_Weight
modelN = unique(T.ModelNumber);
......@@ -49,16 +52,16 @@ for com =1:length(comps)
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)))
load(oEFfile)
else
fprintf('Calculating New EFA_Table_MODEL_%s file\n',char(comps(com)))
load(iEFfile);
D = size(EF_AVG);
fprintf('EF_AVG -- Dimensions\n')
for i=1:length(D)
fprintf('EF_AVG D%i : %i\n',i,D(i));
fprintf(' D%i:%-3i ',i,D(i));
end
fprintf('\n')
% 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
......@@ -66,14 +69,14 @@ for com =1:length(comps)
TFout = table;
% Loop all model vehicles
for mod = 1:length(modelN)
% Make the subset of emissions/weights needed to calculate a model
% vehicle group.
Tsub = T(T.ModelNumber==modelN(mod),:);
% Make vehicles with HBEFA weight
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=[];
for i =1:size(EFsub,1)
Nef(i) = length(find(~isnan(EFsub(i,:,:,:,:,:,:))));
......@@ -82,7 +85,7 @@ for com =1:length(comps)
% If there are only one amount (1440) of Emission factors
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;
k = 1;
for roa = 1:size(EF_AVG,2)
......@@ -111,8 +114,16 @@ for com =1:length(comps)
EFac = 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
switch Vehicle_weight
case 'Uniform'
......@@ -139,17 +150,20 @@ for com =1:length(comps)
end
end
end
fprintf('\n')
end
Tout.EFac = EFac./Wght;
pos = find(ismember(Tout.Properties.VariableNames,{'EFac'}));
Tout.Properties.VariableNames(pos) = Tm.Name(modelN(mod));
if debug_mode
sprintf('%s_%sWeight',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('%s_%s_weight',char(comps(com)),Vehicle_weight)
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))
else
fprintf('\n')
end
Tout.EFac = EFac./Wght;
Tout.Properties.VariableNames(find(ismember(Tout.Properties.VariableNames,{'EFac'}))) = Tm.Name(modelN(mod));
else
% if this is the case, there are NaNs in the emission factor
% and we will get wrong results.
......@@ -177,65 +191,14 @@ for com =1:length(comps)
end
EFrdCond = table2array(TFout(:,8:end));
EFrdCond = table2array(TFout(:,8:end));
save(oEFfile,'TFout','roads','EFrdCond')
fprintf('Saved an excel-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)
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');
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)
end
end
end
......@@ -16,32 +16,29 @@
function Emission_Factor_Process_HBEFA_Matrix_Raw()
%--------------------------------------------------------------------------
% 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
% processing.
% 22.10.2020 -Henrik Grythe
% 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 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
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
else
fprintf('Remaking HBEFA COMBINED files for Use in HEDGE \n')
fprintf('Combine the "HGV" EF file with the "others" files\n')
fprintf('Remaking HBEFA RAW_MATRIX files for Use in model \n')
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:
SfldList = [{'Case'},{'VehCat'},{'Component'},{'TrafficSit'},{'Gradient'},{'Subsegment'},{'Technology'},{'SizeClasse'},{'EmConcept'},{'x_OfSubsegment'}];
% Numerical fields:
......@@ -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_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.
redo = 1;
redo = 0;
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
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)));
% avoid doing process repeatedly (save a combined file)
ifile3 = sprintf('%sCOMBINED_EFA_HOT_Subsegm_%s.csv',HBEFA_path,char(comps(com)));
if ~exist(ifile3) || redo ==1
fprintf('COMBINIG TWO VERY LARGE FILES! \n')
fprintf('ifile1: %s\n',ifile1)
Tn1 = readtable(ifile1);
fprintf('ifile2: %s\n',ifile2)
Tn2 = readtable(ifile2);
......@@ -133,12 +131,12 @@ for com = 1:length(comps)
fprintf('ifile3: %s\n',ifile3)
Tn = readtable(ifile3);
end
%%%%%% FINISHED PAIRING HGV with Others
%------ END PAIRING HGV and Others
%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find the unique subsegments
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))
if length(sub) ~= expected_veh
warning('May have flawed input data!')
......@@ -387,7 +385,7 @@ for com = 1:length(comps)
DriveOrig(v) = sum(~isnan(Tt.EFA_AVG));
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)))
end
end
......@@ -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')
oEFfile = sprintf('%s/EFA_matrix41_RAW_%s',tfold,char(comps(com)));
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_*
end
......
......@@ -17,16 +17,14 @@ function Emission_Factors_OnRoadAllCond()
% Function for Road link calculations computes for each municipality an
% emission factor (EF) for Light, Heavy and Buses.
% 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
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factors_OnRoadAllCond *\n')
fprintf('---------------------------------------------------------------\n')
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
TM = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4;
HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
......@@ -34,12 +32,10 @@ VD = Vehicle_dist.Vdist;
% Loop all components to be calculated:
for com = 1:length(comps)
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)));
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
oEFfile = sprintf('%sEFA_Table_MODEL_%s.mat',tfold,char(comps(com)));
......@@ -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))};
end
% These are the on road emission factors used for road link
% calculations in each municipality.
K_EF.distNames = Trout.Properties.VariableNames;
K_EF.traffSit = Trout.Name;
K_EF.TraffSitID = Trout(:,2:7);
......@@ -113,67 +111,69 @@ for com = 1:length(comps)
K_EF.kommNamesL = Trout.Properties.VariableNames(idl);
K_EF.kommNamesH = Trout.Properties.VariableNames(idh);
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)
writetable(Trout,ofile,'Sheet',osheet)
fprintf('Wrote Sheet: %s \n to file; %s\n',osheet,ofile)
% ofile = sprintf('OnRoadEF_RoadClasses_%s.xlsx',char(comps(com)));
% 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)))
% Use a switch for string as MatLab do not love variable names changes
% inside loops...
switch char(comps(com))
case 'FC'
OnRoadEF_RoadClasses_FC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append');
case 'FC_MJ'
OnRoadEF_RoadClasses_FC_MJ = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append');
case 'CH4'
OnRoadEF_RoadClasses_CH4 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append');
case 'BC'
OnRoadEF_RoadClasses_BC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append');
case 'PM'
OnRoadEF_RoadClasses_PM = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append');
case 'HC'
OnRoadEF_RoadClasses_HC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append');
case 'CO'
OnRoadEF_RoadClasses_CO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append');
case 'NOx'
OnRoadEF_RoadClasses_NOx = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append');
case 'Be'
OnRoadEF_RoadClasses_Be = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append');
case 'NMHC'
OnRoadEF_RoadClasses_NMHC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append');
case 'NO2'
OnRoadEF_RoadClasses_NO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append');
case 'NO'
OnRoadEF_RoadClasses_NO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO','-append');
case 'PN'
OnRoadEF_RoadClasses_PN = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PN','-append');
case 'CO2'
OnRoadEF_RoadClasses_CO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO2','-append');
case 'N2O'
OnRoadEF_RoadClasses_N2O = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_N2O','-append');
case 'NH3'
OnRoadEF_RoadClasses_NH3 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NH3','-append');
end
% switch char(comps(com))
% case 'FC'
% OnRoadEF_RoadClasses_FC = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append');
% case 'FC_MJ'
% OnRoadEF_RoadClasses_FC_MJ = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append');
% case 'CH4'
% OnRoadEF_RoadClasses_CH4 = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append');
% case 'BC'
% OnRoadEF_RoadClasses_BC = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append');
% case 'PM'
% OnRoadEF_RoadClasses_PM = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append');
% case 'HC'
% OnRoadEF_RoadClasses_HC = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append');
% case 'CO'
% OnRoadEF_RoadClasses_CO = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append');
% case 'NOx'
% OnRoadEF_RoadClasses_NOx = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append');
% case 'Be'
% OnRoadEF_RoadClasses_Be = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append');
% case 'NMHC'
% OnRoadEF_RoadClasses_NMHC = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append');
% case 'NO2'
% OnRoadEF_RoadClasses_NO2 = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append');
% case 'NO'
% OnRoadEF_RoadClasses_NO = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO','-append');
% case 'PN'
% OnRoadEF_RoadClasses_PN = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PN','-append');
% case 'CO2'
% OnRoadEF_RoadClasses_CO2 = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO2','-append');
% case 'N2O'
% OnRoadEF_RoadClasses_N2O = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_N2O','-append');
% case 'NH3'
% OnRoadEF_RoadClasses_NH3 = Trout;
% save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NH3','-append');
% end
end
end
......
......@@ -19,24 +19,21 @@ function Emission_Factors_Road_DrivingDistance_IN_Municipalities()
global RLinks tfold Tyear Vehicle_dist debug_mode SSB_Vehicle_dist ofiles
global tfiles
global tfiles input
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factors_Road_DrivingDistance_IN_Municipalities *\n')
fprintf('---------------------------------------------------------------\n')
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4;
HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
T = readtable('modelHBEFA.xlsx','Sheet','Roads');
T = readtable(input.files.HBEFA_roads,'Sheet','Roads');
file = sprintf('%s%s',tfold,'roads');
fprintf('### Warning,using roads file not produced by NERVE model\n%s\n',file)
fprintf('### Warning,circumventing temp file "roads" \n not produced by NERVE model\n%s\n',file)
load(file)
% All road links kilometer per type of road Light / Heavy / Bus
nDD_L = zeros(height(T),1);
nDD_H = zeros(height(T),1);
......@@ -61,7 +58,7 @@ uKomm = unique(KommunerS);
% Congestion weights. Traffic part delayed (TPD)
% Combine the different congestion levels by volume to determine the
% actual EF:
fprintf('### Warning, using parameterized CONGESTION\n%s\n',file)
fprintf('### Warning, using parameterized CONGESTION\n\n')
TPD_L=[1.0, 0.0, 0.0, 0.0, 0.0;...
0.6, 0.4, 0.0, 0.0, 0.0;...
0.6, 0.2, 0.2, 0.0, 0.0;...
......@@ -115,7 +112,7 @@ for komm = 1:length(uKomm)
KOMS = extractfield(MRLinks,'KOMMS');
if debug_mode
fprintf(' Light Traffic L=%7.1f (1 000 000) Km TDL=%9.3f \n',1e-6*sum(L.*IDO.*LEN)*dayInYear,1e-6*sum(Vehicle_dist.modelTD(komm,LightVehiclesIdx)))
fprintf(' Light Traffic L=%7.1f (1 000 000) Km TDL=%9.3f \n',1e-6*sum(L.*IDO.*LEN)*dayInYear,1e-6*sum(Vehicle_dist.modelTD(komm,LightVehiclesIdx)))
fprintf(' Heavy Traffic H=%7.1f (1 000 000) Km TDH=%9.3f \n',1e-6*sum(H.*IDO.*LEN)*dayInYear,1e-6*sum(Vehicle_dist.modelTD(komm,HeavyVehiclesIdx)))
fprintf(' Buses Traffic B=%7.1f (1 000 000) Km TDB=%9.3f \n',1e-6*sum(B.*IDO.*LEN)*dayInYear,1e-6*sum(Vehicle_dist.modelTD(komm,BusesVehiclesIdx)))
end
......@@ -172,7 +169,7 @@ fprintf(' Light Traffic L=%7.1f (1 000 000) Km TDL=%7.1f (%5.1f%%) \n',LW,
fprintf(' Heavy Traffic H=%7.1f (1 000 000) Km TDH=%7.1f (%5.1f%%) \n',HW,HTD,100*HW/HTD)
fprintf(' Buses Traffic B=%7.1f (1 000 000) Km TDB=%7.1f (%5.1f%%) \n',BW,BTD,100*BW/BTD)
writetable(Tout,'Municipal_DrivingDistances_per_RoadType.xlsx','Sheet',sprintf('DD_%i',Tyear))
% writetable(Tout,'Municipal_DrivingDistances_per_RoadType.xlsx','Sheet',sprintf('DD_%i',Tyear))
KDD.distNames = Tout.Properties.VariableNames;
KDD.traffSit = Tout.Name;
......@@ -187,9 +184,9 @@ KDD.kommNamesL = Tout.Properties.VariableNames(idl);
KDD.kommNamesH = Tout.Properties.VariableNames(idh);
KDD.kommNamesB = Tout.Properties.VariableNames(idb);
KDD.Tyear = Tyear;
save(tfiles.DD_Municipal,'KDD')
save(ofiles.MatlabOutput,'KDD','-append')
save(tfiles.DD_Municipal,'KDD','Tout')
% save(ofiles.MatlabOutput,'KDD','-append')
fprintf('Finished processing driving distances\n\n')
% DrivingDistances_per_RoadType = Tout;
% save(ofiles.MatlabOutput,'DrivingDistances_per_RoadType','-append')
end
\ No newline at end of file
......@@ -37,7 +37,7 @@ file = sprintf('%s%s',tfold,'roads');
fprintf('### Warning, using roads file not produced by NERVE model\n%s\n',file)
load(file)
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
TM = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
BusesVehiclesIdx = TM.ClassNum==3|TM.ClassNum==4;
HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
......@@ -110,18 +110,12 @@ for com = 1:length(comps)
EMISS_B = zeros(size(RLinks));
Link_emission_factor= zeros(size(RLinks));
fprintf('<--- %s ---\n',char(comps(com)))
fprintf('Loading large file\n...')
%%%%%%%%%%%%%%%%%%%%%%%
% try
% TEF = load(ofiles.MatlabOutput,sprintf('OnRoadEF_RoadClasses_%i',char(coms(com))))
% catch
% fprintf('reading excel file\n')
TEF = readtable(sprintf('OnRoadEF_RoadClasses_%s.xlsx',char(comps(com))),'Sheet',sprintf('%s_%i',char(comps(com)),Tyear),'PreserveVariableNames',1);
tmpfile = sprintf('%sEF_On_AllRoadCond_Municipality_%i_%s.mat',tfold,Tyear,char(comps(com)));
load(tmpfile)
% end
%%%%%%%%%%%%%%%%%%%%%%
TEF = Trout;
fprintf('Loaded.\n')
tef = TEF.Name;
for r =1:length(L)
......@@ -176,7 +170,7 @@ for com = 1:length(comps)
RLinks = table2struct(TLinks);
% Print some statistical output
fprintf('\n---- NORGE --- %i\n',Tyear)
fprintf('\n---- NORGE --- %i %s \n',Tyear,char(comps(com)))
fprintf('---- Lette %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*sum(EMISS_L),char(comps(com)),100*nansum(EMISS_L)/nansum(EMISS_L + EMISS_H + EMISS_B))
fprintf('---- Tunge %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*nansum(EMISS_H),char(comps(com)),100*nansum(EMISS_H)/nansum(EMISS_L + EMISS_H + EMISS_B))
fprintf('---- Busser %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*nansum(EMISS_B),char(comps(com)),100*nansum(EMISS_B)/nansum(EMISS_L + EMISS_H + EMISS_B))
......
......@@ -28,7 +28,7 @@ function TMout = Emissions_Factor_Mix_in_biofuels(TFout)
% 09.03.2018 -Henrik Grythe
% Kjeller NILU
%--------------------------------------------------------------------------
global Tyear debug_mode text_div exchfile input
global Tyear debug_mode tfold input
fprintf('\t---------------------------------------------------------------\n')
fprintf('\tin Emissions_Factor_Mix_in_biofuels *\n')
fprintf('\t---------------------------------------------------------------\n')
......@@ -136,5 +136,7 @@ fprintf('\tAdjusted Gas by -%4.1f%% of %4.1f%%\n',100*(1-nanmean(EFnew(Gas))/
fprintf('\t CONTINUING\n-----------------------------\n')
TFout(:,8:end) = array2table(EFs);
TMout = TFout;
save(sprintf('%sEFA_Table_MODEL_CO2_Bio%i.mat',tfold,Tyear),'TFout')
end
......@@ -3,7 +3,9 @@ function NERVE_Emissions_Statistical_Oputput()
comps = [{'N2O'}];
comps = [{'CO2'},{'FC'},{'CH4'},{'N2O'}];
comps = [{'CO2'},{'FC'},{'CH4'}];
comps = [{'CO2'},{'FC'}];
%comps = [{'CO2'},{'FC'}];
%comps = [{'CH4'}];
%x NV(kom,veh) %#
%x TD(kom,veh) %km
%x ORdComp(kom,veh) % frac
......@@ -21,7 +23,6 @@ comps = [{'CO2'},{'FC'}];
%s EF_FROM(kom,veh) % g/km
%s EM_FROM(kom,veh) % g/yr
% Files that must be read once only
% 'Model_Vehicles_Merge_SSB_and_HBEFA_Vehicles.xlsx'
TM = readtable('Input/Model_Vehicles_Merge_SSB_and_HBEFA_Vehicles.xlsx','Sheet','MODEL');
......@@ -31,23 +32,32 @@ HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
for com = 1:length(comps)
% files that must be read per species
R_EF_File = sprintf('Temp/EFA_Table_MODEL_%s.mat',char(comps(com)));
load(R_EF_File,'TFout'); % TFout
fprintf('%s\n',char(comps(com)))
for Tyear = 2009:2019