Skip to content

Commit

Permalink
Merge pull request #1346 from dklein-pik/develop
Browse files Browse the repository at this point in the history
MAgPIE coupling: use new MAgPIE variable names; allow negative values for n2ofertsom (tiny fraction of total n2o)
  • Loading branch information
LaviniaBaumstark committed Jul 1, 2023
2 parents af701bd + a11d1d5 commit 86c2d5d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
1 change: 1 addition & 0 deletions core/bounds.gms
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ v_adjFactor.fx("2005",regi,te)=0;

vm_emiMacSector.lo(t,regi,enty) = 0;
vm_emiMacSector.lo(t,regi,"co2luc")= -5.0; !! afforestation can lead to negative emissions
vm_emiMacSector.lo(t,regi,"n2ofertsom") = -1; !! small negative emissions can result from human activity
vm_emiMac.fx(t,regi,"so2") = 0;
vm_emiMac.fx(t,regi,"bc") = 0;
vm_emiMac.fx(t,regi,"oc") = 0;
Expand Down
2 changes: 2 additions & 0 deletions core/datainput.gms
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,8 @@ $if %carbonprice% == "NPi2018" pm_macSwitch(emiMacMagpie) = 0;
$if %cm_MAgPIE_coupling% == "on" pm_macSwitch(enty)$emiMacMagpie(enty) = 0;
*** As long as there is hardly any CO2 LUC reduction in MAgPIE we dont need MACs in REMIND
$if %cm_MAgPIE_coupling% == "off" pm_macSwitch("co2luc") = 0;
*** The tiny fraction n2ofertsom of total land use n2o can get slitghliy negative in some cases. Ignore MAC for n2ofertsom by default.
$if %cm_MAgPIE_coupling% == "off" pm_macSwitch("n2ofertsom") = 0;

pm_macCostSwitch(enty)=pm_macSwitch(enty);
pm_macSwitch("co2cement_process") =0 ;
Expand Down
26 changes: 1 addition & 25 deletions scripts/start/getReportData.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,6 @@ getReportData <- function(path_to_report,inputpath_mag="magpie",inputpath_acc="c
for (i in 1:nrow(map)) {
tmp<-setNames(mag[,,map[i,]$emimag],map[i,]$emirem)
tmp<-tmp*map[i,]$factor_mag2rem
#tmp["JPN",is.na(tmp["JPN",,]),] <- 0
# preliminary fix 20160111
#cat("Preliminary quick fix: filtering out NAs for all and negative values for almost all landuse emissions except for co2luc and n2ofertrb\n")
#tmp[is.na(tmp)] <- 0
# preliminary 20160114: filter out negative values except for co2luc and n2ofertrb
#if (map[i,]$emirem!="co2luc" && map[i,]$emirem!="n2ofertrb") {
# tmp[tmp<0] <- 0
#}

# Check for negative values, since only "co2luc" is allowed to be
# negative. All other emission variables are positive by definition.
if(map[i,]$emirem != "co2luc"){
if( !(all(tmp>=0)) ){
# Hotfix 2021-09-28: Raise warning and set negative values to zero.
# XXX Todo XXX: Make sure that MAgPIE is not reporting negative N2O
# or CH4 emissions and convert this warning into an error that
# breaks the model instead of setting the values to zero.
print(paste0("Warning: Negative values detected for '",
map[i,]$emirem, "' / '", map[i,]$emimag, "'. ",
"Hot fix: Set respective values to zero."))
tmp[tmp < 0] <- 0
}
}

# Add emission variable to full dataframe
out<-mbind(out,tmp)
}
Expand All @@ -147,7 +123,7 @@ getReportData <- function(path_to_report,inputpath_mag="magpie",inputpath_acc="c
}
.agriculture_costs <- function(mag){
notGLO <- getRegions(mag)[!(getRegions(mag)=="GLO")]
out <- mag[,,"Costs|MainSolve w/o GHG Emissions (million US$05/yr)"]/1000/1000 # with transformation factor from 10E6 US$2005 to 10E12 US$2005
out <- mag[,,"Costs Without Incentives (million US$05/yr)"]/1000/1000 # with transformation factor from 10E6 US$2005 to 10E12 US$2005
out["JPN",is.na(out["JPN",,]),] <- 0
dimnames(out)[[3]] <- NULL #Delete variable name to prevent it from being written into output file
write.magpie(out[notGLO,,],paste0("./modules/26_agCosts/",inputpath_acc,"/input/p26_totLUcost_coupling.csv"),file_type="csvr")
Expand Down

0 comments on commit 86c2d5d

Please sign in to comment.