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

bug: non-unique technologies across sectors produce wrong scenario target values #495

Closed
jacobvjk opened this issue May 6, 2024 · 2 comments · Fixed by #496
Closed

bug: non-unique technologies across sectors produce wrong scenario target values #495

jacobvjk opened this issue May 6, 2024 · 2 comments · Fixed by #496
Assignees
Labels
ADO Maintenance Day! bug an unexpected problem or unintended behavior priority

Comments

@jacobvjk
Copy link
Member

jacobvjk commented May 6, 2024

When we have abcd that have only one technology in a sector (e.g. ice) for company X, the target market share should produce scenario target values for all technologies within the sector for this company (e.g. also for hybrid and electric). When the name of the technology is not unique to the given sector, this is not the case however, it will only return scenario targets for the existing technology. Specifically, this can be a problem in case users have a P4B abcd that includes automotive and hdv, which are treated as separate sectors but share technology names

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)
library(r2dii.analysis)

lbk <- 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_abcd, ~sector_abcd,
  "L162", 1, "EUR", 2, "EUR", "UP1", "ultimate_parent", 1, "automotive", "shaanxi auto", "automotive"
)

abcd_good <- tibble::tribble(
  ~name_company, ~sector, ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
  "shaanxi auto", "automotive", "ice", 2020, 1, 1, "BF", TRUE,
  "shaanxi auto", "automotive", "ice", 2025, 1, 1, "BF", TRUE
)

result_comp_good <- r2dii.analysis::target_market_share(
  data = lbk,
  abcd = abcd_good,
  scenario = r2dii.data::scenario_demo_2020,
  region_isos = r2dii.data::region_isos_demo,
  by_company = TRUE,
  weight_production = FALSE
)

result_lbk_good <- r2dii.analysis::target_market_share(
  data = lbk,
  abcd = abcd_good,
  scenario = r2dii.data::scenario_demo_2020,
  region_isos = r2dii.data::region_isos_demo,
  by_company = FALSE,
  weight_production = TRUE
)

abcd_bad <- tibble::tribble(
  ~name_company, ~sector, ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
  "shaanxi auto", "automotive", "ice", 2020, 1, 1, "BF", TRUE,
  "shaanxi auto", "automotive", "ice", 2025, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "ice", 2020, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "ice", 2025, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "hybrid", 2020, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "hybrid", 2025, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "electric", 2020, 1, 1, "BF", TRUE,
  "shaanxi auto", "hdv", "electric", 2025, 1, 1, "BF", TRUE
)

result_comp_bad <- r2dii.analysis::target_market_share(
  data = lbk,
  abcd = abcd_bad,
  scenario = r2dii.data::scenario_demo_2020,
  region_isos = r2dii.data::region_isos_demo,
  by_company = TRUE,
  weight_production = FALSE
)

result_lbk_bad <- r2dii.analysis::target_market_share(
  data = lbk,
  abcd = abcd_bad,
  scenario = r2dii.data::scenario_demo_2020,
  region_isos = r2dii.data::region_isos_demo,
  by_company = FALSE,
  weight_production = TRUE
)

lbk %>% dplyr::distinct(name_abcd, sector)
#> # A tibble: 1 × 2
#>   name_abcd    sector    
#>   <chr>        <chr>     
#> 1 shaanxi auto automotive

r2dii.data::scenario_demo_2020 %>%
  dplyr::filter(sector == "automotive", region == "global") %>% 
  dplyr::distinct(sector, technology)
#> # A tibble: 3 × 2
#>   sector     technology
#>   <chr>      <chr>     
#> 1 automotive electric  
#> 2 automotive hybrid    
#> 3 automotive ice

result_comp_good %>% dplyr::distinct(name_abcd, sector, technology)
#> # A tibble: 4 × 3
#>   name_abcd         sector     technology
#>   <chr>             <chr>      <chr>     
#> 1 shaanxi auto      automotive electric  
#> 2 shaanxi auto      automotive hybrid    
#> 3 shaanxi auto      automotive ice       
#> 4 corporate_economy automotive ice
result_comp_bad %>% dplyr::distinct(name_abcd, sector, technology)
#> # A tibble: 2 × 3
#>   name_abcd         sector     technology
#>   <chr>             <chr>      <chr>     
#> 1 shaanxi auto      automotive ice       
#> 2 corporate_economy automotive ice

result_lbk_good %>% dplyr::distinct(sector, technology)
#> # A tibble: 3 × 2
#>   sector     technology
#>   <chr>      <chr>     
#> 1 automotive electric  
#> 2 automotive hybrid    
#> 3 automotive ice
result_lbk_bad %>% dplyr::distinct(sector, technology)
#> # A tibble: 1 × 2
#>   sector     technology
#>   <chr>      <chr>     
#> 1 automotive ice

Created on 2024-05-06 with reprex v2.1.0

AB#10949

@jacobvjk jacobvjk added bug an unexpected problem or unintended behavior ADO Maintenance Day! priority labels May 6, 2024
@jacobvjk jacobvjk self-assigned this May 6, 2024
@jacobvjk jacobvjk changed the title bug: non unique technologies across sectors produce wrong scenario target values bug: non-unique technologies across sectors produce wrong scenario target values May 6, 2024
@jdhoffa
Copy link
Member

jdhoffa commented May 6, 2024

@jacobvjk shall we get this ticket into this sprint? since it is a bug.

If you have capacity, I would just put it directly in this sprint.

@jacobvjk
Copy link
Member Author

jacobvjk commented May 7, 2024

@jacobvjk shall we get this ticket into this sprint? since it is a bug.

If you have capacity, I would just put it directly in this sprint.

Absolutely, just did not manage to get the ticket ready in time for the sprint planning

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 priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants