Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EmissionModels
NERVE
Commits
cd53ea8e
Commit
cd53ea8e
authored
Nov 12, 2020
by
Henrik Grythe
Browse files
Cleaning commensed
parent
825dfbcd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Emission_Factor_Model_group_HBEFA.m
View file @
cd53ea8e
...
...
@@ -175,9 +175,23 @@ for com =1:length(comps)
end
save
(
oEFfile
,
'TFout'
,
'roads'
);
switch
char
(
comps
(
com
))
case
'CO2'
MunicpalHBEFA_RoadsEF_
=
TFout
;
save
(
ofiles
.
MatlabOutput
,
'MunicpalHBEFA_RoadsEF_'
,
'roads'
,
'-append'
);
case
'FC'
case
'NOx'
case
'CO2'
case
'CO2'
case
'CO2'
end
writetable
(
TFout
,
'modelHBEFA.xlsx'
,
'Sheet'
,
sprintf
(
'%s_%s_Weight'
,
char
(
comps
(
com
)),
Vehicle_weight
)
)
fprintf
(
'Saved a temp-file for Emission Factors Model:\n%s\n'
,
oEFfile
)
end
% OLD METHOD
...
...
Emission_Factors_OnRoadAllCond.m
View file @
cd53ea8e
function
Emission_Factors_OnRoadAllCond
()
global
tfold
Tyear
SSB_Vehicle_dist
comps
Vehicle_dist
Vehicle_weight
global
debug_mode
global
debug_mode
ofile
%--------------------------------------------------------------
% COMBINE Municipal VEHICLE DISTRIBUTION & EMISSION FACTORS
%--------------------------------------------------------------
...
...
@@ -72,7 +72,7 @@ for com = 1:length(comps)
ofile
=
'OnRoadEF_RoadClasses.xlsx'
;
OnRoadEF_RoadClasses
=
Trout
;
save
(
'OnRoadEF_RoadClasses.mat'
,
'OnRoadEF_RoadClasses'
)
save
(
ofile
.
MatlabOutput
,
'OnRoadEF_RoadClasses'
,
'-append'
)
writetable
(
Trout
,
ofile
,
'Sheet'
,
sprintf
(
'%s_%i'
,
char
(
comps
(
com
)),
Tyear
))
fprintf
(
'%s--- >\n'
,
char
(
comps
(
com
)))
end
...
...
Emission_Factors_Road_DrivingDistance_IN_Municipalities.m
View file @
cd53ea8e
function
Emission_Factors_Road_DrivingDistance_IN_Municipalities
()
global
RLinks
tfold
Tyear
Vehicle_dist
debug_mode
SSB_Vehicle_dist
global
RLinks
tfold
Tyear
Vehicle_dist
debug_mode
SSB_Vehicle_dist
ofiles
TM
=
readtable
(
SSB_Vehicle_dist
,
'Sheet'
,
'MODEL'
);
...
...
@@ -135,11 +135,6 @@ for komm = 1:length(uKomm)
Tout
.
Properties
.
VariableNames
(
find
(
ismember
(
Tout
.
Properties
.
VariableNames
,
'Buses_DD'
)))
=
{
sprintf
(
'DD_Buses_%04i'
,
Vehicle_dist
.
D1_KommNr
(
komm
))};
end
save
(
sprintf
(
'Municipal_DrivingDistances_per_RoadType_%i.mat'
,
Tyear
),
'Tout'
)
writetable
(
Tout
,
'Municipal_DrivingDistances_per_RoadType.xlsx'
,
'Sheet'
,
sprintf
(
'DD_%i'
,
Tyear
))
fprintf
(
'\n---- NORGE --- \n'
)
L
=
extractfield
(
RLinks
,
sprintf
(
'L_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
H
=
extractfield
(
RLinks
,
sprintf
(
'H_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
...
...
@@ -156,6 +151,13 @@ 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
))
DrivingDistances_per_RoadType
=
Tout
;
save
(
ofiles
.
MatlabOutput
,
'DrivingDistances_per_RoadType'
,
'-append'
)
end
%
...
...
Emissions_Calculations_SSB.m
View file @
cd53ea8e
...
...
@@ -20,12 +20,10 @@ function [Sn] = Emissions_Calculations_SSB()
% Kjeller NILU
%--------------------------------------------------------------------------
global
tfold
Tyear
SSB_Vehicle_dist
comps
RLinks
Vehicle_dist
Vehicle_weight
global
debug_mode
global
debug_mode
ofiles
%--------------------------------------------------------------
% ROAD LINK Calculations
% ROAD LINK
EMISSIONS
Calculations
%--------------------------------------------------------------
% extract fields needed for calculations
fprintf
(
'\nExtracts necessary fields \n'
)
...
...
@@ -33,7 +31,7 @@ fprintf('Traffic and Vehicle Year: %i \n',Tyear)
fprintf
(
'RoadLinks : %i \n'
,
size
(
RLinks
,
1
))
file
=
sprintf
(
'%s%s'
,
tfold
,
'roads'
);
fprintf
(
'Warning,using roads file not produced by NERVE model\n%s\n'
,
file
)
fprintf
(
'
###
Warning,
using roads file not produced by NERVE model\n%s\n'
,
file
)
load
(
file
)
TM
=
readtable
(
SSB_Vehicle_dist
,
'Sheet'
,
'MODEL'
);
...
...
@@ -43,14 +41,11 @@ HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
dayInYear
=
round
(
datenum
([
Tyear
+
1
,
1
,
1
,
12
0
0
])
-
datenum
([
Tyear
,
1
,
1
,
12
,
0
,
0
]));
fprintf
(
'Found %i days in year: %i\n'
,
dayInYear
,
Tyear
)
% Make a cleaned version for writing to file
% Tout = struct2table(RLinks);
% roads
KommunerS
=
extractfield
(
RLinks
,
'KOMMS'
);
KommunerE
=
extractfield
(
RLinks
,
'KOMME'
);
uKomm
=
unique
(
KommunerS
);
uKomm
=
unique
(
KommunerS
);
% Congestion weights. Traffic part delayed (TPD)
% Combine the different congestion levels by volume to determine the
...
...
@@ -75,16 +70,16 @@ TPD =[1.0, 0.0, 0.0, 0.0, 0.0;...
0.6
,
0.2
,
0.2
,
0.0
,
0.0
;
...
0.5
,
0.2
,
0.15
,
0.15
,
0.0
];
% EXTRACT
L
=
extractfield
(
RLinks
,
sprintf
(
'L_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
H
=
extractfield
(
RLinks
,
sprintf
(
'H_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
B
=
extractfield
(
RLinks
,
sprintf
(
'B_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
LEN
=
extractfield
(
RLinks
,
'DISTANCE'
);
% Length of Road (in kilometres)
HBEFA
=
extractfield
(
RLinks
,
'HBEFA_EQIV'
);
% Type of Road (Access->MW)
SPD
=
extractfield
(
RLinks
,
'SPEED'
);
% Speed on Road (km hr-1)
DEC
=
extractfield
(
RLinks
,
'SLOPE'
);
% Verticality of Road (%)
ENV
=
extractfield
(
RLinks
,
'URBAN'
);
% Urbanity of Road (URB/RUR)
LEN
=
extractfield
(
RLinks
,
'DISTANCE'
);
% Length of Road (in kilometres)
RU
=
extractfield
(
RLinks
,
'RUSH_DELAY'
);
% Classification of rush hour traffic. 0-4 (4 is congested)
...
...
@@ -144,12 +139,11 @@ for com = 1:length(comps)
EMISS_B
(
r
)
=
sum
(
Bmy
(
idx
)
.*
table2array
(
TEF
(
idx
,
Bef
))
'
);
% Calculate roadLink Emission Factor:
% Calculate roadLink Emission Factor:
(Not used as of now)
Link_Light_emission_factor
(
r
)
=
EMISS_L
(
r
)/
sum
(
Lmy
(
idx
));
Link_Heavy_emission_factor
(
r
)
=
EMISS_H
(
r
)/
sum
(
Hmy
(
idx
));
Link_Buses_emission_factor
(
r
)
=
EMISS_B
(
r
)/
sum
(
Bmy
(
idx
));
Link_emission_factor
(
r
)
=
(
EMISS_L
(
r
)
+
EMISS_H
(
r
)
+
EMISS_B
(
r
))/(
sum
(
Lmy
(
idx
))
+
sum
(
Hmy
(
idx
))
+
sum
(
Bmy
(
idx
)));
if
rem
(
r
,
10000
)
==
0
;
fprintf
(
'Roads Calculated %i/%i\n L:%f\n H:%f\n B:%f\nEF: %f\n'
,
r
,
length
(
RLinks
),
sum
(
EMISS_L
)
*
1e-9
,
sum
(
EMISS_H
)
*
1e-9
,
sum
(
EMISS_B
)
*
1e-9
,
Link_emission_factor
(
r
));
end
end
TLinks
=
struct2table
(
RLinks
);
...
...
@@ -160,19 +154,15 @@ for com = 1:length(comps)
TLinks
.
Properties
.
VariableNames
(
find
(
ismember
(
TLinks
.
Properties
.
VariableNames
,
'LetEM'
)))
=
{
sprintf
(
'EM_Light_%s'
,
char
(
comps
(
com
)))};
TLinks
.
Properties
.
VariableNames
(
find
(
ismember
(
TLinks
.
Properties
.
VariableNames
,
'HeaEM'
)))
=
{
sprintf
(
'EM_Heavy_%s'
,
char
(
comps
(
com
)))};
TLinks
.
Properties
.
VariableNames
(
find
(
ismember
(
TLinks
.
Properties
.
VariableNames
,
'BusEM'
)))
=
{
sprintf
(
'EM_Buses_%s'
,
char
(
comps
(
com
)))};
RLinks
=
table2struct
(
TLinks
);
% Print some statistical output
fprintf
(
'\n---- NORGE --- \n'
)
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
))
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
))
fprintf
(
'---- Totalt %11.1f (1000)Ton %s \n\n'
,
1e-9
*
nansum
(
EMISS_B
+
EMISS_H
+
EMISS_L
),
char
(
comps
(
com
)))
L
=
extractfield
(
RLinks
,
sprintf
(
'L_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
H
=
extractfield
(
RLinks
,
sprintf
(
'H_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
B
=
extractfield
(
RLinks
,
sprintf
(
'B_ADT%04i'
,
Tyear
));
% Traffic Volume (# day-1)
LEN
=
extractfield
(
RLinks
,
'DISTANCE'
);
LW
=
1e-6
*
sum
(
L
.*
LEN
)
*
dayInYear
;
HW
=
1e-6
*
sum
(
H
.*
LEN
)
*
dayInYear
;
BW
=
1e-6
*
sum
(
B
.*
LEN
)
*
dayInYear
;
...
...
@@ -186,7 +176,11 @@ for com = 1:length(comps)
fprintf
(
' Light Traffic L=%7.1f g/Km\n'
,
1e-6
*
sum
(
EMISS_L
)/
LW
)
fprintf
(
' Heavy Traffic H=%7.1f g/Km\n'
,
1e-6
*
sum
(
EMISS_H
)/
HW
)
fprintf
(
' Buses Traffic B=%7.1f g/Km\n'
,
1e-6
*
sum
(
EMISS_B
)/
BW
)
fprintf
(
'--- %s --->\n'
,
char
(
comps
(
com
)))
fprintf
(
'--- %s --->\n'
,
char
(
comps
(
com
)))
end
save
(
ofiles
.
MatlabOutput
,
'RLinks'
,
'-append'
)
Sn
=
RLinks
;
end
PreProcess_Emission_Factors_HBEFA.m
View file @
cd53ea8e
%--------------------------------------------------------------------------
% This file is part of NERVE
%
%
% NERVE is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation version 3.
%
%
% NERVE is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
%
% You should have received a copy of the GNU General Public License
% along with NERVE. If not, see <https://www.gnu.org/licenses/>.
%--------------------------------------------------------------------------
function
PreProcess_Emission_Factors_HBEFA
()
%--------------------------------------------------------------------------
global
use_temporary_files
do_preProcessing_HBEFA
comps
tfold
% 22.10.2020 -Henrik Grythe
% Kjeller NILU
%--------------------------------------------------------------------------
if
use_temporary_files
&&
~
do_preProcessing_HBEFA
try
for
com
=
1
:
length
(
comps
)
ifile
=
sprintf
(
'%sEFA_Table_MODEL_%s.mat'
,
tfold
,
char
(
comps
(
com
)));
if
~
exist
(
ifile
,
'file'
)
error
(
sprintf
(
'### file not found\n%s\n will make new'
,
ifile
))
end
end
fprintf
(
'Temporary files found\n CONTINUE\n'
)
return
catch
end
end
Emission_Factor_Process_HBEFA_Matrix_Raw
()
Emission_Factor_Model_group_HBEFA
()
end
Set_Temporary_and_Output_FileNames.m
View file @
cd53ea8e
function [tfiles ofiles] = Set_Temporary_and_Output_FileNames()
global Tyear ofold tfold traffile
function
[
input
,
tfiles
,
ofiles
]
=
Set_Temporary_and_Output_FileNames
()
global
do_preProcessing_HBEFA
debug_mode
use_temporary_files
ofiles
tfiles
global
Vehicle_source
remove_NoTrafficRoads
Vehicle_weight
% folders
global
ifold
tfold
ofold
HBEFA_path
HBEFA_roads
Kartverket
% files
global
traffile
tettfile
Komm_shape
Light_traff_years
Heavy_traff_years
global
Buses_traff_years
HBEFA_vehicles
SSB_vehicle
tfiles
traff_exchange
global
traff_exchange_sh
SSB_Vehicle_dist
% variables
global
Ryear
Tyear
Myear
comps
Vehicle_dist
RLinks
input
.
Tyear
=
Tyear
;
input
.
Myear
=
Myear
;
input
.
Components
=
comps
;
input
.
options
.
do_preProcessing_HBEFA
=
do_preProcessing_HBEFA
;
input
.
options
.
debug_mode
=
debug_mode
;
input
.
options
.
use_temporary_files
=
use_temporary_files
;
input
.
options
.
Vehicle_source
=
Vehicle_source
;
input
.
options
.
remove_NoTrafficRoads
=
remove_NoTrafficRoads
;
input
.
options
.
Vehicle_weight
=
Vehicle_weight
;
input
.
ifold
=
ifold
;
input
.
tfold
=
tfold
;
input
.
tfolde
=
tfold
;
input
.
HBEFA_path
=
HBEFA_path
;
input
.
files
.
HBEFA_roads
=
HBEFA_roads
;
input
.
files
.
Kartverket
=
Kartverket
;
input
.
files
.
Trafficfile
=
traffile
;
input
.
files
.
Tettstedfile
=
tettfile
;
input
.
files
.
Kommune_shape
=
Komm_shape
;
input
.
files
.
Light_traff_scale
=
Light_traff_years
;
input
.
files
.
Heavy_traff_scale
=
Heavy_traff_years
;
input
.
files
.
Buses_traff_scale
=
Buses_traff_years
;
input
.
files
.
HBEFA_vehicles
=
HBEFA_vehicles
;
input
.
files
.
SSB_vehicle
=
SSB_vehicle
;
input
.
files
.
traff_exchange
=
traff_exchange
;
input
.
files
.
traff_exchange_sh
=
traff_exchange_sh
;
input
.
files
.
SSB_Vehicle_dist
=
SSB_Vehicle_dist
;
tfiles
.
EF
=
sprintf
(
'%sHEDGE_EF_%4i'
,
tfold
,
Tyear
);
tfiles
.
CarPark
=
sprintf
(
'%sSSB_CarPark_%4i'
,
ofold
,
Tyear
);
a
=
strfind
(
traffile
,
'/'
);
if
~
isempty
(
a
)
tfiles
.
RL
=
sprintf
(
'%sHEDGE_RL_%4i_%s_temp'
,
tfold
,
Tyear
,
traffile
(
a
(
end
)
+
1
:
end
));
...
...
@@ -17,7 +53,11 @@ end
ofiles
.
RLShape
=
sprintf
(
'%sTraffic_Emissions_%4i'
,
ofold
,
Tyear
);
ofiles
.
SSB_Stat
=
sprintf
(
'%sNational_SSB_Vehicle_Number_Distribution.xlsx'
,
ofold
);
ofiles
.
MatlabOutput
=
sprintf
(
'%sOutput_%4i_Simulation_%s.mat'
,
ofold
,
Tyear
,
datestr
(
now
,
'yyyymmmdd_HH'
));
fprintf
(
'initiated new output file: \n %s\n'
,
ofiles
.
MatlabOutput
)
save
(
ofiles
.
MatlabOutput
,
'input'
,
'tfiles'
,
'ofiles'
)
ofiles.MatlabOutput = sprintf('%sOutput.mat',ofold);
end
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment