@@ -23,15 +23,17 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
2323 FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_FAO_iso_reg" ),
2424 " L105.Bal_new_all" ,
2525 " 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" )
2728
2829 MODULE_OUTPUTS <-
2930 c(CSV = " Metadata_GCAMFAOSTAT_Traceable_FBS" ,
3031 CSV = " Nested_Mapping_SUA_To_Traceable_FBS" ,
3132 CSV = " SUA_2010_2022" ,
3233 CSV = " SUA_Food_Calorie_Macronutrient_2010_2022" ,
3334 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" )
3537
3638 if (command == driver.DECLARE_INPUTS ) {
3739 return (MODULE_INPUTS )
@@ -111,7 +113,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
111113
112114 output_csv_data(
113115 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()) ,
115117 col_type_nonyear = " ccicici" ,
116118 title = " Mapping of SUA items to aggregated primary commodity equivalent products by level of nestings" ,
117119 unit = " NA" ,
@@ -148,7 +150,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
148150
149151 output_csv_data(
150152 gcam_dataset = SUA_2010_2022 ,
151- out_filename = " SUA_2010_2022" ,
153+ out_filename = " SUA_2010_2022" % > % paste0( " _ " , Sys.Date()) ,
152154 col_type_nonyear = " ccifc" ,
153155 title = " Supply utilization accounts for all FAO items in 2010 - 2022" ,
154156 unit = " 1000 tonnes" ,
@@ -177,7 +179,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
177179
178180 output_csv_data(
179181 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()) ,
181183 col_type_nonyear = " ccicc" ,
182184 title = " SUA: food energy and macronutrient in 2010 - 2022" ,
183185 unit = " Mt or Mkcal" ,
@@ -206,7 +208,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
206208
207209 output_csv_data(
208210 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()) ,
210212 col_type_nonyear = " cccc" ,
211213 title = " Traceable FBS: supply utilization accounts in primary equivalent for APE items in 2010 - 2022" ,
212214 unit = " 1000 tonnes" ,
@@ -235,7 +237,7 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
235237
236238 output_csv_data(
237239 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()) ,
239241 col_type_nonyear = " cccc" ,
240242 title = " Traceable FBS: food energy and macronutrient in 2010 - 2022" ,
241243 unit = " Mt or Mkcal" ,
@@ -248,6 +250,71 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
248250 " Traceable_FBS_Food_Calorie_Macronutrient_2010_2022" )
249251
250252
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+
251318 # Metadata ----
252319 output_csv_data(
253320 gcam_dataset = Metadata_GCAMFAOSTAT_Traceable_FBS ,
0 commit comments