From f21ae45763c2d61f3d2785d470258a9856226a0d Mon Sep 17 00:00:00 2001
From: christophbertram <bertram@pik-potsdam.de>
Date: Mon, 13 Jan 2020 16:04:40 +0100
Subject: [PATCH] Introducing the option to scale CH4 and N2O emissions so to
 match CEDS historic values

---
 config/default.cfg    |  1 +
 core/datainput.gms    | 18 ++++++++++++++++++
 core/declarations.gms |  3 +++
 core/preloop.gms      | 25 +++++++++++++++++++++++++
 core/presolve.gms     | 18 ++++++++++++++++++
 core/sets.gms         | 22 ++++++++++++++++++++++
 main.gms              |  1 +
 7 files changed, 88 insertions(+)

diff --git a/config/default.cfg b/config/default.cfg
index 8328592..4badf10 100644
--- a/config/default.cfg
+++ b/config/default.cfg
@@ -365,6 +365,7 @@ cfg$gms$cm_APscen              <- "SSP2"  # def <- SSP2
 cfg$gms$cm_Full_Integration    <- "off"   # def = off
 
 cfg$gms$c_CO2priceDependent_AdjCosts    <- "on"   # def = on
+cfg$gms$c_scaleEmiHistorical   <- "off"    # def = off
 
 # MAGICC configuration (AJS)
 # Calibrate year 2000 temperature to HADCRUT4 data (which is very close to AR5).
diff --git a/core/datainput.gms b/core/datainput.gms
index ebcc5bf..2f16ffb 100644
--- a/core/datainput.gms
+++ b/core/datainput.gms
@@ -293,6 +293,24 @@ table f_dataetaglob(tall,all_te)                      "global eta data"
 $include "./core/input/generisdata_varying_eta.prn"
 ;
 
+* Read in mac historical emissions to calibrate MAC reference emissions
+parameter p_histEmiMac(tall,all_regi,all_enty)    "historical emissions per MAC"
+/
+$ondelim
+$include "./core/input/p_histEmiMac.cs4r"
+$offdelim
+/
+;
+* Read in historical emissions per sector to calibrate MAC reference emissions
+parameter p_histEmiSector(tall,all_regi,all_enty,emi_sectors,sector_types)    "historical emissions per sector"
+/
+$ondelim
+$include "./core/input/p_histEmiSector.cs4r"
+$offdelim
+/
+;
+
+
 ***---------------------------------------------------------------------------
 *** Import and set regional data
 ***---------------------------------------------------------------------------
diff --git a/core/declarations.gms b/core/declarations.gms
index 0df22bf..0532e7c 100644
--- a/core/declarations.gms
+++ b/core/declarations.gms
@@ -235,6 +235,9 @@ pm_cumDeprecFactor_old(ttot,all_regi,all_in)         "investment depreciation wi
 pm_cumDeprecFactor_new(ttot,all_regi,all_in)         "investment depreciation within a period, applied to the investment of t"
 
 p_Mport2005correct(all_regi,all_enty)                "correction factor to match fossil supply and internal region energy demand in the initial year"
+
+p_histEmiMac(tall,all_regi,all_enty)                 "historical emissions per MAC; from Eurostat and CEDS, to correct CH4 and N2O reporting"
+p_histEmiSector(tall,all_regi,all_enty,emi_sectors,sector_types) "historical emissions per sector; from Eurostat and CEDS, to correct CH4 and N2O reporting"
 ;
 
 ***----------------------------------------------------------------------------------------
