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

Initial value of technology_share differs between projected and target_* #277

Closed
jdhoffa opened this issue Feb 11, 2021 · 1 comment · Fixed by #294
Closed

Initial value of technology_share differs between projected and target_* #277

jdhoffa opened this issue Feb 11, 2021 · 1 comment · Fixed by #294
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@jdhoffa
Copy link
Member

jdhoffa commented Feb 11, 2021

The technology_share should be identical between the projected and target_* values at the start year of the analysis. In the reprex below, we can see that this is not the case.

I have a hunch as to why this is, I believe the target technology_share is being calculated the old way (dividing weighted_production by the sum of weighted_production). Need to explore how to solve this.

Thanks as always @georgeharris2deg

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.analysis)

matched <- tibble::tribble(
  ~id_loan, ~loan_size_outstanding, ~loan_size_outstanding_currency, ~loan_size_credit_limit, ~loan_size_credit_limit_currency, ~id_2dii,            ~level, ~score,      ~sector,   ~name_ald,  ~sector_ald,
  "L1",                      1,                           "EUR",                       2,                            "EUR",    "UP1", "ultimate_parent",      1, "automotive", "company a", "automotive",
  "L2",                      1,                           "EUR",                       2,                            "EUR",    "UP1", "ultimate_parent",      1, "automotive", "company b", "automotive"
)

ald <- tibble::tribble(
  ~name_company,      ~sector, ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
  "company a", "automotive",       "ice",  2020,         100,                1,            "BF",               TRUE,
  "company b", "automotive",       "ice",  2020,           1,                1,            "BF",               TRUE,
  "company a", "automotive",  "electric",  2020,         100,                1,            "BF",               TRUE,
  "company b", "automotive",  "electric",  2020,           3,                1,            "BF",               TRUE
)

scenario <- tibble::tribble(
  ~scenario,      ~sector, ~technology,  ~region, ~year, ~tmsr, ~smsp, ~scenario_source,
  "sds", "automotive",       "ice", "global",  2020,     1,     0,      "demo_2020",
  "sds", "automotive",  "electric", "global",  2020,     1,     0,      "demo_2020"
)

out <- target_market_share(matched, ald, scenario, region_isos_demo)

out %>% 
  filter(
    metric %in% c("projected", "target_sds"),
    year == 2020
    ) %>% 
  select(technology, metric, technology_share)
#> # A tibble: 4 x 3
#>   technology metric     technology_share
#>   <chr>      <chr>                 <dbl>
#> 1 electric   projected             0.625
#> 2 electric   target_sds            0.505
#> 3 ice        projected             0.375
#> 4 ice        target_sds            0.495

Created on 2021-02-11 by the reprex package (v1.0.0)

@jdhoffa jdhoffa self-assigned this Feb 11, 2021
@jdhoffa jdhoffa added the bug an unexpected problem or unintended behavior label Feb 11, 2021
@jdhoffa jdhoffa changed the title Large discrepancy with technology_share Initial value of technology_share differs between projected and target_* Feb 11, 2021
@jdhoffa
Copy link
Member Author

jdhoffa commented Feb 15, 2021

Getting into the guts of this problem, it seems that the first step will be a rather large refactoring of target_market_share.
I want to keep track of my thoughts here, my goal is to:

  • Refactor target_market_share so that the order of operations is: "calculate ald targets at company-level", "weight values (or not)", "calculate tech_share", "summarize (or not)". Open PR with just this, and ensure existing tests pass, with the incorrect tech_share
  • Implement correct calculation of tech_share targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant