| Title: | REMIND integration of IIASA's `climate-assessment` package |
|---|---|
| Description: | The REMIND integration of IIASA's `climate-assessment` provides a standardized interface to simple climate models such as MAGICC7. |
| Authors: | Tonn Rüter [aut, cre] |
| Maintainer: | Tonn Rüter <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-06-10 07:40:52 UTC |
| Source: | https://github.com/pik-piam/remindClimateAssessment |
This function appends climate assessment data to a MIF (Model Intercomparison Framework) file. It removes data from old MAGICC7 runs to avoid duplication and then writes the updated data back to the MIF file.
appendClimateAssessmentToMif(qf, mif)appendClimateAssessmentToMif(qf, mif)
qf |
'quitte' data frame containing the climate assessment data to be appended |
mif |
File path to the MIF to which the data will be appended |
The function returns the result of writing the updated data to the MIF file.
Archives climate assessment data by copying all *.csv/*.xlsx from climate diretory (and, if specified, extra files) to a temporary directory, then tar'ing and gzip'ing the temporary directory & deleting it afterwards
archiveClimateAssessmentData( climateDir, climateArchiveDir = NULL, suffix = "", extraFiles = c(), returnFn = TRUE )archiveClimateAssessmentData( climateDir, climateArchiveDir = NULL, suffix = "", extraFiles = c(), returnFn = TRUE )
climateDir |
Base directory containing climate assessment data |
climateArchiveDir |
Directory where the climate assessment data will be archived. Default is NULL, in which case a new 'archive' subdir is created in the climate directory. Note: This directory is NOT deleted after archiving, only the temporary directory created within it is |
suffix |
String appended to the file name. Can be used to identify the climate assessment run mode (i.e. 'report', 'iteration', 'impulse') in the archive file name. Defaults to empty string |
extraFiles |
Character vector of additional file paths to include in the archive. Default is an empty vector |
returnFn |
A logical value indicating whether to return the path to the tar file. Defaults to TRUE |
If returnFn is TRUE, the function returns the path to the tar file. Otherwise, it returns invisible()
Tonn Rüter
## Not run: cfg <- climateAssessmentConfig("<outputDir>", "iteration") extraFiles <- c("pm_globalMeanTemperature", "p15_forc_magicc") archiveClimateAssessmentData(cfg$climateArchiveDir, extraFiles) ## End(Not run)## Not run: cfg <- climateAssessmentConfig("<outputDir>", "iteration") extraFiles <- c("pm_globalMeanTemperature", "p15_forc_magicc") archiveClimateAssessmentData(cfg$climateArchiveDir, extraFiles) ## End(Not run)
Something
dumpToGDX( assessmentData, exportConf, interpolateYears = NULL, logFile = NULL, verbose = NULL )dumpToGDX( assessmentData, exportConf, interpolateYears = NULL, logFile = NULL, verbose = NULL )
assessmentData |
Data frame as produced by |
exportConf |
Associates climate assessment variables with the GDX file names and their GAMS counterpart |
interpolateYears |
In case the periods in the emission report do not match the one reported by climate assessment, we need to interpolate to be able to integrate them with existing GAMS data |
logFile |
Path to the log file. Default is NULL |
verbose |
Determines logging level. If set to TRUE, log messages are printed to std out |
Tonn Rüter
## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)
This function cleans up climate assessment data by filtering for specific periods, interpolating missing periods, and renaming variables from MAGICC7 to REMIND naming convention
cleanUpClimateAssessment(qf, periods)cleanUpClimateAssessment(qf, periods)
qf |
A 'quitte' object containing the climate assessment data to be cleaned |
periods |
Vector periods (years) to be considered |
A cleaned 'quitte' object with filtered periods, interpolated missing periods, and renamed variables
Collects all necessary files and directories to set up climate assessment run from a REMIND output directory
climateAssessmentConfig(outputDir, mode)climateAssessmentConfig(outputDir, mode)
outputDir |
A REMIND output directory |
mode |
Determines which probabiliy files is used. Must be either "report", "iteration" or "impulse" |
A list containing the configuration settings for the climate assessment
## Not run: climateAssessmentConfig("<outputDir>", "iteration") # yields list( outputDir = "/p/tmp/tonnru/remind/output/h_cpol_KLW_d50_2025-02-06_18.10.48", scenario = "h_cpol_KLW_d50", condaEnv = "/p/projects/rd3mod/python/environments/scm_magicc7_hpc", isArchived = FALSE, logFile = "<outputDir>/log_climate.txt", workersDir = "<outputDir>/climate-assessment-data/workers", climateDir = "<outputDir>/climate-assessment-data", archiveDir = "", scriptsDir = "<Depending on your installation>", magiccBin = "<Depending on your installation>", variablesFile = "<Depending on piamInterfaces>", infillingDatabase = "<Depending on your REMIND default.cfg>", probabilisticFile = "<Depending on your REMIND default.cfg>", nSets = "<Depending on your REMIND probabilisticFile>", ... ) ## End(Not run)## Not run: climateAssessmentConfig("<outputDir>", "iteration") # yields list( outputDir = "/p/tmp/tonnru/remind/output/h_cpol_KLW_d50_2025-02-06_18.10.48", scenario = "h_cpol_KLW_d50", condaEnv = "/p/projects/rd3mod/python/environments/scm_magicc7_hpc", isArchived = FALSE, logFile = "<outputDir>/log_climate.txt", workersDir = "<outputDir>/climate-assessment-data/workers", climateDir = "<outputDir>/climate-assessment-data", archiveDir = "", scriptsDir = "<Depending on your installation>", magiccBin = "<Depending on your installation>", variablesFile = "<Depending on piamInterfaces>", infillingDatabase = "<Depending on your REMIND default.cfg>", probabilisticFile = "<Depending on your REMIND default.cfg>", nSets = "<Depending on your REMIND probabilisticFile>", ... ) ## End(Not run)
Something
dumpToGdx(relevantData, fileName, variables)dumpToGdx(relevantData, fileName, variables)
relevantData |
FOO |
fileName |
BAR |
variables |
BAZ |
Tonn Rüter
## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)
Converts remind emission data from long to wide format suitable for climate assessment. Only considers regions "GLO" and "World" and extracts only the variables needed for climate assessment. Per default these are provided from the AR6 mapping in the piamInterfaces package. The resulting data frame has one column for each year and one row for each variable. For more information visit https://pyam-iamc.readthedocs.io/en/stable/data.html
emissionDataForClimateAssessment( qf, scenario, mapping = "AR6", variablesFile = NULL, logFile = NULL )emissionDataForClimateAssessment( qf, scenario, mapping = "AR6", variablesFile = NULL, logFile = NULL )
qf |
|
scenario |
Name of the scenario |
mapping |
Name of the mapping file from the |
variablesFile |
Path to the yaml file containing the variables needed for climate-assessment. If no file path is provided, the function gets the yaml file from the piamInterfaces package |
logFile |
Path to the log file. Default is "output/missing.log" |
quitte data frame with the REMIND emission data reshaped for climate assessment
Tonn Rüter
## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)## Not run: # Generates REMIND emission report, extracts relevant variables and reshapes. Note: This funtion can be used in a tidyverse pipeline. emissionDataForClimateAssessment( remind2::reportEmi(fulldata.gdx), scenarioName = "SSP2EU-NPi-ar6", climateAssessmentYaml = file.path( system.file(package = "piamInterfaces"), "iiasaTemplates", "climate_assessment_variables.yaml" ) logFile = "output/missing.log" ) ## End(Not run)
Geenerates emission impulse scenarios from a harmonized and infilled emissions data by repeating the unperturbed scenario as baseline and concatenating perturbed scenarios. Each scenario adds a specified quantity of additional emissions to the spcified emission variable in the given time periods. The periods of the original data frame can be extended to observe long term effects in the climate emulation
emissionImpulseSenarios( qf, var = "AR6 climate diagnostics|Infilled|Emissions|CO2|Energy and Industrial Processes", impulse = 3660, periods = c(2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090, 2100, 2110, 2130), endYear = 2200, inbetween = 1 )emissionImpulseSenarios( qf, var = "AR6 climate diagnostics|Infilled|Emissions|CO2|Energy and Industrial Processes", impulse = 3660, periods = c(2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090, 2100, 2110, 2130), endYear = 2200, inbetween = 1 )
qf |
|
var |
Name of the variable to be perturbed |
impulse |
Amount of additional emissions. Defaults to 3.66e2, CO2 equivalent in Mt to 1 GtC |
periods |
Periods in which to add the emissions impulse. Defaults to c(2020, 2030, ..., 2110, 2130) |
endYear |
Extends the original observation periods. Defaults to 2200 |
inbetween |
Duration of the extended observation periods in years. Defaults to 1 |
quitte data frame containing all data for the emission impulse scenarios
Tonn Rüter
## Not run: impulses <- read.quitte(cfg$harmInfEmissionsFile) %>% emissionImpulseSenarios() %>% write_csv(cfg$emissionsImpulseFile, quote = "none") ## End(Not run)## Not run: impulses <- read.quitte(cfg$harmInfEmissionsFile) %>% emissionImpulseSenarios() %>% write_csv(cfg$emissionsImpulseFile, quote = "none") ## End(Not run)
Read yaml export configuration. It determines which variables to extract from the MAGICC7 climate assessment data &
to which file they are supposed to be written. Resulting data frame contains magicc7Variable, gamsVariable and
fileName columns.
exportConfFromYaml(yamlFileName = "default.yaml")exportConfFromYaml(yamlFileName = "default.yaml")
yamlFileName |
Location of the configuration file. Default is 'which_var_in_which_file.yaml' |
A tibble data frame containing the association between climate assessment and gams variable names
Tonn Rüter
Substitutes parts of MAGICC7 variable names to create REMIND compatible variable names
renameVariableMagicc7ToRemind(varName)renameVariableMagicc7ToRemind(varName)
varName |
Variable to be renamed |
Renamed variable
Tonn Rüter
Renames climate assessment variables given in the REMIND convetion MAGICC7 compatible variable names
renameVariableRemindToMagicc7(varName, magiccVersion = "7.5.3")renameVariableRemindToMagicc7(varName, magiccVersion = "7.5.3")
varName |
Variable to be renamed |
magiccVersion |
Version string of the MAGICC model in use. Default is "7.5.3" |
Renamed variable
Tonn Rüter
Returns a string represenatation of a climate assessment configuration
reportClimateAssessmentConfig(cfg)reportClimateAssessmentConfig(cfg)
cfg |
Path to default.cfg file |
A string detailing the configuration settings.
## Not run: cfg <- climateAssessmentConfig("<outputDir>", "iteration") report <- reportClimateAssessmentConfig(cfg) cat(report) ## End(Not run)## Not run: cfg <- climateAssessmentConfig("<outputDir>", "iteration") report <- reportClimateAssessmentConfig(cfg) cat(report) ## End(Not run)
This function takes a named vector of run times and generates a formatted report showing the duration of each run. The names of the run times must follow the pattern 'task_id_1 start' and 'task_id_1 end', where 'task_id_1' can be any string identifier.
runTimeReport(runTimes, prefix = "")runTimeReport(runTimes, prefix = "")
runTimes |
A named vector of run times |
prefix |
A string to prefix each line of the report. Default is "". |
A formatted string showing the duration of each run.
## Not run: # Typical usage: Set up as empty vector runTimes <- c() # [... run set up ...] runTimes <- c("task1 start" = Sys.time()) # [... run task1 ...] runTimes <- c("task1 end" = Sys.time()) # [... something untimed in between ...] runTimes <- c("task2 start" = Sys.time()) # [... run task2 ...] runTimes <- c("task2 end" = Sys.time()) runTimeReport(runTimes) ## End(Not run)## Not run: # Typical usage: Set up as empty vector runTimes <- c() # [... run set up ...] runTimes <- c("task1 start" = Sys.time()) # [... run task1 ...] runTimes <- c("task1 end" = Sys.time()) # [... something untimed in between ...] runTimes <- c("task2 start" = Sys.time()) # [... run task2 ...] runTimes <- c("task2 end" = Sys.time()) runTimeReport(runTimes) ## End(Not run)