Skip to content

Commit

Permalink
adjust to new piamInterfaces interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Feb 22, 2024
1 parent 3341f41 commit 7d032d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 7 additions & 12 deletions scripts/output/export/xlsx_IIASA.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,19 @@ 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.")
}

# 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")
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions tutorials/13_Submit_to_IIASA_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7d032d2

Please sign in to comment.