Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate_metric_from_name() splits up some scenario names wrong #425

Closed
jacobvjk opened this issue Dec 12, 2022 · 0 comments · Fixed by #464
Closed

separate_metric_from_name() splits up some scenario names wrong #425

jacobvjk opened this issue Dec 12, 2022 · 0 comments · Fixed by #464
Assignees
Labels
ADO Maintenance Day! bug an unexpected problem or unintended behavior small Likely finished in under a day

Comments

@jacobvjk
Copy link
Member

When running target_market_share on a scenario that has a name which includes a dash, separate_metric_from_name() will wrongly split everything after the dash and drop that part of the name.

While the calculation does not necessarily fail, this generates a warning and produces inconsistent scenario names between input and output (see reprex below).

Note that this can be problematic, if one were to use geco_2021 scenarios for 1.5c-unif and 1.5c-diff. The scenarios names in the result would be indistinguishable.


library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(r2dii.data)
library(r2dii.match)


scenario_test <- tibble::tribble(
  ~scenario_source,   ~scenario, ~sector,     ~technology,  ~region, ~year,              ~tmsr,                  ~smsp,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2021L,                  1,                      0,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2022L,  0.980550658847261,   -0.00533815150443876,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2022L,   1.03354175921615,      0.007450150681128,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2022L,   1.00999497266883,     0.0019055064844559,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2022L,    1.0211760246908,    0.00102774473801909,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2022L,  0.996148327056334,  -0.000188168602196809,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2022L,   1.16216522079607,     0.0349281658652597,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2023L,  0.961101317694522,    -0.0106763030088775,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2023L,    1.0670835184323,      0.014900301362256,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2023L,   1.01998994533766,    0.00381101296891184,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2023L,    1.0423520493816,    0.00205548947603818,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2023L,  0.992296654112668,  -0.000376337204393625,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2023L,   1.32433044159215,     0.0698563317305194,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2024L,  0.941651976541783,    -0.0160144545133162,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2024L,   1.10062527764846,      0.022350452043384,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2024L,   1.02998491800648,    0.00571651945336774,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2024L,    1.0635280740724,    0.00308323421405727,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2024L,  0.988444981169002,  -0.000564505806590434,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2024L,   1.48649566238822,      0.104784497595779,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2025L,  0.922202635389044,     -0.021352606017755,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2025L,   1.13416703686461,      0.029800602724512,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2025L,   1.03997989067531,    0.00762202593782364,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2025L,    1.0847040987632,    0.00411097895207636,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2025L,  0.984593308225336,  -0.000752674408787243,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2025L,   1.64866088318429,      0.139712663461039,
       "test_2021", "1.5c-scen", "power",       "coalcap", "global", 2026L,   0.88869003909333,    -0.0305506202295842,
       "test_2021", "1.5c-scen", "power",        "gascap", "global", 2026L,   1.15655075755489,     0.0347723780828709,
       "test_2021", "1.5c-scen", "power",      "hydrocap", "global", 2026L,   1.05502014053871,     0.0104893968243815,
       "test_2021", "1.5c-scen", "power",    "nuclearcap", "global", 2026L,   1.22288798195939,     0.0108175143338382,
       "test_2021", "1.5c-scen", "power",        "oilcap", "global", 2026L,    1.0149329550691,   0.000729530602187077,
       "test_2021", "1.5c-scen", "power", "renewablescap", "global", 2026L,   2.02141641037022,      0.219999094897005
  )


region_isos_test <- r2dii.data::region_isos %>% 
  dplyr::filter(source == "geco_2021", region == "global") %>% 
  dplyr::mutate(source = "test_2021")

matched <- match_name(r2dii.data::loanbook_demo, r2dii.data::abcd_demo) %>%
  prioritize()

tms <- r2dii.analysis::target_market_share(
  data = matched,
  abcd = r2dii.data::abcd_demo,
  scenario = scenario_test,
  region_isos = region_isos_test
)
#> Warning: Expected 2 pieces. Additional pieces discarded in 72 rows [3, 4, 7, 8,
#> 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31, 32, 35, 36, 39, 40, ...].

unique(scenario_test$scenario)
#> [1] "1.5c-scen"

unique(tms$metric)
#> [1] "projected"         "target_1.5c"       "corporate_economy"
Created on 2022-12-12 with [reprex v2.0.2](https://reprex.tidyverse.org/)
@jacobvjk jacobvjk added the bug an unexpected problem or unintended behavior label Dec 12, 2022
@jdhoffa jdhoffa added small Likely finished in under a day ADO Maintenance Day! labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADO Maintenance Day! bug an unexpected problem or unintended behavior small Likely finished in under a day
Projects
None yet
2 participants