Commit 96e79357 authored by Henrik Grythe's avatar Henrik Grythe
Browse files

cleaning

parent b0ae3e9d
......@@ -19,24 +19,21 @@ function Emission_Factor_Model_group_HBEFA()
% 22.10.2020 -Henrik Grythe
% Kjeller NILU
%--------------------------------------------------------------------------
global tfold comps SSB_Vehicle_dist Vehicle_source debug_mode
global EFA EF_AVG roads Vehicle_weight
% global rfid
% global exchfile debug_mode SSB_sheet_col HBEFA_temp_Matfile
% global NERVE_EF_file text_div
global tfold comps Vehicle_source debug_mode
global EFA EF_AVG roads Vehicle_weight ofiles input
if ~ismember(Vehicle_source,{'SSB'})
return
end
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factor_Model_group_HBEFA *\n')
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factor_Model_group_HBEFA *\n')
fprintf('--- Grouping Vehicles according to ---\n--- Model SSB HBEFA merger specifications ---\n%s \n',SSB_Vehicle_dist)
fprintf('--- Grouping Vehicles according to ---\n--- Model SSB HBEFA merger specifications ---\n%s \n',input.files.SSB_Vehicle_dist)
T = readtable(SSB_Vehicle_dist,'Sheet','HBEFA778toMODEL');
Tm = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
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')
% ModelNumber HBEFA_Weight Uniform_Weight
......@@ -179,7 +176,7 @@ for com =1:length(comps)
switch char(comps(com))
case 'CO2'
fprintf('### ADD CALL TO: Emission_Factor_mix_in_biofuels()\n')
TFout = Emissions_Factor_Mix_in_biofuels(TFout)
TFout = Emissions_Factor_Mix_in_biofuels(TFout);
end
end
%__________________________________________________________________________
......@@ -235,100 +232,10 @@ for com =1:length(comps)
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NH3','roads','-append');
end
writetable(TFout,'modelHBEFA.xlsx','Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight) )
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
% for com =1:length(comps)
% fprintf('<--- \nSpec| %s\n',char(comps(com)))
% iEFfile = sprintf('%s/EFA_matrix41_RAW_%s',tfold,char(comps(com)));
% oEFfile = sprintf('%s/EFA_matrix41_MODEL_%s',tfold,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));
% end
%
% Defines the EFA
% EFA = nan(length(modelN),size(EF_AVG,2),size(EF_AVG,3),size(EF_AVG,4),size(EF_AVG,5),size(EF_AVG,6));
% for mod = 1:length(modelN)
% Tsub = T(T.ModelNumber==modelN(mod),:);
%
% Make vehicles with HBEFA weight
% EFsub = EF_AVG(Tsub.HBEFA_Num,:,:,:,:,:);
%
% switch Vehicle_weight
%
% case 'Uniform'
% Make vehicles with Uniform weight
% Wu = sum(Tsub.Uniform_Weight);
% if abs(Wu-1)>1e-5
% fprintf('### error Model Vehicle Weight does not add to 1 but %d!\n',Wu)
% Tsub
% end
% for roa = 1:size(EFA,2)
% for spd = 1:size(EFA,3)
% for dec = 1:size(EFA,4)
% for cog = 1:size(EFA,5)
% for urb = 1:size(EFA,6)
% TW = 0;
% has_EF = 0;
% for i =1:size(EFsub,1)
% if ~isnan(EFsub(i,roa,spd,dec,cog,urb))
% EFA(modelN(mod),roa,spd,dec,cog,urb)= EFA(modelN(mod),roa,spd,dec,cog,urb) + ...
% EFsub(i,roa,spd,dec,cog,urb)*Tsub.Uniform_Weight(i);
% TW = TW + Tsub.Uniform_Weight(i);
% has_EF = 1;
% end
%
% end
% if has_EF>0;
% fprintf('i=%i;modelN(mod)=%i;roa=%i;spd=%i;dec=%i;cog=%i;urb=%i; TW = %f\n',i,modelN(mod),roa,spd,dec,cog,urb,TW)
% pause;
% end
% if abs(TW-1)> 1e-3 && has_EF && ~isnan(EFA(modelN(mod),roa,spd,dec,cog,urb))
% fprintf('modelN(mod)=%i;roa=%i;spd=%i;dec=%i;cog=%i;urb=%i; TW = %f\n',modelN(mod),roa,spd,dec,cog,urb,TW)
% EFA(modelN(mod),roa,spd,dec,cog,urb) = EFA(modelN(mod),roa,spd,dec,cog,urb)/TW;
% end
% end
% end
% end
% end
% end
%
% case 'HBEFA'
% Wh = sum(Tsub.HBEFA_Weight);
% if abs(Wh-1)>1e-5
% fprintf('### error Model Vehicle Weight does not add to 1 but %d\n',Wh)
% Tsub
% end
% case 'NERVE'
% Wn = sum(Tsub.NERVE_Weight);
% if abs(Wn-1)>1e-5
% fprintf('### error Model Vehicle Weight does not add to 1!\n')
% Tsub
% end
%
% end % switch
%
%
% fprintf('#%i EF No NAN EFs found: %i\n',modelN(mod),length(find(~isnan(EFA(modelN(mod),:,:,:,:,:,:)))))
%
%
%
% end % for mod
%
% Emission_Factor_Test_HBEFA_to_MODEL_conversion(com,ConVfile)
%
%
% save(oEFfile,'EFA','T','roads');
% fprintf('Saved a temp-file for Emission Factors Model:\n%s\n',oEFfile)
%
% end % comps
end
......@@ -53,7 +53,7 @@ for com = 1:length(comps)
sum(VD(komm,BusesVehiclesIdx)))
else
% fprintf('Komm:%04i;',Vehicle_dist.D1_KommNr(komm))
if rem(komm,15)==0;fprintf('@%i/%i \n',komm,length(Vehicle_dist.D1_KommNr)); end
if rem(komm,15)==0;fprintf('@%03i/%3i \n',komm,length(Vehicle_dist.D1_KommNr)); end
end
if abs(sum(VD(komm,:))-3)>1e-5
......
%--------------------------------------------------------------------------
% 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_Road_DrivingDistance_IN_Municipalities()
global RLinks tfold Tyear Vehicle_dist debug_mode SSB_Vehicle_dist ofiles
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');
file = sprintf('%s%s',tfold,'roads');
fprintf('### Warning,using roads file not produced by NERVE model\n%s\n',file)
......@@ -68,9 +84,10 @@ for komm = 1:length(uKomm)
f3 = find(Kommuner == uKomm(komm));
f = unique([f1,f2,f3]);
MRLinks = RLinks(f);
if debug_mode
fprintf('\n-%3i Kommune_%04i --- \n',komm,Vehicle_dist.D1_KommNr(komm))
fprintf(' Has %i (%i) Roads \n',length(f1),length(f))
end
L = extractfield(MRLinks,sprintf('L_ADT%04i',Tyear)); % Traffic Volume (# day-1)
H = extractfield(MRLinks,sprintf('H_ADT%04i',Tyear)); % Traffic Volume (# day-1)
B = extractfield(MRLinks,sprintf('B_ADT%04i',Tyear)); % Traffic Volume (# day-1)
......@@ -133,7 +150,7 @@ 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
fprintf('\n---- NORGE --- \n')
fprintf('\n---- NORGE --- %i\n',Tyear)
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)
......@@ -153,135 +170,4 @@ writetable(Tout,'Municipal_DrivingDistances_per_RoadType.xlsx','Sheet',sprintf('
DrivingDistances_per_RoadType = Tout;
save(ofiles.MatlabOutput,'DrivingDistances_per_RoadType','-append')
end
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% % EMISS_* are the road link emissions for each link in the
% % municipality
% EMISS_L = zeros(size(MRLinks));
% EMISS_H = zeros(size(MRLinks));
% EMISS_B = zeros(size(MRLinks));
%
% for r =1:length(L)
% dec = find(roads.RoadGradient == DEC(r));
% env = find(roads.RoadEnvID == ENV(r)+1);
% SPD(r) = round(SPD(r)/10)*10;
% if SPD(r) < 30; SPD(r)=30; end
% if SPD(r) > 110; SPD(r)=110; end
% spd = find(roads.RoadSpeeds == SPD(r));
% name = {sprintf('%s/%s-%i/%i%%/%s',char(roads.RoadEnv(env)),char(roads.RoadType(HBEFA(r))),roads.RoadSpeeds(spd),roads.RoadGradient(dec))};
%
% idx = find(contains(Tef.Name,name));
% if KOMS(r) == uKomm(komm)
% Lmy(idx) = Lmy(idx) + dayInYear *IDO(r)* L(r) *LEN(r)*TPD_L(ru(r),:)';
% Hmy(idx) = Hmy(idx) + dayInYear *IDO(r)* H(r) *LEN(r)*TPD_H(ru(r),:)';
% Bmy(idx) = Bmy(idx) + dayInYear *IDO(r)* B(r) *LEN(r)*TPD_B(ru(r),:)';
% else
% Lmy(idx) = Lmy(idx) + dayInYear *IDO(r)* L(r) *LEN(r)*TPD_L(ru(r),:)';
% Hmy(idx) = Hmy(idx) + dayInYear *IDO(r)* H(r) *LEN(r)*TPD_H(ru(r),:)';
% Bmy(idx) = Bmy(idx) + dayInYear *IDO(r)* B(r) *LEN(r)*TPD_B(ru(r),:)';
% end
% % EMISS_L(r) = sum(Lmy(idx).*table2array(Tef(idx,Lef)))/sum(Lmy(idx));
% % EMISS_H(r) = sum(Hmy(idx).*table2array(Tef(idx,Hef)))/sum(Lmy(idx));
% % EMISS_B(r) = sum(Bmy(idx).*table2array(Tef(idx,Bef)))/sum(Lmy(idx));
% EMISS_L(r) = sum(Lmy(idx).*table2array(Tef(idx,Lef)));
% EMISS_H(r) = sum(Hmy(idx).*table2array(Tef(idx,Hef)));
% EMISS_B(r) = sum(Bmy(idx).*table2array(Tef(idx,Bef)));
% end
%
%
% tEML = Lmy.*table2array(Tef(:,Lef));
% tEMH = Hmy.*table2array(Tef(:,Hef));
% tEMB = Bmy.*table2array(Tef(:,Bef));
%
%
% % nDD_L = nDD_L + Lmy
% % nDD_H = nDD_H + Hmy
% % nDD_B = nDD_B + Bmy
%
% nEMISS_L(f) = nEMISS_L(f) + EMISS_L;
% nEMISS_H(f) = nEMISS_H(f) + EMISS_H;
% nEMISS_B(f) = nEMISS_B(f) + EMISS_B;
%
%
% if debug_mode
% fprintf('---- Lette %11.1f Kilometer (%3.0f%%) \n' ,sum(L),100*sum(Lmy)/sum(Lmy+Hmy+Bmy))
% fprintf('---- Tunge %11.1f Kilometer (%3.0f%%) \n' ,sum(H),100*sum(Hmy)/sum(Lmy+Hmy+Bmy))
% fprintf('---- Busser %11.1f Kilometer (%3.0f%%) \n\n',sum(B),100*sum(Bmy)/sum(Lmy+Hmy+Bmy))
%
% fprintf('---- Lette %11.1f Gram %s (%3.0f%%)\n' ,sum(tEML),char(comps(com)),100*sum(tEML)/sum(tEML+tEMH+tEMB))
% fprintf('---- Tunge %11.1f Gram %s (%3.0f%%)\n' ,sum(tEMH),char(comps(com)),100*sum(tEMH)/sum(tEML+tEMH+tEMB))
% fprintf('---- Busser %11.1f Gram %s (%3.0f%%)\n\n',sum(tEMB),char(comps(com)),100*sum(tEMB)/sum(tEML+tEMH+tEMB))
%
% fprintf('---- Lette %11.1f Gram/Kilometer \n' ,sum(tEML)/sum(Lmy))
% fprintf('---- Tunge %11.1f Gram/Kilometer \n' ,sum(tEMH)/sum(Hmy))
% fprintf('---- Busser %11.1f Gram/Kilometer \n\n',sum(tEMB)/sum(Bmy))
% end
%
%
%
% KEF(komm,1) = sum(Tef(:,Lef).*Tef.Light_DD)/sum(Tef.Light_DD)
%
%
% Tef.Properties.VariableNames(find(ismember(Tef.Properties.VariableNames,'Light_DD'))) = {sprintf('DD_Light_%04i',Vehicle_dist.D1_KommNr(komm))};
% Tef.Properties.VariableNames(find(ismember(Tef.Properties.VariableNames,'Heavy_DD'))) = {sprintf('DD_Heavy_%04i',Vehicle_dist.D1_KommNr(komm))};
% Tef.Properties.VariableNames(find(ismember(Tef.Properties.VariableNames,'Buses_DD'))) = {sprintf('DD_Buses_%04i',Vehicle_dist.D1_KommNr(komm))};
%
%
%
% end
%
%
% fprintf('\n---- NORGE --- \n')
% fprintf('---- Lette %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*sum(nEMISS_L),char(comps(com)),100*nansum(nEMISS_L)/nansum(nEMISS_L+nEMISS_H+nEMISS_B))
% fprintf('---- Tunge %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*nansum(nEMISS_H),char(comps(com)),100*nansum(nEMISS_H)/nansum(nEMISS_L+nEMISS_H+nEMISS_B))
% fprintf('---- Busser %11.1f (1000)Ton %s (%3.0f%%)\n' ,1e-9*nansum(nEMISS_B),char(comps(com)),100*nansum(nEMISS_B)/nansum(nEMISS_L+nEMISS_H+nEMISS_B))
% fprintf('---- Totalt %11.1f (1000)Ton %s \n\n',1e-9*nansum(nEMISS_B+nEMISS_H+nEMISS_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;
% 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',sum(nEMISS_L)/LW)
% fprintf(' Heavy Traffic H=%7.1f g/Km\n',sum(nEMISS_H)/HW)
% fprintf(' Buses Traffic B=%7.1f g/Km\n',sum(nEMISS_B)/BW)
%
%
%
%
%
% TLinks = struct2table(RLinks);
% TLinks.LetEM = nEMISS_L;
% TLinks.HeaEM = nEMISS_H;
% TLinks.BusEM = nEMISS_B;
%
% 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);
% end
end
\ No newline at end of file
......@@ -21,6 +21,9 @@ function [Sn] = Emissions_Calculations_SSB()
%--------------------------------------------------------------------------
global tfold Tyear SSB_Vehicle_dist comps RLinks Vehicle_dist Vehicle_weight
global debug_mode ofiles
fprintf('---------------------------------------------------------------\n')
fprintf('in Emissions_Calculations_SSB *\n')
fprintf('---------------------------------------------------------------\n')
%--------------------------------------------------------------
% ROAD LINK EMISSIONS Calculations
......@@ -86,6 +89,9 @@ RU = extractfield(RLinks,'RUSH_DELAY');
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)));
% Classification of rush hour traffic. 0-4 (4 is congested)
ru = zeros(size(RU));
......@@ -97,16 +103,22 @@ ru(RU>15) = 4;
IDO = extractfield(RLinks,'IDO');
KOMS = extractfield(RLinks,'KOMMS');
% All road links emissions Light / Heavy / Bus
EMISS_L = zeros(size(RLinks));
EMISS_H = zeros(size(RLinks));
EMISS_B = zeros(size(RLinks));
Link_emission_factor= zeros(size(RLinks));
for com = 1:length(comps)
% All road links emissions Light / Heavy / Bus
EMISS_L = zeros(size(RLinks));
EMISS_H = zeros(size(RLinks));
EMISS_B = zeros(size(RLinks));
Link_emission_factor= zeros(size(RLinks));
fprintf('<--- %s ---\n',char(comps(com)))
fprintf('Loading large file\n...')
TEF = readtable('OnRoadEF_RoadClasses.xlsx','Sheet',sprintf('%s_%i',char(comps(com)),Tyear),'PreserveVariableNames',1);
%%%%%%%%%%%%%%%%%%%%%%%
% try
% TEF = load(ofiles.MatlabOutput,sprintf('OnRoadEF_RoadClasses_%i',char(coms(com))))
% catch
% fprintf('reading excel file\n')
TEF = readtable('OnRoadEF_RoadClasses.xlsx','Sheet',sprintf('%s_%i',char(comps(com)),Tyear),'PreserveVariableNames',1);
% end
%%%%%%%%%%%%%%%%%%%%%%
fprintf('Loaded.\n')
tef = TEF.Name;
for r =1:length(L)
......@@ -167,9 +179,6 @@ for com = 1:length(comps)
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)))
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 g/Km\n',1e-6*sum(EMISS_L)/LW)
fprintf(' Heavy Traffic H=%7.1f g/Km\n',1e-6*sum(EMISS_H)/HW)
......
%--------------------------------------------------------------------------
% 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 TMout = Emissions_Factor_Mix_in_biofuels(TFout)
%--------------------------------------------------------------------------
% Miljodirektoratet Traffic emission model NERVE:
%
% FUNCTION :: mix_in_biofuels_NERVE ::
%
% Function to adjust emission factor for biofuels. Only applied if comp == CO2.
%
% -INPUT : .xlsx biofules file (biofuelsf) sheet='Biofuels'. Emssion
% factors per municipality (KEF).
% -OUTPUT : KEF adjusted for biofuels.
%
% 09.03.2018 -Henrik Grythe
% Kjeller NILU
%--------------------------------------------------------------------------
global Tyear debug_mode text_div exchfile input
fprintf('---------------------------------------------------------------\n')
fprintf('in Emissions_Mix_in_biofuels *\n')
fprintf('---------------------------------------------------------------\n')
fprintf('---- Subtracting biofuel share from CO2 Emission Factors \n')
sheet = 'Biofuels';
BioInnblanding = readtable(input.files.Bio_mix_file,'Sheet',sheet,'ReadVariableNames',true);
fprintf('Read Biofuels from %s\nSheet ::: %s\n',input.files.Bio_mix_file,sheet)
pos = find(ismember(BioInnblanding.Properties.VariableNames,sprintf('x%i',Tyear)));
Bio = table2array(BioInnblanding(:,pos));
fprintf('-----------\n')
fprintf('BioInnblanding i år %-20i var: \n %5.2f %% Totalt \n% 5.2f %% i Bensin\n %5.2f %% i Diesel\n %5.2f %% i Gass\n',Tyear,Bio*100)
fprintf('-----------\n')
fprintf('Adjusting Emission Factors *\n')
% load exchange file sheet model ID tags SSB_Vehicle_dist
TM = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
fuels = unique(TM.FuelNum);
Vehnames = TFout.Properties.VariableNames;
%__________________________________________________________________________
ZeroE = find(TM.FuelNum == 0 | TM.FuelNum == 10| TM.FuelNum == 4);
for i = 1:length(ZeroE)
idE(i) = find(ismember(Vehnames,TM.Name(ZeroE(i))));
if debug_mode
fprintf('Zero EMission, No BIO : %i %s \n',TM.ModelNumber(ZeroE(i)),char(TM.Name(ZeroE(i))));
end
end
fprintf('Found %i Zero Emission Vehicle Groups\n',length(idE))
%__________________________________________________________________________
Petrol = find(TM.FuelNum == 1 | TM.FuelNum == 6 | TM.FuelNum == 8| TM.FuelNum == 9 |TM.FuelNum == 11 |TM.FuelNum == 13|TM.FuelNum == 12);
for i = 1:length(Petrol)
idP(i) = find(ismember(Vehnames,TM.Name(Petrol(i))));
if isempty(idP)
fprintf('### MODEL NOT FOUND %s\n',char(TM.Name(Petrol(i))))
else
if debug_mode
fprintf('Petrol MODEL : %i %s \n',TM.ModelNumber(Petrol(i)),char(TM.Name(Petrol(i))));
end
TFout(:,idP(i)) = TFout(:,idP(i))*(1-Bio(2));
end
end
fprintf('Found %i Petrol Vehicle Groups\n',length(idP))
%__________________________________________________________________________
Diesel = find(TM.FuelNum == 2 | TM.FuelNum == 7 | TM.FuelNum == 9);
for i = 1:length(Diesel)
idD(i) = find(ismember(Vehnames,TM.Name(Diesel(i))));
if isempty(idD)
fprintf('### MODEL NOT FOUND %s\n',char(TM.Name(Diesel(i))))
else
if debug_mode
fprintf('Diesel MODEL : %i %s \n',TM.ModelNumber(Diesel(i)),char(TM.Name(Diesel(i))));
end
TFout(:,idD(i)) = TFout(:,idD(i))*(1-Bio(3));
end
end
fprintf('Found %i Diesel Vehicle Groups\n',length(idD))
%__________________________________________________________________________
Gas = find(TM.FuelNum ==3);
for i = 1:length(Gas)
idG(i) = find(ismember(Vehnames,TM.Name(Gas(i))));
if isempty(idG)
fprintf('### MODEL NOT FOUND %s\n',char(TM.Name(Gas(i))))
else
if debug_mode
fprintf('Diesel MODEL : %i %s \n',TM.ModelNumber(Gas(i)),char(TM.Name(Gas(i))));
end
TFout(:,idG(i)) = TFout(:,idG(i))*(1-Bio(4));
end
end
fprintf('Found %i Gas Vehicle Groups\n',length(idG))
fprintf('Total %i Vehicle Groups\n',length(idE)+length(idP)+length(idD)+length(idG))
%__________________________________________________________________________
unspecified = find(TM.FuelNum >11);
for i = 1:length(unspecified)
idU(i) = find(ismember(Vehnames,TM.Name(unspecified(i))));
if isempty(idU)
fprintf('### MODEL NOT FOUND %s\n',char(TM.Name(Gas(i))))
else
%if debug_mode
fprintf('unspecified fuel by MODEL : %i %s idU(i)=%i\n',TM.ModelNumber(unspecified(i)),char(TM.Name(unspecified(i))),idU(i));
%end
% TFout(:,idU(i)) = TFout(:,idU(i))*(1-Bio(4));
end
end
fprintf('Found %i unspecified Vehicle Groups\n',length(idU))
% Annet is for now LPG / CNG
TM(Annet,:)
if debug_mode
fprintf('Others added Biofuel to Fuel categories other than Petrol Diesel.\n')
warning('If adding Hybrid, code must change')
end
BF_EF(:,Electric) = KEF(:,Electric);
BF_EF(:,Bensin) = KEF(:,Bensin)*(1-Bio(2));
BF_EF(:,Diesel) = KEF(:,Diesel)*(1-Bio(3));
BF_EF(:,Annet) = KEF(:,Annet) *(1-Bio(4));
TMout = TFout;
end
%--------------------------------------------------------------------------
% 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 [Sn] = Roads_Clean_Annual(RLinks)
global Listfields Tyear
fprintf('---------------------------------------------------------------\n')
fprintf('in Roads_clean_Annual *\n')
fprintf('---------------------------------------------------------------\n')
% Tabelize Roads
Tlink = struct2table(RLinks);
fprintf('--- Structuring Roads --- \n')
ladt = find(ismember(Tlink.Properties.VariableNames,sprintf('L_ADT%i',Tyear)));
hadt = find(ismember(Tlink.Properties.VariableNames,sprintf('H_ADT%i',Tyear)));
badt = find(ismember(Tlink.Properties.VariableNames,sprintf('B_ADT%i',Tyear)));
Outfields = [Listfields, Tlink.Properties.VariableNames(ladt), ...
Tlink.Properties.VariableNames(hadt), Tlink.Properties.VariableNames(badt)];
clear f
for i=1:length(Outfields)
try
f(i) = find(ismember(Tlink.Properties.VariableNames,Outfields(i)));
catch
fprintf('### !! MISSING OUTPUT FIELD !! : %s\n',char(Outfields(i)))
end
end
f = f(find(f));
Sn = table2struct(Tlink(:,f));
fprintf('--->\n')
end
% clear f
% for i=1:length(Listfields)
% f(i) = find(ismember(Tlink.Properties.VariableNames,Listfields(i)));
% end
%
% light_adt = find(ismember(Tlink.Properties.VariableNames,'L_ADT'));
% heavy_adt = find(ismember(Tlink.Properties.VariableNames,'H_ADT'));
% bus_adt = find(ismember(Tlink.Properties.VariableNames,'B_ADT'));
%