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

use final common year across sectors as limit for p4b scenarios #60

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all 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
30 changes: 26 additions & 4 deletions format_scenarios_for_p4b.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ final_year <- dplyr::summarise(
.by = "source"
)

final_year <- min(final_year$final_year_source, na.rm = TRUE)

logger::log_info("Define interpolation groups for interpolation of yearly values.")

interpolation_groups <- c(
Expand All @@ -81,10 +79,22 @@ scenario_input_p4b <- pacta.scenario.data.preparation::interpolate_yearly(
scenario_input_p4b <- dplyr::filter(
scenario_input_p4b,
.data$year >= .env$reference_year,
.data$year <= .env$final_year,
.data$sector %in% .env$market_share_sectors
)

final_year_by_sector_market_share <- dplyr::summarise(
scenario_input_p4b,
final_year = max(.data$year, na.rm = TRUE),
.by = "sector"
)

final_year_market_share <- min(final_year_by_sector_market_share$final_year, na.rm = TRUE)

scenario_input_p4b <- dplyr::filter(
scenario_input_p4b,
.data$year <= .env$final_year_market_share
)

scenario_input_p4b <- pacta.scenario.data.preparation::add_market_share_columns(
data = scenario_input_p4b,
reference_year = reference_year
Expand Down Expand Up @@ -119,10 +129,22 @@ scenario_input_p4b_ei <- pacta.scenario.data.preparation::interpolate_yearly(
scenario_input_p4b_ei <- dplyr::filter(
scenario_input_p4b_ei,
.data$year >= .env$reference_year,
.data$year <= .env$final_year,
.data$sector %in% .env$emission_intensity_sectors
)

final_year_by_sector_ei <- dplyr::summarise(
scenario_input_p4b,
final_year = max(.data$year, na.rm = TRUE),
.by = "sector"
)

final_year_ei <- min(final_year_by_sector_ei$final_year, na.rm = TRUE)

scenario_input_p4b <- dplyr::filter(
scenario_input_p4b,
.data$year <= .env$final_year_ei
)

scenario_input_p4b_ei <- pacta.scenario.data.preparation::format_p4b_ei(scenario_input_p4b_ei)

if (pacta.data.validation::validate_intermediate_scenario_output(scenarios_p4b)) {
Expand Down