pik-piam / magpie4

R package | MAgPIE outputs R package for MAgPIE version 4.x
GNU Lesser General Public License v3.0
1 stars 23 forks source link

Rewrite of reportEmissions.R #48

Closed mscrawford closed 11 months ago

mscrawford commented 11 months ago

This is a re-write of the reportEmissions.R function, which additionally adds the option to calculate the land-use sink without the Grassi coefficients.

The primary focus of the re-write was to simplify the CO2 calculation's structure and then subsequent reporting. There is now a local function, .calcCO2, that takes as arguments ".lowpass", ".cumulative", and ".raw". The CO2 reports are thus now single calls to this function and the subsequent naming of the reporting variables.

A secondary aspect was simplifying the nitrogen reporting, also through the use of helper functions. This process revealed that peatland emissions had previously been left out of the N2O|Direct|... reporting variables (though was present in the larger N2O variable). This is now fixed.

Testing

I tested this function by anti_joining this version of the reportEmissions function with the current piam magpie4 version for a MAgPIE .gdx file. The differences are:

  1. Emissions|N2O|Direct|Land (Mt N2O/yr) Now includes the previously unaccounted peatland emissions.
  2. This list of emissions now exists in the final reporting object:
 [1] Emissions|NH3|Land|+|Peatland (Mt NH3/yr)                 
 [2] Emissions|NH3|Land|Peatland|+|Managed (Mt NH3/yr)         
 [3] Emissions|NO2|Land|+|Peatland (Mt NO2/yr)                 
 [4] Emissions|NO2|Land|Peatland|+|Managed (Mt NO2/yr)         
 [5] Emissions|NO3-|Land|+|Peatland (Mt NO3-/yr)               
 [6] Emissions|NO3-|Land|Peatland|+|Managed (Mt NO3-/yr)       
 [7] Emissions|N2O|Direct|Land (Mt N2O/yr)                     
 [8] Emissions|N2O|Direct|Land|+|Peatland (Mt N2O/yr)          
 [9] Emissions|N2O|Direct|Land|Peatland|+|Managed (Mt N2O/yr)  
[10] Emissions|N2O|Indirect|Land|+|Peatland (Mt N2O/yr)        
[11] Emissions|N2O|Indirect|Land|Peatland|+|Managed (Mt N2O/yr)

Only the N2O|Direct|... variables are populated with non-zero values. The rest of these emissions are currently 0 for each of the reports.

Land-carbon sink with and without Grassi emissions

I incorporate the following code to either replace the "MAgPIE-own" land-carbon sink with the Grassi coefficients:

# Replace indirect emissions from climate change on managed land with the Grassi coefficients?
if (grassi) {
    climateChange <- landCarbonSink(gdx, level = "regglo", cumulative = .cumulative)
} else {
    climateChange <- dimSums(co2[, , "cc"], dim = 3)
}

And test this new code with some runs of Gabriel's, which varied the climate change, the RCP, the peak carbon budget, and afforestation. I don't completely understand the results. In particular, I wonder if there was something strange in his runs' afforestation settings, because it makes no difference in the end, in terms of CO2 emissions. That said, for the plots of indirect emissions it does seem that the land-carbon sink is working as expected.

Land-use Change

LanduseChange.pdf

Indirect

Indirect.pdf

Land

Land.pdf

Outstanding questions

  1. I'm not sure if Grassi should be an argument to the larger function or have its own reporting variables in the final reporting document. On one side, unless we are going to be using these values it may be potentially confusing. On the other hand, the only way to retrieve the "MAgPIE-own" land-use sink with this implementation is to call reportEmissions.R by hand. Certainly not the most convenient method.
  2. On L115 the value for storage in the context of wood products is written over, without the older value of the variable ever being used. I'm not sure if this is desired behavior.