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
b0ae3e9d
Commit
b0ae3e9d
authored
Nov 13, 2020
by
Henrik Grythe
Browse files
Syncronising functions
parent
58e4d225
Changes
8
Hide whitespace changes
Inline
Side-by-side
Emission_Factors_OnRoadAllCond.m
View file @
b0ae3e9d
%--------------------------------------------------------------------------
% 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
Emission_Factors_OnRoadAllCond
()
global
tfold
Tyear
SSB_Vehicle_dist
comps
Vehicle_dist
Vehicle_weight
global
debug_mode
ofile
global
debug_mode
ofile
s
use_temporary_files
%--------------------------------------------------------------
% COMBINE Municipal VEHICLE DISTRIBUTION & EMISSION FACTORS
% This is an extremely slow loop
%--------------------------------------------------------------
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'in Emission_Factors_OnRoadAllCond *\n'
)
TM
=
readtable
(
SSB_Vehicle_dist
,
'Sheet'
,
'MODEL'
);
fprintf
(
'---------------------------------------------------------------\n'
)
ofile
=
'OnRoadEF_RoadClasses.xlsx'
;
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
;
VD
=
Vehicle_dist
.
Vdist
;
% Loop all components to be calculated:
for
com
=
1
:
length
(
comps
)
% Load the component file with
fprintf
(
'<--- %s\n'
,
char
(
comps
(
com
)))
TFout
=
readtable
(
'modelHBEFA.xlsx'
,
'Sheet'
,
sprintf
(
'%s_%s_Weight'
,
char
(
comps
(
com
)),
Vehicle_weight
),
'PreserveVariableNames'
,
1
);
TFout
=
readtable
(
'modelHBEFA.xlsx'
,
'Sheet'
,
sprintf
(
'%s_%s_Weight'
,
char
(
comps
(
com
)),
Vehicle_weight
),
'PreserveVariableNames'
,
1
);
osheet
=
sprintf
(
'%s_%i'
,
char
(
comps
(
com
)),
Tyear
);
for
i
=
1
:
height
(
TM
)
idef
(
i
)
=
find
(
ismember
(
TFout
.
Properties
.
VariableNames
,
TM
.
Name
(
i
)));
...
...
@@ -32,8 +52,8 @@ for com = 1:length(comps)
sum
(
VD
(
komm
,
HeavyVehiclesIdx
)),
...
sum
(
VD
(
komm
,
BusesVehiclesIdx
)))
else
fprintf
(
'Komm:%04i;'
,
Vehicle_dist
.
D1_KommNr
(
komm
))
if
rem
(
komm
,
15
)
==
0
;
fprintf
(
'
\n'
);
end
%
fprintf('Komm:%04i;',Vehicle_dist.D1_KommNr(komm))
if
rem
(
komm
,
15
)
==
0
;
fprintf
(
'
@%i/%i \n'
,
komm
,
length
(
Vehicle_dist
.
D1_KommNr
)
);
end
end
if
abs
(
sum
(
VD
(
komm
,:))
-
3
)
>
1e-5
...
...
@@ -63,8 +83,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
% 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
;
...
...
@@ -117,7 +137,9 @@ for com = 1:length(comps)
end
ofile
=
'OnRoadEF_RoadClasses.xlsx'
;
writetable
(
Trout
,
ofile
,
'Sheet'
,
sprintf
(
'%s_%i'
,
char
(
comps
(
com
)),
Tyear
))
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
)))
end
...
...
Emission_Factors_Road_DrivingDistance_IN_Municipalities.m
View file @
b0ae3e9d
...
...
@@ -4,7 +4,6 @@ global RLinks tfold Tyear Vehicle_dist debug_mode SSB_Vehicle_dist ofiles
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
;
...
...
@@ -150,10 +149,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
))
DrivingDistances_per_RoadType
=
Tout
;
save
(
ofiles
.
MatlabOutput
,
'DrivingDistances_per_RoadType'
,
'-append'
)
...
...
Emissions_Calculations_SSB.m
View file @
b0ae3e9d
...
...
@@ -82,6 +82,11 @@ DEC = extractfield(RLinks,'SLOPE'); % Verticality of Roa
ENV
=
extractfield
(
RLinks
,
'URBAN'
);
% Urbanity of Road (URB/RUR)
RU
=
extractfield
(
RLinks
,
'RUSH_DELAY'
);
% Calculated Properties
LW
=
1e-6
*
sum
(
L
.*
LEN
)
*
dayInYear
;
HW
=
1e-6
*
sum
(
H
.*
LEN
)
*
dayInYear
;
BW
=
1e-6
*
sum
(
B
.*
LEN
)
*
dayInYear
;
% Classification of rush hour traffic. 0-4 (4 is congested)
ru
=
zeros
(
size
(
RU
));
ru
(
RU
<=
0.1
)
=
1
;
...
...
@@ -138,7 +143,6 @@ for com = 1:length(comps)
EMISS_H
(
r
)
=
sum
(
Hmy
(
idx
)
.*
table2array
(
TEF
(
idx
,
Hef
))
'
);
EMISS_B
(
r
)
=
sum
(
Bmy
(
idx
)
.*
table2array
(
TEF
(
idx
,
Bef
))
'
);
% 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
));
...
...
@@ -157,25 +161,23 @@ for com = 1:length(comps)
RLinks
=
table2struct
(
TLinks
);
% Print some statistical output
fprintf
(
'\n---- NORGE --- \n'
)
fprintf
(
'\n---- NORGE ---
%i
\n'
,
Tyear
)
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
)))
LW
=
1e-6
*
sum
(
L
.*
LEN
)
*
dayInYear
;
HW
=
1e-6
*
sum
(
H
.*
LEN
)
*
dayInYear
;
BW
=
1e-6
*
sum
(
B
.*
LEN
)
*
dayInYear
;
LTD
=
1e-6
*
sum
(
sum
(
Vehicle_dist
.
modelTD
(:,
LightVehiclesIdx
)));
HTD
=
1e-6
*
sum
(
sum
(
Vehicle_dist
.
modelTD
(:,
HeavyVehiclesIdx
)));
BTD
=
1e-6
*
sum
(
sum
(
Vehicle_dist
.
modelTD
(:,
BusesVehiclesIdx
)));
fprintf
(
' Light Traffic L=%7.1f (1 000 000) Km TDL=%7.1f (%5.1f%%) \n'
,
LW
,
LTD
,
100
*
LW
/
LTD
)
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
)
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
(
' Light Traffic L=%7.1f (1 000 000) Km TDL=%7.1f (%5.1f%%) \n'
,
LW
,
LTD
,
100
*
LW
/
LTD
)
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
)
fprintf
(
'--- %s --->\n'
,
char
(
comps
(
com
)))
end
...
...
PreProcess_Roads_Input_Traffic.m
View file @
b0ae3e9d
...
...
@@ -141,4 +141,5 @@ CLinks = Roads_Clean_Annual(CLinks);
if
use_temporary_files
Save_shape
(
CLinks
,
tfiles
.
RL
)
end
fprintf
(
'\n\n\n\n ROADS PROCESSED \n\n\n\n\n\n'
)
end
PreProcess_Vehicle_Distribution.m
View file @
b0ae3e9d
...
...
@@ -17,9 +17,11 @@ function [Vehicle_dist] = PreProcess_Vehicle_Distribution()
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
global
Vehicle_source
global
Vehicle_source
ofiles
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'in PreProcess_Vehicle_Distribution\n'
)
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'\t in PreProcess_Vehicle_Distribution\n'
)
Vehicle_dist
=
[];
if
ismember
(
Vehicle_source
,{
'SSB'
})
...
...
Roads_Find_StartMuncipalityFraction.m
View file @
b0ae3e9d
...
...
@@ -13,7 +13,7 @@
% You should have received a copy of the GNU General Public License
% along with NERVE. If not, see <https://www.gnu.org/licenses/>.
%--------------------------------------------------------------------------
function
wRLinks
=
Roads_Find_StartMuncipalityFraction
(
RLinks
)
function
Sn
=
Roads_Find_StartMuncipalityFraction
(
RLinks
)
global
Komm_shape
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'in Roads_Find_StartMuncipalityFraction *\n'
)
...
...
@@ -79,7 +79,7 @@ KeepT.IDO(:) = 1;
t_T
.
IDO
(:)
=
Fraction
;
Tble
=
[
KeepT
;
t_T
];
Tble
=
sortrows
(
Tble
,{
'KOMMS'
});
wRLinks
=
table2struct
(
Tble
);
Sn
=
table2struct
(
Tble
);
end
% startkommune = extractfield(RLinks,'KOMMS');
...
...
Roads_Scale_Traffic_to_Year.m
View file @
b0ae3e9d
...
...
@@ -27,10 +27,6 @@ global Listfields
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'in Scale_Road_Traffic_Year *\n'
)
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'To scale Light Traffic from %i to %i \n'
,
Ryear
,
Tyear
)
% Read the Light csv scaling file into table
...
...
Vehicle_Distribution_per_Municipality_SSB.m
View file @
b0ae3e9d
...
...
@@ -16,8 +16,9 @@
function
[
Vehicle_dist
]
=
Vehicle_Distribution_per_Municipality_SSB
()
% Module for processing SSB DD.
global
Tyear
SSB_Vehicle_dist
fprintf
(
'---------------------------------------------------------------\n'
)
fprintf
(
'in Vehicle_Distribution_per_Municipality_SSB *\n'
)
fprintf
(
'---------------------------------------------------------------\n'
)
% OPT TODO: ADD a test to check for data from municipality and year
...
...
@@ -89,6 +90,7 @@ for i=1:size(TrafficIN)
end
Vehicle_dist
.
Vdist
=
modelVdistIN
;
Vehicle_dist
.
VdistFROM
=
modelTDfrac
;
Vehicle_dist
.
modelNV
=
modelNV
;
Vehicle_dist
.
modelTD
=
modelTD
;
Vehicle_dist
.
D1_KommNr
=
SSBkomm
;
...
...
@@ -97,8 +99,6 @@ Vehicle_dist.D2_VehicleNum = T.ModelNumber;
Vehicle_dist
.
TrafficIN
=
TrafficIN
;
Vehicle_dist
.
TrafficFROM
=
TrafficFROM
;
Vehicle_dist
.
D12_Traffic
=
EXkmneNr
;
%--------------------------------------------------------------------------
% Statistical output.
Vehicle_Distribution_Statistical_output
(
Vehicle_data
,
T
)
...
...
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