-
Notifications
You must be signed in to change notification settings - Fork 4
/
scenarios_01_calc_alt_feed_constants.R
193 lines (165 loc) · 9.04 KB
/
scenarios_01_calc_alt_feed_constants.R
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
# Generate alternate feed constants for lever scenarios
# Do this for both Mass allocation and Economic allocation versions
# Libraries for processing and analyses
rm(list=ls())
library(tidyverse)
library(countrycode)
source("Functions.R")
#_________________________________________________________________________________________________________________________________#
# Load and clean data
#_________________________________________________________________________________________________________________________________#
# Mac
datadir <- "/Volumes/jgephart/BFA Environment 2/Data"
outdir <- "/Volumes/jgephart/BFA Environment 2/Outputs"
feed_fp <- read.csv(file.path(datadir, "feed_impact_factors.csv"))
feed_fp$iso3c <- countrycode(feed_fp$Country.Region, origin = "country.name", destination = "iso3c")
feed_fp$iso3c[is.na(feed_fp$iso3c)] <- "Other"
feed_fp <- feed_fp %>%
mutate(iso3c = ifelse(Country.Region == "Europe" & Input %in% c("Chicken by-product meal", "Chicken by-product oil"),
"EUR", iso3c))
# DATA DOCUMENTATION: FAO export data should be downloaded from FAOSTAT
# http://www.fao.org/faostat/en/#data/TP
# Query terms for downloading: SELECT All countries, Export quantity, All items
# File can also be provided by corresponding author upon request
faostat <- read.csv(file.path(datadir, "FAOSTAT_data_12-9-2020.csv"))
faostat$iso3c <- countrycode(faostat$Area, origin = "country.name", destination = "iso3c")
##########################################################################################################################
# OPTION: Choose allocation method (used for all analyses below and filenames)
# allocation_method <- "Mass"
allocation_method <- "Economic"
##########################################################################################################################
#_________________________________________________________________________________________________________________________________#
# Load baseline feed data
#_________________________________________________________________________________________________________________________________#
feed_fp_baseline <- read.csv(file.path(outdir, "weighted_feed_fp.csv"))
#_________________________________________________________________________________________________________________________________#
# No land use soy and crops - create mass and economic allocation versions of this
#_________________________________________________________________________________________________________________________________#
weighted_soy <- calc_soy_weights(faostat, feed_fp, deforestation_free = TRUE)
weighted_crop <- calc_crop_weights(faostat, feed_fp, deforestation_free = TRUE)
# Replace baseline soy and crops with new soy and crops
feed_fp_noland <- feed_fp_baseline %>%
filter(Input.type != "Soy") %>%
filter(Input.type != "Crop") %>%
bind_rows(weighted_soy) %>%
bind_rows(weighted_crop)
# Format for analysis
feed_fp_noland <- feed_fp_noland %>%
mutate(feed_type = case_when(
(Input.type == "Soy") ~ "soy",
(Input.type == "Crop") ~ "crops",
(Input.type == "Fishery") ~ "fmfo",
(Input.type == "Livestock") ~ "animal"
)) %>%
select(-Input.type) %>%
mutate(stressor = case_when(
Impact.category == "Global warming potential" ~ "ghg",
Impact.category == "Marine eutrophication" ~ "N",
Impact.category == "Freshwater eutrophication" ~ "P",
Impact.category == "Land use" ~ "land",
Impact.category == "Water consumption" ~ "water"
)) %>%
filter(Allocation == allocation_method) %>%
select(feed_type, stressor, ave_stressor)
feed_fp_noland_filename <- paste("feed_fp_scenario_7_", str_to_lower(allocation_method), ".csv", sep = "")
write.csv(feed_fp_noland, file.path(outdir, feed_fp_noland_filename), row.names = FALSE)
#_________________________________________________________________________________________________________________________________#
# Replace FMFO with fishery by-products - create mass and economic allocation versions of this
#_________________________________________________________________________________________________________________________________#
# Calculate fish byproduct weights
fmfo_prod <- read.csv(file.path(datadir, "fish_weightings.csv"))
weighted_fishbyproduct <- calc_byproduct_weights(fmfo_prod, feed_fp)
weighted_fishbyproduct$Input.type <- "Fishery"
feed_fp_fish_bp <- feed_fp_baseline %>%
filter(Input.type != "Fishery") %>%
bind_rows(weighted_fishbyproduct)
# Format for analysis
feed_fp_fish_bp <- feed_fp_fish_bp %>%
mutate(feed_type = case_when(
(Input.type == "Soy") ~ "soy",
(Input.type == "Crop") ~ "crops",
(Input.type == "Fishery") ~ "fmfo",
(Input.type == "Livestock") ~ "animal"
)) %>%
select(-Input.type) %>%
mutate(stressor = case_when(
Impact.category == "Global warming potential" ~ "ghg",
Impact.category == "Marine eutrophication" ~ "N",
Impact.category == "Freshwater eutrophication" ~ "P",
Impact.category == "Land use" ~ "land",
Impact.category == "Water consumption" ~ "water"
)) %>%
filter(Allocation == allocation_method) %>%
select(feed_type, stressor, ave_stressor)
feed_fp_fish_bp_filename <- paste("feed_fp_scenario_2c_", str_to_lower(allocation_method), ".csv", sep = "")
write.csv(feed_fp_fish_bp, file.path(outdir, feed_fp_fish_bp_filename), row.names = FALSE)
#_________________________________________________________________________________________________________________________________#
# Replace FMFO with low impact (Alaska Pollock) fishery by-products - create mass and economic allocation versions of this
#_________________________________________________________________________________________________________________________________#
# Modified function calc_byproduct_weights for just Alaska Pollock
weighted_fishbyproduct_pollock <- feed_fp %>%
filter(Input.type == c("Fishery by-product")) %>%
filter(str_detect(Input, pattern = "pollock")) %>%
left_join(fmfo_prod, by = c("Input" = "Name")) %>%
group_by(Input.type, Impact.category, Allocation, Units) %>%
# Normalize weightings to sum to 1
mutate(reweighting = Weighting/sum(Weighting, na.rm = TRUE)) %>%
summarise(Value = sum(Value * reweighting)) %>%
# If weighting ingredient types, do here along with country weightings
group_by(Impact.category, Allocation, Units) %>%
summarise(ave_stressor = mean(Value, na.rm = TRUE))
weighted_fishbyproduct_pollock$Input.type <- "Fishery"
feed_fp_fish_low_impact_bp <- feed_fp_baseline %>%
filter(Input.type != "Fishery") %>%
bind_rows(weighted_fishbyproduct_pollock)
# Format for analysis
# Change names to match df
feed_fp_fish_low_impact_bp <- feed_fp_fish_low_impact_bp %>%
mutate(feed_type = case_when(
(Input.type == "Soy") ~ "soy",
(Input.type == "Crop") ~ "crops",
(Input.type == "Fishery") ~ "fmfo",
(Input.type == "Livestock") ~ "animal"
)) %>%
select(-Input.type) %>%
mutate(stressor = case_when(
Impact.category == "Global warming potential" ~ "ghg",
Impact.category == "Marine eutrophication" ~ "N",
Impact.category == "Freshwater eutrophication" ~ "P",
Impact.category == "Land use" ~ "land",
Impact.category == "Water consumption" ~ "water"
)) %>%
filter(Allocation == allocation_method) %>%
select(feed_type, stressor, ave_stressor)
feed_fp_fish_low_impact_bp_filename <- paste("feed_fp_scenario_2d_", str_to_lower(allocation_method), ".csv", sep = "")
write.csv(feed_fp_fish_low_impact_bp, file.path(outdir, feed_fp_fish_low_impact_bp_filename), row.names = FALSE)
#_________________________________________________________________________________________________________________________________#
# Low impact (Alaska Pollock) fishery by-products in FMFO - create mass and economic allocation versions of this
#_________________________________________________________________________________________________________________________________#
weighted_fishery <- calc_fishery_weights(fmfo_prod, feed_fp)
weighted_fish <- combine_fish_weights(weighted_fishery, weighted_fishbyproduct_pollock)
weighted_fish$Input.type <- "Fishery"
feed_fp_fmfo_low_impact_bp <- feed_fp_baseline %>%
filter(Input.type != "Fishery") %>%
bind_rows(weighted_fish)
# Format for analysis
# Change names to match df
feed_fp_fmfo_low_impact_bp <- feed_fp_fmfo_low_impact_bp %>%
mutate(feed_type = case_when(
(Input.type == "Soy") ~ "soy",
(Input.type == "Crop") ~ "crops",
(Input.type == "Fishery") ~ "fmfo",
(Input.type == "Livestock") ~ "animal"
)) %>%
select(-Input.type) %>%
mutate(stressor = case_when(
Impact.category == "Global warming potential" ~ "ghg",
Impact.category == "Marine eutrophication" ~ "N",
Impact.category == "Freshwater eutrophication" ~ "P",
Impact.category == "Land use" ~ "land",
Impact.category == "Water consumption" ~ "water"
)) %>%
filter(Allocation == allocation_method) %>%
select(feed_type, stressor, ave_stressor)
feed_fp_fmfo_low_impact_bp_filename <- paste("feed_fp_scenario_6_", str_to_lower(allocation_method), ".csv", sep = "")
write.csv(feed_fp_fmfo_low_impact_bp, file.path(outdir, feed_fp_fmfo_low_impact_bp_filename), row.names = FALSE)