diff --git a/CHANGELOG.md b/CHANGELOG.md index 968060cdb..a09854528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [[#1773](https://github.com/remindmodel/remind/pull/1773)] - **scripts** add support for EDGE-Transport standalone results to cs2 [[#1780](https://github.com/remindmodel/remind/pull/1780)] +- **scripts** add option to use raw land-use change emissions variable in coupled runs + [[#1796](https://github.com/remindmodel/remind/pull/1796)] - **testthat** fail if manipulating main.gms with default cfg drops/changes switches and comments [[#1764](https://github.com/remindmodel/remind/pull/1764)] and [[#1767](https://github.com/remindmodel/remind/pull/1767)] diff --git a/scripts/start/getReportData.R b/scripts/start/getReportData.R index 1c89f50bd..d244c3d3c 100644 --- a/scripts/start/getReportData.R +++ b/scripts/start/getReportData.R @@ -5,7 +5,7 @@ # | REMIND License Exception, version 1.0 (see LICENSE file). # | Contact: remind@pik-potsdam.de -getReportData <- function(path_to_report,inputpath_mag="magpie_40",inputpath_acc="costs") { +getReportData <- function(path_to_report,inputpath_mag="magpie_40",inputpath_acc="costs",var_luc="smooth") { require(magclass, quietly = TRUE,warn.conflicts =FALSE) @@ -43,6 +43,15 @@ getReportData <- function(path_to_report,inputpath_mag="magpie_40",inputpath_acc } .emissions_mac <- function(mag) { + # Select the LUC variable according to setting. + if (var_luc == "smooth") { + emi_co2_luc <- "Emissions|CO2|Land|+|Land-use Change (Mt CO2/yr)" + } else if (var_luc == "raw") { + emi_co2_luc <- "Emissions|CO2|Land RAW|+|Land-use Change (Mt CO2/yr)" + } else { + stop(paste0("Unkown setting for 'var_luc': `", var_luc, "`. Only `smooth` or `raw` are allowed.")) + } + # define three columns of dataframe: # emirem (remind emission names) # emimag (magpie emission names) @@ -53,7 +62,7 @@ getReportData <- function(path_to_report,inputpath_mag="magpie_40",inputpath_acc map <- data.frame(emirem=NULL,emimag=NULL,factor_mag2rem=NULL,stringsAsFactors=FALSE) if("Emissions|N2O|Land|Agriculture|+|Animal Waste Management (Mt N2O/yr)" %in% getNames(mag)) { # MAgPIE 4 (up to date) - map <- rbind(map,data.frame(emimag="Emissions|CO2|Land|+|Land-use Change (Mt CO2/yr)", emirem="co2luc", factor_mag2rem=1/1000*12/44,stringsAsFactors=FALSE)) + map <- rbind(map,data.frame(emimag=emi_co2_luc, emirem="co2luc", factor_mag2rem=1/1000*12/44,stringsAsFactors=FALSE)) map <- rbind(map,data.frame(emimag="Emissions|N2O|Land|Agriculture|+|Animal Waste Management (Mt N2O/yr)", emirem="n2oanwstm", factor_mag2rem=28/44,stringsAsFactors=FALSE)) map <- rbind(map,data.frame(emimag="Emissions|N2O|Land|Agriculture|Agricultural Soils|+|Inorganic Fertilizers (Mt N2O/yr)", emirem="n2ofertin", factor_mag2rem=28/44,stringsAsFactors=FALSE)) map <- rbind(map,data.frame(emimag="Emissions|N2O|Land|Agriculture|Agricultural Soils|+|Manure applied to Croplands (Mt N2O/yr)", emirem="n2oanwstc", factor_mag2rem=28/44,stringsAsFactors=FALSE)) diff --git a/scripts/start/prepare.R b/scripts/start/prepare.R index 07d93af87..c35c79030 100644 --- a/scripts/start/prepare.R +++ b/scripts/start/prepare.R @@ -123,7 +123,12 @@ prepare <- function() { # If a path to a MAgPIE report is supplied use it as REMIND input (used for REMIND-MAgPIE coupling) # ATTENTION: modifying gms files if (!is.null(cfg$pathToMagpieReport)) { - getReportData(path_to_report = cfg$pathToMagpieReport,inputpath_mag=cfg$gms$biomass,inputpath_acc=cfg$gms$agCosts) + getReportData( + path_to_report = cfg$pathToMagpieReport, + inputpath_mag = cfg$gms$biomass, + inputpath_acc = cfg$gms$agCosts, + var_luc = cfg$var_luc + ) } # Update module paths in GAMS code diff --git a/scripts/start/readCheckScenarioConfig.R b/scripts/start/readCheckScenarioConfig.R index a6309199d..b749a3ecd 100644 --- a/scripts/start/readCheckScenarioConfig.R +++ b/scripts/start/readCheckScenarioConfig.R @@ -132,7 +132,7 @@ readCheckScenarioConfig <- function(filename, remindPath = ".", testmode = FALSE if (grepl("scenario_config_coupled", filename)) { knownColumnNames <- c(knownColumnNames, "cm_nash_autoconverge_lastrun", "oldrun", "path_report", "magpie_scen", "no_ghgprices_land_until", "qos", "sbatch", "path_mif_ghgprice_land", "max_iterations", - "magpie_empty") + "magpie_empty", "var_luc") # identify MAgPIE switches by "cfg_mag" and "scenario_config" knownColumnNames <- c(knownColumnNames, grep("cfg_mag|scenario_config", names(scenConf), value = TRUE)) } diff --git a/start_bundle_coupled.R b/start_bundle_coupled.R index 5c2266a3f..1b39f98bf 100755 --- a/start_bundle_coupled.R +++ b/start_bundle_coupled.R @@ -419,6 +419,17 @@ for(scen in common){ cfg_mag$mute_ghgprices_until <- scenarios_coupled[scen, "no_ghgprices_land_until"] } + # Write choice of land-use change variable to config. Use smoothed variable + # if not specified otherwise in coupled config, i.e. if the column is missing + # completely or if the row entry is empty. + if (! "var_luc" %in% names(scenarios_coupled) || is.na(scenarios_coupled[scen, "var_luc"]) { + cfg_rem$var_luc <- "smooth" + } else if (scenarios_coupled[scen, "var_luc"] %in% c("smooth", "raw")) { + cfg_rem$var_luc <- scenarios_coupled[scen, "var_luc"] + } else { + stop(paste0("Unkown setting in coupled config file for 'var_luc': `", scenarios_coupled[scen, "var_luc"], "`. Please chose either `smooth` or `raw`")) + } + # Edit remind main model file, region settings and input data revision based on scenarios table, if cell non-empty cfg_rem_options <- c("model", "regionmapping", "extramappings_historic", "inputRevision", setdiff(names(cfg_rem), c("gms", "output"))) for (switchname in intersect(cfg_rem_options, names(settings_remind))) { @@ -611,6 +622,7 @@ for(scen in common){ } message("path_report : ",ifelse(file.exists(path_report),green,red), path_report, NC) message("no_ghgprices_land_until: ", cfg_mag$gms$c56_mute_ghgprices_until) + message("var_luc: ", cfg_rem$var_luc) if ("--gamscompile" %in% flags) { message("Compiling ", fullrunname) diff --git a/tutorials/04_RunningREMINDandMAgPIE.md b/tutorials/04_RunningREMINDandMAgPIE.md index a0cf54aa6..ebc19a8db 100644 --- a/tutorials/04_RunningREMINDandMAgPIE.md +++ b/tutorials/04_RunningREMINDandMAgPIE.md @@ -107,7 +107,7 @@ All the columns must be present in the `scenario_config_coupled.csv` file, but m - `magpie_scen`: A pipe (`|`) separated list of configurations to pass to MAgPIE. Each entry should correspond to a column in [MAgPIE's scenario_config](https://github.com/magpiemodel/magpie/blob/master/config/scenario_config.csv), each one of them setting the multiple configuration flags listed in that file. The configurations are applied in the order that they appear. For example, to configure MAgPIE with SSP2 settings and climate change impacts according to RCP45 set `magpie_scen` to `SSP2|cc|rcp4p5`. To select scenarios from a different `scenario_config*.csv` file replace `magpie_scen` by the path to that file relative to MAgPIE's main folder, for example: `config/projects/scenario_config_PROJECT.csv`. The filename *must contain* the string `scenario_config`. You can also specify more than one column directing to another `scenario_config_PROJECT2.csv` file. They will be evaluated in the order in which they appear in the `scenario_config_coupled.csv`. There is another option of addressing MAgPIE switches described at the end of the list of optional columns below. - `no_ghgprices_land_until`: Controls at which timestep in the MAgPIE runs GHG prices from REMIND will start to be applied. This essentially enables you to set whether or not (or when) GHG prices on land should be applied in MAgPIE. If you want MAgPIE to always apply the same GHG prices from REMIND, you should set this to a timestep corresponding to the start of your REMIND run, such as `y2020` to start in the 2020 timestep. If you want to disable GHG prices in MAgPIE, regardless of what REMIND finds, set this to the last timestep of the run (usually `y2150`). Values in between allow the simulation of policies where GHG prices are only applied in the land use sector after a certain year. -Other, optional columns allow you to make a run start only after another has finished, set starting conditions, and give you finer control over which data is fed to MAgPIE. +Other, optional columns allow you to make a run start only after another has finished, set starting conditions, and give you finer control over which data is fed from REMIND to MAgPIE or from MAgPIE to REMIND. - `path_gdx`, `path_gdx_ref`, `path_gdx_refpolicycost`, `path_gdx_carbonprice`, `path_gdx_bau`, : Override these same settings in REMIND's `scenario_config`, see [`03_RunningBundleOfRuns`](./03_RunningBundleOfRuns.md) for a detailed explanation. - You can set these switches either to the full path of a `fulldata.gdx` file or simply to the name of another scenario in the file (without the "C_"!). So if you want a certain scenario (say `NDC`) to use as starting point the results of a `Base` scenario, you can simply set `path_gdx` to `Base` and it will automatically locate the appropriate `fulldata.gdx` in `Base`, for example `path_remind/C_Base-rem-x/fulldata.gdx`. @@ -121,6 +121,7 @@ Other, optional columns allow you to make a run start only after another has fin - `path_report: Provide a path to a MAgPIE report here if you want REMIND to start with it. It overwrites whatever might have been automatically found from former MAgPIE runs. - `cm_nash_autoconverge_lastrun`: can be used to specify `cm_nash_autoconverge`, but only for the last REMIND run, for example to increase precision there by setting it to `2`. - `cfg_mag$...`: If you don't want to select composed scenarios in MAgPIE to address switches, you can directly address individual MAgPIE switches in the `scenario_config_coupled.csv`. Add any number of columns to your `scenario_config_coupled.csv` that have the name of the MAgPIE switch as the column name. They need to start with `cfg_mag$`. For example: if you want to set `gms$s56_cprice_red_factor` to `3.14` for `SSP2-NPi`, add the column `cfg_mag$gms$s56_cprice_red_factor` to your `scenario_config_coupled.csv` and fill in `3.14` in the row that defines `SSP2-NPi`. + - `var_luc`: Controls, which variable to use in REMIND to represent land-use change (LUC) CO2 emissions from MAgPIE (`co2luc` in REMIND). By default, this switch is set to `smooth` such that the variable `Emissions|CO2|Land|+|Land-use Change` is used. This variable was i.a. obtained by applying a low-pass filter to the raw LUC emissions in order to smooth out spikes. Alternatively, this switch can be set to `raw`. Then the unfiltered variable `Emissions|CO2|Land RAW|+|Land-use Change` is used instead. ### Perform test start before actually submitting runs