-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_combined_protein_and_comparisons.Rmd
347 lines (231 loc) · 11.8 KB
/
7_combined_protein_and_comparisons.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
---
title: 'Comparisons: grazing livestock and crops'
author: "Johannes Piipponen"
date: "`r Sys.Date()`"
output: html_document
---
!! EDIT in revision
- "mixed" area analysis removed
- SI < 10 areas removed --> we now use SI < 33 areas to get more spatial coverage
Data saved to folder Intermediate inputs
# Calculate livestock contribution to total protein
Update: calculated only for current herd structure.
However, old codes below just in case one wants to explore this for different livestock species
Grazing livestock's share of total protein production on agricultural land
This map illustrates the percentage of protein produced by grazing livestock in relation to the combined protein production from both grazing livestock and the 27 SPAM food crops on agricultural land. It highlights the areas where grazing livestock plays a more significant role in contributing to the total protein production within agricultural systems.
# First, plot protein production levels
Both from AGB and SPAM, then also combined
```{r}
# calculate combined protein that we can get from a cell (combined = protein_grazing_livestock + protein_crops)
r_protein_combined_kg_perpix <-
1000 * classify(r_prot_allcrops_sum_mt_perpix, cbind(NA, 0)) +
classify(r_protein_from_AGB_kg_perpix$current_herd_str, cbind(NA, 0))
names(r_protein_combined_kg_perpix) <- "combined_protein"
#plot(r_protein_combined_kg_perpix, main = "combined protein")'
r_protein_combined_kg_perpix_0toNA <-
classify(r_protein_combined_kg_perpix, cbind(0, NA))
pal_protein_lajolla <- scico(n = 6, palette = "lajolla", begin = 0.15, end = 1, direction = -1)
# PER PIX
(plt_agb_and_crop_protein <-
create_index_map(r_index = c( r_prot_allcrops_sum_mt_perpix,
r_protein_from_AGB_kg_perpix$current_herd_str/1000,
r_protein_combined_kg_perpix_0toNA/1000),
tocrs = "ESRI:54030",
index_main_title = "Protein production from AGB and from SPAM food crops in 2010",
index_label = "[kg/ha]",
colorpal = pal_protein_lajolla,
breakvals = c(0, 10, 50, 100, 250, 500, Inf),
breaknames = c("0-10","10-50", "50-100",
"100-250","250-500", ">500")))
# # interpretation:
# animals produce much less
```
# Grasing animals share of the total protein production
```{r}
# Grazing livestock's share of total protein production on agricultural land
# share of the total protein that originates from livestock
## first convert NA to 0
r_protein_from_AGB_current_str_kg_perpix_NAto0 <-
classify(r_protein_from_AGB_kg_perpix$current_herd_str, cbind(NA, 0))
r_share_of_total_protein_livestock <-
100* (r_protein_from_AGB_current_str_kg_perpix_NAto0 /
r_protein_combined_kg_perpix)
qtm(r_share_of_total_protein_livestock, title = "Contribution of livestock to total protein production")
# just shows that gl area >> cl area
pal_share <- scico(n = 10, palette = "roma", begin = 0.1, end = 0.9, direction = -1) # change name?
create_index_map(r_index = r_share_of_total_protein_livestock ,
tocrs = "ESRI:54030",
index_main_title = "Grazing livestock share of tot protein prod",
index_label = "[%]",
colorpal = pal_share,
colorNA = "NA",
breakvals = c(0, 10, 25, 50, 75, 90, 100),
breaknames = c("<10", "10-25", "25-50","50-75","75-90", "90-100"))
# ------------------------------------------------------ mask these to key areas (defined in another script called)
# over 90% grazing lands
# r_share_of_total_protein_livestock_whereover90gl <- # not sure if this is relevant
# mask(r_share_of_total_protein_livestock,
# r_gl_share_of_agrland_over90)
# over 90% croplands
# r_share_of_total_protein_livestock_whereover90cl <- # not sure if needed
# mask(r_share_of_total_protein_livestock,
# r_cl_share_of_agrland_over90)
# 10% of over (of agr land) croplands AND 10% of over (of agr land) grazing lands
# r_share_of_total_protein_livestock_mixed <-
# mask(r_share_of_total_protein_livestock,
# r_gl_cl_share_mixed)
# --------------------------------------------------- same masked to cl
## cropland mask
## share of livestock masked to croplands to show that on cropland areas livestock produce only a little
# r_share_of_total_protein_livestock_croplandmask <-
# mask(r_share_of_total_protein_livestock,
# r_fraction_cl_0toNA)
#
# plot(r_share_of_total_protein_livestock_croplandmask,
# main = "Contribution of livestock to total protein production on croplands")
# ----------------------- further masked to cl where SI extremely low (below 10)
## SI below 10 mask -- must also be larger than 0
# SI_5arcmin_range_1to10 <- SI_5arcmin # check what "source" row says -- should be rcp rainfed
# SI_5arcmin_range_1to10[SI_5arcmin_range_1to10 >= 10] <- NA
# SI_5arcmin_range_1to10[SI_5arcmin_range_1to10 <= 1] <- NA
## 1<=SI<33
# SI_5arcmin_range_1to33 <- ifel(SI_5arcmin_range_1to33 >= 1 & SI_5arcmin_range_1to33 < 33, 1, NA)
#
# plot(SI_5arcmin_range_1to33, main = "1<= SI < 33")
#
#
# r_share_of_total_protein_livestock_SIbetween1to33mask <-
# mask(r_share_of_total_protein_livestock,
# SI_5arcmin_range_1to33)
#
# plot(r_share_of_total_protein_livestock_SIbetween1to33mask)
# SI_5arcmin_below10_croplandmask <- mask(SI_5arcmin_below10, r_fraction_cl_0toNA) # no need to show this - use all agr land instead?
# plot(SI_5arcmin_below10_croplandmask, main = "SI below 10 on croplands")
#
# r_share_of_total_protein_livestock_SIbelow10mask_croplandmask <-
# mask(r_share_of_total_protein_livestock, SI_5arcmin_below10_croplandmask)
#
# plot(r_share_of_total_protein_livestock_SIbelow10mask_croplandmask,
# main = "Contribution of livestock to total protein production on croplands where SI < 10")
```
# Protein kg per ha for figures
```{r}
# total combined protein per ha
r_protein_from_AGB_current_str_kg_ha_NAto0 <-
classify(r_protein_from_AGB_kg_ha$current_herd_str, cbind(NA,0))
r_prot_allcrops_sum_kg_ha_NAto0 <-
classify(r_prot_allcrops_sum_kg_ha, cbind(NA,0))
r_protein_combined_kg_ha <-
r_protein_from_AGB_current_str_kg_ha_NAto0 +
r_prot_allcrops_sum_kg_ha_NAto0
r_protein_combined_kg_ha <-
mask(r_protein_combined_kg_ha,
r_fraction_gl_cl_total_0toNA) # focus only on our study area
# total combined protein per ha - masked to key cropland areas
# r_protein_combined_kg_ha_whereover90cl <-
# mask(r_protein_combined_kg_ha,
# r_cl_share_of_agrland_over90)
# total combined protein per ha - masked to mixed areas
# r_protein_combined_kg_ha_wheremixed <-
# mask(r_protein_combined_kg_ha,
# r_gl_cl_share_mixed)
# total combined protein per ha - croplandmask
# r_protein_combined_kg_ha_croplandmask <-
# mask(r_protein_combined_kg_ha,
# r_fraction_cl_0toNA)
# total combined protein per ha - outside croplandmask -- same as only livestock here
# r_protein_combined_kg_ha_outside_croplands <-
# mask(r_protein_from_AGB_kg_ha$current_herd_str, # could be also r_protein_combined_kg_ha but this is more correct
# r_fraction_cl_0toNA, inverse = T)
# further masked to cl where SI is marginal
r_protein_combined_kg_ha_SIbetween1to33mask <-
mask(r_protein_combined_kg_ha,
SI_5arcmin_range_1to33)
plot(r_protein_combined_kg_ha_SIbetween1to33mask)
```
# Global sums
```{r}
# Total combined protein
global(r_protein_combined_kg_perpix, "sum", na.rm = T)/1e9 # 385 in 2020, was 285 mmt in 2010
# Total combined protein on key cropland areas
# r_protein_combined_kg_perpix_whereover90cl <-
# mask(r_protein_combined_kg_perpix,
# r_cl_share_of_agrland_over90)
# global(r_protein_combined_kg_perpix_whereover90cl, "sum", na.rm = T)/1e9 # 107
# Total combined protein on mixed areas
# r_protein_combined_kg_perpix_wheremixed <-
# mask(r_protein_combined_kg_perpix,
# r_gl_cl_share_mixed)
# global(r_protein_combined_kg_perpix_wheremixed, "sum", na.rm = T)/1e9 # was 170
# Total combined protein on croplands
# r_protein_combined_kg_perpix_croplandmask <-
# mask(r_protein_combined_kg_perpix,
# r_fraction_cl_0toNA)
# global(r_protein_combined_kg_perpix_croplandmask, "sum", na.rm = T)/1e9 # 281
# Total combined protein on croplands where 1<= SI < 33
r_protein_combined_kg_perpix_SIbetween1to33mask <-
mask(r_protein_combined_kg_perpix,
SI_5arcmin_range_1to33)
global(r_protein_combined_kg_perpix_SIbetween1to33mask, "sum", na.rm = T)/1e9 #55.6
# Total combined protein outside croplands -- this should be same as amount of protein current herd produces outside cl
r_protein_combined_kg_perpix_outside_croplands <-
mask(r_protein_combined_kg_perpix,
r_fraction_cl_0toNA, inverse = T)
global(r_protein_combined_kg_perpix_outside_croplands, "sum", na.rm = T)/1e9 # 6.7 -- 4
mask(r_protein_from_AGB_kg_perpix$current_herd_str,
r_fraction_cl_0toNA, inverse = T) %>%
global(., "sum", na.rm = T)/1e9 # 6.7 -- was 4
```
# Global sums in broader context
```{r}
# combined protein from crops and livestock = 385.1329 mmt. This is
(1e12 * global(r_protein_combined_kg_perpix, "sum", na.rm = T)/1e9) /
6869581990 / # persons
365
# 154 --> was114 g/capita/day
# how many people can be fed with this?
#((1e12 * global(r_protein_combined_kg_perpix, "sum", na.rm = T)/1e9) / # grams (mmt = 1e9 kg)
# ((1000 * global(r_protein_combined_kg_perpix, "sum", na.rm = T)) / # grams of protein produced
# (1000* foodBalanceSheets_semiraw %>% filter(Area == "World", Item == "Population") %>% pull(Y2020)) / # number of persons in 2020
# 365 ) /# days in a year
# (0.8*70) # protein need in
#
```
# Save rasters
```{r}
# -------------------------------------------- save rasters we need
writeRaster(r_protein_combined_kg_ha,
filename = here("Data", "Intermediate_input", "r_protein_combined_kg_ha.tif"),
overwrite = TRUE)
# writeRaster(r_protein_combined_kg_ha_whereover90cl,
# filename = here("Data", "Intermediate_input", "r_protein_combined_kg_ha_whereover90cl.tif"),
# overwrite = TRUE)
# writeRaster(r_protein_combined_kg_ha_wheremixed,
# filename = here("Data", "Intermediate_input", "r_protein_combined_kg_ha_wheremixed.tif"),
# overwrite = TRUE)
writeRaster(r_protein_combined_kg_perpix,
filename = here("Data", "Intermediate_input", "r_protein_combined_kg_perpix.tif"),
overwrite = TRUE)
# writeRaster(r_protein_combined_kg_ha_croplandmask,
# filename = here("Data", "Intermediate_input", "r_protein_combined_kg_ha_croplandmask.tif"),
# overwrite = TRUE)
writeRaster(r_protein_combined_kg_ha_SIbetween1to33mask,
filename = here("Data", "Intermediate_input", "r_protein_combined_kg_ha_SIbetween1to33mask.tif"),
overwrite = TRUE)
################################## shares
writeRaster(r_share_of_total_protein_livestock,
filename = here("Data", "Intermediate_input", "r_share_of_total_protein_livestock.tif"),
overwrite = TRUE)
# writeRaster(r_share_of_total_protein_livestock_croplandmask,
# filename = here("Data", "Intermediate_input", "r_share_of_total_protein_livestock_croplandmask.tif"),
# overwrite = TRUE)
# writeRaster(r_share_of_total_protein_livestock_mixed,
# filename = here("Data", "Intermediate_input", "r_share_of_total_protein_livestock_mixed.tif"),
# overwrite = TRUE)
writeRaster(r_share_of_total_protein_livestock_SIbetween1to33mask,
filename = here("Data", "Intermediate_input", "r_share_of_total_protein_livestock_SIbetween1to33mask.tif"),
overwrite = TRUE)
# writeRaster(SI_5arcmin_range_1to10,
# filename = here("Data", "Intermediate_input", "SI_5arcmin_range_1to10.tif"),
# overwrite = TRUE)
```