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

Revision of emisCO2.R #67

Closed mscrawford closed 1 month ago

mscrawford commented 2 months ago

This is a complete re-write of emisCO2.R. The calculations of gross emissions (deforestation, degradation, other land conversion and harvesting emissions), are now fully aligned with the area-based emissions as one would calculate through tracking only the changes in land type areas multiplied by their carbon densities over time. The calculation for these "main emissions" is also improved, as it incorporates the "interaction emissions" which emerge when changes in land area and carbon densities influence one another. These are a relatively small source of emissions, roughly 0.1-1% compared to area emissions (land-use emissions). Aside from the inclusion of these, the main emissions haven't changed between implementations of emisCO2.R.

I have a series of plots generated from a suite of scenarios factorially switching forestry, degradation, CO2 afforestation, climate change, and SOM. Please find them attached to this PR, here: plots.zip. Of key importance for judging inconsistencies in the new approach will be the "residual emissions", between our total land use emissions (emisArea) and the sum of regrowth and gross emissions. The function now checks to ensure that these residual unaccounted for emissions are less that 1e-06. It also ensures that the stock derivation of carbonstock (which uses the raw carbon densities ov_carbon_stock) is roughly equal to our independent calculation. The check for this has to be cut off at 1e-05, because of one cell in REF. I'm eager to discuss further checks you might devise.

@ Kristine, I mainly want you to check the implementation of the SOM module's CO2 emissions. Mostly, I've just separated the calculation into first generating the areas and then the carbon densities. You'll therefore want to in particularly attend to the composeDensity function. Notably, in my checks I found that pastures' SOM were not synchronized with the actual output of MAgPIE's carbonstock function. After Florian investigated further, we found that the implementation of SOM in the older emisCO2.R function was out of sync with the actual static SOM module implementation. In the actual implementation, the soil carbon in pasture is derived from fm_carbon_density. Therefore, I updated that here. Everything else should be the same. Since we don't have any mechanistic gross emission categories for SOM (like vegc has deforestation, e.g.), I'm attaching the "main emissions" for SOM to the "gross emissions" to make them match. You might also look at SOM emissions for a few choice scenarios (perhaps just SOM ON/SOM OFF) within the disaggregated emissions plots to make sure that they look reasonable. Something I'm interested to know, is whether you would expect the net SOM emissions to mostly be 0.

You might also see some commented code relating to croptreecover, which is ongoing with Florian. I wanted to get this PR through before confronting those changes, so for now they will be comments.

mscrawford commented 2 months ago

We've now corrected a small bug in the emissions from forestry, wherein ndc and aff plantations were sometimes subject to harvesting. Now, we can integrate the check that gross emissions have to be greater than zero.

mscrawford commented 1 month ago

Jan, I made it lintr friendly with two exceptions, one is a cyclic comp lintr that I am going to nolint (but it wasn't working so I asked Pascal and will update later). The other is commented code from the agroforestry that will soon be implemented.