-
Notifications
You must be signed in to change notification settings - Fork 7
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
148 fix target sda outputs #153
148 fix target sda outputs #153
Conversation
ref values are wrong to begin with, so i am commenting these out while I fix the code.
I will work on the code until this massive expect known_output test passes. After this, I will refactor the test into more meaningful chunks.
tests/testthat/test-target_sda.R
Outdated
test_that("with known input outputs as expected", { | ||
#TODO: Refactor this test into smaller isolated expected output tests | ||
matched <- fake_matched(sector_ald = "cement") | ||
|
||
ald <- fake_ald( | ||
sector = "cement", | ||
technology = "cement", | ||
name_company = c(rep("shaanxi auto", 4), "company 2"), | ||
year = c(2020, 2021, 2022, 2025, 2020), | ||
emission_factor = c(0.9, 0.9, 0.8, 0.5, 12) | ||
) | ||
|
||
|
||
co2_intensity_scenario <- fake_co2_scenario( | ||
scenario = c(rep("b2ds", 2), rep("sds", 2)), | ||
year = rep(c(2020, 2025), 2), | ||
emission_factor = c(0.5, 0.1, 0.5, 0.4) | ||
|
||
) | ||
|
||
out <- target_sda(matched, | ||
ald, | ||
co2_intensity_scenario) %>% | ||
arrange(.data$year) | ||
|
||
out <- split(out, out$emission_factor_metric) | ||
|
||
expected_out <- tibble::tribble( | ||
~sector, ~year, ~emission_factor_metric, ~emission_factor_value, | ||
"cement", 2020L, "projected", 0.9, | ||
"cement", 2021L, "projected", 0.9, | ||
"cement", 2022L, "projected", 0.8, | ||
"cement", 2025L, "projected", 0.5, | ||
"cement", 2020L, "target_b2ds", 0.9, | ||
"cement", 2025L, "target_b2ds", 1.29, | ||
"cement", 2020L, "target_sds", 0.9, | ||
"cement", 2025L, "target_sds", 5.16, | ||
"cement", 2020L, "adjusted_scenario_b2ds", 6.45, | ||
"cement", 2025L, "adjusted_scenario_b2ds", 1.29, | ||
"cement", 2020L, "adjusted_scenario_sds", 6.45, | ||
"cement", 2025L, "adjusted_scenario_sds", 5.16, | ||
"cement", 2020L, "corporate_economy", 6.45, | ||
"cement", 2021L, "corporate_economy", 0.9, | ||
"cement", 2022L, "corporate_economy", 0.8, | ||
"cement", 2025L, "corporate_economy", 0.5 | ||
) | ||
|
||
|
||
expect_equal(out$projected$emission_factor_value, c(0.9, 0.9, 0.8, 0.5)) | ||
expect_equal(out$corporate_economy$emission_factor_value, c(06.45, 0.9, 0.8, 0.5)) | ||
expect_equal(out$adjusted_scenario_b2ds$emission_factor_value, c(6.45, 1.29)) | ||
expect_equal(out$adjusted_scenario_sds$emission_factor_value, c(6.45, 5.16)) | ||
expect_equal(out$target_b2ds$emission_factor_value, c(0.9, 1.29)) | ||
expect_equal(out$target_sds$emission_factor_value, c(0.9, 5.16)) | ||
|
||
|
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test I am aiming to have pass
@maurolepore there are a few TODO's, that I wanted your input on, and still that |
tests/testthat/test-target_sda.R
Outdated
|
||
out <- split(out, out$emission_factor_metric) | ||
|
||
expected_out <- tibble::tribble( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why R CMD check complained. We import dplyr::tibble()
, not tibble::tibble()
.
We could import tibble in DESCRIPTION, then @importFrom tibble tibble
; but we already depend on dplyr, and it reexports tibble()
-- so we use dplyr::tibble()
. This is confusing.
tests/testthat/test-target_sda.R
Outdated
expected_out <- tribble( | ||
~sector, ~year, ~emission_factor_metric, ~emission_factor_value, | ||
"cement", 2020L, "projected", 0.9, | ||
"cement", 2021L, "projected", 0.9, | ||
"cement", 2022L, "projected", 0.8, | ||
"cement", 2025L, "projected", 0.5, | ||
"cement", 2020L, "target_b2ds", 0.9, | ||
"cement", 2025L, "target_b2ds", 1.29, | ||
"cement", 2020L, "target_sds", 0.9, | ||
"cement", 2025L, "target_sds", 5.16, | ||
"cement", 2020L, "adjusted_scenario_b2ds", 6.45, | ||
"cement", 2025L, "adjusted_scenario_b2ds", 1.29, | ||
"cement", 2020L, "adjusted_scenario_sds", 6.45, | ||
"cement", 2025L, "adjusted_scenario_sds", 5.16, | ||
"cement", 2020L, "corporate_economy", 6.45, | ||
"cement", 2021L, "corporate_economy", 0.9, | ||
"cement", 2022L, "corporate_economy", 0.8, | ||
"cement", 2025L, "corporate_economy", 0.5 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dead code? expected_out
seems unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup you are correct! Thanks
Just had a look, and all the changes look good to me. Once we sort the regression value issues out after the team meeting, lets merge this :) |
…dhoffa/r2dii.analysis into 148-enhance-target_sda-outputs
The original
target_sda
function had several places in which the output was unexpected. This was a result of basing the function off of a methodology document with errors.In this PR, I have already:
updated the
vignettes/target_sda.Rmd
to reflect the correct methodology (and reworded the article to make it more clear)temporarily removed regression tests that reflect potentially incorrect output
added on LARGE regression test, that reflects the correct output (including a new possibility to output several targets for several scenarios)
work on
target_sda()
until that large test passesrefactor that test into smaller more meaningful tests
Relates to #144, #145, #148