diff --git a/core/preloop.gms b/core/preloop.gms
index 49bf48e..dd946a4 100644
--- a/core/preloop.gms
+++ b/core/preloop.gms
@@ -110,5 +110,30 @@ pm_vintage_in(regi,"1",te) = pm_vintage_in(regi,"1",te) * max((pm_histfegrowth(r
 pm_vintage_in(regi,"6",te) = pm_vintage_in(regi,"6",te) * max(((pm_histfegrowth(regi,entyFe)- 0.005 + 1/fm_dataglob("lifetime",te))/(1/fm_dataglob("lifetime",te)) + 1) * 0.75,0.2);
 );
 
+$ifthen setGlobal c_scaleEmiHistorical
+*re-scale MAgPie reference emissions to be inline with eurostat data (MagPie overestimates non-CO2 GHG emissions by a factor of 50% more)
+display p_macBaseMagpie;
+loop(enty$(sameas(enty,"ch4rice") OR sameas(enty,"ch4animals") OR sameas(enty,"ch4anmlwst")),
+  p_macBaseMagpie(ttot,regi,enty)$(p_histEmiSector("2005",regi,"ch4","agriculture","process") AND (ttot.val ge 2005)) =
+   p_macBaseMagpie(ttot,regi,enty) *
+    ( (p_histEmiSector("2005",regi,"ch4","agriculture","process")+p_histEmiSector("2005",regi,"ch4","lulucf","process")) !!no rescaling needed - REMIND-internal unit is Mt CH4
+      /
+      (sum(enty2$(sameas(enty2,"ch4rice") OR sameas(enty2,"ch4animals") OR sameas(enty2,"ch4anmlwst")), p_macBaseMagpie("2005",regi,enty2)) + p_macBaseExo("2005",regi,"ch4agwaste"))
+    )
+  ;
+);
+loop(enty$(sameas(enty,"n2ofertin") OR sameas(enty,"n2ofertcr") OR sameas(enty,"n2oanwstc") OR sameas(enty,"n2oanwstm") OR sameas(enty,"n2oanwstp")),
+  p_macBaseMagpie(ttot,regi,enty)$(p_histEmiSector("2005",regi,"n2o","agriculture","process") AND (ttot.val ge 2005)) =
+    p_macBaseMagpie(ttot,regi,enty) *
+    ( p_histEmiSector("2005",regi,"n2o","agriculture","process")/( 44 / 28) !! rescaling to Mt N (internal unit for N2O emissions)
+* eurostat uses 298 to convert N2O to CO2eq
+      /
+      (sum(enty2$(sameas(enty,"n2ofertin") OR sameas(enty2,"n2ofertcr") OR sameas(enty2,"n2oanwstc") OR sameas(enty2,"n2oanwstm") OR sameas(enty2,"n2oanwstp")), p_macBaseMagpie("2005",regi,enty2)) + p_macBaseExo("2005",regi,"n2oagwaste"))
+    )
+  ;
+);
+display p_macBaseMagpie;
+$endif
+
 
 *** EOF ./core/preloop.gms
diff --git a/core/presolve.gms b/core/presolve.gms
index c88b227..65e53a0 100644
--- a/core/presolve.gms
+++ b/core/presolve.gms
@@ -326,7 +326,25 @@ p_macLevFree(ttot,regi,enty)$( ttot.val gt 2005 )
       p_macUse2005(regi,enty)
     )$( (ttot.val gt 2040) )
 ;
+
+$ifthen setGlobal c_scaleEmiHistorical
+
+**p_macLevFree(ttot,regi,emiMacMagpie(enty))=0;
+* Set minimum abatment levels based on historical emissions
+p_macLevFree("2010",regi,enty)$(p_histEmiSector("2005",regi,"ch4","agriculture","process") AND (sameas(enty,"ch4rice") OR sameas(enty,"ch4animals") OR sameas(enty,"ch4anmlwst"))) = max( 0, 1 - (p_histEmiSector("2010",regi,"ch4","agriculture","process")+p_histEmiSector("2010",regi,"ch4","lulucf","process"))/(p_histEmiSector("2005",regi,"ch4","agriculture","process")+p_histEmiSector("2005",regi,"ch4","lulucf","process")));
+p_macLevFree(ttot,regi,enty)$((ttot.val ge 2015) AND p_histEmiSector("2005",regi,"ch4","agriculture","process") AND (sameas(enty,"ch4rice") OR sameas(enty,"ch4animals") OR sameas(enty,"ch4anmlwst"))) = max( 0, 1 - (p_histEmiSector("2015",regi,"ch4","agriculture","process")+p_histEmiSector("2015",regi,"ch4","lulucf","process"))/(p_histEmiSector("2005",regi,"ch4","agriculture","process")+p_histEmiSector("2005",regi,"ch4","lulucf","process")) );
+p_macLevFree("2010",regi,enty)$(p_histEmiSector("2005",regi,"ch4","agriculture","process") AND (sameas(enty,"n2ofertin") OR sameas(enty,"n2ofertcr") OR sameas(enty,"n2oanwstc") OR sameas(enty,"n2oanwstm") OR sameas(enty,"n2oanwstp"))) = max( 0, 1 - (p_histEmiSector("2010",regi,"n2o","agriculture","process")+p_histEmiSector("2010",regi,"n2o","lulucf","process"))/(p_histEmiSector("2005",regi,"n2o","agriculture","process")+p_histEmiSector("2005",regi,"n2o","lulucf","process")) );
+p_macLevFree(ttot,regi,emiMacMagpie(enty))$((ttot.val ge 2015) AND p_histEmiSector("2005",regi,"n2o","agriculture","process") AND (sameas(enty,"n2ofertin") OR sameas(enty,"n2ofertcr") OR sameas(enty,"n2oanwstc") OR sameas(enty,"n2oanwstm") OR sameas(enty,"n2oanwstp"))) = max( 0, 1 - (p_histEmiSector("2015",regi,"n2o","agriculture","process")+p_histEmiSector("2015",regi,"n2o","lulucf","process"))/(p_histEmiSector("2005",regi,"n2o","agriculture","process")+p_histEmiSector("2005",regi,"n2o","lulucf","process")) );
+
+p_macLevFree("2010",regi,enty)$((p_histEmiMac("2010",regi,enty)) AND (sameas(enty,"ch4wstl") OR sameas(enty,"ch4wsts"))) = max( 0, 1 - (p_histEmiMac("2010",regi,enty)) /vm_macBase.l("2010",regi,enty) );
+p_macLevFree(ttot,regi,enty)$((ttot.val ge 2015) AND (p_histEmiMac("2015",regi,enty)) AND (sameas(enty,"ch4wstl") OR sameas(enty,"ch4wsts"))) = max( 0, 1 - (p_histEmiMac("2015",regi,enty))/vm_macBase.l("2015",regi,enty) );
+
+$else
+
 p_macLevFree(ttot,regi,emiMacMagpie(enty))=0;
+
+$endif
+
 pm_macAbatLev(ttot,regi,enty) = 0.0;
 pm_macAbatLev("2005",regi,enty) = p_macUse2005(regi,enty);
 pm_macAbatLev("2010",regi,enty) = p_macLevFree("2010",regi,enty);
diff --git a/core/sets.gms b/core/sets.gms
index 8a2c4f0..aec6ea8 100644
--- a/core/sets.gms
+++ b/core/sets.gms
@@ -1688,6 +1688,28 @@ sectorExogEmi(all_sectorEmi) "sectors with exogenous emissions"
     extraction
     indprocess
 /
+emi_sectors  "comprehensive sector set used for more detailed emissions accounting (REMIND-EU) and for CH4 tier 1 scaling - potentially to be integrated with similar set all_exogEmi"
+/
+        power   "public electricity and heat production"
+        refining "petroleum refining"
+        solids  "manufacture of solid fuels and other energy industries"
+        extraction "fugitive emissions from fuel extraction"
+        build   "Commercial sector, institutional sector and households"
+        indst   "industry (including industrial processes)"
+        trans   "transportation"
+        agriculture "agriculture (plus forestry and fishing energy use)"
+        waste   "waste management"
+        cdr     "Transport, capture and storage of CO2"
+        lulucf  "Land use,  land use change,  and forestry (LULUCF)"
+        bunkers "International bunkers (maritime and aviation)"
+        other   "other sectors and multilateral operations"
+        indirect
+/
+sector_types
+/
+        energy "fuel combustion part (and emissions) of the sector activity"
+        process "process sepecific part (and emissions) of the sector activity"
+/
 ccsCo2(all_enty)    "only cco2 (???)"
 /
         cco2
diff --git a/main.gms b/main.gms
index aa3b7e8..b98deaa 100644
--- a/main.gms
+++ b/main.gms
@@ -364,6 +364,7 @@ cm_carbonprice_temperatureLimit       = 1.8;   !! def = 1.8
 cm_DiscRateScen = 0;!! def = 0
 cm_noReboundEffect = 0;
 $setGlobal cm_EsubGrowth  low  !! def = low
+$setGlobal c_scaleEmiHistorical  off  !! def = off
 
 *** --------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ***                           YOU ARE IN THE WARNING ZONE (DON'T DO CHANGES HERE)
-- 
GitLab