Commit 35b088f8 authored by Wacker, Jan-David's avatar Wacker, Jan-David
Browse files

Adjusted LossFraction sheet and created FertNutr sheet from excel file

parent 69cadd1e
...@@ -2146,6 +2146,26 @@ loss_maped %>% write_csv("Input_data/loss_fraction.csv") ...@@ -2146,6 +2146,26 @@ loss_maped %>% write_csv("Input_data/loss_fraction.csv")
# write_csv(loss_frac_all, "Input_data/loss_frac_all.csv") # write_csv(loss_frac_all, "Input_data/loss_frac_all.csv")
# Loss fraction sheet - UPDATE 22/02/2022 --------------------------------------
# - one table with loss fractions per category in Gustavsson et al. (2013)
# - one classification tabl: FamGustavson to Product
if (Sys.getenv("USERNAME") == "wacke003"){
localGit = "C:/Users/wacke003/Git/cifos-model.eu/"
} else {
localGit = "C:/Wolfram_Admin/GAMS/EU_model_frmSep21/cifos-model_eu/"
}
excel_file = paste(localGit,"European_CiFoS_model_data.xlsx",sep="")
fLoss = readxl::read_excel(excel_file, sheet = "Loss_Fraction") %>%
dplyr::select("Fam_Gustavson","Postharvest","ProcessingPackaging",
"Distribution","Consumption","Feeding") %>%
distinct()
write_csv(fLoss,"Input_data/LossFraction.csv")
# Consistency checks ----------------------------------------------------- # Consistency checks -----------------------------------------------------
# RULE: What is in the procout ani nutrition should be in the processing and the loss fraction sheet product # RULE: What is in the procout ani nutrition should be in the processing and the loss fraction sheet product
# A$C[!A$C %in% B$C] # returns all values of A$C that are NOT in B$C # A$C[!A$C %in% B$C] # returns all values of A$C that are NOT in B$C
...@@ -2756,4 +2776,35 @@ dat_dist = dat_distance %>% pivot_longer(names_to = "CountryB", ...@@ -2756,4 +2776,35 @@ dat_dist = dat_distance %>% pivot_longer(names_to = "CountryB",
write_csv(dat_dist, "Input_data/dat_dist.csv") write_csv(dat_dist, "Input_data/dat_dist.csv")
# FertNutr sheet -------------------------------------------------------------
if (Sys.getenv("USERNAME") == "wacke003"){
localGit = "C:/Users/wacke003/Git/cifos-model.eu/"
} else {
localGit = "C:/Wolfram_Admin/GAMS/EU_model_frmSep21/cifos-model_eu/"
}
excel_file = paste(localGit,"European_CiFoS_model_data.xlsx",sep="")
FertNutr = readxl::read_excel(excel_file, sheet = "FertNutr")
AnimalNutr = readxl::read_excel(excel_file, sheet = "Animal_Feed_Nutr")
CropNutr = readxl::read_excel(excel_file, sheet = "Crop_Nutrient")
tmp = FertNutr %>%
select(-c("N","P")) %>% left_join(AnimalNutr,by="Product") %>%
select(ProductType,Product,N,P) %>%
left_join(CropNutr %>% select(crop_cifos,Nharv,Pharv),
by=c("Product"="crop_cifos")) %>%
mutate(across(c("N","P"),as.numeric)) %>%
mutate(N=N*1e-3,P=P*1e-3) %>% # convert values to mass fractions
mutate(N_=case_when(ProductType=="ProcOut"~N, # if processing product, prioritise value from animal nutr sheet
ProductType=="ProcRaw" & !is.na(Nharv) ~ Nharv, # if raw product, prioritise value from crop nutr sheet
ProductType=="ProcOut" & is.na(N) ~ Nharv, # use value from CropNutr sheet if no value in AnimalNutr sheet
TRUE ~ N))%>%
mutate(P_=case_when(ProductType=="ProcOut"~P, # if processing product, prioritise value from animal nutr sheet
ProductType=="ProcRaw" & !is.na(Pharv) ~ Pharv, # if raw product, prioritise value from crop nutr sheet
ProductType=="ProcOut" & is.na(P) ~ Pharv, # use value from CropNutr sheet if no value in AnimalNutr sheet
TRUE ~ P)) %>%
select(ProductType,Product,N_,P_) %>% rename(N=N_,P=P_)
write_csv(tmp,"Input_data/FertNutr.csv")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment