@@ -23,15 +23,17 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
23
23
FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_FAO_iso_reg" ),
24
24
" L105.Bal_new_all" ,
25
25
" L107.Traceable_FBS_PCe_2010Plus" ,
26
- " L107.Traceable_FBS_Food_Calorie_Macronutrient_2010Plus" )
26
+ " L107.Traceable_FBS_Food_Calorie_Macronutrient_2010Plus" ,
27
+ " L107.Traceable_FBS_PCe_Gross_Extraction_Rates_2010Plus" )
27
28
28
29
MODULE_OUTPUTS <-
29
30
c(CSV = " Metadata_GCAMFAOSTAT_Traceable_FBS" ,
30
31
CSV = " Nested_Mapping_SUA_To_Traceable_FBS" ,
31
32
CSV = " SUA_2010_2022" ,
32
33
CSV = " SUA_Food_Calorie_Macronutrient_2010_2022" ,
33
34
CSV = " Traceable_FBS_PCe_2010_2022" ,
34
- CSV = " Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" )
35
+ CSV = " Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" ,
36
+ CSV = " Traceable_FBS_Extraction_Rate_2010_2022" )
35
37
36
38
if (command == driver.DECLARE_INPUTS ) {
37
39
return (MODULE_INPUTS )
@@ -111,7 +113,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
111
113
112
114
output_csv_data(
113
115
gcam_dataset = Nested_Mapping_SUA_To_Traceable_FBS ,
114
- out_filename = " Nested_Mapping_SUA_To_Traceable_FBS" ,
116
+ out_filename = " Nested_Mapping_SUA_To_Traceable_FBS" % > % paste0( " _ " , Sys.Date()) ,
115
117
col_type_nonyear = " ccicici" ,
116
118
title = " Mapping of SUA items to aggregated primary commodity equivalent products by level of nestings" ,
117
119
unit = " NA" ,
@@ -148,7 +150,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
148
150
149
151
output_csv_data(
150
152
gcam_dataset = SUA_2010_2022 ,
151
- out_filename = " SUA_2010_2022" ,
153
+ out_filename = " SUA_2010_2022" % > % paste0( " _ " , Sys.Date()) ,
152
154
col_type_nonyear = " ccifc" ,
153
155
title = " Supply utilization accounts for all FAO items in 2010 - 2022" ,
154
156
unit = " 1000 tonnes" ,
@@ -177,7 +179,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
177
179
178
180
output_csv_data(
179
181
gcam_dataset = SUA_Food_Calorie_Macronutrient_2010_2022 ,
180
- out_filename = " SUA_Food_Calorie_Macronutrient_2010_2022" ,
182
+ out_filename = " SUA_Food_Calorie_Macronutrient_2010_2022" % > % paste0( " _ " , Sys.Date()) ,
181
183
col_type_nonyear = " ccicc" ,
182
184
title = " SUA: food energy and macronutrient in 2010 - 2022" ,
183
185
unit = " Mt or Mkcal" ,
@@ -206,7 +208,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
206
208
207
209
output_csv_data(
208
210
gcam_dataset = Traceable_FBS_PCe_2010_2022 ,
209
- out_filename = " Traceable_FBS_PCe_2010_2022" ,
211
+ out_filename = " Traceable_FBS_PCe_2010_2022" % > % paste0( " _ " , Sys.Date()) ,
210
212
col_type_nonyear = " cccc" ,
211
213
title = " Traceable FBS: supply utilization accounts in primary equivalent for APE items in 2010 - 2022" ,
212
214
unit = " 1000 tonnes" ,
@@ -235,7 +237,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
235
237
236
238
output_csv_data(
237
239
gcam_dataset = Traceable_FBS_Food_Calorie_Macronutrient_2010_2022 ,
238
- out_filename = " Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" ,
240
+ out_filename = " Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" % > % paste0( " _ " , Sys.Date()) ,
239
241
col_type_nonyear = " cccc" ,
240
242
title = " Traceable FBS: food energy and macronutrient in 2010 - 2022" ,
241
243
unit = " Mt or Mkcal" ,
@@ -248,6 +250,71 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
248
250
" Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" )
249
251
250
252
253
+
254
+
255
+
256
+ # * Traceable_FBS_Extraction_Rate_2010_2022 ----
257
+ # generate a base mapping to join table
258
+ # there is some info from the mapping to be used to update the rates
259
+ # E.g., output specific
260
+
261
+ Mapping_gcamdata_SUA_PrimaryEquivalent %> %
262
+ distinct(APE_comm_Agg , APE_comm , nest_level , source_item ,
263
+ sink_item , sink_item , source_item ,
264
+ output_specific_extraction_rate ,
265
+ min_extraction_rate = extraction_rate_Q25 , Q25asMin ) %> %
266
+ filter(nest_level > = 1 ) %> %
267
+ mutate(min_extraction_rate = if_else(Q25asMin == F , 0 , min_extraction_rate )) - >
268
+ Extraction_Rate_Mapping
269
+
270
+ Extraction_Rate_Mapping %> %
271
+ replace_na(list (output_specific_extraction_rate = 1 )) %> %
272
+ full_join(L107.Traceable_FBS_PCe_Gross_Extraction_Rates_2010Plus ,
273
+ by = c(" APE_comm" , " nest_level" , " source_item" , " sink_item" )) %> %
274
+ left_join_error_no_match(
275
+ Mapping_gcamdata_FAO_iso_reg %> % select(region_ID , iso ), by = " region_ID" ) %> %
276
+ transmute(aggregated_PCe_item = APE_comm_Agg , PCe_item = APE_comm , iso , year ,
277
+ nest_level , source_item , sink_item ,
278
+ output_specific_extraction_rate ,
279
+ ER_imported = bal_import ,
280
+ ER_domestic = bal_domestic_current ,
281
+ ER_lagged = bal_domestic_lag ) %> %
282
+ gather(ER , value , ER_imported , ER_domestic , ER_lagged ) %> %
283
+ # incorporate output_specific_extraction_rate into ER
284
+ mutate(value = value * output_specific_extraction_rate ) %> %
285
+ select(- output_specific_extraction_rate ) %> %
286
+ rename(source_item0 = source_item , sink_item0 = sink_item ) %> %
287
+ left_join_error_no_match(
288
+ Mapping_gcamdata_SUA_ItemCode %> %
289
+ distinct(source_item0 = item , source_item_code = item_code , source_item = item_new_2024 ), by = " source_item0" ) %> %
290
+ left_join_error_no_match(
291
+ Mapping_gcamdata_SUA_ItemCode %> %
292
+ distinct(sink_item0 = item , sink_item_code = item_code , sink_item = item_new_2024 ), by = " sink_item0" ) %> %
293
+ transmute(aggregated_PCe_item , PCe_item , iso , year ,
294
+ nest_level , source_item , sink_item , extraction_point = ER , value ) %> %
295
+ filter(is.finite(value )) %> %
296
+ add_title(" Traceable_FBS_Extraction_Rate_2010_2022" ) %> %
297
+ add_units(" none" ) %> %
298
+ add_comments(" gcamfaostat Export CSV" ) %> %
299
+ add_precursors(file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_SUA_PrimaryEquivalent" )) %> %
300
+ spread(year , value )- >
301
+ Traceable_FBS_Extraction_Rate_2010_2022
302
+
303
+ output_csv_data(
304
+ gcam_dataset = Traceable_FBS_Extraction_Rate_2010_2022 ,
305
+ out_filename = " Traceable_FBS_Extraction_Rate_2010_2022" %> % paste0(" _" , Sys.Date()),
306
+ col_type_nonyear = " cciiccc" ,
307
+ title = " Extraction rates used for compiling the traceable FBS dataset" ,
308
+ unit = " NA" ,
309
+ code = " NA" ,
310
+ description = " Data is compiled and generated by gcamfaostat." ,
311
+ out_dir = DIR_OUTPUT_CSV ,
312
+ GZIP = F )
313
+
314
+ add_to_output_meta(.df = Traceable_FBS_Extraction_Rate_2010_2022 %> % rename(item = sink_item ),
315
+ " Traceable_FBS_Extraction_Rate_2010_2022" )
316
+
317
+
251
318
# Metadata ----
252
319
output_csv_data(
253
320
gcam_dataset = Metadata_GCAMFAOSTAT_Traceable_FBS ,
0 commit comments