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

add correct missing low carbon technologies to abcd #496

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/join_abcd_scenario.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ add_green_technologies_to_abcd <- function(data, scenario) {
unique() %>%
inner_join(increasing_techs, by = c("sector", "technology"))

increasing_techs_not_in_abcd <- dplyr::filter(
increasing_techs_not_in_abcd <- dplyr::anti_join(
increasing_techs_in_scenario,
!(.data[["technology"]] %in% unique(data$technology))
data,
by = c("sector", "technology")
)

# TODO: the summarize should be replaced with a distinct. the left_join should be an inner_join to avoid adding NAs
jacobvjk marked this conversation as resolved.
Show resolved Hide resolved
green_rows_to_add <- data %>%
group_by(
.data$name_company,
Expand Down
72 changes: 72 additions & 0 deletions tests/testthat/test-target_market_share.R
Original file line number Diff line number Diff line change
Expand Up @@ -1494,3 +1494,75 @@ test_that("with duplicated id_loan throws informative error (#489)", {
class = "unique_ids"
)
})

test_that("target_market_share() calculates target_* values for missing low carbon technologies (#495)", {
match_result <- fake_matched(name_abcd = "company a")

abcd <- fake_abcd(
name_company = "company a",
sector = c(rep("automotive", 2), rep("hdv", 6)),
technology = c(rep("ice", 4), rep("hybrid", 2), rep("electric", 2)),
year = rep(c(2020, 2025), 4)
)

scen <- fake_scenario(
sector = "automotive",
technology = c(rep("ice", 2), rep("hybrid", 2), rep("electric", 2)),
year = rep(c(2020, 2025), 3),
tmsr = c(1, 0.5, 1, 1.5, 1, 1.5),
smsp = c(0, -0.08, 0, 0.1, 0, 0.1)
)

scen_technologies <- scen %>%
dplyr::filter(.data$sector == "automotive") %>%
dplyr::arrange(.data$technology) %>%
dplyr::distinct(.data$technology) %>%
dplyr::pull()

results_tms_comp <- target_market_share(
match_result,
abcd,
scen,
region_isos = region_isos_stable,
by_company = TRUE,
weight_production = FALSE
)

results_tms_comp_targets <- results_tms_comp %>%
dplyr::filter(
.data$name_abcd == "company a",
.data$sector == "automotive",
grepl("target_", .data$metric)
) %>%
dplyr::arrange(.data$technology) %>%
dplyr::distinct(.data$technology) %>%
dplyr::pull()

expect_equal(
results_tms_comp_targets,
scen_technologies
)

results_tms_lbk <- target_market_share(
match_result,
abcd,
scen,
region_isos = region_isos_stable,
by_company = FALSE,
weight_production = TRUE
)

results_tms_lbk_targets <- results_tms_lbk %>%
dplyr::filter(
.data$sector == "automotive",
grepl("target_", .data$metric)
) %>%
dplyr::arrange(.data$technology) %>%
dplyr::distinct(.data$technology) %>%
dplyr::pull()

expect_equal(
results_tms_lbk_targets,
scen_technologies
)
})
Loading