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 prep_emissions_trajectory() #26

Closed
wants to merge 1 commit into from
Closed
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
92 changes: 75 additions & 17 deletions main.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,66 @@ prep_key_bars_portfolio <-
}


# -------------------------------------------------------------------------
# prep_emissions_trajectory ------------------------------------------------------
# based on pacta.portfolio.report:::prep_emissions_trajectory, but does not
# filter by scenario and scenario source

prep_emissions_trajectory <-
function(equity_results_portfolio,
bonds_results_portfolio,
portfolio_name,
pacta_sectors,
year_span,
start_year
) {
emissions_units <-
c(
Automotive = "tons of CO\U00002082 per km per cars produced",
Aviation = "tons of CO\U00002082 per passenger km per active planes",
Cement = "tons of CO\U00002082 per tons of cement",
Coal = "tons of CO\U00002082 per tons of coal",
`Oil&Gas` = "tons of CO\U00002082 per GJ",
Power = "tons of CO\U00002082 per MWh",
Steel = "tons of CO\U00002082 per tons of steel"
)
Comment on lines +411 to +420
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB/ unrelated to this PR but.... this seems very likely to fall out of sync 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'm not sure where to put it. It was baked-in to pacta.portfolio.report:::prep_emissions_trajectory(), so ported over here, unless/until it's available somewhere in a better format.


list(`Listed Equity` = equity_results_portfolio,
`Corporate Bonds` = bonds_results_portfolio) %>%
bind_rows(.id = "asset_class") %>%
filter(.data$portfolio_name == .env$portfolio_name) %>%
filter(.data$scenario_geography == "Global") %>%
select(
"asset_class",
"allocation",
"equity_market",
sector = "ald_sector",
"year",
plan = "plan_sec_emissions_factor",
scen = "scen_sec_emissions_factor",
"scenario",
"scenario_source"
) %>%
distinct() %>%
filter(!is.nan(.data$plan)) %>%
pivot_longer(c("plan", "scen"), names_to = "plan") %>%
unite("name", "sector", "plan", remove = FALSE) %>%
mutate(disabled = !.data$sector %in% .env$pacta_sectors) %>%
mutate(unit = .env$emissions_units[.data$sector]) %>%
group_by(.data$asset_class) %>%
filter(!all(.data$disabled)) %>%
mutate(equity_market = case_when(
.data$equity_market == "GlobalMarket" ~ "Global Market",
.data$equity_market == "DevelopedMarket" ~ "Developed Market",
.data$equity_market == "EmergingMarket" ~ "Emerging Market",
TRUE ~ .data$equity_market)
) %>%
filter(.data$year <= .env$start_year + .env$year_span) %>%
arrange(.data$asset_class, factor(.data$equity_market, levels = c("Global Market", "Developed Market", "Emerging Market"))) %>%
ungroup()
}


# input and output directories -------------------------------------------------

input_dir <- "./inputs"
Expand Down Expand Up @@ -665,23 +725,7 @@ pacta.portfolio.report:::prep_trajectory_alignment(
jsonlite::write_json(path = file.path(output_dir, "data_trajectory_alignment.json"))


# data_emissions.json ----------------------------------------------------------

pacta.portfolio.report:::prep_emissions_trajectory(
equity_results_portfolio = equity_results_portfolio,
bonds_results_portfolio = bonds_results_portfolio,
investor_name = investor_name,
portfolio_name = portfolio_name,
select_scenario_other = select_scenario_other,
select_scenario = select_scenario,
pacta_sectors = pacta_sectors,
year_span = year_span,
start_year = start_year
) %>%
pacta.portfolio.report:::translate_df_contents("data_emissions", dictionary) %>%
jsonlite::write_json(path = file.path(output_dir, "data_emissions.json"))

# data_exposure_stats.json
# data_exposure_stats.json -----------------------------------------------------

prep_exposure_stats(
audit_file = audit_file,
Expand Down Expand Up @@ -731,3 +775,17 @@ prep_key_bars_portfolio(
) %>%
pacta.portfolio.report:::translate_df_contents("data_key_bars_portfolio", dictionary) %>%
jsonlite::write_json(path = file.path(output_dir, "data_techexposure_company_portfolio.json"))


# data_emissions.json ----------------------------------------------------------

prep_emissions_trajectory(
equity_results_portfolio = equity_results_portfolio,
bonds_results_portfolio = bonds_results_portfolio,
portfolio_name = portfolio_name,
pacta_sectors = pacta_sectors,
year_span = year_span,
start_year = start_year
) %>%
pacta.portfolio.report:::translate_df_contents("data_emissions", dictionary) %>%
jsonlite::write_json(path = file.path(output_dir, "data_emissions.json"))