From 79a0a3667f7115f830c8021f87d1b19f93f23a6a Mon Sep 17 00:00:00 2001
From: "WUR\\simon083" <wolfram.simon@wur.nl>
Date: Sat, 27 Mar 2021 22:39:08 +0100
Subject: [PATCH] NAL global file: SPAM_GGS_all_global_recspread_area_ratio.csv
 (27.03.2021) > No NA's > Only the **ratio of harvested area** for
 disaggregation. Like this, there is more consistency with the presence of
 nuts/veggies in adm1 zones. Otherwise, it happened that there is area but no
 production vice versa. Then you divide by 0 = inf. > No inf values: The inf
 values came from the division of P/H=Y calculation. The P was in all cases
 very low so I decided to simply recode them to 0. Then Yields would be also
 0. > rounding fixed > 1 decimal like in the original dataset so we do not
 lose the level of detail. > Yield conversion (production in mt) checked and
 correct. > Aggregation to adm1 checked and correct.

---
 SPAM_Data_Transformation/SPAM2010_aggregationADM1.R | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/SPAM_Data_Transformation/SPAM2010_aggregationADM1.R b/SPAM_Data_Transformation/SPAM2010_aggregationADM1.R
index 2fbf246..442bcff 100644
--- a/SPAM_Data_Transformation/SPAM2010_aggregationADM1.R
+++ b/SPAM_Data_Transformation/SPAM2010_aggregationADM1.R
@@ -870,7 +870,7 @@ dat_har_prod <- do.call("rbind", lst.har) # merging all tech types
 # har_dat <- read_csv(here::here("Input_data", "Core_data", "harvestedarea_all_rec_tech_adm1.csv"))#, locale = locale(encoding = "LATIN2"))
 
 # Final global transformed SPAM2010 dataset. This df is in lign with GGS adm1 units.
-SPAM_GGS_all = rbind(dat_prd_prod, dat_har_prod, dat_phy_prod)
+SPAM_GGS_all = rbind(dat_prd_area, dat_har_area, dat_phy_area)
 
 # Changing format and calculating yields
 dat_spam_global = SPAM_GGS_all %>%
@@ -882,8 +882,9 @@ dat_spam_global = SPAM_GGS_all %>%
   mutate(Y = round((P*1000/H),1))%>% #checked for result. We are transforming mt to kg  when multiplying Production by 1000 to get unit kg/ha for yields
   mutate_at(vars(Y), ~replace(., is.nan(.), 0)) %>% 
   mutate(P = ifelse(is.infinite(Y), 0, P)) %>% #If Yields show inf values P is changed to 0.
-  mutate(Y = ifelse(is.infinite(Y),0, Y)) #inf values in Y column are changed to 0's
-write.csv(dat_spam_global, here::here("Input_data", "Core_data", "SPAM_GGS_all_global_recspread_harvrationly.csv"))
+  mutate(Y = ifelse(is.infinite(Y),0, Y)) %>%   #inf values in Y column are changed to 0's
+  mutate_at(7:8, round, 1) #H and A had rounding errors. 
+write.csv(dat_spam_global, here::here("Input_data", "Core_data", "SPAM_GGS_all_global_recspread_area_ratio.csv")) #Final global dataset aggregated to adm1 level and disaggregating tnuts and three veggies
 
 
 # Subsetting EU -----------------------------------------------------------
-- 
GitLab