From 4c5008912d74d78dbedda96e90820d531c850ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Thu, 14 Mar 2024 14:18:28 +0100 Subject: [PATCH 1/3] Corrected variable name for remindReportingFile --- scripts/output/single/ar6Climate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/single/ar6Climate.R b/scripts/output/single/ar6Climate.R index 5ddd4feb2..e276a877e 100644 --- a/scripts/output/single/ar6Climate.R +++ b/scripts/output/single/ar6Climate.R @@ -224,7 +224,7 @@ climateAssessmentData <- read.quitte(climateAssessmentOutput) %>% interpolate_missing_periods(usePeriods, expand.values = FALSE) %>% write.mif(remindReportingFile, append = TRUE) -deletePlus(remind_reporting_file, writemif = TRUE) +deletePlus(remindReportingFile, writemif = TRUE) logmsg <- paste0( date(), " postprocessing done! Results appended to REMIND mif '", remindReportingFile, "'\n", From 4fbf3fa47896c68d39c92a2ffc88033cd8997b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Thu, 14 Mar 2024 14:43:00 +0100 Subject: [PATCH 2/3] Fixed variable names, log messaging --- scripts/output/single/ar6Climate.R | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/output/single/ar6Climate.R b/scripts/output/single/ar6Climate.R index e276a877e..5964b6a9d 100644 --- a/scripts/output/single/ar6Climate.R +++ b/scripts/output/single/ar6Climate.R @@ -146,7 +146,7 @@ Sys.setenv(MAGICC_WORKER_NUMBER = 1) # TODO: Get this from slurm or nproc #activate_venv_cmd <- paste("source", normalizePath(file.path(cfg$climate_assessment_root, "..", "venv", "bin", "activate"))) #deactivate_venv_cmd <- "deactivate" -run_harm_inf_cmd <- paste( +runHarmoniseAndInfillCmd <- paste( "python", file.path(scriptsFolder, "run_harm_inf.py"), climateAssessmentEmi, climateAssessmentFolder, @@ -154,7 +154,7 @@ run_harm_inf_cmd <- paste( "--infilling-database", infillingDatabaseFile ) -run_clim_cmd <- paste( +runClimateEmulatorCmd <- paste( "python", file.path(scriptsFolder, "run_clim.py"), normalizePath(file.path(climateAssessmentFolder, paste0(baseFileName, "_harmonized_infilled.csv"))), climateAssessmentFolder, @@ -176,14 +176,14 @@ logmsg <- paste0( " MAGICC_WORKER_ROOT_DIR = ", Sys.getenv("MAGICC_WORKER_ROOT_DIR") ,"\n", " MAGICC_WORKER_NUMBER = ", Sys.getenv("MAGICC_WORKER_NUMBER") ,"\n", date(), " =================== RUN climate-assessment infilling & harmonization ===================\n", - run_harm_inf_cmd, "'\n" + runHarmoniseAndInfillCmd, "'\n" ) cat(logmsg) capture.output(cat(logmsg), file = logFile, append = TRUE) ############################# HARMONIZATION/INFILLING ############################# -system(run_harm_inf_cmd) +system(runHarmoniseAndInfillCmd) logmsg <- paste0(date(), " Done with harmonization & infilling\n") cat(logmsg) @@ -192,14 +192,15 @@ capture.output(cat(logmsg), file = logFile, append = TRUE) ############################# RUNNING MODEL ############################# logmsg <- paste0( - date(), " Found ", nparsets, " nparsets, start climate-assessment model runs\n", run_harm_inf_cmd, "\n", + date(), " Found ", nparsets, " nparsets, start climate-assessment climate emulator step\n", + runHarmoniseAndInfillCmd, "\n", date(), " =================== RUN climate-assessment model ============================\n", - run_clim_cmd, "'\n" + runClimateEmulatorCmd, "'\n" ) cat(logmsg) capture.output(cat(logmsg), file = logFile, append = TRUE) -system(run_clim_cmd) +system(runClimateEmulatorCmd) ############################# POSTPROCESS CLIMATE OUTPUT ############################# climateAssessmentOutput <- file.path( @@ -208,7 +209,7 @@ climateAssessmentOutput <- file.path( ) logmsg <- paste0( - date(), " climate-assessment finished\n", + date(), " climate-assessment climate emulator finished\n", date(), " =================== POSTPROCESS climate-assessment output ==================\n", " climateAssessmentOutput = '", climateAssessmentOutput, "'\n" ) From a3d1fcf3204259446946891ee6d0eabea6a1bd8f Mon Sep 17 00:00:00 2001 From: orichters Date: Thu, 14 Mar 2024 14:01:56 +0100 Subject: [PATCH 3/3] adjust MAGICC7_AR6 --- CHANGELOG.md | 2 ++ DESCRIPTION | 6 ++-- output.R | 2 +- scripts/cs2/MAGICC7_AR6.Rmd | 36 +++++++++++++++++++ scripts/cs2/profiles.json | 4 +++ scripts/output/comparison/varListHtml.R | 6 ++-- .../single/{ar6Climate.R => MAGICC7_AR6.R} | 10 +++--- .../output/single/checkProjectSummations.R | 2 +- 8 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 scripts/cs2/MAGICC7_AR6.Rmd rename scripts/output/single/{ar6Climate.R => MAGICC7_AR6.R} (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b18c320..bc9c6dd83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **core** change of preference parameters and associated computation of interest rates/mark ups - **scripts** add script to automatically check project summations from piamInterfaces [[#1587](https://github.com/remindmodel/remind/pull/1587)] +- **scripts** add compareScenarios section for MAGICC7 AR6 output + [[#1615](https://github.com/remindmodel/remind/pull/1615) ### fixed - fixed weights of energy carriers in `pm_IndstCO2Captured` diff --git a/DESCRIPTION b/DESCRIPTION index b665cea18..8cd5d6804 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Imports: data.table, devtools, dplyr, - edgeTransport, + edgeTransport (>= 1.5.4), flexdashboard, GDPuc, gdx, @@ -43,7 +43,7 @@ Imports: magclass, magpie4, magpiesets, - mip, + mip (>= 0.148.11), modelstats, mrremind, mrvalidation, @@ -51,7 +51,7 @@ Imports: nleqslv, optparse, piamenv (>= 0.4.0), - piamInterfaces (>= 0.15.1), + piamInterfaces (>= 0.15.2), plotly, purrr, quitte (>= 0.3128.4), diff --git a/output.R b/output.R index e2a0d9943..eb09f8fd8 100755 --- a/output.R +++ b/output.R @@ -137,7 +137,7 @@ if (! exists("output")) { # Select output directories if not defined by readArgs if (! exists("outputdir")) { modulesNeedingMif <- c("compareScenarios2", "xlsx_IIASA", "policyCosts", "Ariadne_output", - "plot_compare_iterations", "varListHtml", "fixOnRef") + "plot_compare_iterations", "varListHtml", "fixOnRef", "MAGICC7_AR6") needingMif <- any(modulesNeedingMif %in% output) if (exists("remind_dir")) { dir_folder <- c(file.path(remind_dir, "output"), remind_dir) diff --git a/scripts/cs2/MAGICC7_AR6.Rmd b/scripts/cs2/MAGICC7_AR6.Rmd new file mode 100644 index 000000000..b0e9c3e62 --- /dev/null +++ b/scripts/cs2/MAGICC7_AR6.Rmd @@ -0,0 +1,36 @@ + +# Climate + +```{r MAGICC6} +showLinePlots(data, "Forcing") +showLinePlots(data, "Temperature|Global Mean") +``` + +# MAGICC7 AR6 Climate + +```{r Climate} + +allmagiccvar <- grep("^MAGICC7.*50\\.0th Percentile", unique(data$variable), value = TRUE) +mainmagiccvar <- c("Surface Temperature (GSAT)", "Atmospheric Concentrations|CO2", + "Effective Radiative Forcing|Basket|Anthropogenic") +mainmagiccvar <- paste0("MAGICC7 AR6|", mainmagiccvar, "|50.0th Percentile") +allmagiccvar <- unique(c(mainmagiccvar, allmagiccvar)) # main first + +if (length(allmagiccvar) == 0) { + print("No MAGICC7 data found, run output.R -> single -> MAGICC7_AR6") +} else { + for (mv in allmagiccvar) { + showLinePlots(data, mv) + print(plotPercentiles(data, variables = gsub("|50.0th Percentile", "", mv, fixed = TRUE))) + cat("\n\n") + } +} + +``` diff --git a/scripts/cs2/profiles.json b/scripts/cs2/profiles.json index 148bf2a82..cce22ea5f 100644 --- a/scripts/cs2/profiles.json +++ b/scripts/cs2/profiles.json @@ -44,6 +44,10 @@ "sections": "0", "userSectionPath": "normalizePath('./scripts/cs2/magpie.Rmd')" }, + "MAGICC7_AR6": { + "sections": "0", + "userSectionPath": "normalizePath('./scripts/cs2/MAGICC7_AR6.Rmd')" + }, "mySection": { "sections": "0", "userSectionPath": "normalizePath('./scripts/cs2/mySection.Rmd')" diff --git a/scripts/output/comparison/varListHtml.R b/scripts/output/comparison/varListHtml.R index 159564e31..d242c425c 100644 --- a/scripts/output/comparison/varListHtml.R +++ b/scripts/output/comparison/varListHtml.R @@ -31,12 +31,12 @@ mifs <- c( details <- readr::read_delim( - "https://raw.githubusercontent.com/pik-piam/project_interfaces/master/ar6/mapping_template_AR6.csv", + "https://raw.githubusercontent.com/pik-piam/piamInterfaces/master/inst/templates/mapping_template_AR6.csv", delim = ";", - col_select = c(r21m42, Definition), + col_select = c(piam_variable, Definition), col_types = "cc" ) |> - dplyr::rename(name = r21m42) + dplyr::rename(name = piam_variable) remind2::createVarListHtml( x = mifs, diff --git a/scripts/output/single/ar6Climate.R b/scripts/output/single/MAGICC7_AR6.R similarity index 96% rename from scripts/output/single/ar6Climate.R rename to scripts/output/single/MAGICC7_AR6.R index 5ddd4feb2..8a809cfee 100644 --- a/scripts/output/single/ar6Climate.R +++ b/scripts/output/single/MAGICC7_AR6.R @@ -61,7 +61,7 @@ logmsg <- paste0( " climateAssessmentYaml = '", climateAssessmentYaml, "' exists? ", file.exists(climateAssessmentYaml), "\n", " climateAssessmentEmi = '", climateAssessmentEmi, "' exists? ", file.exists(climateAssessmentEmi), "\n", date(), " =================== EXTRACT REMIND emission data ===========================\n", - " ar6Climate.R: Extracting REMIND emission data\n" + " MAGICC7_AR6.R: Extracting REMIND emission data\n" ) cat(logmsg) capture.output(cat(logmsg), file = logFile, append = TRUE) @@ -87,7 +87,7 @@ climateAssessmentInputData <- as.quitte(remindReportingFile) %>% write_csv(climateAssessmentEmi, quote = "none") logmsg <- paste0( - date(), " ar6Climate.R: Wrote REMIND emission data to '", climateAssessmentEmi, "' for climate-assessment\n" + date(), " MAGICC7_AR6.R: Wrote REMIND emission data to '", climateAssessmentEmi, "' for climate-assessment\n" ) cat(logmsg) capture.output(cat(logmsg), file = logFile, append = TRUE) @@ -222,13 +222,15 @@ usePeriods <- as.numeric(grep("[0-9]+", quitte::read_mif_header(remindReportingF climateAssessmentData <- read.quitte(climateAssessmentOutput) %>% filter(period %in% usePeriods) %>% interpolate_missing_periods(usePeriods, expand.values = FALSE) %>% + mutate(variable = gsub("|MAGICCv7.5.3", "", .data$variable, fixed = TRUE)) %>% + mutate(variable = gsub("AR6 climate diagnostics|", "MAGICC7 AR6|", .data$variable, fixed = TRUE)) %>% write.mif(remindReportingFile, append = TRUE) -deletePlus(remind_reporting_file, writemif = TRUE) +deletePlus(remindReportingFile, writemif = TRUE) logmsg <- paste0( date(), " postprocessing done! Results appended to REMIND mif '", remindReportingFile, "'\n", - "ar6Climate.R finished\n" + "MAGICC7_AR6.R finished\n" ) cat(logmsg) capture.output(cat(logmsg), file = logFile, append = TRUE) diff --git a/scripts/output/single/checkProjectSummations.R b/scripts/output/single/checkProjectSummations.R index 530b66443..dbb6b0a37 100644 --- a/scripts/output/single/checkProjectSummations.R +++ b/scripts/output/single/checkProjectSummations.R @@ -24,7 +24,7 @@ gases <- c("BC", "CO", "CO2", "Kyoto Gases", "NOx", "OC", "Sulfur", "VOC") vars <- c("", "|Energy", "|Energy Demand|Transportation", "|Energy and Industrial Processes", "|Energy|Demand", "|Energy|Demand|Transportation") gasvars <- expand.grid(gases, vars, stringsAsFactors = FALSE) -bunkervars <- unique(sort(paste0("Emissions|", gasvars$Var1, gasvars$Var2))) +bunkervars <- unique(sort(c("Gross Emissions|CO2", paste0("Emissions|", gasvars$Var1, gasvars$Var2)))) for (template in c("AR6", "NAVIGATE")) { message("\n### Check project summations for ", template)