-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-comparing_inventories.Rmd
231 lines (190 loc) · 8.05 KB
/
09-comparing_inventories.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Comparing Inventories
This chapter is about comparing one inventory to another. You might wish, for example, to see the differences between the BY2011 and BY2008 versions of a single category. Or, you might want to compare groups of related categories.
Let's use #288 Domestic Woodstoves as a simple example of how to do this with a single category.
## Binding inventories together
First, we need to gain access to the BY2008 data, via `library(BY2008)`. This is just like we did in [Chapter 2](#setup), with `library(BY2011)`.
```{r library-BY2008, message=FALSE}
library(BY2011)
library(BY2008)
```
Now we combine `BY2011_annual_emission_data` and `BY2008_annual_emission_data` into a single dataset named `BY_data`. We do this with `bind_inventories()`.
```{r BY_data}
#
# Using `bind_inventories()` creates a new column named `inventory`.
#
BY_data <-
bind_inventories(
BY2011 = BY2011_annual_emission_data,
BY2008 = BY2008_annual_emission_data)
```
With our new `BY_data`, we can reuse the same old `chart_annual_emissions_by()`.
## Comparing two versions of a single category
Here we do just two things differently, compared to previous chapters:
- We specify `opacity = inventory`. This causes the BY2011 data and the BY2008 data to be drawn with distinct line types (solid and dashed, respectively).
- We supply `c(288, "A288")` instead of just `288`. (See the note below.)
```{block type="note"}
In `BY2008_annual_emission_data`, category IDs are prefixed by either "P" or "A", and the numeric part of the ID doesn't have to be unique! This is a convention that is no longer followed, from BY2011 onwards.
```
```{r BY_data-domestic-woodstoves-data}
#
# Treat both of the following as "Domestic Wood Stoves":
#
# - BY2011 category #288
# - BY2008 category #A288
#
chart_data <-
BY_data %>%
filter_categories(
"Domestic Wood Stoves" = c(288, "A288")) %>%
filter_pollutants(
"NOx",
"CO")
```
The `c(288, "A288")` tells `filter_categories()` to treat either/both of these categories as "Domestic Wood Stoves".
```{r BY_data-domestic-woodstoves-chart, fig.height=6.5, out.height=650}
#
# Chart by inventory, so we can compare.
#
chart_data %>%
chart_annual_emissions_by(
opacity = inventory,
flag_years = CY(1990, 2010, 2030),
title = "Domestic Woodstoves: BY2011 Updates",
subtitle = str_c(
"- CY1990-2005 estimates are about 10% lower.",
"- Estimates circa CY2010 are about 40% lower.",
"- Forecast is flat, rather than increasing.",
sep = "\n"))
```
## Groups of categories {#multiple-categories}
What if we want to chart more than just a single category?
When groups of related category identifiers change from one year to the next, we can still visualize the data effectively using `filter_categories()` and `chart_annual_emissions()`.
Here is a concrete example.
- In `BY2008_annual_emission_data`, we can see both `"P304"` and `"A304"` in `cat_id`.
- Taken together, these comprise estimates of emissions from stationary-source liquid-fueled reciprocating engines.
- The scope of `P304` is limited to permitted sources, and is calculated using a point-source methodology.
- The scope of `A304` comprises any remaining emissions from the same kind of source, and is calculated using an area-source methodology.
- In `BY2011_annual_emission_data`, emissions from the same real-world activities are assigned to BY2011 categories `#304` (point) and `#1578` (area).
```{block type="note"}
This can create some confusion. It means that when someone is speaking about "category 304", they could be referring to BY2011 category #304 (point sources only). Or, if they have BY2008 in mind, they might be speaking about both `P304` and `A304` together.
```
### Comparing totals {-}
First, let's treat all of these "Reciprocating Engines, Liquid Fuel" categories as one big group. And, let's focus on just one pollutant, to keep things simple.
```{r BY_data-recip_eng-liquid_fuel-data-1}
#
# Treat all of the following as "Recip Eng, Liquid Fuel":
#
# - BY2011 category #304 (point)
# - BY2008 category #P304 (point)
# - BY2011 category #1578 (area)
# - BY2008 category #A304 (area)
#
chart_data <-
BY_data %>%
filter_categories(
"Recip Eng, Liquid" = c(304, "P304", 1578, "A304")) %>%
filter_pollutants(
"NOx")
```
```{r BY_data-recip_eng-liquid_fuel-chart-1, fig.height=4, out.height=400}
#
# Chart by inventory, so we can compare the totals.
#
chart_data %>%
chart_annual_emissions_by(
opacity = inventory,
title = "Reciprocating Engines (Liquid Fuel): BY2011 Updates",
subtitle = str_c(
"BY2008 = Categories #P304 (point) and/or #A304 (area).",
"BY2011 = Categories #304 (point) and/or #1578 (area).",
sep = "\n"))
```
### Comparing subtotals {-}
We can see above that, for these categories, there are some considerable differences between BY2011 and BY2008 estimates of NO~x~ emissions. What's going on?
Let's try grouping the "point" and "area" subsets *separately* in our call to `filter_categories()`, and see what happens. We'll create one group named "Recip Eng, Liquid (point)", and one group named "Recip Eng, Liquid (area)". To the former, we'll assign BY2011 #304 and BY2008 #P304; to the latter, BY2011 #1578 and BY2008 #A304.
```{r BY_data-recip_eng-liquid_fuel-data-2}
#
# Treat these as "Recip Eng, Liquid Fuel (Point)":
#
# - BY2011 category #304
# - BY2008 category #P304
#
# ... and treat these as "Recip Eng, Liquid Fuel (Area)":
#
# - BY2011 category #1578
# - BY2008 category #A304
#
chart_data <-
BY_data %>%
filter_categories(
"Recip Eng, Liquid (point)" = c(304, "P304"),
"Recip Eng, Liquid (area)" = c(1578, "A304")) %>%
filter_pollutants(
"NOx")
```
```{r BY_data-recip_eng-liquid_fuel-chart-2, fig.height=4, out.height=400}
#
# Chart by inventory and by point/area, so we can compare the subtotals.
#
chart_data %>%
chart_annual_emissions_by(
opacity = inventory,
color = category,
title = "Reciprocating Engines (Liquid Fuel): BY2011 Updates",
subtitle = str_c(
"BY2008 = Categories #P304 (point) and/or #A304 (area).",
"BY2011 = Categories #304 (point) and/or #1578 (area).",
sep = "\n"))
```
From this, we can see that the bulk of the difference is due to a much lower estimate for the area-source component.
**Using `filter_categories()` and `chart_annual_emissions()` together is powerful.** With it, you can review updates to any related groups of categories from different BY inventories, regardless of how their `cat_id` identifiers might have changed.
## More Examples
### Residential Combustion: Distillate Oil (Relative Growth) {-}
```{r BY_data-combust-domestic-liquid-chart, fig.height=4, out.height=400}
BY_data %>%
filter_categories(
"#287 Distillate Oil" = c(287, "A287")) %>%
filter_pollutants(
"NOx") %>%
chart_annual_growth_by(
opacity = inventory,
base_year = CY(2011),
flag_years = CY(1990, 2030),
title = "Residential Combustion",
subtitle = "#287 Distillate Oil")
```
### Petroleum Refining: Flares and Blowdown Systems {-}
```{r BY_data-petref-fac-general, fig.height=4, out.height=400}
BY_data %>%
filter_categories(
"#15 Flares and Blowdown Systems" = c(15, "P15")) %>%
filter_pollutants(
"CO2") %>%
chart_annual_emissions_by(
opacity = inventory,
base_year = CY(2011),
flag_years = CY(1990, 2011, 2030),
title = "Petroleum Refining",
subtitle = "#15 Flares and Blowdown Systems")
```
### Small Bakeries {-}
```{r BY_data-indcom-bakery-small, fig.height=4, out.height=400}
#
# To remove redundant flags, pass `flag_unique = TRUE`. Notice how the value
# "190.3 ton/yr" is now only displayed once at CY1990. Please note: This
# behavior may be changed in future updates to `ggtools` --- don't use it (yet)
# in production code.
#
BY_data %>%
filter_categories(
"#935 Small Bakeries" = c(935, "A935")) %>%
filter_pollutants(
"TOG") %>%
chart_annual_emissions_by(
alpha = inventory,
base_year = CY(2011),
flag_years = CY(1990, 2011, 2030),
flag_unique = TRUE,
title = "Industrial and Commercial Processes",
subtitle = "#935 Small Bakeries")
```