Skip to content

Commit

Permalink
Reorganize CBE for a state. Automated references not working for HTML…
Browse files Browse the repository at this point in the history
… output. issue #29. See notes below

-add table for CBE totals and then move territorial inventory comparison up
-remove by region consumption analysis
- add figures for both per $ and per resident intensities
  • Loading branch information
WesIngwersen committed Dec 26, 2024
1 parent d6b8ce9 commit ab6c351
Showing 1 changed file with 104 additions and 188 deletions.
292 changes: 104 additions & 188 deletions examples/StateCBE.Rmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
title: Consumption-Based Greenhouse Gas Emissions Results for `r params$state` for `r min(params$years)`- `r max(params$years)`
title: Consumption-Based Greenhouse Gas Emissions Results for `r params$state` for `r min(params$years)`-`r max(params$years)`
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
bookdown::html_document2:
default
officedown::rdocx_document:
fig_caption: true
bookdown::html_document2:
fig_caption: yes
params:
model:
label: "Model Type"
Expand Down Expand Up @@ -35,19 +33,23 @@ install_useeior()
source("../R/StateEEIOFigures.R")
source("../R/StateEEIOCalculations.R")
library(useeior)
# devtools::load_all("../../useeior/") # Requires develop branch (to be v1.6.1)
library(knitr)
# Stop execution of Rmd if params not selected
if (params$state=="" || length(params$year) < 2) {
stop("You must select a state and at least two years.")
}
## Select model build parameters
#Select model build parameters
state <- params$state
years <- params$years
spec <- params$model
focal_year <- max(years)
#state <- "WA"
#years <- c(2012:2020)
#spec <- "v1.1-GHG"
focal_year <- 2019
indicator <- "Greenhouse Gases"
Expand Down Expand Up @@ -78,27 +80,17 @@ for(y in years) {
```

#
#*List of Figures*
```{r echo=FALSE}
#library(officedown)
#library(officer)
#block_toc(seq_id = "fig") # or "tab" for #ables
# block_toc(style = "Image Caption") # or #"Table Caption" for tables
```

#*List of Tables*
```{r echo=FALSE}
#block_toc(seq_id = "tab")
```

A consumption-based emissions inventory (CBEI) is an accounting method that can be applied to a region, including a state, that quantifies emissions associated with all goods and services consumed by a state, regardless of their origin.
This approach allows these regions to account for more complete emissions caused by the consumption of goods in their region.

This document presents summary CBEI results for **`r state`** for the years **`r paste0(min(years), "-", max(years))`**.
Further details on the methods for calculating consumption based emissions (CBE) and interpreting CBEI results can be found in the associated EPA Report, [Consumption-Based Greenhouse Gas Inventories for Northeastern States](https://cfpub.epa.gov/si/si_public_search_results.cfm?simpleSearch=0&showCriteria=2&sortBy=pubDate&searchAll=consumption-based&TIMSType=Published+Report).
This document presents summary consumption-based emission (CBE) results for **`r state`** for the years **`r paste0(min(years), "-", max(years))`**.
These results were generated using USEEIO State models along with state-specific territorial GHG inventories estimated by EPA.
Further details on the methods for calculating consumption based emissions and interpreting the results can be found in the associated EPA Report, [Consumption-Based Greenhouse Gas Inventories for Northeastern States](https://cfpub.epa.gov/si/si_public_record_Report.cfm?dirEntryId=352619&Lab=CESER).


# Total Consumption-Based Emissions

```{r calculate_results, include=FALSE}
```{r calculate_results, include=FALSE, echo=FALSE}
cbe_all <- sapply(models,calculateStateCBE,simplify=TRUE,USE.NAMES=TRUE)
row.names(cbe_all) <- row.names(calculateStateCBE(models[[1]]))
Expand All @@ -107,94 +99,42 @@ cbe_agg_soi <- aggregateStateResultMatrix(models[[1]], cbe_all, region=state)
cbe_agg_rous <- aggregateStateResultMatrix(models[[1]], cbe_all, region='RoUS')
cbe_agg_row <- aggregateStateResultMatrix(models[[1]], cbe_all, region='RoW')
cbe_agg <- cbe_agg_soi + cbe_agg_rous + cbe_agg_row
households_all <- sapply(models, calculateHouseholdShares, indicator=indicator, simplify=TRUE, USE.NAMES=TRUE)
rownames(households_all) <- rownames(calculateHouseholdShares(models[[1]], indicator))
#households_all <- readRDS("../models/households_all.RDS")
```
result_code_loc <- gsub(models[[1]]$specs$ModelRegionAcronyms[1], "SoI", row.names(cbe_all[[1]]))
cbe_all_total <- matrix(unlist(cbe_all), ncol=length(cbe_all), dimnames=list(result_code_loc,names(cbe_all)))
```{r cbe_results, echo=FALSE, results='asis', fig.height=4, fig.width=6.5, warning=FALSE}
cbe_by_year_list <- c()
for(y in years) {
col <- paste0(state, "-", y)
cbe_agg_soi_year <- as.matrix(cbe_agg_soi[, col])
cbe_agg_rous_year <- as.matrix(cbe_agg_rous[, col])
cbe_agg_row_year <- as.matrix(cbe_agg_row[, col])
v <- c(RoUS='cbe_agg_rous_year', RoW='cbe_agg_row_year')
v[state] <- 'cbe_agg_soi_year' # Set state specific name for this vector
ghgs <- combineResults(v)
ghgs$Value <- ghgs$Value / 10^9
ghgs <- subset(ghgs, !(ghgs$Sector %in% c("Used", "Other")))
# Split Household Shares before developing figure
households <- as.data.frame(households_all[, col, drop=FALSE])
households <- cbind(newSector= rownames(households), households)
households$Sector <- "F010"
ghgs2 <- merge(ghgs, households, by = "Sector", all.x=TRUE)
idx <- !is.na(ghgs2$newSector)
ghgs2$Sector[idx] <- ghgs2$newSector[idx]
ghgs2$Value[idx] <- ghgs2$Value[idx] * ghgs2[idx, col]
ghgs <- ghgs2[c("ID", "Sector", "Value")]
p <- stackedBarChartResultFigure(ghgs, models[[col]])
p <- p +
xlab('Greenhouse Gases (million tonnes)') +
labs(fill = 'Region') +
ggtitle(col) +
theme(axis.text.y = element_text(size = 7))
cbe_by_year_list[[toString(y)]] <- p
}
cbe_all_totals <- data.frame(CBE=colSums(cbe_all))
cbe_all_wide_MMT <- convertStateResultFormatToStatebyYear(cbe_all_totals, value.var="CBE")/1E9
```
Many U.S. states compile regular annual greenhouse gas inventories (GHGIs) that are used as a benchmark in measuring progress toward greenhouse gas (GHG) emissions reduction goals.
These territorial (also called sector-based) inventories typically cover GHG emissions occurring within the state’s borders.
They typically include emissions associated with transportation, electricity production, industry, land use and forestry, commercial and residential buildings, and waste disposal.
CBEs include emissions occurring upstream of the point of consumption; when those emissions occur out of state, they would not appear in the state’s territorial inventory.
The CBEI results are contrasted with the state territorial emissions in Figure \@ref(fig:cbe_territorial).


A CBE increase can be driven by an increase in the consumption of goods and services or in the embodied carbon intensity, measured in GHG emissions per dollar spent on goods and services, or by increases in both.
Changes in consumption as measured in current U.S. dollars, which are the dollar value for the year in which goods are consumed, can be influenced by the changing value of the dollar when inflation or deflation are present.
Changes in real consumption are better measured by using a constant dollar value across time to control for this effect.
State level consumption in constant dollars are shown by source region and by final consumer type in Figure \@ref(fig:demand-1) and Figure \@ref(fig:demand-2), respectively.
To account for changes in population growth, CBE per person is shown in Figure \@ref(fig:per_person).


```{r time_series_demand, echo=FALSE}
```{r cbe_total, echo=FALSE}
demand_types <- c(state, "RoUS", "RoW", "Total")
ylabel <- paste0("Billion $ (",focal_year,")")
d <- sapply(models, calculateDemandByRegion, price_year=focal_year)
rownames(d) <- demand_types
demand1 <- lineChartFigure(d / 10^9,ylabel)
demand1 <- demand1 + theme(text = element_text(size=12))
demand_types <- c("Household", "Investment", "Federal Government", "State Government", "Total")
ylabel <- paste0("Billion $ (",focal_year,")")
d <- sapply(models, calculateDemandByType, price_year=focal_year)
rownames(d) <- demand_types
demand2 <- lineChartFigure(d / 10^9,ylabel)
demand2 <- demand2 + theme(text = element_text(size=12))
kable(cbe_all_wide_MMT, digits=1, caption = 'Consumption-based emissions in million metric tons.')
```

```{r ghg_time_series, echo=FALSE}
cbe_agg <- (aggregateStateResultMatrix(models[[1]], cbe_all, region=state) +
aggregateStateResultMatrix(models[[1]], cbe_all, region='RoUS') +
aggregateStateResultMatrix(models[[1]], cbe_all, region='RoW'))
households <- sweep(households_all, 2, cbe_agg['F010', ], "*") # convert from pct to mass
cbe_agg <- rbind(cbe_agg[rownames(cbe_agg) != 'F010', ], households)
\\@ref(tab:cbe_total) shows the

tsghg1 <- twoRegionTimeSeriesPlot(cbe_agg / 10^9, model = models[[1]], plottype = "bar")
tsghg1 <- tsghg1 + labs(y = "MMT CO2e")
(\#tab:cbe_total) tries another way to cross-reference

tsghg2 <- twoRegionTimeSeriesPlot(cbe_agg/ 10^9, model = models[[1]], plottype = "line")
tsghg2 <- tsghg2 + labs(y = "MMT CO2e")
[@tab:cbe_total] tries another way to cross-reference

```
# Comparison to Territorial Inventory

Many U.S. states compile regular annual greenhouse gas inventories (GHGIs) that are used as a benchmark in measuring progress toward greenhouse gas (GHG) emissions reduction goals.
These territorial (also called sector-based) inventories typically cover GHG emissions occurring within the state’s borders.
They typically include emissions associated with transportation, electricity production, industry, land use and forestry, commercial and residential buildings, and waste disposal.
CBEs include emissions occurring upstream of the point of consumption; when those emissions occur out of state, they would not appear in the state’s territorial inventory.
The CBEI results are contrasted with the state territorial emissions in Figure \\@ref(fig:cbe_territorial).

```{r cbe_territorial, echo=FALSE, fig.width=6.5, fig.height=4}
```{r cbe_territorial, echo=FALSE, fig.width=6.5, fig.height=4, fig.cap="Comparison of consumption-based and territorial GHG emissions." }
ghgi_all <- sapply(models, getStateGHGI, simplify=TRUE, USE.NAMES=TRUE)
# Compare CBE to Territorial for Focal state
Expand All @@ -204,33 +144,33 @@ combined <- as.matrix(rbind(terr, cbe))
rownames(combined) <- c("Territorial", "CBE")
p <- lineChartFigure(combined / 10^9, ylabel="MMT CO2e")
p <- p +
scale_y_continuous(limits = c(0, NA)) +
theme(text = element_text(size=12))
scale_y_continuous(limits = c(0, NA)) +
theme(text = element_text(size=12))
p
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "cbe_territorial")
block_caption("Comparison of CBEI and territorial inventory totals across time.",
style = "Image Caption",
autonum = fig_num
)
```
# Consumption-Based Emissions Intensity

```{r time_series_demand_figure, echo=FALSE, fig.width=6.5, fig.height=4}
demand1
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "demand-1")
block_caption("Consumption in constant dollars. Consumption of commodities sourced in the three regions are shown on separate lines, along with a total consumption line.",
style = "Image Caption",
autonum = fig_num
)
demand2
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "demand-2")
block_caption("Trends in consumption by consumer category in constant dollars.",
style = "Image Caption",
autonum = fig_num
)
A CBE increase can be driven by an increase in the consumption of goods and services or in the embodied carbon intensity, measured in GHG emissions per dollar spent on goods and services, or by increases in both.
Changes in consumption as measured in current U.S. dollars, which are the dollar value for the year in which goods are consumed, can be influenced by the changing value of the dollar when inflation or deflation are present.
Changes in real consumption are better measured by using a constant dollar value across time to control for this effect.
To account for changes in population growth, CBE per person is shown in Figure \@ref(fig:per_person).

Figures in this section show a time series of these different intensities.

```{r per_dollar, fig.caption="Consumption-based emissions per dollar consumed by state residents.", echo=FALSE}
d <- sapply(models, calculateDemandByRegion, price_year=focal_year, USE.NAMES = TRUE)
d <- colSums(d)
per_d <- (cbe*1000)/d
rownames(per_d) <- "CBE per $ consumed"
per_d_fig <- lineChartFigure(per_d, "g CO2e per $ consumed")
per_d_fig <- per_d_fig + theme(text = element_text(size=12),
legend.position="none")
per_d_fig
```

```{r per_person, echo=FALSE}

```{r per_person, echo=FALSE, fig.cap="CBE per state resident."}
pop <- load_state_population()
pop <- pop[which(pop$Year %in% years),]
pop_wide <- reformatStatebyYearLongtoWide(pop, value.var="Population")
Expand All @@ -241,54 +181,57 @@ per_person <- lineChartFigure(per_p, "tonnes CO2e per person")
per_person <- per_person + theme(text = element_text(size=12),
legend.position="none")
per_person
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "per_person")
block_caption("Per person consumption based emissions.",
style = "Image Caption",
autonum = fig_num
)
```

Table \@ref(tab:cbe_table) presents the embodied carbon intensity of total consumption in `r state` from `r paste0(head(years, 1), "-", tail(years,1 ))`.
<!--Maine embodied carbon consumption intensity increases in the initial study years and then decreases from 2015–2020 from 428 g CO2e per dollar spent to 345, approximately a 19% decrease over the time period -->

```{r cbe_table, echo=FALSE}
per_dollar <- round(cbe / d["Total", ] * 1000,1)
table <- round(rbind(cbe, d["Total", ]) / 10^9, 1)
table <- rbind(table, per_dollar)
table <- rbind(table, round(per_p, 1))
colnames(table) <- years
rownames(table) <- c("CBE (MMT CO2e)",
paste0("Spending (Billion USD ", focal_year, ")"),
"CBE / $ (grams per $)",
"CBE per person (tonnes)")
knitr::kable(table, format='markdown')
tab_num <- run_autonum(seq_id = "tab", pre_label = "Table ", bkm = "cbe_table")
block_caption("Trends in CBE, demand, and CBE per dollar spent.",
style = "Image Caption",
autonum = tab_num
)
# Consumption-Based Emissions By Category of Goods or Service Consumed and Region of Origin

\@ref(fig:cbe_results) shows the CBE of `r state` by aggregate sector and the region of origin of GHG emissions for year `r focal_year`.

```{r cbe_results, echo=FALSE, fig.cap="test caption cab_results. RoUS = Rest of US; RoW = Rest of World"}
#cbe_by_year_list <- c()
#for(y in years) {
col <- paste0(state, "-", focal_year)
cbe_agg_soi_year <- as.matrix(cbe_agg_soi[, col])
cbe_agg_rous_year <- as.matrix(cbe_agg_rous[, col])
cbe_agg_row_year <- as.matrix(cbe_agg_row[, col])
v <- c(RoUS='cbe_agg_rous_year', RoW='cbe_agg_row_year')
v[state] <- 'cbe_agg_soi_year' # Set state specific name for this vector
ghgs <- combineResults(v)
ghgs$Value <- ghgs$Value / 10^9
ghgs <- subset(ghgs, !(ghgs$Sector %in% c("Used", "Other")))
# Split Household Shares before developing figure
households <- as.data.frame(households_all[, col, drop=FALSE])
households <- cbind(newSector= rownames(households), households)
households$Sector <- "F010"
ghgs2 <- merge(ghgs, households, by = "Sector", all.x=TRUE)
idx <- !is.na(ghgs2$newSector)
ghgs2$Sector[idx] <- ghgs2$newSector[idx]
ghgs2$Value[idx] <- ghgs2$Value[idx] * ghgs2[idx, col]
ghgs <- ghgs2[c("ID", "Sector", "Value")]
p <- stackedBarChartResultFigure(ghgs, models[[col]])
p <- p +
xlab('Greenhouse Gases (million tonnes)') +
labs(fill = 'Region') +
ggtitle(col) +
theme(axis.text.y = element_text(size = 7))
p
```

Figure \@ref(fig:tsghg-1) shows the trend in CBE broken down by the category of goods and services purchased.
Figure \@ref(fig:tsghg-2) also depicts the trends in these categories as a line graph to increase the ability to detect changes in categories.

```{r ghg_time_series_figures, echo=FALSE, fig.width=6.5, fig.height=8}
tsghg1
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure. ", bkm = "tsghg-1")
block_caption("CBE broken down by aggregate purchase category (bar).",
style = "Image Caption",
autonum = fig_num
)
tsghg2
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "tsghg-2")
block_caption("CBE broken down by aggregate purchase category (line).",
style = "Image Caption",
autonum = fig_num
)

```
# Trade Emissions Balance
A trade emissions balance is another way of assessing emissions from a consumption-based perspective.
A trade balance in economics is typically defined as exports from a region minus the imports into the region, where a trade surplus indicates more goods and services leaving the region that coming in from outside the region.
Analogously, trade balance information can be used to derive a trade emissions balance for each region.
Emissions are exported from the SoI when they occur in the SoI but are associated with a commodity that is consumed outside the state, either in the RoUS or RoW.
Imported emissions are those occurring out of state but associated with a commodity consumed by the SoI.
Figure \@ref(fig:trade_balance) shows the trend balance of emissions for the time series.
A positive value of the balance represents net positive emissions from trade, meaning that a state's consumption results in more emissions than it makes to produce exports.


```{r cbe_trade_balance, include=FALSE}
```{r trade_balance, echo=FALSE, fig.cap="Trade emissions trade balance", fig.width=6.5, fig.height=4, warning=FALSE}
cbe_trade_all <- sapply(models, calculateCBETradeBalance, simplify=FALSE, USE.NAMES=TRUE)
cbe_trade_all_df <- sapply(cbe_trade_all, matricizeandflip)
rownames(cbe_trade_all_df) <- c("Exports to RoUS", "Exports to RoW", "Imports from RoUS",
Expand All @@ -300,34 +243,7 @@ rownames(cbe_trade_summary_df) <- c("Exports", "Imports", "Balance")
# Alternatively can chart "cbe_trade_all_df" to differentiate RoW and RoUS
trade_balance <- lineChartFigure(cbe_trade_summary_df / 10^9, "Greenhouse Gases (million tonnes)")
trade_balance <- trade_balance + theme(text = element_text(size=12))
trade_balance
```

A balance of emissions is another way of assessing emissions from a consumption-based perspective.
A trade balance in economics is typically defined as exports from a region minus the imports into the region, where a trade surplus indicates more goods and services leaving the region that coming in from outside the region.
Analogously, trade balance information can be used to derive a trade emissions balance for each region.
Emissions are exported from the SoI when they occur in the SoI but are associated with a commodity that is consumed outside the state, either in the RoUS or RoW.
Imported emissions are those occurring out of state but associated with a commodity consumed by the SoI.
Figure \@ref(fig:trade_balance) shows the trend balance of emissions for the time series.

```{r cbe_trade_balance_fig, echo=FALSE, fig.width=6.5, fig.height=4}
trade_balance
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = "trade_balance")
block_caption("CBE trade balance.",
style = "Image Caption",
autonum = fig_num
)

```
Additional CBE figures by year are shown below.

```{r cbe_by_year, echo=FALSE, results='asis', fig.height=4, fig.width=6.5, warning=FALSE}
for(i in 1:length(cbe_by_year_list)) {
print(cbe_by_year_list[[toString(years[i])]])
fig_num <- run_autonum(seq_id = "fig", pre_label = "Figure ", bkm = paste0("CBE-", i))
block_caption("CBE Results",
style = "Image Caption",
autonum = fig_num
)
## Can't get captions to work inside the loop
}
```

0 comments on commit ab6c351

Please sign in to comment.