Skip to content
Snippets Groups Projects
Commit 6101c5e6 authored by Blanz, Dr. Benjamin's avatar Blanz, Dr. Benjamin
Browse files

scenario processing scripts for U Melbourne

parent 7ec1d8d7
No related branches found
No related tags found
No related merge requests found
File added
This diff is collapsed.
H2,mapping,mappingNACE
afs,trd,I
atp,tsp,H
b_t,b_t,C
bph,crp,C
c_b,c_b,A
chm,crp,C
cmn,cmn,H
cmt,cmt,C
cns,cns,F
coa,min,B
ctl,ctl,A
dwe,svs,L
edu,osg,P
eeq,eqm,C
ele,eqm,C
ely,utl,D
fmp,mmi,C
frs,frs,A
fsh,fsh,A
gas,min,B
gdt,utl,D
gro,gro,A
hht,osg,Q
i_s,mmi,C
ins,fin,K
lea,twl,C
lum,wpp,C
mil,mil,C
mvh,mvo,C
nfm,mmi,C
nmm,nmm,C
oap,oap,A
obs,svs,M
ocr,ocr,A
ofd,ofd,C
ofi,fin,K
oil,min,B
ome,eqm,C
omf,omf,C
omt,omt,C
osd,osd,A
osg,osg,O
otn,mvo,C
otp,tsp,H
oxt,min,B
p_c,p_c,C
pcr,pcr,C
pdr,pdr,A
pfb,pfb,A
ppp,wpp,C
rmk,rmk,A
ros,svs,R
rpp,crp,C
rsa,svs,L
sgr,sgr,C
tex,twl,C
trd,trd,H
v_f,v_f,A
vol,vol,C
wap,twl,C
whs,svs,H
wht,wht,A
wol,wol,A
wtp,tsp,H
wtr,utl,E
H1,mapping
alb,alb
are,mea_h
arg,lam_m
arm,cas
aus,anuz
aut,aut
aze,cas
bel,bel
ben,ssa_l
bfa,ssa_l
bgd,oas_l
bgr,bgr
bhr,mea_h
blr,blr
bol,lam_m
bra,bra
brn,oas_m
bwa,ssa_l
can,can_xna
che,che
chl,lam_m
chn,chn
civ,ssa_l
cmr,ssa_l
col,lam_m
cri,lam_m
cyp,cyp
cze,cze
deu,deu
dnk,dnk
dom,lam_m
ecu,lam_m
egy,naf
esp,esp
est,est
eth,ssa_l
fin,fin
fra,fra
gbr,gbr
geo,cas
gha,ssa_l
gin,ssa_m
grc,grc
gtm,lam_l
hkg,chn
hnd,lam_l
hrv,hrv
hun,hun
idn,idn
ind,ind
irl,irl
irn,mea_m
isr,mea_h
ita,ita
jam,lam_m
jor,mea_m
jpn,jpn
kaz,cas
ken,ssa_l
kgz,cas
khm,oas_cpa
kor,kor
kwt,mea_h
lao,oas_cpa
lka,oas_m
ltu,ltu
lux,lux
lva,lva
mar,naf
mdg,ssa_l
mex,mex
mlt,mlt
mng,oas_cpa
moz,ssa_l
mus,ssa_m
mwi,ssa_l
mys,oas_m
nam,ssa_l
nga,ssa_l
nic,lam_l
nld,nld
nor,nor
npl,oas_l
nzl,anuz
omn,mea_h
pak,pak
pan,lam_m
per,lam_m
phl,oas_l
pol,pol
pri,usa
prt,prt
pry,lam_m
qat,mea_h
rou,rou
rus,rus
rwa,ssa_l
sau,mea_h
sen,ssa_l
sgp,oas_m
slv,lam_m
svk,svk
svn,svn
swe,swe
tgo,ssa_l
tha,oas_m
tjk,cas
tto,lam_m
tun,naf
tur,tur
twn,twn
tza,ssa_l
uga,ssa_l
ukr,ukr
ury,lam_m
usa,usa
ven,lam_m
vnm,oas_cpa
xac,ssa_m
xca,lam_l
xcb,lam_m
xcf,ssa_l
xea,oas_l
xec,ssa_l
xee,xee
xef,xef
xer,xer
xna,can_xna
xnf,naf
xoc,oas_l
xsa,pak
xsc,ssa_l
xse,oas_l
xsm,lam_m
xsu,cas
xtw,oas_l
xwf,ssa_l
xws,mea_m
zaf,zaf
zmb,ssa_l
zwe,ssa_l
# This script takes the relative country level NACE data and fills in the aefall.csv
# file from Matthew Cantele to run the scenarios in the U Melbourne CGE model.
#
# Benjamin Blanz, 2024
# load the mappings and the template for aefall.csv
mapping.sectors <- read.csv("helperData/melbourne/p21b.csv")
mapping.regions <- read.csv("helperData/melbourne/r32.csv")
aefall.base <- read.csv("helperData/melbourne/afeall.csv")
regions <- unique(mapping.regions$mapping)
# aefall.template <- read.csv("helperData/melbourne/afeall.csv")
ENDW_COMMi <- unique(aefall.base$ENDW_COMMi)
# collect the scenario files that are relative impacts at the CNT level
files <- list.files('scenarios',pattern = 'NACE-aggCNT-rel.csv',recursive = T)
cat('copying over mapping files...')
file.copy(c("helperData/melbourne/p21b.csv","helperData/melbourne/r32.csv"),
'scenarios/forMelbourne',overwrite = T)
cat('done\n')
cat('Processing to aefall format...\n')
f.i <- 0
for(file in files){
f.i <- f.i +1
cat(sprintf('%i of %i %s\n',f.i, length(files),file))
data <- read.csv(paste0('scenarios/',file))
rownames(data) <- data$CNTR_CODE
outputFilename <- gsub('NACE','aefall',basename(file))
aefall.scenario <- aefall.base
for(r.i in 1:nrow(aefall.base)){
sector <- aefall.base$PROD_COMMj[r.i]
sector.nace <- mapping.sectors[which(mapping.sectors$mapping==sector),'mappingNACE']
region <- aefall.base$REGr[r.i]
data.row <- which(apply(data, 1, function(r) any(r %in% c(region,toupper(region),tolower(region)))))
if(length(data.row)==1){
value <- mean(as.numeric(data[data.row,sector.nace]))
} else if (length(data.row)>1) {
stop(paste('ambiguous region country identifier',region,'\n'))
}
aefall.scenario$Value[r.i] <- value
}
write.csv(aefall.scenario,paste0('scenarios/forMelbourne/',outputFilename))
# sink(file=paste0('scenarios/forMelbourne/',outputFilename))
# cat('ENDW_COMMi,PROD_COMMj,REGr,Value\n')
# for(endo in ENDW_COMMi){
# for(sector in unique(mapping.sectors$mapping)){
# for(region in regions){
# if (endo =='capital'){
# sector.nace <- mapping.sectors[which(mapping.sectors$mapping==sector),'mappingNACE']
# data.row <- which(apply(data, 1, function(r) any(r %in% c(region,toupper(region),tolower(region)))))
# if(length(data.row)==1){
# value <- mean(as.numeric(data[data.row,sector.nace]))
# } else if (length(data.row)>1) {
# stop(paste('ambiguous region country identifier',region,'\n'))
# } else {
# value <- 0
# }
# } else {
# value <- 0
# }
# cat(sprintf("%s\n",paste(endo,sector,region,sprintf('%0.10f',value),sep=',')))
# }
# }
# }
# sink()
}
cat('done\n')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment