diff --git a/DESCRIPTION b/DESCRIPTION index e5db17743..c1c99ca6a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,7 +51,7 @@ Imports: nleqslv, optparse, piamenv (>= 0.4.0), - piamInterfaces (>= 0.5.0), + piamInterfaces (>= 0.12.18), plotly, purrr, quitte (>= 0.3123.0), diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index 6152b2de5..485ba5c87 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -64,6 +64,12 @@ for (p in intersect(varnames, names(projectdata))) { lucode2::readArgs("outputdirs", "filename_prefix", "outputFilename", "model", "mapping", "logFile", "removeFromScen", "addToScen", "iiasatemplate") +if (is.null(mapping)) { + mapping <- gms::chooseFromList(names(piamInterfaces::templateNames()), type = "mapping template") +} +if (length(mapping) == 0 || ! all(file.exists(mapping) | mapping %in% names(templateNames()))) + stop("mapping='", paste(mapping, collapse = ", "), "' not found.") +} if (exists("iiasatemplate") && ! is.null(iiasatemplate) && ! file.exists(iiasatemplate)) { stop("iiasatemplate=", iiasatemplate, " not found.") } @@ -71,17 +77,6 @@ if (exists("iiasatemplate") && ! is.null(iiasatemplate) && ! file.exists(iiasate # variables to be deleted although part of the template temporarydelete <- NULL # example: c("GDP|MER", "GDP|PPP") -### select mapping - -mappingFile <- NULL -if (length(mapping) == 1 && file.exists(mapping)) { - mappingFile <- mapping - mapping <- NULL -} else if (! all(mapping %in% names(templateNames())) || length(mapping) == 0) { - message("# Mapping = '", paste(mapping, collapse = ","), "' exists neither as file nor mapping name.") - mapping <- gms::chooseFromList(names(piamInterfaces::templateNames()), type = "mapping template") -} - ### define filenames outputFolder <- file.path("output", "export") @@ -140,7 +135,7 @@ withCallingHandlers({ # piping messages to logFile # message("\n### Generate joint mif, remind2 format: ", filename_remind2_mif) # write.mif(mifdata, filename_remind2_mif) - generateIIASASubmission(mifdata, mapping = mapping, model = model, mappingFile = mappingFile, + generateIIASASubmission(mifdata, mapping = mapping, model = model, removeFromScen = removeFromScen, addToScen = addToScen, outputDirectory = outputFolder, logFile = logFile, outputFilename = basename(OUTPUT_xlsx), diff --git a/tutorials/13_Submit_to_IIASA_database.md b/tutorials/13_Submit_to_IIASA_database.md index bd35c3d2e..e2b497b5b 100644 --- a/tutorials/13_Submit_to_IIASA_database.md +++ b/tutorials/13_Submit_to_IIASA_database.md @@ -23,16 +23,14 @@ You can generate the file to be uploaded by either calling [`piamInterfaces::gen - `iiasatemplate`: optional path to the xlsx or yaml file obtained in the project with the variables and units that are accepted in the database - `addToScen`: optional string added in front of all scenario names - `removeFromScen`: optional regular expression of parts to be deleted from the scenario names, such as "C_|_bIT|_bit|_bIt" -- you have to specify at least one of: - - `mappingFile`: filename of the csv file generated by [`piamInterfaces::generateMappingfile`](https://github.com/pik-piam/piamInterfaces/blob/master/R/generateMappingfile.R) that is used. If `mapping` is also supplied, this file is overwritten - - `mapping`: vector of templates from [this directory](https://github.com/pik-piam/piamInterfaces/tree/master/inst/templates) (such as `c("AR6", "AR6_NGFS")` or `c("NAVIGATE", "SHAPE")`) that then generates the template (and writes it to `mappingFile` if defined) +- `mapping`: vector of templates from [this directory](https://github.com/pik-piam/piamInterfaces/tree/master/inst/templates) (such as `c("AR6", "AR6_NGFS")` or `c("NAVIGATE", "SHAPE")`) or a local file with identical structure. Usually, you will find the result in in the `output` subdirectory, but you can adapt this, see [the function documentation](https://github.com/pik-piam/piamInterfaces/blob/master/R/generateIIASASubmission.R). Starting from your REMIND directory, you can start this process by running `./output.R`, then selecting `export` and `xlsx_IIASA`. Then choose the directories of the runs you would like to use. This works also for coupled runs, as the `REMIND_generic_*.mif` contains the MAgPIE output since [October 4, 2022](https://github.com/remindmodel/remind/pull/992). The script requires the inputs as above, expect that it lets you select the `mifs` from a list, and provides additional options: -- mapping: either the path to a mapping file you generated using [`piamInterfaces::generateMappingfile`](https://github.com/pik-piam/piamInterfaces/blob/master/R/generateMappingfile.R), or a vector of templates such as `c("NAVIGATE", "SHAPE")` referring to the last part of the file names in [this piamInterfaces directory](https://github.com/pik-piam/piamInterfaces/tree/master/inst/templates) +- mapping: either the path to a mapping template or a vector of template names such as `c("NAVIGATE", "SHAPE")` referring to the last part of the file names in [this piamInterfaces directory](https://github.com/pik-piam/piamInterfaces/tree/master/inst/templates) - filename_prefix: optional prefix of the resulting outputFile, such as your project name You can specify the information above in two ways: Either edit [`xlsx_IIASA.R`](../scripts/output/export/xlsx_IIASA.R) and add a project in a similar way to `NGFS_v4` or `ENGAGE_4p5`. You can then start the scripts with: