diff --git a/DESCRIPTION b/DESCRIPTION
index 57c8b76..dc1dcb7 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -35,7 +35,8 @@ Imports:
utils,
rlang,
stringr,
- ggplot2
+ ggplot2,
+ openxlsx
Suggests:
knitr,
rmarkdown,
diff --git a/R/compare_scenario.R b/R/compare_scenario.R
index 254537b..4926e8c 100644
--- a/R/compare_scenario.R
+++ b/R/compare_scenario.R
@@ -33,365 +33,447 @@
#'
#' @export
#'
-compare_scenario <- function(baseRun, outFile, oDir2){
-
+compare_scenario <- function (baseRun, outFile, oDir2)
+{
base_run <- baseRun
-
outFile <- jsonlite::fromJSON(outFile, flatten = TRUE)
-
oDir2 <- oDir2
-
- base_run_df <- outFile[outFile$scenario == base_run,]
- scenarios_df <- outFile[outFile$scenario != base_run,]
-
+ base_run_df <- outFile[outFile$scenario == base_run, ]
+ scenarios_df <- outFile[outFile$scenario != base_run, ]
scenarioList <- list()
+ output_list <- list()
+
for (i in 1:nrow(scenarios_df)) {
- # Scenario
- scenario_df <- scenarios_df[i,]
+ scenario_df <- scenarios_df[i, ]
scenario <- scenario_df$scenario
-
- total_milk_produced_kg_fpcm_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_kg_fpcm_per_year - base_run_df$total_milk_produced_kg_fpcm_per_year)/base_run_df$total_milk_produced_kg_fpcm_per_year)*100),0,
- ((scenario_df$total_milk_produced_kg_fpcm_per_year - base_run_df$total_milk_produced_kg_fpcm_per_year)/base_run_df$total_milk_produced_kg_fpcm_per_year)*100)
-
- total_meat_produced_kg_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_kg_per_year - base_run_df$total_meat_produced_kg_per_year)/base_run_df$total_meat_produced_kg_per_year)*100),0,
- ((scenario_df$total_meat_produced_kg_per_year - base_run_df$total_meat_produced_kg_per_year)/base_run_df$total_meat_produced_kg_per_year)*100)
-
- total_protein_produced_kg_per_year <- ifelse(!is.finite(((scenario_df$total_protein_produced_kg_per_year - base_run_df$total_protein_produced_kg_per_year)/base_run_df$total_protein_produced_kg_per_year)*100),0,
- ((scenario_df$total_protein_produced_kg_per_year - base_run_df$total_protein_produced_kg_per_year)/base_run_df$total_protein_produced_kg_per_year)*100)
-
- total_tlu <- ifelse(!is.finite(((scenario_df$total_tlu - base_run_df$total_tlu)/base_run_df$total_tlu)*100),0,
- ((scenario_df$total_tlu - base_run_df$total_tlu)/base_run_df$total_tlu)*100)
-
- total_land_requirement_ha <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha - base_run_df$total_land_requirement_ha)/base_run_df$total_land_requirement_ha)*100),0,
- ((scenario_df$total_land_requirement_ha - base_run_df$total_land_requirement_ha)/base_run_df$total_land_requirement_ha)*100)
-
- total_land_requirement_ha_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_fpcm - base_run_df$total_land_requirement_ha_per_kg_fpcm)/base_run_df$total_land_requirement_ha_per_kg_fpcm)*100),0,
- ((scenario_df$total_land_requirement_ha_per_kg_fpcm - base_run_df$total_land_requirement_ha_per_kg_fpcm)/base_run_df$total_land_requirement_ha_per_kg_fpcm)*100)
-
- total_land_requirement_ha_per_kg_meat <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_meat - base_run_df$total_land_requirement_ha_per_kg_meat)/base_run_df$total_land_requirement_ha_per_kg_meat)*100),0,
- ((scenario_df$total_land_requirement_ha_per_kg_meat - base_run_df$total_land_requirement_ha_per_kg_meat)/base_run_df$total_land_requirement_ha_per_kg_meat)*100)
-
- total_land_requirement_ha_per_kg_protein <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_protein - base_run_df$total_land_requirement_ha_per_kg_protein)/base_run_df$total_land_requirement_ha_per_kg_protein)*100),0,
- ((scenario_df$total_land_requirement_ha_per_kg_protein - base_run_df$total_land_requirement_ha_per_kg_protein)/base_run_df$total_land_requirement_ha_per_kg_protein)*100)
-
- total_land_requirement_ha_per_tlu <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_tlu - base_run_df$total_land_requirement_ha_per_tlu)/base_run_df$total_land_requirement_ha_per_tlu)*100),0,
- ((scenario_df$total_land_requirement_ha_per_tlu - base_run_df$total_land_requirement_ha_per_tlu)/base_run_df$total_land_requirement_ha_per_tlu)*100)
-
- total_n_balance_kg_n_per_year <- ifelse(!is.finite(((scenario_df$total_n_balance_kg_n_per_year - base_run_df$total_n_balance_kg_n_per_year)/base_run_df$total_n_balance_kg_n_per_year)*100),0,
- ((scenario_df$total_n_balance_kg_n_per_year - base_run_df$total_n_balance_kg_n_per_year)/base_run_df$total_n_balance_kg_n_per_year)*100)
-
- percent_area_mining <- ifelse(!is.finite(((scenario_df$percent_area_mining - base_run_df$percent_area_mining)/base_run_df$percent_area_mining)*100),0,
- ((scenario_df$percent_area_mining - base_run_df$percent_area_mining)/base_run_df$percent_area_mining)*100)
-
- percent_area_leaching <- ifelse(!is.finite(((scenario_df$percent_area_leaching - base_run_df$percent_area_leaching)/base_run_df$percent_area_leaching)*100),0,
- ((scenario_df$percent_area_leaching - base_run_df$percent_area_leaching)/base_run_df$percent_area_leaching)*100)
-
- n_balance_kg_n_per_ha_per_year <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_ha_per_year - base_run_df$n_balance_kg_n_per_ha_per_year)/base_run_df$n_balance_kg_n_per_ha_per_year)*100),0,
- ((scenario_df$n_balance_kg_n_per_ha_per_year - base_run_df$n_balance_kg_n_per_ha_per_year)/base_run_df$n_balance_kg_n_per_ha_per_year)*100)
-
- n_balance_kg_n_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_fpcm - base_run_df$n_balance_kg_n_per_kg_fpcm)/base_run_df$n_balance_kg_n_per_kg_fpcm)*100),0,
- ((scenario_df$n_balance_kg_n_per_kg_fpcm - base_run_df$n_balance_kg_n_per_kg_fpcm)/base_run_df$n_balance_kg_n_per_kg_fpcm)*100)
-
- n_balance_kg_n_per_kg_meat <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_meat - base_run_df$n_balance_kg_n_per_kg_meat)/base_run_df$n_balance_kg_n_per_kg_meat)*100),0,
- ((scenario_df$n_balance_kg_n_per_kg_meat - base_run_df$n_balance_kg_n_per_kg_meat)/base_run_df$n_balance_kg_n_per_kg_meat)*100)
-
- n_balance_kg_n_per_kg_protein <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_protein - base_run_df$n_balance_kg_n_per_kg_protein)/base_run_df$n_balance_kg_n_per_kg_protein)*100),0,
- ((scenario_df$n_balance_kg_n_per_kg_protein - base_run_df$n_balance_kg_n_per_kg_protein)/base_run_df$n_balance_kg_n_per_kg_protein)*100)
-
- erosion_t_soil_year <- ifelse(!is.finite(((scenario_df$erosion_t_soil_year - base_run_df$erosion_t_soil_year)/base_run_df$erosion_t_soil_year)*100),0,
- ((scenario_df$erosion_t_soil_year - base_run_df$erosion_t_soil_year)/base_run_df$erosion_t_soil_year)*100)
-
- erosion_t_soil_per_ha_per_year <- ifelse(!is.finite(((scenario_df$erosion_t_soil_per_ha_per_year - base_run_df$erosion_t_soil_per_ha_per_year)/base_run_df$erosion_t_soil_per_ha_per_year)*100),0,
- ((scenario_df$erosion_t_soil_per_ha_per_year - base_run_df$erosion_t_soil_per_ha_per_year)/base_run_df$erosion_t_soil_per_ha_per_year)*100)
-
- erosion_kgsoil_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_fpcm - base_run_df$erosion_kgsoil_per_kg_fpcm)/base_run_df$erosion_kgsoil_per_kg_fpcm)*100),0,
- ((scenario_df$erosion_kgsoil_per_kg_fpcm - base_run_df$erosion_kgsoil_per_kg_fpcm)/base_run_df$erosion_kgsoil_per_kg_fpcm)*100)
-
- erosion_kgsoil_per_kg_meat <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_meat - base_run_df$erosion_kgsoil_per_kg_meat)/base_run_df$erosion_kgsoil_per_kg_meat)*100),0,
- ((scenario_df$erosion_kgsoil_per_kg_meat - base_run_df$erosion_kgsoil_per_kg_meat)/base_run_df$erosion_kgsoil_per_kg_meat)*100)
-
- erosion_kgsoil_per_kg_protein <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_protein - base_run_df$erosion_kgsoil_per_kg_protein)/base_run_df$erosion_kgsoil_per_kg_protein)*100),0,
- ((scenario_df$erosion_kgsoil_per_kg_protein - base_run_df$erosion_kgsoil_per_kg_protein)/base_run_df$erosion_kgsoil_per_kg_protein)*100)
-
- ghg_emission_t_co2_eq_per_year <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_year - base_run_df$ghg_emission_t_co2_eq_per_year)/base_run_df$ghg_emission_t_co2_eq_per_year)*100),0,
- ((scenario_df$ghg_emission_t_co2_eq_per_year - base_run_df$ghg_emission_t_co2_eq_per_year)/base_run_df$ghg_emission_t_co2_eq_per_year)*100)
-
- ghg_emission_t_co2_eq_per_ha_per_year <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_ha_per_year - base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)/base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)*100),0,
- ((scenario_df$ghg_emission_t_co2_eq_per_ha_per_year - base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)/base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)*100)
-
- ghg_emission_t_co2_eq_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_fpcm - base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)/base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)*100),0,
- ((scenario_df$ghg_emission_t_co2_eq_per_kg_fpcm - base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)/base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)*100)
-
- ghg_emission_t_co2_eq_per_kg_meat <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_meat - base_run_df$ghg_emission_t_co2_eq_per_kg_meat)/base_run_df$ghg_emission_t_co2_eq_per_kg_meat)*100),0,
- ((scenario_df$ghg_emission_t_co2_eq_per_kg_meat - base_run_df$ghg_emission_t_co2_eq_per_kg_meat)/base_run_df$ghg_emission_t_co2_eq_per_kg_meat)*100)
-
- ghg_emission_t_co2_eq_per_kg_protein <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_protein - base_run_df$ghg_emission_t_co2_eq_per_kg_protein)/base_run_df$ghg_emission_t_co2_eq_per_kg_protein)*100),0,
- ((scenario_df$ghg_emission_t_co2_eq_per_kg_protein - base_run_df$ghg_emission_t_co2_eq_per_kg_protein)/base_run_df$ghg_emission_t_co2_eq_per_kg_protein)*100)
-
- percent_precipitation_used_for_feed_production <- ifelse(!is.finite(((scenario_df$percent_precipitation_used_for_feed_production - base_run_df$percent_precipitation_used_for_feed_production)/base_run_df$percent_precipitation_used_for_feed_production)*100),0,
- ((scenario_df$percent_precipitation_used_for_feed_production - base_run_df$percent_precipitation_used_for_feed_production)/base_run_df$percent_precipitation_used_for_feed_production)*100)
-
- total_water_use_m3 <- ifelse(!is.finite(((scenario_df$total_water_use_m3 - base_run_df$total_water_use_m3)/base_run_df$total_water_use_m3)*100),0,
- ((scenario_df$total_water_use_m3 - base_run_df$total_water_use_m3)/base_run_df$total_water_use_m3)*100)
-
- total_water_use_m3_per_ha <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_ha - base_run_df$total_water_use_m3_per_ha)/base_run_df$total_water_use_m3_per_ha)*100),0,
- ((scenario_df$total_water_use_m3_per_ha - base_run_df$total_water_use_m3_per_ha)/base_run_df$total_water_use_m3_per_ha)*100)
-
- total_water_use_m3_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_fpcm - base_run_df$total_water_use_m3_per_kg_fpcm)/base_run_df$total_water_use_m3_per_kg_fpcm)*100),0,
- ((scenario_df$total_water_use_m3_per_kg_fpcm - base_run_df$total_water_use_m3_per_kg_fpcm)/base_run_df$total_water_use_m3_per_kg_fpcm)*100)
-
- total_water_use_m3_per_kg_meat <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_meat - base_run_df$total_water_use_m3_per_kg_meat)/base_run_df$total_water_use_m3_per_kg_meat)*100),0,
- ((scenario_df$total_water_use_m3_per_kg_meat - base_run_df$total_water_use_m3_per_kg_meat)/base_run_df$total_water_use_m3_per_kg_meat)*100)
-
- total_water_use_m3_per_kg_protein <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_protein - base_run_df$total_water_use_m3_per_kg_protein)/base_run_df$total_water_use_m3_per_kg_protein)*100),0,
- ((scenario_df$total_water_use_m3_per_kg_protein - base_run_df$total_water_use_m3_per_kg_protein)/base_run_df$total_water_use_m3_per_kg_protein)*100)
-
- carbon_stock_change_t_co2eq_per_year <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_year - base_run_df$carbon_stock_change_t_co2eq_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_year)*100),0,
- ((scenario_df$carbon_stock_change_t_co2eq_per_year - base_run_df$carbon_stock_change_t_co2eq_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_year)*100)
-
- carbon_stock_change_t_co2eq_per_ha_per_year <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_ha_per_year - base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)*100),0,
- ((scenario_df$carbon_stock_change_t_co2eq_per_ha_per_year - base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)*100)
-
- carbon_stock_change_t_co2eq_per_fpcm <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_fpcm - base_run_df$carbon_stock_change_t_co2eq_per_fpcm)/base_run_df$carbon_stock_change_t_co2eq_per_fpcm)*100),0,
- ((scenario_df$carbon_stock_change_t_co2eq_per_fpcm - base_run_df$carbon_stock_change_t_co2eq_per_fpcm)/base_run_df$carbon_stock_change_t_co2eq_per_fpcm)*100)
-
- carbon_stock_change_t_co2eq_per_meat <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_meat - base_run_df$carbon_stock_change_t_co2eq_per_meat)/base_run_df$carbon_stock_change_t_co2eq_per_meat)*100),0,
- ((scenario_df$carbon_stock_change_t_co2eq_per_meat - base_run_df$carbon_stock_change_t_co2eq_per_meat)/base_run_df$carbon_stock_change_t_co2eq_per_meat)*100)
-
- carbon_stock_change_t_co2eq_per_protein <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_protein - base_run_df$carbon_stock_change_t_co2eq_per_protein)/base_run_df$carbon_stock_change_t_co2eq_per_protein)*100),0,
- ((scenario_df$carbon_stock_change_t_co2eq_per_protein - base_run_df$carbon_stock_change_t_co2eq_per_protein)/base_run_df$carbon_stock_change_t_co2eq_per_protein)*100)
-
- total_milk_produced_energy_kcal_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_energy_kcal_per_year - base_run_df$total_milk_produced_energy_kcal_per_year)/base_run_df$total_milk_produced_energy_kcal_per_year)*100),0,
- ((scenario_df$total_milk_produced_energy_kcal_per_year - base_run_df$total_milk_produced_energy_kcal_per_year)/base_run_df$total_milk_produced_energy_kcal_per_year)*100)
-
- total_meat_produced_energy_kcal_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_energy_kcal_per_year - base_run_df$total_meat_produced_energy_kcal_per_year)/base_run_df$total_meat_produced_energy_kcal_per_year)*100),0,
- ((scenario_df$total_meat_produced_energy_kcal_per_year - base_run_df$total_meat_produced_energy_kcal_per_year)/base_run_df$total_meat_produced_energy_kcal_per_year)*100)
-
- total_milk_produced_ame_days_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_ame_days_per_year - base_run_df$total_milk_produced_ame_days_per_year)/base_run_df$total_milk_produced_ame_days_per_year)*100),0,
- ((scenario_df$total_milk_produced_ame_days_per_year - base_run_df$total_milk_produced_ame_days_per_year)/base_run_df$total_milk_produced_ame_days_per_year)*100)
-
- total_meat_produced_ame_days_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_ame_days_per_year - base_run_df$total_meat_produced_ame_days_per_year)/base_run_df$total_meat_produced_ame_days_per_year)*100),0,
- ((scenario_df$total_meat_produced_ame_days_per_year - base_run_df$total_meat_produced_ame_days_per_year)/base_run_df$total_meat_produced_ame_days_per_year)*100)
-
- total_carbon_balance_per_fpcm <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_fpcm - base_run_df$total_carbon_balance_per_fpcm)/base_run_df$total_carbon_balance_per_fpcm)*100),0,
- ((scenario_df$total_carbon_balance_per_fpcm - base_run_df$total_carbon_balance_per_fpcm)/base_run_df$total_carbon_balance_per_fpcm)*100)
-
- total_carbon_balance_per_meat <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_meat - base_run_df$total_carbon_balance_per_meat)/base_run_df$total_carbon_balance_per_meat)*100),0,
- ((scenario_df$total_carbon_balance_per_meat - base_run_df$total_carbon_balance_per_meat)/base_run_df$total_carbon_balance_per_meat)*100)
-
- total_carbon_balance_per_protein <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_protein - base_run_df$total_carbon_balance_per_protein)/base_run_df$total_carbon_balance_per_protein)*100),0,
- ((scenario_df$total_carbon_balance_per_protein - base_run_df$total_carbon_balance_per_protein)/base_run_df$total_carbon_balance_per_protein)*100)
-
- scenarioList[[i]] <- data.frame(scenario,
- total_milk_produced_kg_fpcm_per_year,
- total_meat_produced_kg_per_year,
- total_protein_produced_kg_per_year,
- total_tlu,
- total_land_requirement_ha,
- total_land_requirement_ha_per_kg_fpcm,
- total_land_requirement_ha_per_kg_meat,
- total_land_requirement_ha_per_kg_protein,
- total_land_requirement_ha_per_tlu,
- total_n_balance_kg_n_per_year,
- percent_area_mining,
- percent_area_leaching,
- n_balance_kg_n_per_ha_per_year,
- n_balance_kg_n_per_kg_fpcm,
- n_balance_kg_n_per_kg_meat,
- n_balance_kg_n_per_kg_protein,
- erosion_t_soil_year,
- erosion_t_soil_per_ha_per_year,
- erosion_kgsoil_per_kg_fpcm,
- erosion_kgsoil_per_kg_meat,
- erosion_kgsoil_per_kg_protein,
- ghg_emission_t_co2_eq_per_year,
- ghg_emission_t_co2_eq_per_ha_per_year,
- ghg_emission_t_co2_eq_per_kg_fpcm,
- ghg_emission_t_co2_eq_per_kg_meat,
- ghg_emission_t_co2_eq_per_kg_protein,
- percent_precipitation_used_for_feed_production,
- total_water_use_m3,
- total_water_use_m3_per_ha,
- total_water_use_m3_per_kg_fpcm,
- total_water_use_m3_per_kg_meat,
- total_water_use_m3_per_kg_protein,
- carbon_stock_change_t_co2eq_per_year,
- carbon_stock_change_t_co2eq_per_ha_per_year,
- carbon_stock_change_t_co2eq_per_fpcm,
- carbon_stock_change_t_co2eq_per_meat,
- carbon_stock_change_t_co2eq_per_protein,
- total_milk_produced_energy_kcal_per_year,
- total_meat_produced_energy_kcal_per_year,
- total_milk_produced_ame_days_per_year,
- total_meat_produced_ame_days_per_year,
- total_carbon_balance_per_fpcm,
- total_carbon_balance_per_meat,
- total_carbon_balance_per_protein)
+ total_milk_produced_kg_fpcm_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_kg_fpcm_per_year -
+ base_run_df$total_milk_produced_kg_fpcm_per_year)/base_run_df$total_milk_produced_kg_fpcm_per_year) *
+ 100), 0, ((scenario_df$total_milk_produced_kg_fpcm_per_year -
+ base_run_df$total_milk_produced_kg_fpcm_per_year)/base_run_df$total_milk_produced_kg_fpcm_per_year) *
+ 100)
+ total_meat_produced_kg_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_kg_per_year -
+ base_run_df$total_meat_produced_kg_per_year)/base_run_df$total_meat_produced_kg_per_year) *
+ 100), 0, ((scenario_df$total_meat_produced_kg_per_year -
+ base_run_df$total_meat_produced_kg_per_year)/base_run_df$total_meat_produced_kg_per_year) *
+ 100)
+ total_protein_produced_kg_per_year <- ifelse(!is.finite(((scenario_df$total_protein_produced_kg_per_year -
+ base_run_df$total_protein_produced_kg_per_year)/base_run_df$total_protein_produced_kg_per_year) *
+ 100), 0, ((scenario_df$total_protein_produced_kg_per_year -
+ base_run_df$total_protein_produced_kg_per_year)/base_run_df$total_protein_produced_kg_per_year) *
+ 100)
+ total_tlu <- ifelse(!is.finite(((scenario_df$total_tlu -
+ base_run_df$total_tlu)/base_run_df$total_tlu) *
+ 100), 0, ((scenario_df$total_tlu - base_run_df$total_tlu)/base_run_df$total_tlu) *
+ 100)
+ total_land_requirement_ha <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha -
+ base_run_df$total_land_requirement_ha)/base_run_df$total_land_requirement_ha) *
+ 100), 0, ((scenario_df$total_land_requirement_ha -
+ base_run_df$total_land_requirement_ha)/base_run_df$total_land_requirement_ha) *
+ 100)
+ total_land_requirement_ha_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_fpcm -
+ base_run_df$total_land_requirement_ha_per_kg_fpcm)/base_run_df$total_land_requirement_ha_per_kg_fpcm) *
+ 100), 0, ((scenario_df$total_land_requirement_ha_per_kg_fpcm -
+ base_run_df$total_land_requirement_ha_per_kg_fpcm)/base_run_df$total_land_requirement_ha_per_kg_fpcm) *
+ 100)
+ total_land_requirement_ha_per_kg_meat <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_meat -
+ base_run_df$total_land_requirement_ha_per_kg_meat)/base_run_df$total_land_requirement_ha_per_kg_meat) *
+ 100), 0, ((scenario_df$total_land_requirement_ha_per_kg_meat -
+ base_run_df$total_land_requirement_ha_per_kg_meat)/base_run_df$total_land_requirement_ha_per_kg_meat) *
+ 100)
+ total_land_requirement_ha_per_kg_protein <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_kg_protein -
+ base_run_df$total_land_requirement_ha_per_kg_protein)/base_run_df$total_land_requirement_ha_per_kg_protein) *
+ 100), 0, ((scenario_df$total_land_requirement_ha_per_kg_protein -
+ base_run_df$total_land_requirement_ha_per_kg_protein)/base_run_df$total_land_requirement_ha_per_kg_protein) *
+ 100)
+ total_land_requirement_ha_per_tlu <- ifelse(!is.finite(((scenario_df$total_land_requirement_ha_per_tlu -
+ base_run_df$total_land_requirement_ha_per_tlu)/base_run_df$total_land_requirement_ha_per_tlu) *
+ 100), 0, ((scenario_df$total_land_requirement_ha_per_tlu -
+ base_run_df$total_land_requirement_ha_per_tlu)/base_run_df$total_land_requirement_ha_per_tlu) *
+ 100)
+ total_n_balance_kg_n_per_year <- ifelse(!is.finite(((scenario_df$total_n_balance_kg_n_per_year -
+ base_run_df$total_n_balance_kg_n_per_year)/base_run_df$total_n_balance_kg_n_per_year) *
+ 100), 0, ((scenario_df$total_n_balance_kg_n_per_year -
+ base_run_df$total_n_balance_kg_n_per_year)/base_run_df$total_n_balance_kg_n_per_year) *
+ 100)
+ percent_area_mining <- ifelse(!is.finite(((scenario_df$percent_area_mining -
+ base_run_df$percent_area_mining)/base_run_df$percent_area_mining) *
+ 100), 0, ((scenario_df$percent_area_mining - base_run_df$percent_area_mining)/base_run_df$percent_area_mining) *
+ 100)
+ percent_area_leaching <- ifelse(!is.finite(((scenario_df$percent_area_leaching -
+ base_run_df$percent_area_leaching)/base_run_df$percent_area_leaching) *
+ 100), 0, ((scenario_df$percent_area_leaching - base_run_df$percent_area_leaching)/base_run_df$percent_area_leaching) *
+ 100)
+ n_balance_kg_n_per_ha_per_year <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_ha_per_year -
+ base_run_df$n_balance_kg_n_per_ha_per_year)/base_run_df$n_balance_kg_n_per_ha_per_year) *
+ 100), 0, ((scenario_df$n_balance_kg_n_per_ha_per_year -
+ base_run_df$n_balance_kg_n_per_ha_per_year)/base_run_df$n_balance_kg_n_per_ha_per_year) *
+ 100)
+ n_balance_kg_n_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_fpcm -
+ base_run_df$n_balance_kg_n_per_kg_fpcm)/base_run_df$n_balance_kg_n_per_kg_fpcm) *
+ 100), 0, ((scenario_df$n_balance_kg_n_per_kg_fpcm -
+ base_run_df$n_balance_kg_n_per_kg_fpcm)/base_run_df$n_balance_kg_n_per_kg_fpcm) *
+ 100)
+ n_balance_kg_n_per_kg_meat <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_meat -
+ base_run_df$n_balance_kg_n_per_kg_meat)/base_run_df$n_balance_kg_n_per_kg_meat) *
+ 100), 0, ((scenario_df$n_balance_kg_n_per_kg_meat -
+ base_run_df$n_balance_kg_n_per_kg_meat)/base_run_df$n_balance_kg_n_per_kg_meat) *
+ 100)
+ n_balance_kg_n_per_kg_protein <- ifelse(!is.finite(((scenario_df$n_balance_kg_n_per_kg_protein -
+ base_run_df$n_balance_kg_n_per_kg_protein)/base_run_df$n_balance_kg_n_per_kg_protein) *
+ 100), 0, ((scenario_df$n_balance_kg_n_per_kg_protein -
+ base_run_df$n_balance_kg_n_per_kg_protein)/base_run_df$n_balance_kg_n_per_kg_protein) *
+ 100)
+ erosion_t_soil_year <- ifelse(!is.finite(((scenario_df$erosion_t_soil_year -
+ base_run_df$erosion_t_soil_year)/base_run_df$erosion_t_soil_year) *
+ 100), 0, ((scenario_df$erosion_t_soil_year - base_run_df$erosion_t_soil_year)/base_run_df$erosion_t_soil_year) *
+ 100)
+ erosion_t_soil_per_ha_per_year <- ifelse(!is.finite(((scenario_df$erosion_t_soil_per_ha_per_year -
+ base_run_df$erosion_t_soil_per_ha_per_year)/base_run_df$erosion_t_soil_per_ha_per_year) *
+ 100), 0, ((scenario_df$erosion_t_soil_per_ha_per_year -
+ base_run_df$erosion_t_soil_per_ha_per_year)/base_run_df$erosion_t_soil_per_ha_per_year) *
+ 100)
+ erosion_kgsoil_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_fpcm -
+ base_run_df$erosion_kgsoil_per_kg_fpcm)/base_run_df$erosion_kgsoil_per_kg_fpcm) *
+ 100), 0, ((scenario_df$erosion_kgsoil_per_kg_fpcm -
+ base_run_df$erosion_kgsoil_per_kg_fpcm)/base_run_df$erosion_kgsoil_per_kg_fpcm) *
+ 100)
+ erosion_kgsoil_per_kg_meat <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_meat -
+ base_run_df$erosion_kgsoil_per_kg_meat)/base_run_df$erosion_kgsoil_per_kg_meat) *
+ 100), 0, ((scenario_df$erosion_kgsoil_per_kg_meat -
+ base_run_df$erosion_kgsoil_per_kg_meat)/base_run_df$erosion_kgsoil_per_kg_meat) *
+ 100)
+ erosion_kgsoil_per_kg_protein <- ifelse(!is.finite(((scenario_df$erosion_kgsoil_per_kg_protein -
+ base_run_df$erosion_kgsoil_per_kg_protein)/base_run_df$erosion_kgsoil_per_kg_protein) *
+ 100), 0, ((scenario_df$erosion_kgsoil_per_kg_protein -
+ base_run_df$erosion_kgsoil_per_kg_protein)/base_run_df$erosion_kgsoil_per_kg_protein) *
+ 100)
+ ghg_emission_t_co2_eq_per_year <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_year -
+ base_run_df$ghg_emission_t_co2_eq_per_year)/base_run_df$ghg_emission_t_co2_eq_per_year) *
+ 100), 0, ((scenario_df$ghg_emission_t_co2_eq_per_year -
+ base_run_df$ghg_emission_t_co2_eq_per_year)/base_run_df$ghg_emission_t_co2_eq_per_year) *
+ 100)
+ ghg_emission_t_co2_eq_per_ha_per_year <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_ha_per_year -
+ base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)/base_run_df$ghg_emission_t_co2_eq_per_ha_per_year) *
+ 100), 0, ((scenario_df$ghg_emission_t_co2_eq_per_ha_per_year -
+ base_run_df$ghg_emission_t_co2_eq_per_ha_per_year)/base_run_df$ghg_emission_t_co2_eq_per_ha_per_year) *
+ 100)
+ ghg_emission_t_co2_eq_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_fpcm -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)/base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm) *
+ 100), 0, ((scenario_df$ghg_emission_t_co2_eq_per_kg_fpcm -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm)/base_run_df$ghg_emission_t_co2_eq_per_kg_fpcm) *
+ 100)
+ ghg_emission_t_co2_eq_per_kg_meat <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_meat -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_meat)/base_run_df$ghg_emission_t_co2_eq_per_kg_meat) *
+ 100), 0, ((scenario_df$ghg_emission_t_co2_eq_per_kg_meat -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_meat)/base_run_df$ghg_emission_t_co2_eq_per_kg_meat) *
+ 100)
+ ghg_emission_t_co2_eq_per_kg_protein <- ifelse(!is.finite(((scenario_df$ghg_emission_t_co2_eq_per_kg_protein -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_protein)/base_run_df$ghg_emission_t_co2_eq_per_kg_protein) *
+ 100), 0, ((scenario_df$ghg_emission_t_co2_eq_per_kg_protein -
+ base_run_df$ghg_emission_t_co2_eq_per_kg_protein)/base_run_df$ghg_emission_t_co2_eq_per_kg_protein) *
+ 100)
+ percent_precipitation_used_for_feed_production <- ifelse(!is.finite(((scenario_df$percent_precipitation_used_for_feed_production -
+ base_run_df$percent_precipitation_used_for_feed_production)/base_run_df$percent_precipitation_used_for_feed_production) *
+ 100), 0, ((scenario_df$percent_precipitation_used_for_feed_production -
+ base_run_df$percent_precipitation_used_for_feed_production)/base_run_df$percent_precipitation_used_for_feed_production) *
+ 100)
+ total_water_use_m3 <- ifelse(!is.finite(((scenario_df$total_water_use_m3 -
+ base_run_df$total_water_use_m3)/base_run_df$total_water_use_m3) *
+ 100), 0, ((scenario_df$total_water_use_m3 - base_run_df$total_water_use_m3)/base_run_df$total_water_use_m3) *
+ 100)
+ total_water_use_m3_per_ha <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_ha -
+ base_run_df$total_water_use_m3_per_ha)/base_run_df$total_water_use_m3_per_ha) *
+ 100), 0, ((scenario_df$total_water_use_m3_per_ha -
+ base_run_df$total_water_use_m3_per_ha)/base_run_df$total_water_use_m3_per_ha) *
+ 100)
+ total_water_use_m3_per_kg_fpcm <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_fpcm -
+ base_run_df$total_water_use_m3_per_kg_fpcm)/base_run_df$total_water_use_m3_per_kg_fpcm) *
+ 100), 0, ((scenario_df$total_water_use_m3_per_kg_fpcm -
+ base_run_df$total_water_use_m3_per_kg_fpcm)/base_run_df$total_water_use_m3_per_kg_fpcm) *
+ 100)
+ total_water_use_m3_per_kg_meat <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_meat -
+ base_run_df$total_water_use_m3_per_kg_meat)/base_run_df$total_water_use_m3_per_kg_meat) *
+ 100), 0, ((scenario_df$total_water_use_m3_per_kg_meat -
+ base_run_df$total_water_use_m3_per_kg_meat)/base_run_df$total_water_use_m3_per_kg_meat) *
+ 100)
+ total_water_use_m3_per_kg_protein <- ifelse(!is.finite(((scenario_df$total_water_use_m3_per_kg_protein -
+ base_run_df$total_water_use_m3_per_kg_protein)/base_run_df$total_water_use_m3_per_kg_protein) *
+ 100), 0, ((scenario_df$total_water_use_m3_per_kg_protein -
+ base_run_df$total_water_use_m3_per_kg_protein)/base_run_df$total_water_use_m3_per_kg_protein) *
+ 100)
+ carbon_stock_change_t_co2eq_per_year <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_year -
+ base_run_df$carbon_stock_change_t_co2eq_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_year) *
+ 100), 0, ((scenario_df$carbon_stock_change_t_co2eq_per_year -
+ base_run_df$carbon_stock_change_t_co2eq_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_year) *
+ 100)
+ carbon_stock_change_t_co2eq_per_ha_per_year <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_ha_per_year -
+ base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year) *
+ 100), 0, ((scenario_df$carbon_stock_change_t_co2eq_per_ha_per_year -
+ base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year)/base_run_df$carbon_stock_change_t_co2eq_per_ha_per_year) *
+ 100)
+ carbon_stock_change_t_co2eq_per_fpcm <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_fpcm -
+ base_run_df$carbon_stock_change_t_co2eq_per_fpcm)/base_run_df$carbon_stock_change_t_co2eq_per_fpcm) *
+ 100), 0, ((scenario_df$carbon_stock_change_t_co2eq_per_fpcm -
+ base_run_df$carbon_stock_change_t_co2eq_per_fpcm)/base_run_df$carbon_stock_change_t_co2eq_per_fpcm) *
+ 100)
+ carbon_stock_change_t_co2eq_per_meat <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_meat -
+ base_run_df$carbon_stock_change_t_co2eq_per_meat)/base_run_df$carbon_stock_change_t_co2eq_per_meat) *
+ 100), 0, ((scenario_df$carbon_stock_change_t_co2eq_per_meat -
+ base_run_df$carbon_stock_change_t_co2eq_per_meat)/base_run_df$carbon_stock_change_t_co2eq_per_meat) *
+ 100)
+ carbon_stock_change_t_co2eq_per_protein <- ifelse(!is.finite(((scenario_df$carbon_stock_change_t_co2eq_per_protein -
+ base_run_df$carbon_stock_change_t_co2eq_per_protein)/base_run_df$carbon_stock_change_t_co2eq_per_protein) *
+ 100), 0, ((scenario_df$carbon_stock_change_t_co2eq_per_protein -
+ base_run_df$carbon_stock_change_t_co2eq_per_protein)/base_run_df$carbon_stock_change_t_co2eq_per_protein) *
+ 100)
+ total_milk_produced_energy_kcal_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_energy_kcal_per_year -
+ base_run_df$total_milk_produced_energy_kcal_per_year)/base_run_df$total_milk_produced_energy_kcal_per_year) *
+ 100), 0, ((scenario_df$total_milk_produced_energy_kcal_per_year -
+ base_run_df$total_milk_produced_energy_kcal_per_year)/base_run_df$total_milk_produced_energy_kcal_per_year) *
+ 100)
+ total_meat_produced_energy_kcal_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_energy_kcal_per_year -
+ base_run_df$total_meat_produced_energy_kcal_per_year)/base_run_df$total_meat_produced_energy_kcal_per_year) *
+ 100), 0, ((scenario_df$total_meat_produced_energy_kcal_per_year -
+ base_run_df$total_meat_produced_energy_kcal_per_year)/base_run_df$total_meat_produced_energy_kcal_per_year) *
+ 100)
+ total_milk_produced_ame_days_per_year <- ifelse(!is.finite(((scenario_df$total_milk_produced_ame_days_per_year -
+ base_run_df$total_milk_produced_ame_days_per_year)/base_run_df$total_milk_produced_ame_days_per_year) *
+ 100), 0, ((scenario_df$total_milk_produced_ame_days_per_year -
+ base_run_df$total_milk_produced_ame_days_per_year)/base_run_df$total_milk_produced_ame_days_per_year) *
+ 100)
+ total_meat_produced_ame_days_per_year <- ifelse(!is.finite(((scenario_df$total_meat_produced_ame_days_per_year -
+ base_run_df$total_meat_produced_ame_days_per_year)/base_run_df$total_meat_produced_ame_days_per_year) *
+ 100), 0, ((scenario_df$total_meat_produced_ame_days_per_year -
+ base_run_df$total_meat_produced_ame_days_per_year)/base_run_df$total_meat_produced_ame_days_per_year) *
+ 100)
+ total_carbon_balance_per_fpcm <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_fpcm -
+ base_run_df$total_carbon_balance_per_fpcm)/base_run_df$total_carbon_balance_per_fpcm) *
+ 100), 0, ((scenario_df$total_carbon_balance_per_fpcm -
+ base_run_df$total_carbon_balance_per_fpcm)/base_run_df$total_carbon_balance_per_fpcm) *
+ 100)
+ total_carbon_balance_per_meat <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_meat -
+ base_run_df$total_carbon_balance_per_meat)/base_run_df$total_carbon_balance_per_meat) *
+ 100), 0, ((scenario_df$total_carbon_balance_per_meat -
+ base_run_df$total_carbon_balance_per_meat)/base_run_df$total_carbon_balance_per_meat) *
+ 100)
+ total_carbon_balance_per_protein <- ifelse(!is.finite(((scenario_df$total_carbon_balance_per_protein -
+ base_run_df$total_carbon_balance_per_protein)/base_run_df$total_carbon_balance_per_protein) *
+ 100), 0, ((scenario_df$total_carbon_balance_per_protein -
+ base_run_df$total_carbon_balance_per_protein)/base_run_df$total_carbon_balance_per_protein) *
+ 100)
+ scenarioList[[i]] <- data.frame(scenario, total_milk_produced_kg_fpcm_per_year,
+ total_meat_produced_kg_per_year, total_protein_produced_kg_per_year,
+ total_tlu, total_land_requirement_ha, total_land_requirement_ha_per_kg_fpcm,
+ total_land_requirement_ha_per_kg_meat, total_land_requirement_ha_per_kg_protein,
+ total_land_requirement_ha_per_tlu, total_n_balance_kg_n_per_year,
+ percent_area_mining, percent_area_leaching, n_balance_kg_n_per_ha_per_year,
+ n_balance_kg_n_per_kg_fpcm, n_balance_kg_n_per_kg_meat,
+ n_balance_kg_n_per_kg_protein, erosion_t_soil_year,
+ erosion_t_soil_per_ha_per_year, erosion_kgsoil_per_kg_fpcm,
+ erosion_kgsoil_per_kg_meat, erosion_kgsoil_per_kg_protein,
+ ghg_emission_t_co2_eq_per_year, ghg_emission_t_co2_eq_per_ha_per_year,
+ ghg_emission_t_co2_eq_per_kg_fpcm, ghg_emission_t_co2_eq_per_kg_meat,
+ ghg_emission_t_co2_eq_per_kg_protein, percent_precipitation_used_for_feed_production,
+ total_water_use_m3, total_water_use_m3_per_ha, total_water_use_m3_per_kg_fpcm,
+ total_water_use_m3_per_kg_meat, total_water_use_m3_per_kg_protein,
+ carbon_stock_change_t_co2eq_per_year, carbon_stock_change_t_co2eq_per_ha_per_year,
+ carbon_stock_change_t_co2eq_per_fpcm, carbon_stock_change_t_co2eq_per_meat,
+ carbon_stock_change_t_co2eq_per_protein, total_milk_produced_energy_kcal_per_year,
+ total_meat_produced_energy_kcal_per_year, total_milk_produced_ame_days_per_year,
+ total_meat_produced_ame_days_per_year, total_carbon_balance_per_fpcm,
+ total_carbon_balance_per_meat, total_carbon_balance_per_protein)
}
-
results <- scenarioList %>% dplyr::bind_rows()
-
- # Save results in excel
- excel_output_path <- paste0(oDir2, "/scenario_comparison.xlsx")
- write.xlsx(results, excel_output_path, overwrite = TRUE)
-
- # Generate plots
-
- for(i in 2:ncol(results)){
-
+ for (i in 2:ncol(results)) {
datos <- results %>% select(1, all_of(i))
-
- # titles
tt <- colnames(datos[2])
-
-
- if(tt == "total_milk_produced_kg_fpcm_per_year"){
+ if (tt == "total_milk_produced_kg_fpcm_per_year") {
title = "Total milk FPCM (kg/yr)"
y_title = "% change in milk FPCM (kg/yr)"
- }else if(tt == "total_meat_produced_kg_per_year"){
+ }
+ else if (tt == "total_meat_produced_kg_per_year") {
title = "Total meat (kg/yr)"
y_title = "% change in meat (kg/yr)"
- }else if(tt == "total_protein_produced_kg_per_year"){
+ }
+ else if (tt == "total_protein_produced_kg_per_year") {
title = "Total protein (kg/yr)"
y_title = "% change in protein (kg/yr)"
- }else if (tt == "total_tlu"){
+ }
+ else if (tt == "total_tlu") {
title = "Tropical Livestock Unit"
y_title = "% change in Tropical Livestock Unit"
- }else if (tt == "total_land_requirement_ha"){
+ }
+ else if (tt == "total_land_requirement_ha") {
title = "Land required (ha/yr)"
y_title = "% change in land required (ha/yr)"
- }else if (tt == "total_land_requirement_ha_per_kg_fpcm"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_fpcm") {
title = "Land required (ha/kg FPCM)"
y_title = "% change in land required (ha/kg FPCM)"
- }else if (tt == "total_land_requirement_ha_per_kg_meat"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_meat") {
title = "Land required (ha/kg meat)"
y_title = "% change in land required (ha/kg meat)"
- }else if (tt == "total_land_requirement_ha_per_kg_protein"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_protein") {
title = "Land required (ha/kg protein)"
y_title = "% change in land required (ha/kg protein)"
- }else if (tt == "total_land_requirement_ha_per_tlu"){
+ }
+ else if (tt == "total_land_requirement_ha_per_tlu") {
title = "Land required (ha/TLU)"
y_title = "% change in land required (ha/TLU)"
- }else if (tt == "total_n_balance_kg_n_per_year"){
+ }
+ else if (tt == "total_n_balance_kg_n_per_year") {
title = "N balance (kg N/yr)"
y_title = "% change in N balance (kg N/yr)"
- }else if (tt == "percent_area_mining"){
+ }
+ else if (tt == "percent_area_mining") {
title = "Soil mining (%)"
y_title = "% change in soil mining"
- }else if (tt == "percent_area_leaching"){
+ }
+ else if (tt == "percent_area_leaching") {
title = "Soil leaching (%)"
y_title = "% change in soil leaching"
- }else if (tt == "n_balance_kg_n_per_ha_per_year"){
+ }
+ else if (tt == "n_balance_kg_n_per_ha_per_year") {
title = "N balance (kg N/ha/yr)"
y_title = "% change in N balance (kg N/ha/yr)"
- }else if (tt == "n_balance_kg_n_per_kg_fpcm"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_fpcm") {
title = "N balance (kg N/kg FPCM)"
y_title = "% change in N balance (kg N/kg FPCM)"
- }else if (tt == "n_balance_kg_n_per_kg_meat"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_meat") {
title = "N balance (kg N/kg meat)"
y_title = "% change in N balance (kg N/kg meat)"
- }else if (tt == "n_balance_kg_n_per_kg_protein"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_protein") {
title = "N balance (kg N/kg protein)"
y_title = "% change in N balance (kg N/kg protein)"
- }else if (tt == "erosion_t_soil_year"){
+ }
+ else if (tt == "erosion_t_soil_year") {
title = "Erosion (t soil/yr)"
y_title = "% change in erosion (t soil/yr)"
- }else if (tt == "erosion_t_soil_per_ha_per_year"){
+ }
+ else if (tt == "erosion_t_soil_per_ha_per_year") {
title = "Erosion (t soil/ha/yr)"
y_title = "% change in erosion (t soil/ha/yr)"
- }else if (tt == "erosion_kgsoil_per_kg_fpcm"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_fpcm") {
title = "Erosion (t soil/kg FPCM)"
y_title = "% change in erosion (t soil/kg FPCM)"
- }else if (tt == "erosion_kgsoil_per_kg_meat"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_meat") {
title = "Erosion (t soil/kg meat)"
y_title = "% change in erosion (t soil/kg meat)"
- }else if (tt == "erosion_kgsoil_per_kg_protein"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_protein") {
title = "Erosion (t soil/kg protein)"
y_title = "% change in erosion (t soil/kg protein)"
- }else if (tt == "ghg_emission_t_co2_eq_per_year"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_year") {
title = "GHG (t CO2eq/yr)"
y_title = "% change in GHG (t CO2eq/yr)"
- }else if (tt == "ghg_emission_t_co2_eq_per_ha_per_year"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_ha_per_year") {
title = "GHG (t CO2eq/ha/yr)"
y_title = "% change in GHG (t CO2eq/ha/yr)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_fpcm"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_fpcm") {
title = "GHG (CO2eq/kg FPCM)"
y_title = "% change in GHG (CO2eq/kg FPCM)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_meat"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_meat") {
title = "GHG (CO2eq/kg meat)"
y_title = "% change in GHG (CO2eq/kg meat)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_protein"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_protein") {
title = "GHG (CO2eq/kg protein)"
y_title = "% change in GHG (CO2eq/kg protein)"
- }else if (tt == "percent_precipitation_used_for_feed_production"){
+ }
+ else if (tt == "percent_precipitation_used_for_feed_production") {
title = "% Precipitation use for feed production"
y_title = "% change in % precipitation use for feed production"
- }else if (tt == "total_water_use_m3"){
+ }
+ else if (tt == "total_water_use_m3") {
title = "Water use (m3/yr)"
y_title = "% change water use (m3/yr)"
- }else if (tt == "total_water_use_m3_per_ha"){
+ }
+ else if (tt == "total_water_use_m3_per_ha") {
title = "Water use (m3/ha)"
y_title = "% change in water use (m3/ha)"
- }else if (tt == "total_water_use_m3_per_kg_fpcm"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_fpcm") {
title = "Water use (m3/kg FPCM)"
y_title = "% change in water use (m3/kg FPCM)"
- }else if (tt == "total_water_use_m3_per_kg_meat"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_meat") {
title = "Water use (m3/kg meat)"
y_title = "% change in water use (m3/kg meat)"
- }else if (tt == "total_water_use_m3_per_kg_protein"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_protein") {
title = "Water (m3/kg protein)"
y_title = "% change in water (m3/kg protein)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_year"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_year") {
title = "Carbon stock changes (t CO2eq/yr)"
y_title = "% change in carbon stock changes (t CO2eq/yr)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_ha_per_year"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_ha_per_year") {
title = "Carbon stock changes (t CO2eq/ha/yr)"
y_title = "% change in carbon stock changes (t CO2eq/ha/yr)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_fpcm"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_fpcm") {
title = "Carbon stock changes (t CO2eq/kg FPCM)"
y_title = "% change in carbon stock changes (t CO2eq/kg FPCM)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_meat"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_meat") {
title = "Carbon stock changes (t CO2eq/kg meat)"
y_title = "% change in carbon stock changes (t CO2eq/kg meat)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_protein"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_protein") {
title = "Carbon stock changes (t CO2eq/kg protein)"
y_title = "% change in carbon stock changes (t CO2eq/kg protein)"
- }else if (tt == "total_milk_produced_energy_kcal_per_year"){
+ }
+ else if (tt == "total_milk_produced_energy_kcal_per_year") {
title = "Energy (kcal/kg FPCM)"
y_title = "% change in energy (kcal/kg FPCM)"
- }else if (tt == "total_meat_produced_energy_kcal_per_year"){
+ }
+ else if (tt == "total_meat_produced_energy_kcal_per_year") {
title = "Energy (kcal/kg meat)"
y_title = "% change in energy (kcal/kg meat)"
- }else if (tt == "total_milk_produced_ame_days_per_year"){
+ }
+ else if (tt == "total_milk_produced_ame_days_per_year") {
title = "AME (days/kg FPCM)"
y_title = "% change in AME (days/kg FPCM)"
- }else if (tt == "total_meat_produced_ame_days_per_year"){
+ }
+ else if (tt == "total_meat_produced_ame_days_per_year") {
title = "AME (days/kg meat)"
y_title = "% change in AME (days/kg meat)"
- }else if (tt == "total_carbon_balance_per_fpcm"){
+ }
+ else if (tt == "total_carbon_balance_per_fpcm") {
title = "Carbon balance (t CO2eq/kg FPCM)"
y_title = "% change in carbon balance (t CO2eq/kg FPCM)"
- }else if (tt == "total_carbon_balance_per_meat"){
+ }
+ else if (tt == "total_carbon_balance_per_meat") {
title = "Carbon balance (t CO2eq/kg meat)"
y_title = "% change in carbon balance (t CO2eq/kg meat)"
- }else if (tt == "total_carbon_balance_per_protein"){
+ }
+ else if (tt == "total_carbon_balance_per_protein") {
title = "Carbon balance (t CO2eq/kg protein)"
y_title = "% change in carbon balance (t CO2eq/kg protein)"
- }else{
+ }
+ else {
NA
}
- ggplot(datos, aes_string("scenario", y = tt, fill = "scenario")) +
- geom_bar(stat = "identity",
- position = "dodge",
- width = 0.2) +
- geom_text(aes(label = round(datos[,2],2)), position = position_dodge(width = 0.2), vjust = -0.5, size = 2) +
- labs(x = "", y = y_title, title = title, fill = "Scenario") +
- theme_bw()
-
- ggsave(paste0(oDir2, tt, ".png"), width = 150, height = 100, units = "mm")
-
+ output_list[[tt]] <- list(
+ datos = datos,
+ tt = tt,
+ title = title,
+ y_title = y_title
+ )
}
+ return(output_list)
}
-
diff --git a/R/feed_quality.R b/R/feed_quality.R
index 67541e2..6ad7b9f 100644
--- a/R/feed_quality.R
+++ b/R/feed_quality.R
@@ -39,7 +39,6 @@ feed_quality <- function(para) {
livestock_type_selected <- livestock_df[livestock_df$livetype_code == livestock, ]
-
for (season in 1:nrow(seasons)) {
feed_production <- unnest(para[["feed_items"]], cols = c(feed_type_name))
@@ -49,9 +48,7 @@ feed_quality <- function(para) {
feed_allocation <- list()
for (i in 1:length(feed_types)) {
-
- feed_selected <- feed_production %>% dplyr::filter(feed_type_name %in%
- feed_production$feed_type_name[i])
+ feed_selected <- feed_production %>% dplyr::filter(feed_type_name %in% feed_types[i])
#feed_item <- as.data.frame(feed_selected[["feed_items"]])
@@ -77,7 +74,7 @@ feed_quality <- function(para) {
seasons$season_name[season])
feed_item_selected <- feeding_seasons %>%
- dplyr::filter(feed_item_code == feed_selected[["feed_item_code"]])
+ dplyr::filter(feed_item_code %in% feed_selected[["feed_item_code"]])
livestock_selected <- feed_item_selected[["livestock"]] %>%
as.data.frame() %>%
@@ -135,7 +132,7 @@ feed_quality <- function(para) {
feed_allocation_all[is.na(feed_allocation_all)] <- 0
# Bind and add into the season list
- season_allocation[[season]] <- cbind(season_name = rep(feed_item_selected$season_name, times = nrow(feed_allocation_all)),
+ season_allocation[[season]] <- cbind(season_name = rep(feed_item_selected$season_name[1],times = nrow(feed_allocation_all)),
livestock_category_code = rep(livestock_selected$livetype_code, times = nrow(feed_allocation_all)),
livestock_category_name = rep(livestock_type_selected$livetype_desc, times = nrow(feed_allocation_all)),
feed_allocation_all)
@@ -155,4 +152,6 @@ feed_quality <- function(para) {
# Bind by rows
livestock_feed_allocation <- livestock_allocation %>% bind_rows()
+ return(livestock_feed_allocation)
+
}
diff --git a/R/ghg_emission.R b/R/ghg_emission.R
index 55bccea..1d829ef 100644
--- a/R/ghg_emission.R
+++ b/R/ghg_emission.R
@@ -97,7 +97,7 @@ ghg_emission <- function(para, energy_required, ghg_ipcc_data, land_required, ni
#Computing methane enteric emission factor
ef <- ym1%>%
- mutate(enteric_methane_emissions = (ge_intake*(ym/100)*no_days)/55.65) #equation 10.21
+ mutate(enteric_methane_emissions = ((ge_intake/no_days)*(ym/100)*no_days)/55.65) #equation 10.21
############################################################################################################################
#Computing methane emission from manure management T2
diff --git a/R/merge_outputs.R b/R/merge_outputs.R
index 974bbfe..2f1e648 100644
--- a/R/merge_outputs.R
+++ b/R/merge_outputs.R
@@ -47,14 +47,15 @@
#' soil_carbon <- soil_organic_carbon(para, land_required, biomass)
#' ghg_emission <- ghg_emission(para,energy_required,ghg_para,land_required,nitrogen_balance)
#' combineOutputs(para,feed_basket_quality,energy_required,land_required,soil_erosion,water_required,
-#' nitrogen_balance,livestock_productivity,biomass,soil_carbon,ghg_emission,filePath,readMe,benchMark)
+#' nitrogen_balance,livestock_productivity,biomass,soil_carbon,ghg_emission,filePath)
#' }
#'
#' @export
#'
+
combineOutputs <- function(para, feed_basket_quality, energy_required, land_required,
soil_erosion, water_required, nitrogen_balance, livestock_productivity,
- biomass,soil_carbon, ghg_emission, filePath, readMe, benchMark){
+ biomass,soil_carbon, ghg_emission, filePath, primary_excel){
if (exists("para")) {
para = para
}else {para = "ERROR: Data is not provided"}
@@ -106,18 +107,11 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
# Extract the file name
fileName <- sub("\\.\\w+$", "", basename(filePath))
}else {filePath = "ERROR: File path is not provided"}
-
- if (exists("readMe")) {
- readMe = readMe
- # Load readme workbook
- readMe_wb <- loadWorkbook(readMe)
- }else {filePath = "ERROR: ReadMe file is not provided"}
-
- if (exists("benchMark")) {
- benchMark = benchMark
- # Load Benchmark workbook
- benchMark_wb <- loadWorkbook(benchMark)
- }else {filePath = "ERROR: Benchmark file is not provided"}
+ if (exists("primary_excel")) {
+ primary_excel = primary_excel
+ # Load primary_excel workbook
+ primary_excel_wb <- loadWorkbook(primary_excel)
+ }else {filePath = "ERROR: primary excel file is not provided"}
feed_basket_quality <- lapply(feed_basket_quality, function(x) {x <- x[,-1]})
@@ -135,24 +129,12 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
# geom_text(aes(label = round(area_feed_total, 2)), vjust = -0.5, size = 1, angle = 45) +
# theme_bw()+
# theme(axis.text.x = element_text(angle = 45, hjust = 1))
- land_required %>%
+ land_required_output <- land_required %>%
group_by(feed, season_name) %>%
summarise(area_feed_total = sum(area_feed, na.rm = TRUE)) %>%
group_by(feed) %>%
mutate(cumulative_area = cumsum(area_feed_total),
- label_position = cumulative_area - 0.7 * area_feed_total) %>%
- ggplot(aes(x = feed, y = area_feed_total, fill = season_name)) +
- geom_bar(stat = "identity", width = 0.6) +
- geom_text(aes(label = round(area_feed_total, 2), y = label_position),
- size = 1, angle = 45, vjust = -0.) +
- labs(x = "Feed Item", y = "Area (Ha)", fill = "Seasons", title = "Land Requirement and Feed Basket") +
- theme_bw() +
- theme(axis.text.x = element_text(size = 5, angle = 45, hjust = 1),
- axis.text.y = element_text(size = 5)) +
- scale_fill_discrete(guide = guide_legend(title = "Seasons"))
-
- ggsave(paste0(directoryPath, "/", fileName, "_land_required.png"), width = 150, height = 100, units = "mm")
-
+ label_position = cumulative_area - 0.7 * area_feed_total)
# Expanded table land requirement
ex_land_required <- land_required %>%
@@ -293,7 +275,7 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
production_kg_per_year = c("",cattle_milk_kg,cattle_meat_kg,"",other_milk_kg,other_meat_kg,"",total_milk_kg,total_meat_kg),
production_energy_kcal_per_year = c("",cattle_milk_energy,cattle_meat_energy,"",other_milk_energy,other_meat_energy,"",total_milk_energy,total_meat_energy),
protein_kg_per_year = c("",cattle_milk_protein,cattle_meat_protein,"",other_milk_protein,other_meat_protein,"",total_milk_protein,total_meat_protein)
- ) %>% mutate(ame_days = as.numeric(production_energy_kcal_per_year)/2500)
+ ) %>% mutate(ame_days = as.numeric(production_energy_kcal_per_year)/2500)
# Produced manure
cattle_number <- sum(livestock_productivity$number_cattle, na.rm = T)
@@ -328,18 +310,9 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
## Soil impact
###############################################################################################
# Plotting N balance
- nitrogen_balance %>%
+ nitrogen_balance_output <- nitrogen_balance %>%
group_by(feed) %>%
- summarise(nbalance_kg_n_total = sum(nbalance_kg_n_total, na.rm = T)) %>%
- ggplot2::ggplot(aes(x=feed, y=nbalance_kg_n_total))+
- geom_bar(stat = "identity", width = 0.6)+
- labs(x = "Feed Item", y = "Kg N", title = "Total Nitrogen Balance by Feed Item") +
- geom_text(aes(label = round(nbalance_kg_n_total, 2)), vjust = -0.5, size = 1, angle = 0) +
- theme_bw()+
- theme(axis.text.x = element_text(size = 5, angle = 45, hjust = 1),
- axis.text.y = element_text(size = 5))
-
- ggsave(paste0(directoryPath, "/", fileName, "_nbalance.png"), width = 150, height = 100, units = "mm")
+ summarise(nbalance_kg_n_total = sum(nbalance_kg_n_total, na.rm = T))
## OVERALL SOIL IMPACTS
nitrogen_balance <- nitrogen_balance
@@ -350,7 +323,7 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
conc_ip_soil_loss = ifelse(stringr::str_detect(feed_item, "IP"), as.numeric(soil_loss_plot), 0),
farm_soil_loss = (as.numeric(soil_loss_plot) - rough_of_soil_loss - conc_of_soil_loss - conc_ip_soil_loss))
- overal_soil_impact <- data.frame(
+ overal_soil_impact <- data.frame(
sources = c("total", "on-farm", "rough of", "conc of", "conc ip"),
balance_N_kg_N_year = c(sum(nitrogen_balance$nbalance_feed_only_kg_n, na.rm = T), sum(nitrogen_balance$farm_kg_n, na.rm = T),
sum(nitrogen_balance$rough_of_kg_n, na.rm = T), sum(nitrogen_balance$conc_of_kg_n, na.rm = T), sum(nitrogen_balance$conc_ip_kg_n, na.rm = T)),
@@ -363,16 +336,16 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
erosion_t_soil_year = c(sum(as.numeric(soil_erosion$soil_loss_plot, na.rm = T)), sum(soil_erosion$rough_of_soil_loss, na.rm = T), sum(soil_erosion$conc_of_soil_loss, na.rm = T),
sum(soil_erosion$conc_ip_soil_loss, na.rm = T), sum(soil_erosion$farm_soil_loss, na.rm = T))
)%>%
- mutate(percent_area_mining = ifelse(!is.finite(percent_area_mining),0,percent_area_mining),
- percent_area_leaching = ifelse(!is.finite(percent_area_leaching),0,percent_area_leaching),
- erosion_t_soil_ha = erosion_t_soil_year/c(sum(nitrogen_balance$area_total, na.rm = T), sum(nitrogen_balance$farm_area, na.rm = T), sum(nitrogen_balance$rough_of_area, na.rm = T),
- sum(nitrogen_balance$conc_of_area, na.rm = T), sum(nitrogen_balance$conc_ip_area, na.rm = T)))
+ mutate(percent_area_mining = ifelse(!is.finite(percent_area_mining),0,percent_area_mining),
+ percent_area_leaching = ifelse(!is.finite(percent_area_leaching),0,percent_area_leaching),
+ erosion_t_soil_ha = erosion_t_soil_year/c(sum(nitrogen_balance$area_total, na.rm = T), sum(nitrogen_balance$farm_area, na.rm = T), sum(nitrogen_balance$rough_of_area, na.rm = T),
+ sum(nitrogen_balance$conc_of_area, na.rm = T), sum(nitrogen_balance$conc_ip_area, na.rm = T)))
# Feed items specific N balance
nitrogen_balance <- nitrogen_balance %>%
- select(c(feed,nin,nout,nbalance_kg_n_total,nbalance_kg_n_ha_total,nbalance_feed_only_kg_n,nbalance_feed_only_kg_n_ha)) %>%
- mutate(nbalance_food_only_kg_n = nbalance_kg_n_total-nbalance_feed_only_kg_n,
- nbalance_food_only_kg_n_ha = nbalance_kg_n_ha_total-nbalance_feed_only_kg_n_ha)
+ select(c(feed,nin,nout,nbalance_kg_n_total,nbalance_kg_n_ha_total,nbalance_feed_only_kg_n,nbalance_feed_only_kg_n_ha)) %>%
+ mutate(nbalance_food_only_kg_n = nbalance_kg_n_total-nbalance_feed_only_kg_n,
+ nbalance_food_only_kg_n_ha = nbalance_kg_n_ha_total-nbalance_feed_only_kg_n_ha)
soil_impacts <- list(overal_soil_impact = overal_soil_impact,
nitrogen_balance = nitrogen_balance)
@@ -382,16 +355,7 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
###############################################################################################
water_use_per_feed_item <- water_required[["water_use_per_feed_item"]]
- ggplot(water_use_per_feed_item, aes(x = "", y = feed_water_use, fill = feed)) +
- geom_bar(stat = "identity", width = 1) +
- coord_polar("y", start = 0) +
- labs(fill = "Feed Item", title = "Water Use per Feed Crop") +
- theme_bw()+
- geom_text(aes(label = scales::percent(feed_water_use / sum(feed_water_use))),
- position = position_stack(vjust = 0.5),
- size = 1)
-
- ggsave(paste0(directoryPath, "/", fileName, "_water_use_per_feed.png"), width = 150, height = 100, units = "mm")
+ water_use_per_feed_item_output <- water_use_per_feed_item
###############################################################################################
## GHG Impacts
@@ -447,8 +411,12 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
rice_production_methane_tot_kg_co2_e <- rice_production_methane*methane
rice_production_methane_per_ha_kg_co2_e <- ifelse(area_required_on_farm_ha<0.001,0,rice_production_methane_tot_kg_co2_e/area_required_on_farm_ha)
rice_production_methane_kg_co2_e_per_kg_fpcm <- rice_production_methane_tot_kg_co2_e/total_milk_produced_kg_fpcm_per_year
-
- on_farm_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$farm_fertiliser_emission)
+ # quick fix for the case with no fertilizer
+ if (!is.list(ghg_emissions[["fetilizer_ghg"]])) {
+ on_farm_fertilizer_emission <- 0
+ } else {
+ on_farm_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$farm_fertiliser_emission)
+ }
on_farm_fertilizer_emission_per_ha_kg_co2_e <- ifelse(area_required_on_farm_ha<0.001,0,on_farm_fertilizer_emission/area_required_on_farm_ha)
on_farm_fertilizer_emission_kg_co2_e_per_kg_fpcm <- on_farm_fertilizer_emission/total_milk_produced_kg_fpcm_per_year
@@ -464,13 +432,18 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
rough_of_soil_indirect_N2O_per_ha_kg_co2_e <- ifelse(area_required_roughages_off_farm_ha<0.001,0,rough_of_soil_indirect_N2O_tot_kg_co2_e/area_required_roughages_off_farm_ha)
rough_of_soil_indirect_N2O_kg_co2_e_per_kg_fpcm <- rough_of_soil_indirect_N2O_tot_kg_co2_e/total_milk_produced_kg_fpcm_per_year
- rough_of_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$rough_of_fertiliser_emission)
+ # fix for the case with no fertilizer
+ if (!is.list(ghg_emissions[["fetilizer_ghg"]])) {
+ rough_of_fertilizer_emission <- 0
+ } else {
+ rough_of_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$rough_of_fertiliser_emission)
+ }
rough_of_fertilizer_emission_per_ha_kg_co2_e <- ifelse(area_required_roughages_off_farm_ha<0.001,0,rough_of_fertilizer_emission/area_required_roughages_off_farm_ha)
rough_of_fertilizer_emission_kg_co2_e_per_kg_fpcm <- rough_of_fertilizer_emission/total_milk_produced_kg_fpcm_per_year
# Concentrates off-farm
conc_of_Soil_direct_N2O <- sum(ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]][ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]]$anthropogenic_N_input == "conc_of_n_synthetic_fertilizer_managed_soil","annual_N20N_direct_emission_from_managed_soil"],
- ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]][ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]]$anthropogenic_N_input == "conc_of_n_from_crop_residue_managed_soil","annual_N20N_direct_emission_from_managed_soil"],na.rm = T)
+ ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]][ghg_emissions[["ghg_soil"]][["annual_N20N_soil_direct_emission"]]$anthropogenic_N_input == "conc_of_n_from_crop_residue_managed_soil","annual_N20N_direct_emission_from_managed_soil"],na.rm = T)
conc_of_Soil_direct_N2O_tot_kg_co2_e <- conc_of_Soil_direct_N2O*N2O
conc_of_Soil_direct_N2O_per_ha_kg_co2_e <- ifelse(area_required_concentrates_off_farm_ha<0.001,0,conc_of_Soil_direct_N2O_tot_kg_co2_e/area_required_concentrates_off_farm_ha)
conc_of_Soil_direct_N2O_kg_co2_e_per_kg_fpcm <- conc_of_Soil_direct_N2O_tot_kg_co2_e/total_milk_produced_kg_fpcm_per_year
@@ -480,7 +453,12 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
conc_of_soil_indirect_N2O_per_ha_kg_co2_e <- ifelse(area_required_concentrates_off_farm_ha<0.001,0,conc_of_soil_indirect_N2O_tot_kg_co2_e/area_required_concentrates_off_farm_ha)
conc_of_soil_indirect_N2O_kg_co2_e_per_kg_fpcm <- conc_of_soil_indirect_N2O_tot_kg_co2_e/total_milk_produced_kg_fpcm_per_year
- conc_of_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$conc_of_fertiliser_emission)
+ if (!is.list(ghg_emissions[["fetilizer_ghg"]])) {
+ conc_of_fertilizer_emission <- 0
+ } else {
+ conc_of_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$conc_of_fertiliser_emission)
+ }
+
conc_of_fertilizer_emission_per_ha_kg_co2_e <- ifelse(area_required_concentrates_off_farm_ha<0.001,0,conc_of_fertilizer_emission/area_required_concentrates_off_farm_ha)
conc_of_fertilizer_emission_kg_co2_e_per_kg_fpcm <- conc_of_fertilizer_emission/total_milk_produced_kg_fpcm_per_year
@@ -496,7 +474,12 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
conc_ip_soil_indirect_N2O_per_ha_kg_co2_e <- ifelse(area_required_imported_concentrates_ha<0.001,0,conc_ip_soil_indirect_N2O_tot_kg_co2_e/area_required_imported_concentrates_ha)
conc_ip_soil_indirect_N2O_kg_co2_e_per_kg_fpcm <- conc_ip_soil_indirect_N2O_tot_kg_co2_e/total_milk_produced_kg_fpcm_per_year
- conc_ip_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$conc_ip_fertiliser_emission)
+ if (!is.list(ghg_emissions[["fetilizer_ghg"]])) {
+ conc_ip_fertilizer_emission <- 0
+ } else {
+ conc_ip_fertilizer_emission <- sum(ghg_emissions[["fetilizer_ghg"]][["fertlizer_emission_by_crop"]]$conc_ip_fertiliser_emission)
+ }
+
conc_ip_fertilizer_emission_per_ha_kg_co2_e <- ifelse(area_required_imported_concentrates_ha<0.001,0,conc_ip_fertilizer_emission/area_required_imported_concentrates_ha)
conc_ip_fertilizer_emission_kg_co2_e_per_kg_fpcm <- conc_ip_fertilizer_emission/total_milk_produced_kg_fpcm_per_year
@@ -609,18 +592,18 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
"", conc_ip_Soil_direct_N2O_kg_co2_e_per_kg_fpcm,
conc_ip_soil_indirect_N2O_kg_co2_e_per_kg_fpcm,
conc_ip_fertilizer_emission_kg_co2_e_per_kg_fpcm)
- )
+ )
# Global warming potential (CO2eq)
soil_on_farm <- (as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Direct N2O", "kg_co2_e_per_ha"][1]) +
- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][1]))/1000
+ as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][1]))/1000
soil_off_farm <- (sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Direct N2O", "kg_co2_e_per_ha"][-1])) +
- sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][-1])))/1000
+ sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][-1])))/1000
livestock_manure <- (as.numeric(ghg_balance[ghg_balance$GHG_balance == "Manure-Methane", "kg_co2_e_per_ha"]) +
- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Manure-Direct N2O", "kg_co2_e_per_ha"]) +
- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Manure-Indirect N2O", "kg_co2_e_per_ha"]))/1000
+ as.numeric(ghg_balance[ghg_balance$GHG_balance == "Manure-Direct N2O", "kg_co2_e_per_ha"]) +
+ as.numeric(ghg_balance[ghg_balance$GHG_balance == "Manure-Indirect N2O", "kg_co2_e_per_ha"]))/1000
livestock_enteric_fermentation <- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Enteric fermentation-Methane", "kg_co2_e_per_ha"])/1000
@@ -636,12 +619,12 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
fertilizer_off_farm_rough <- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Production fertilizer", "kg_co2_e_per_ha"][2])/1000
soil_off_farm_conc <- (sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Direct N2O", "kg_co2_e_per_ha"][3])) +
- sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][3])))/1000
+ sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][3])))/1000
fertilizer_off_farm_conc <- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Production fertilizer", "kg_co2_e_per_ha"][3])/1000
soil_ip_farm_conc <- (sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Direct N2O", "kg_co2_e_per_ha"][4])) +
- sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][4])))/1000
+ sum(as.numeric(ghg_balance[ghg_balance$GHG_balance == "Soil-Indirect N2O", "kg_co2_e_per_ha"][4])))/1000
fertilizer_ip_farm_conc <- as.numeric(ghg_balance[ghg_balance$GHG_balance == "Production fertilizer", "kg_co2_e_per_ha"][4])/1000
@@ -659,19 +642,10 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
on_farm_table,
off_farm_table)
ghg_emission <- list(ghg_balance = ghg_balance,
- global_warming_potential = global_warming_potential)
+ global_warming_potential = global_warming_potential)
# Plotting GHG emission
- on_farm_table %>%
- ggplot2::ggplot(aes(x=sources_and_sinks, y=t_CO2e_per_ha))+
- geom_bar(stat = "identity", width = 0.6)+
- labs(x = "", y = "t CO2e/ha", title = "GHG emissions") +
- geom_text(aes(label = round(t_CO2e_per_ha, 2)), vjust = -0.5, size = 1, angle = 0) +
- theme_bw()+
- theme(axis.text.x = element_text(size = 5, angle = 45, hjust = 1),
- axis.text.y = element_text(size = 5))
-
- ggsave(paste0(directoryPath, "/", fileName, "_ghg_emission.png"), width = 150, height = 100, units = "mm")
+ on_farm_table_output <- on_farm_table
###############################################################################################
## Waste
@@ -691,45 +665,58 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ
soil_carbon = soil_carbon,
product_waste = product_waste)
- # Add worksheet to the readme workbook
- addWorksheet(readMe_wb, "Land Required")
- writeData(readMe_wb, sheet = "Land Required", x = output_list$land_required$land_required)
- addWorksheet(readMe_wb, "DM Required")
- writeData(readMe_wb, sheet = "DM Required", x = output_list$land_required$dm_required)
- addWorksheet(readMe_wb, "Land and DM Required")
- writeData(readMe_wb, sheet = "Land and DM Required", x = output_list$land_required$land_and_dm_required)
- addWorksheet(readMe_wb, "Overall Soil Impact")
- writeData(readMe_wb, sheet = "Overall Soil Impact", x = output_list$soil_impacts$overal_soil_impact)
- addWorksheet(readMe_wb, "Nitrogen Balance")
- writeData(readMe_wb, sheet = "Nitrogen Balance", x = output_list$soil_impacts$nitrogen_balance)
- addWorksheet(readMe_wb, "Water Use Per Feed Item")
- writeData(readMe_wb, sheet = "Water Use Per Feed Item", x = output_list$water_required$water_use_per_feed_item)
- addWorksheet(readMe_wb, "Water Use For Production")
- writeData(readMe_wb, sheet = "Water Use For Production", x = output_list$water_required$water_use_for_production)
- addWorksheet(readMe_wb, "Consumable Livestock Product")
- writeData(readMe_wb, sheet = "Consumable Livestock Product", x = output_list$livestock_productivity$consumable_livestock_product)
- addWorksheet(readMe_wb, "Manure Produced")
- writeData(readMe_wb, sheet = "Manure Produced", x = output_list$livestock_productivity$manure_produced)
- addWorksheet(readMe_wb, "GHG Balance")
- writeData(readMe_wb, sheet = "GHG Balance", x = output_list$ghg_emission$ghg_balance)
- addWorksheet(readMe_wb, "Global Warming Potential")
- writeData(readMe_wb, sheet = "Global Warming Potential", x = output_list$ghg_emission$global_warming_potential)
- addWorksheet(readMe_wb, "Biomass")
- writeData(readMe_wb, sheet = "Biomass", x = output_list$biomass)
- addWorksheet(readMe_wb, "Soil Carbon")
- writeData(readMe_wb, sheet = "Soil Carbon", x = output_list$soil_carbon)
- addWorksheet(readMe_wb, "Product Waste")
- writeData(readMe_wb, sheet = "Product Waste", x = output_list$product_waste)
+ # Add worksheet to the primary_excel workbook
+ addWorksheet(primary_excel_wb, "Land Required")
+ writeData(primary_excel_wb, sheet = "Land Required", x = output_list$land_required$land_required)
+ addWorksheet(primary_excel_wb, "DM Required")
+ writeData(primary_excel_wb, sheet = "DM Required", x = output_list$land_required$dm_required)
+ addWorksheet(primary_excel_wb, "Land and DM Required")
+ writeData(primary_excel_wb, sheet = "Land and DM Required", x = output_list$land_required$land_and_dm_required)
+ addWorksheet(primary_excel_wb, "Overall Soil Impact")
+ writeData(primary_excel_wb, sheet = "Overall Soil Impact", x = output_list$soil_impacts$overal_soil_impact)
+ addWorksheet(primary_excel_wb, "Nitrogen Balance")
+ writeData(primary_excel_wb, sheet = "Nitrogen Balance", x = output_list$soil_impacts$nitrogen_balance)
+ addWorksheet(primary_excel_wb, "Water Use Per Feed Item")
+ writeData(primary_excel_wb, sheet = "Water Use Per Feed Item", x = output_list$water_required$water_use_per_feed_item)
+ addWorksheet(primary_excel_wb, "Water Use For Production")
+ writeData(primary_excel_wb, sheet = "Water Use For Production", x = output_list$water_required$water_use_for_production)
+ addWorksheet(primary_excel_wb, "Consumable Livestock Product")
+ writeData(primary_excel_wb, sheet = "Consumable Livestock Product", x = output_list$livestock_productivity$consumable_livestock_product)
+ addWorksheet(primary_excel_wb, "Manure Produced")
+ writeData(primary_excel_wb, sheet = "Manure Produced", x = output_list$livestock_productivity$manure_produced)
+ addWorksheet(primary_excel_wb, "GHG Balance")
+ writeData(primary_excel_wb, sheet = "GHG Balance", x = output_list$ghg_emission$ghg_balance)
+ addWorksheet(primary_excel_wb, "Global Warming Potential")
+ writeData(primary_excel_wb, sheet = "Global Warming Potential", x = output_list$ghg_emission$global_warming_potential)
+ addWorksheet(primary_excel_wb, "Biomass")
+ writeData(primary_excel_wb, sheet = "Biomass", x = output_list$biomass)
+ addWorksheet(primary_excel_wb, "Soil Carbon")
+ writeData(primary_excel_wb, sheet = "Soil Carbon", x = output_list$soil_carbon)
+ addWorksheet(primary_excel_wb, "Product Waste")
+ writeData(primary_excel_wb, sheet = "Product Waste", x = output_list$product_waste)
+
+ # Change the order of the worksheets
+ worksheetOrder(primary_excel_wb) <- c("1", "8", "9", "10", "11", "12", "13",
+ "14", "15", "16", "17", "18", "19", "20",
+ "21", "2", "3", "4", "5", "6", "7")
# Save to Excel with multiple sheets
excel_output_path <- paste0(directoryPath, "/", fileName, ".xlsx") # Create path for excel
- saveWorkbook(readMe_wb, excel_output_path, overwrite = TRUE)
-
- # Save the benchmark
- benchmark_path <- paste0(directoryPath, "/benchMark.xlsx")
- saveWorkbook(benchMark_wb, benchmark_path, overwrite = TRUE)
+ saveWorkbook(primary_excel_wb, excel_output_path, overwrite = TRUE)
# Save json
+
+
+ return(
+ list(
+ json_output = jsonlite::toJSON(output_list, pretty = TRUE),
+ on_farm_table = on_farm_table_output,
+ nitrogen_balance = nitrogen_balance_output,
+ land_required = land_required_output,
+ water_use_per_feed_item = water_use_per_feed_item_output
+ )
+ )
+
jsonlite::toJSON(output_list, pretty = TRUE)
} #end of output function
diff --git a/R/misc/v37 loop.R b/R/misc/v37 loop.R
new file mode 100644
index 0000000..938de46
--- /dev/null
+++ b/R/misc/v37 loop.R
@@ -0,0 +1,431 @@
+
+# Load packages and function
+pacman::p_load(readxl,cleaned,jsonlite,tidyr,dplyr,miceadds,data.table,openxlsx)
+
+source("R/ghg_emission_v2.R")
+source("R/nitrogen_balance.R")
+source("R/energy_requirement.R")
+source("R/feed_quality.R")
+
+# 1) Load Data ####
+ ## 1.1) V37 data #####
+ file<-"data/v37/Kenya NPA data.xlsx"
+ save_file<-file.path(dirname(file),"Kenya NPA emissions.xlsx")
+ # data <- readxl::read_excel(file,sheet=1)
+
+ herd <- data.table(readxl::read_excel(file,sheet="milk-bodyweight"))
+ herd[,livetype_code:=as.character(livetype_code)]
+ setnames(herd,"livetype_desc","livetype_desc_v37")
+
+ v37_feed_items<-data.table(readxl::read_excel(file,sheet="Feed_items"))
+ v37_feed_items$intercrop<-as.numeric(0)
+ v37_feed_type<-unique(data.table(readxl::read_excel(file,sheet="feed_type")))[order(feed_type_code)]
+
+ # Deal with duplicate entry for item 5 Brachiaria
+ x<-v37_feed_type[feed_type_code==5][, feed_type_name := "Brachiaria"]
+ by_cols<-colnames(x)[1:5]
+ num_cols<-colnames(x)[!colnames(x) %in% by_cols]
+
+ x <- x[, lapply(.SD, mean), by = by_cols, .SDcols = num_cols]
+
+ v37_feed_type<-rbind(v37_feed_type[feed_type_code!=5],x)
+
+ # V37 - Merge feed_items & feed type
+ v37_feed_items_merge<-merge(v37_feed_items,v37_feed_type,by="feed_type_code",all.x=T)
+
+ # Feed basket
+ v37_feed_basket <- data.table(readxl::read_excel(file,sheet="Feedproportions"))
+ v37_feed_basket[,livetype_code:=tolower(livetype_code)]
+
+ # Remove duplicates
+ v37_feed_basket<-unique(v37_feed_basket)
+
+ v37_feed_basket<-melt(v37_feed_basket,
+ id.vars = c("Ids","v37_livestock_type","livetype_code","livetype_desc"),
+ variable.name = "feed_item_code",
+ value.name = "allocation")
+
+ # Check proportions sum to 1
+ v37_feed_basket<-v37_feed_basket[allocation!=0][order(Ids,livetype_code)
+ ][,total:=sum(allocation),by=.(Ids,livetype_code,livetype_desc)]
+
+ unique(v37_feed_basket[total==2,.(Ids,livetype_code,total)])
+
+ v37_feed_basket<-v37_feed_basket[,.(Ids,livetype_code,livetype_desc,feed_item_code,allocation)
+ ][,allocation:=allocation*100
+ ][,feed_item_code:=as.numeric(as.character(feed_item_code))]
+
+ # Add feed type code
+ v37_feed_basket<-merge(v37_feed_basket,v37_feed_items[,.(feed_item_code,feed_type_code)],by="feed_item_code",all.x=T)
+ v37_feed_basket[is.na(feed_type_code)]
+ v37_feed_basket[,feed_item_code:=as.character(feed_item_code)]
+ v37_feed_basket[,feed_type_code:=as.character(feed_type_code)]
+
+ # Simple field parameters
+ v37_simple_fields<-data.table(readxl::read_excel(file,sheet="simple_fields"))
+
+ ## 1.2) Read in parameter tables #####
+ lkp_livetype<-fread("https://raw.githubusercontent.com/CIAT/icleaned/refs/heads/staging/data/primary_database/lkp_livetype.csv")
+ lkp_manureman<-fread("https://raw.githubusercontent.com/CIAT/icleaned/refs/heads/staging/data/primary_database/lkp_manureman.csv")
+
+ energy_parameters <- fromJSON(
+ system.file("extdata", "energy_parameters.json", package = "cleaned"),
+ flatten = TRUE
+ )
+
+ # Read static parameters directory and files
+ ghg_ipcc_data <- fromJSON(
+ system.file("extdata", "ghg_parameters.json", package = "cleaned"),
+ flatten = TRUE
+ )
+
+ ## 1.3) Input template #####
+ file<-"https://raw.githubusercontent.com/CIAT/icleaned/refs/heads/staging/data/shared_folder/study_objects/Study_2.json"
+ template <- fromJSON(file)
+ colnames(template$livestock)
+
+ feed_items<-data.table(template$feed_items)
+ fertilizer<-data.table(template$fertilizer)[0,]
+ fertilizer<-NULL
+
+# 2) Set "fixed" parameters ####
+
+ ## 2.0) "Simple" fields #####
+ template_names<-data.table(field_name=names(template),
+ class=sapply(template,base::class),
+ length=sapply(template,length))
+
+ simple_field_names<-template_names[length==1,field_name]
+
+ simple_fields<-template[simple_field_names]
+
+ for(i in 1:length(simple_fields)){
+ field<-names(simple_fields)[i]
+ simple_fields[field]<-v37_simple_fields[field_name==field,value]
+ }
+
+
+ ## 2.1) Livestock #####
+ mm_code<-"storage"
+ mm_des<-lkp_manureman[manureman_code==mm_code,manureman_desc]
+
+ mm_code2<-"pasture"
+ mm_des2<-lkp_manureman[manureman_code==mm_code,manureman_desc]
+
+ livestock_fixed<-data.frame(
+ manureman_stable=mm_des,
+ manureman_onfarm_grazing=mm_des2,
+ manureman_non_roofed_enclosure=0,
+ manureman_offfarm_grazing=mm_des2,
+ annual_growth=0,
+ annual_wool=0,
+ manure_in_stable=1,
+ manure_in_non_roofed_enclosure=0,
+ manure_in_field=0,
+ manure_onfarm_fraction=0,
+ manure_sales_fraction=0,
+ body_weight_weaning=0,
+ body_weight_year_one=0,
+ adult_weight=600,
+ work_hour=0,
+ piglets_relying_on_milk=0
+ )
+
+ ## 2.2) Feed_Items #####
+ feed_fixed<-c(
+ slope=1,
+ slope_desc="Flat (0-5%)",
+ slope_p_factor=0.11,
+ slope_length=15,
+ water_regime=0,
+ n_content=0,
+ cultivation_period=0,
+ ecosystem_type=0,
+ organic_amendment=0,
+ cut_carry_fraction=0,
+ fraction_as_fertilizer=0, # Needs to be distributed by crop
+ fraction_as_manure=0, # Needs to be distributed by crop
+ n_fertilizer=0,
+ urea=0,
+ npk=0,
+ dap=0,
+ ammonium_nitrate=0,
+ ammonium_sulfate=0,
+ n_solutions=0,
+ ammonia=0,
+ time_horizon=0
+ )
+
+ fi_cols<-colnames(feed_items)
+ zero_cols<-fi_cols[grep("trees|dbh|diameter_",fi_cols)]
+ names(zero_cols)<-zero_cols
+ zero_cols[1:length(zero_cols)]<-0
+ feed_fixed<-c(feed_fixed,zero_cols)
+
+ ### 2.2.1) Add fixed items to input template #####
+ for(k in 1:length(feed_fixed)){
+ variable<-names(feed_fixed)[k]
+ v37_feed_items_merge[,(variable):=feed_fixed[k]]
+ }
+
+ # Check all cols in template are present
+ colnames(feed_items)[!colnames(feed_items) %in% colnames(v37_feed_items_merge)]
+
+ # Enforce numeric class
+ num_cols<-c("slope_p_factor","slope_length")
+ v37_feed_items_merge[, (num_cols) := lapply(.SD, as.numeric), .SDcols = num_cols]
+
+ ## 2.3) Seasons #####
+ season_dat<-data.frame(season_length=180,season_name="season_x")
+
+# 3) Loop through farms ####
+# unique farm ids
+farms<-na.omit(unique(herd$Ids))
+farms<-farms[2]
+
+farm_paras<-lapply(1:length(farms),FUN=function(i){
+ farm<-farms[i]
+
+ ## 3.1) Herds #####
+ # Make a blank herd template to populate
+ livestock<-data.table(template$livestock[1,])
+ livestock[1,1:ncol(livestock)]<-NA
+
+ # Subset v37 data to selected farm
+ livestock_37<-herd[Ids==farm & !grepl("calve",livetype_desc_v37,ignore.case = T)]
+
+ # Loop through herds on the farm
+ paras<-lapply(1:nrow(livestock_37),FUN=function(j){
+ cat("\r", farm, "i =", i, "/", length(farms), "herd (j) =", j, "/", nrow(livestock_37))
+
+ # Subset herds
+ herd_1<-livestock_37[j]
+
+ # Merge lkp_livetype
+ l_code<-herd_1$livetype_code
+ livestock$livetype_code<-l_code
+ livestock$livetype_code<-as.integer(livestock$livetype_code)
+
+ mergedat<-lkp_livetype[livetype_code==l_code]
+
+ cols_m<-colnames(mergedat)
+ cols_m<-cols_m[cols_m != "livetype_code"]
+ cols_l<-c(colnames(livestock)[!colnames(livestock) %in% cols_m])
+ livestock<-livestock[,cols_l,with=F]
+
+ livestock<-merge(livestock,mergedat,by="livetype_code",all.x = T)
+
+ # Insert farm specific V37 herd data
+ cols_m<-colnames(herd_1)
+ livestock$livetype_desc_v37<-herd_1$livetype_desc_v37
+ livestock$herd_composition<-herd_1$number
+ livestock$body_weight<-herd_1$body_weight
+ livestock$annual_milk<-herd_1$annual_milk
+ livestock$time_in_stable<-herd_1$time_in_stable
+ livestock$time_in_onfarm_grazing<-herd_1$time_in_onfarm_grazing
+ livestock$time_in_offfarm_grazing<-herd_1$time_in_offfarm_grazing
+ livestock$time_in_non_roofed_enclosure<-herd_1$time_in_non_roofed_enclosure
+ livestock$distance_to_pasture<-herd_1$distance_to_pasture
+
+ # Add fixed parameters
+ for(k in 1:ncol(livestock_fixed)){
+ variable<-colnames(livestock_fixed)[k]
+ livestock[,(variable):=livestock_fixed[1,k]]
+ }
+
+ # Rename ipcc parameter columns
+ ipcc_new<-c(
+ "ipcc_ef_category_t1",
+ "ipcc_ef_category_t2",
+ "ipcc_meth_man_category",
+ "ipcc_n_exc_category"
+ )
+
+ ipcc_old<-c(
+ "ipcc_meth_ef_t1",
+ "ipcc_meth_ef_t2",
+ "ipcc_meth_man",
+ "ipcc_meth_exc"
+ )
+
+ livestock<-livestock[,!ipcc_new,with = F]
+ setnames(livestock,ipcc_old,ipcc_new)
+
+ # Enforce codes to be character
+ livestock[,livetype_code:=as.character(livetype_code)]
+
+ ## 3.2) Fertilizer #####
+ # Blank table created in section 1.3
+ # 3.3) Feed basket ####
+ ### 3.3.1) Seasons #####
+ # Created in section 2.3
+ ### 3.3.2) Feeds #####
+ feeds<-v37_feed_basket[Ids==farm & tolower(livetype_desc)==tolower(livestock$livetype_desc_v37)]
+ if(nrow(feeds)==0){
+ stop("Feed table is blank, livetype_desc in feed basket not matching herd.")
+ }
+
+ # Average across duplicate rows
+ #feeds<-feeds[,.(allocation=mean(allocation)),by=.(Ids,feed_type_code,feed_item_code,livetype_code)]
+
+ feeds<-feeds[,.(livestock=list(data.table(livetype_code=livetype_code,allocation=allocation))),by=.(feed_item_code,feed_type_code)]
+ feeds<-data.frame(feeds)
+ ### 3.3.3) Combine Season and Feeds #####
+ feed_basket <- data.table(
+ feeds = list(feeds=feeds),
+ season_name = season_dat$season_name[1]
+ )
+ feed_basket<-data.frame(feed_basket)
+
+ ## 3.4) Feed Items #####
+ # v37_feed_items_merge is creted in section 2.2, subset to items in the diet
+ feed_items<-v37_feed_items_merge[feed_item_code %in% feeds$feed_item_code]
+ ## 3.5) Join sections into list structure ####
+ input_object<-c(simple_fields,list(livestock=livestock,
+ feed_items=feed_items,
+ fertilizer=fertilizer,
+ seasons=season_dat,
+ feed_basket=feed_basket))
+ input_object$farm_name<-farm
+ return(input_object)
+ })
+ names(paras)<-paste0("herd-",1:nrow(livestock_37))
+
+ return(paras)
+})
+
+names(farm_paras)<-paste0("f",farms)
+
+
+# 4) Pass to cleaned functions ####
+messages<-F
+
+ghg_emissions<-lapply(1:length(farm_paras),FUN=function(i){
+
+ farm_para<-farm_paras[[i]]
+
+ result<-lapply(1:length(farm_para),FUN=function(j){
+
+ cat("farm",names(farm_paras)[i],i,"/",length(farm_paras),"herd",j," \r")
+
+ para<-farm_para[[j]]
+
+ ## 4.1) feed basket quality #####
+ feed_basket_quality <- feed_quality(para)
+
+ ## 4.2) energy #####
+ # Table 10.4 is in list form this throws an error, convert to data.frame
+ energy_required <- energy_requirement(para,feed_basket_quality,energy_parameters = energy_parameters)
+
+ ## 4.3) land #####
+ para$feed_items$intercrop<-as.numeric(para$feed_items$intercrop)
+ land_required <- land_requirement(feed_basket_quality, energy_required, para)
+
+ ## 4.4) soil erosion #####
+ para$feed_items$slope_p_factor<-as.numeric(para$feed_items$slope_p_factor)
+ soil_erosion <- soil_health(para, land_required)
+
+ ## 4.5) n balance #####
+ para$feed_items$ammonia<-as.numeric(para$feed_items$ammonia)
+ para$feed_items$ammonium_nitrate<-as.numeric(para$feed_items$ammonium_nitrate)
+ para$feed_items$ammonium_sulfate<-as.numeric(para$feed_items$ammonium_sulfate)
+ para$feed_items$dap<-as.numeric(para$feed_items$dap)
+ para$feed_items$n_solutions<-as.numeric(para$feed_items$n_solutions)
+ para$feed_items$npk<-as.numeric(para$feed_items$npk)
+ para$feed_items$urea<-as.numeric(para$feed_items$urea)
+
+ nitrogen_balance <- n_balance(para, land_required, soil_erosion,energy_required)
+
+ ## 4.6) livestock productivity #####
+ livestock_productivity <- land_productivity(para,energy_required)
+
+ ## 4.7) biomass #####
+ num_cols<-c("trees_ha_dbh25","trees_ha_dbh2550","trees_ha_dbh50","increase_dbh25","increase_dbh2550","increase_dbh50",
+ "time_horizon","average_dbh2550","average_dbh25","average_dbh50")
+ para$feed_items<-para$feed_items[, (num_cols) := lapply(.SD, as.numeric), .SDcols = num_cols]
+
+ biomass <- biomass_calculation(para, land_required)
+
+ ## 4.8) ghg_emissions #####
+ char_cols<-c("manureman_non_roofed_enclosure")
+ para$livestock<-para$livestock[, (char_cols) := lapply(.SD, as.character), .SDcols = char_cols]
+
+ if(messages==F){
+ results<-suppressMessages(ghg_emission(para,energy_required,ghg_ipcc_data,land_required,nitrogen_balance,feed_basket_quality,ym_prod=F))
+ }else{
+ results<-ghg_emission(para,energy_required,ghg_ipcc_data,land_required,nitrogen_balance,feed_basket_quality,ym_prod=F)
+ }
+
+ # Unpack soil into 3 tables not a list
+ results$soil_annual_N20N_soil_direct_emission<-results$ghg_soil$annual_N20N_soil_direct_emission
+ results$soil_annual_N20N_soil_indirect_emission<-results$ghg_soil$annual_N20N_soil_indirect_emission
+ results$soil_N20N_off_farm<-results$ghg_soil$N20N_off_farm
+ results$ghg_soil<-NULL
+ results
+ })
+ names(result)<-names(farm_para)
+ return(result)
+})
+
+names(ghg_emissions)<-names(farm_paras)
+
+## 4.9) Add farm and herd name to tables
+ghg_emissions_merge<-lapply(1:length(ghg_emissions),FUN=function(i){
+ farm_name<-names(ghg_emissions)[i]
+ ghg_farm<-ghg_emissions[[i]]
+
+ ghg_farm_updated<-lapply(1:length(ghg_farm),FUN=function(j){
+ cat("\r","i",i,"j",j," ")
+ herd_name<-names(ghg_farm)[j]
+ ghg_herd<-ghg_farm[[j]]
+ ghg_herd_updated<-lapply(1:length(ghg_herd),FUN=function(k){
+ data<-ghg_herd[[k]]
+ data$farm<-farm_name
+ data$herd<-herd_name
+ return(data)
+ })
+ names(ghg_herd_updated)<-names(ghg_herd)
+ return(ghg_herd_updated)
+ })
+
+ tab_names<-names(ghg_farm_updated[[1]])
+ ghg_farm_merged<-lapply(tab_names,FUN=function(tab_name){
+ x<-lapply(ghg_farm_updated,"[[",tab_name)
+ x<-rbindlist(x)
+ x
+ })
+
+ names(ghg_farm_merged)<-tab_names
+ return(ghg_farm_merged)
+})
+names(ghg_emissions_merge)<-names(ghg_emissions)
+
+## 4.10) Combine tables #####
+tab_names<-names(ghg_emissions_merge[[1]])
+
+ghg_emissions_merge_all<-lapply(tab_names,FUN=function(tab_name){
+ x<-lapply(ghg_emissions_merge,"[[",tab_name)
+ x<-rbindlist(x)
+ x
+})
+names(ghg_emissions_merge_all)<-tab_names
+
+n<-nchar(names(ghg_emissions_merge_all))
+names(ghg_emissions_merge_all)[n>31]
+names(ghg_emissions_merge_all)[n>31]<-c("annual_N20N_soil_direct","annual_N20N_soil_indirect")
+
+ghg_emissions_merge_all$ef[farm=="f596171010",.(farm,livetype_desc_v37,ipcc_ef_category_t1,ipcc_ef_category_t2,de,de_intake,ge_intake,dmi_tot,ym,enteric_methane_emissions)]
+
+# Create a new Excel workbook
+wb <- createWorkbook()
+
+# Loop through the list and add each data.frame as a sheet
+for (sheet_name in names(ghg_emissions_merge_all)) {
+ addWorksheet(wb, sheet_name)
+ writeData(wb, sheet = sheet_name, x = ghg_emissions_merge_all[[sheet_name]])
+}
+
+# Save the workbook to a file
+saveWorkbook(wb, file = save_file, overwrite = TRUE)
+
+print("Excel file saved as 'output.xlsx'")
diff --git a/R/nitrogen_balance.R b/R/nitrogen_balance.R
index d72f0eb..9d56dae 100644
--- a/R/nitrogen_balance.R
+++ b/R/nitrogen_balance.R
@@ -74,34 +74,46 @@ n_balance <- function(para, land_required, soil_erosion){
manure_fraction <- as.numeric(feed_selected$fraction_as_fertilizer)
# Computing fertilizer rate
- ammonia_n_frac <- ifelse(feed_selected$ammonia==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonia"),]$fraction))
- ammonia_n_frac <- ifelse(!is.finite(ammonia_n_frac),0,ammonia_n_frac)
-
- ammonium_nitrate_n_frac <- ifelse(feed_selected$ammonium_nitrate==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonium nitrate"),]$fraction))
- ammonium_nitrate_n_frac <- ifelse(!is.finite(ammonium_nitrate_n_frac),0,ammonium_nitrate_n_frac)
-
- ammonium_sulfate_n_frac <- ifelse(feed_selected$ammonium_sulfate==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonium sulfate"),]$fraction))
- ammonium_sulfate_n_frac <- ifelse(!is.finite(ammonium_sulfate_n_frac),0,ammonium_sulfate_n_frac)
-
- dap_n_frac <- ifelse(feed_selected$dap==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "DAP"),]$fraction))
- dap_n_frac <- ifelse(!is.finite(dap_n_frac),0,dap_n_frac)
-
- n_solutions_n_frac <- ifelse(feed_selected$n_solutions==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "N solutions"),]$fraction))
- n_solutions_n_frac <- ifelse(!is.finite(n_solutions_n_frac),0,n_solutions_n_frac)
-
- npk_n_frac <- ifelse(feed_selected$npk==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "NPK"),]$fraction))
- npk_n_frac <- ifelse(!is.finite(npk_n_frac),0,npk_n_frac)
-
- urea_n_frac <- ifelse(feed_selected$urea==0,0,
- as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Urea"),]$fraction))
- urea_n_frac <- ifelse(!is.finite(urea_n_frac),0,urea_n_frac)
-
+ if(
+ length(para[["fertilizer"]]) == 0
+ ) {
+ ammonia_n_frac <- 0
+ ammonium_nitrate_n_frac <- 0
+ ammonium_sulfate_n_frac <- 0
+ dap_n_frac <- 0
+ n_solutions_n_frac <- 0
+ npk_n_frac <- 0
+ urea_n_frac <- 0
+ fertilizer_rate <- 0
+ } else {
+ ammonia_n_frac <- ifelse(feed_selected$ammonia==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonia"),]$fraction))
+ ammonia_n_frac <- ifelse(!is.finite(ammonia_n_frac),0,ammonia_n_frac)
+
+ ammonium_nitrate_n_frac <- ifelse(feed_selected$ammonium_nitrate==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonium nitrate"),]$fraction))
+ ammonium_nitrate_n_frac <- ifelse(!is.finite(ammonium_nitrate_n_frac),0,ammonium_nitrate_n_frac)
+
+ ammonium_sulfate_n_frac <- ifelse(feed_selected$ammonium_sulfate==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Ammonium sulfate"),]$fraction))
+ ammonium_sulfate_n_frac <- ifelse(!is.finite(ammonium_sulfate_n_frac),0,ammonium_sulfate_n_frac)
+
+ dap_n_frac <- ifelse(feed_selected$dap==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "DAP"),]$fraction))
+ dap_n_frac <- ifelse(!is.finite(dap_n_frac),0,dap_n_frac)
+
+ n_solutions_n_frac <- ifelse(feed_selected$n_solutions==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "N solutions"),]$fraction))
+ n_solutions_n_frac <- ifelse(!is.finite(n_solutions_n_frac),0,n_solutions_n_frac)
+
+ npk_n_frac <- ifelse(feed_selected$npk==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "NPK"),]$fraction))
+ npk_n_frac <- ifelse(!is.finite(npk_n_frac),0,npk_n_frac)
+
+ urea_n_frac <- ifelse(feed_selected$urea==0,0,
+ as.numeric(para[["fertilizer"]][which(para[["fertilizer"]]$fertilizer_desc == "Urea"),]$fraction))
+ urea_n_frac <- ifelse(!is.finite(urea_n_frac),0,urea_n_frac)
+ }
fertilizer_rate <- (feed_selected$ammonia*ammonia_n_frac)+(feed_selected$ammonium_nitrate*ammonium_nitrate_n_frac)+(feed_selected$ammonium_sulfate*ammonium_sulfate_n_frac)+
(feed_selected$dap*dap_n_frac)+(feed_selected$n_solutions*n_solutions_n_frac)+(feed_selected$npk*npk_n_frac)+(feed_selected$urea*urea_n_frac)
diff --git a/R/plotting.R b/R/plotting.R
index 5f7270b..8d8026f 100644
--- a/R/plotting.R
+++ b/R/plotting.R
@@ -31,169 +31,207 @@
#' @export
#'
-clean_plotting <- function(outFile,oDir){
-
+clean_plotting <- function (outFile, oDir)
+{
outFile <- jsonlite::fromJSON(outFile, flatten = TRUE)
-
outFile$scenario <- as.factor(outFile$scenario)
-
oDir <- oDir
- if (!file.exists(oDir)) {dir.create(oDir, recursive=T)}
- for(i in 2:ncol(outFile)){
+ if (!file.exists(oDir)) {
+ dir.create(oDir, recursive = T)
+ }
- datos <- outFile %>% select(1, all_of(i))
+ output_list <- list()
- # titles
+ for (i in 2:ncol(outFile)) {
+ datos <- outFile %>% select(1, all_of(i))
tt <- colnames(datos[2])
-
-
- if(tt == "total_milk_produced_kg_fpcm_per_year"){
+ if (tt == "total_milk_produced_kg_fpcm_per_year") {
title = "Total milk FPCM (kg/yr)"
y_title = "Milk FPCM (kg/yr)"
- }else if(tt == "total_meat_produced_kg_per_year"){
+ }
+ else if (tt == "total_meat_produced_kg_per_year") {
title = "Total meat (kg/yr)"
y_title = "Meat (kg/yr)"
- }else if(tt == "total_protein_produced_kg_per_year"){
+ }
+ else if (tt == "total_protein_produced_kg_per_year") {
title = "Total protein (kg/yr)"
y_title = "Protein (kg/yr)"
- }else if (tt == "total_tlu"){
+ }
+ else if (tt == "total_tlu") {
title = "Tropical Livestock Unit"
y_title = "Tropical Livestock Unit"
- }else if (tt == "total_land_requirement_ha"){
+ }
+ else if (tt == "total_land_requirement_ha") {
title = "Land required (ha/yr)"
y_title = "Land required (ha/yr)"
- }else if (tt == "total_land_requirement_ha_per_kg_fpcm"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_fpcm") {
title = "Land required (ha/kg FPCM)"
y_title = "Land required (ha/kg FPCM)"
- }else if (tt == "total_land_requirement_ha_per_kg_meat"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_meat") {
title = "Land required (ha/kg meat)"
y_title = "Land required (ha/kg meat)"
- }else if (tt == "total_land_requirement_ha_per_kg_protein"){
+ }
+ else if (tt == "total_land_requirement_ha_per_kg_protein") {
title = "Land required (ha/kg protein)"
y_title = "Land required (ha/kg protein)"
- }else if (tt == "total_land_requirement_ha_per_tlu"){
+ }
+ else if (tt == "total_land_requirement_ha_per_tlu") {
title = "Land required (ha/TLU)"
y_title = "Land required (ha/TLU)"
- }else if (tt == "total_n_balance_kg_n_per_year"){
+ }
+ else if (tt == "total_n_balance_kg_n_per_year") {
title = "N balance (kg N/yr)"
y_title = "N balance (kg N/yr)"
- }else if (tt == "percent_area_mining"){
+ }
+ else if (tt == "percent_area_mining") {
title = "Soil mining (%)"
y_title = "Soil mining (%)"
- }else if (tt == "percent_area_leaching"){
+ }
+ else if (tt == "percent_area_leaching") {
title = "Soil leaching (%)"
y_title = "Soil leaching (%)"
- }else if (tt == "n_balance_kg_n_per_ha_per_year"){
+ }
+ else if (tt == "n_balance_kg_n_per_ha_per_year") {
title = "N balance (kg N/ha/yr)"
y_title = "N balance (kg N/ha/yr)"
- }else if (tt == "n_balance_kg_n_per_kg_fpcm"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_fpcm") {
title = "N balance (kg N/kg FPCM)"
y_title = "N balance (kg N/kg FPCM)"
- }else if (tt == "n_balance_kg_n_per_kg_meat"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_meat") {
title = "N balance (kg N/kg meat)"
y_title = "N balance (kg N/kg meat)"
- }else if (tt == "n_balance_kg_n_per_kg_protein"){
+ }
+ else if (tt == "n_balance_kg_n_per_kg_protein") {
title = "N balance (kg N/kg protein)"
y_title = "N balance (kg N/kg protein)"
- }else if (tt == "erosion_t_soil_year"){
+ }
+ else if (tt == "erosion_t_soil_year") {
title = "Erosion (t soil/yr)"
y_title = "Erosion (t soil/yr)"
- }else if (tt == "erosion_t_soil_per_ha_per_year"){
+ }
+ else if (tt == "erosion_t_soil_per_ha_per_year") {
title = "Erosion (t soil/ha/yr)"
y_title = "Erosion (t soil/ha/yr)"
- }else if (tt == "erosion_kgsoil_per_kg_fpcm"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_fpcm") {
title = "Erosion (t soil/kg FPCM)"
y_title = "Erosion (t soil/kg FPCM)"
- }else if (tt == "erosion_kgsoil_per_kg_meat"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_meat") {
title = "Erosion (t soil/kg meat)"
y_title = "Erosion (t soil/kg meat)"
- }else if (tt == "erosion_kgsoil_per_kg_protein"){
+ }
+ else if (tt == "erosion_kgsoil_per_kg_protein") {
title = "Erosion (t soil/kg protein)"
y_title = "Erosion (t soil/kg protein)"
- }else if (tt == "ghg_emission_t_co2_eq_per_year"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_year") {
title = "GHG (t CO2eq/yr)"
y_title = "GHG (t CO2eq/yr)"
- }else if (tt == "ghg_emission_t_co2_eq_per_ha_per_year"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_ha_per_year") {
title = "GHG (t CO2eq/ha/yr)"
y_title = "GHG (t CO2eq/ha/yr)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_fpcm"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_fpcm") {
title = "GHG (CO2eq/kg FPCM)"
y_title = "GHG (CO2eq/kg FPCM)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_meat"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_meat") {
title = "GHG (CO2eq/kg meat)"
y_title = "GHG (CO2eq/kg meat)"
- }else if (tt == "ghg_emission_t_co2_eq_per_kg_protein"){
+ }
+ else if (tt == "ghg_emission_t_co2_eq_per_kg_protein") {
title = "GHG (CO2eq/kg protein)"
y_title = "GHG (CO2eq/kg protein)"
- }else if (tt == "percent_precipitation_used_for_feed_production"){
+ }
+ else if (tt == "percent_precipitation_used_for_feed_production") {
title = "% Precipitation use for feed production"
y_title = "% Precipitation use for feed production"
- }else if (tt == "total_water_use_m3"){
+ }
+ else if (tt == "total_water_use_m3") {
title = "Water use (m3/yr)"
y_title = "Water use (m3/yr)"
- }else if (tt == "total_water_use_m3_per_ha"){
+ }
+ else if (tt == "total_water_use_m3_per_ha") {
title = "Water use (m3/ha)"
y_title = "Water use (m3/ha)"
- }else if (tt == "total_water_use_m3_per_kg_fpcm"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_fpcm") {
title = "Water use (m3/kg FPCM)"
y_title = "Water use (m3/kg FPCM)"
- }else if (tt == "total_water_use_m3_per_kg_meat"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_meat") {
title = "Water use (m3/kg meat)"
y_title = "Water use (m3/kg meat)"
- }else if (tt == "total_water_use_m3_per_kg_protein"){
+ }
+ else if (tt == "total_water_use_m3_per_kg_protein") {
title = "Water (m3/kg protein)"
y_title = "Water (m3/kg protein)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_year"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_year") {
title = "Carbon stock changes (t CO2eq/yr)"
y_title = "Carbon stock changes (t CO2eq/yr)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_ha_per_year"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_ha_per_year") {
title = "Carbon stock changes (t CO2eq/ha/yr)"
y_title = "Carbon stock changes (t CO2eq/ha/yr)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_fpcm"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_fpcm") {
title = "Carbon stock changes (t CO2eq/kg FPCM)"
y_title = "Carbon stock changes (t CO2eq/kg FPCM)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_meat"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_meat") {
title = "Carbon stock changes (t CO2eq/kg meat)"
y_title = "Carbon stock changes (t CO2eq/kg meat)"
- }else if (tt == "carbon_stock_change_t_co2eq_per_protein"){
+ }
+ else if (tt == "carbon_stock_change_t_co2eq_per_protein") {
title = "Carbon stock changes (t CO2eq/kg protein)"
y_title = "Carbon stock changes (t CO2eq/kg protein)"
- }else if (tt == "total_milk_produced_energy_kcal_per_year"){
+ }
+ else if (tt == "total_milk_produced_energy_kcal_per_year") {
title = "Energy (kcal/kg FPCM)"
y_title = "Energy (kcal/kg FPCM)"
- }else if (tt == "total_meat_produced_energy_kcal_per_year"){
+ }
+ else if (tt == "total_meat_produced_energy_kcal_per_year") {
title = "Energy (kcal/kg meat)"
y_title = "Energy (kcal/kg meat)"
- }else if (tt == "total_milk_produced_ame_days_per_year"){
+ }
+ else if (tt == "total_milk_produced_ame_days_per_year") {
title = "AME (days/kg FPCM)"
y_title = "AME (days/kg FPCM)"
- }else if (tt == "total_meat_produced_ame_days_per_year"){
+ }
+ else if (tt == "total_meat_produced_ame_days_per_year") {
title = "AME (days/kg meat)"
y_title = "AME (days/kg meat)"
- }else if (tt == "total_carbon_balance_per_fpcm"){
+ }
+ else if (tt == "total_carbon_balance_per_fpcm") {
title = "Carbon balance (t CO2eq/kg FPCM)"
y_title = "Carbon balance (t CO2eq/kg FPCM)"
- }else if (tt == "total_carbon_balance_per_meat"){
+ }
+ else if (tt == "total_carbon_balance_per_meat") {
title = "Carbon balance (t CO2eq/kg meat)"
y_title = "Carbon balance (t CO2eq/kg meat)"
- }else if (tt == "total_carbon_balance_per_protein"){
+ }
+ else if (tt == "total_carbon_balance_per_protein") {
title = "Carbon balance (t CO2eq/kg protein)"
y_title = "Carbon balance (t CO2eq/kg protein)"
- }else{
+ }
+ else {
NA
}
- ggplot(datos, aes_string("scenario", y = tt, fill = "scenario")) +
- geom_bar(stat = "identity",
- position = "dodge",
- width = 0.2) +
- geom_text(aes(label = round(datos[,2],2)), position = position_dodge(width = 0.2), vjust = -0.5, size = 2) +
- labs(x = "", y = y_title, title = title, fill = "Scenario") +
- theme_bw()
-
- ggsave(paste0(oDir, tt, ".png"), width = 150, height = 100, units = "mm")
-
+ output_list[[tt]] <- list(
+ datos = datos,
+ tt = tt,
+ title = title,
+ y_title = y_title
+ )
}
-
+ return(output_list)
}
diff --git a/README.md b/README.md
index ac85037..162b2b2 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-# Comprehensive Livestock Environmental Assessment for Improved Nutrition, a Secured Environment, and Sustainable Development along Livestock and Fish Value Chains (CLEANED)
+# Inclusive and Comprehensive Livestock Environmental Assessment for Improved Nutrition, a Secured Environment, and Sustainable Development along Livestock Value Chains (I-CLEANED)
-The goal of cleaned is to assess changes from transforming livestock value chains.
+The goal of I-CLEANED is to assess changes from transforming livestock value chains by prioritizing profitable, environmentally sustainable and inclusive livestock interventions.
## Installation
diff --git a/data/cleaned.sqlite b/data/cleaned.sqlite
new file mode 100644
index 0000000..e22d755
Binary files /dev/null and b/data/cleaned.sqlite differ
diff --git a/data/energy_parameters.json b/data/energy_parameters.json
new file mode 100644
index 0000000..7a08b3f
--- /dev/null
+++ b/data/energy_parameters.json
@@ -0,0 +1,39 @@
+{
+ "Table 10.4": [
+ {
+ "animal_category": "Cattle_Buffalo",
+ "maintenance_cfi": 0.322,
+ "comments": "All non-lactating cows, steers, heifers and calves"
+ },
+ {
+ "animal_category": "Cattle_Buffalo_lactating_cows",
+ "maintenance_cfi": 0.386,
+ "comments": "Maintenance energy requirements are 20% higher during lactation"
+ },
+ {
+ "animal_category": "Cattle_Buffalo_bulls",
+ "maintenance_cfi": 0.37,
+ "comments": "Maintenance energy requirements are 15% higher for intact males than non lactating females"
+ },
+ {
+ "animal_category": "Sheep_lamb_to _1_year",
+ "maintenance_cfi": 0.236,
+ "comments": "This value can be increased by 15% for intact males"
+ },
+ {
+ "animal_category": "Sheep_older_than_1_year",
+ "maintenance_cfi": 0.217,
+ "comments": "This value can be increased by 15% for intact males."
+ },
+ {
+ "animal_category": "Goats",
+ "maintenance_cfi": 0.315,
+ "comments": "NA"
+ },
+ {
+ "animal_category": "Pigs",
+ "maintenance_cfi": 0.44,
+ "comments": "NA"
+ }
+ ]
+}
diff --git a/data/explore_qt_json.html b/data/explore_qt_json.html
new file mode 100644
index 0000000..bd10de6
--- /dev/null
+++ b/data/explore_qt_json.html
@@ -0,0 +1,6882 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Exploration of CLEANED input files
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
## Loading required package: pacman
+
+
Cleaned Data
+
+
Input data structure
+
The aim of this markdown document is to summarize the structure of
+the .json object that is required as an input for the R cleaned
+packages. It also explores any additional datasets that are used as
+inputs to create this input object, these include
+cleaned/data/ghg_para.R,
+cleaned/data/stock_change_para.rda and
+qlands/cleaned-desktop/cleaned.sqlite.
+
+
+
Simple fields
+
simple_fields<-json_names[class!="data.frame" & length==1,field_name]
+simple_fields<-json_data[json_names[class!="data.frame" & length==1,field_name]]
+simple_fields<-data.table(field=names(simple_fields),
+ value=unlist(simple_fields),
+ class=json_names[class!="data.frame" & length==1,class])
+
+Summary of simple fields containing a single value
+
+
+
+
+
+
+
+
+
+
+| annual_prec |
+1500 |
+integer |
+
+
+| arable_tograssland |
+0 |
+integer |
+
+
+| climate_zone |
+Temperate |
+character |
+
+
+| climate_zone_2 |
+Warm Temperate Dry |
+character |
+
+
+| cropland_orgmatter |
+Low, temperate/boreal, dry |
+character |
+
+
+| cropland_orgmatter_ipcc |
+0.95 |
+numeric |
+
+
+| cropland_system |
+Long term cultivated, temperate/boreal, dry |
+character |
+
+
+| cropland_system_ipcc |
+0.8 |
+numeric |
+
+
+| cropland_tillage |
+Full |
+character |
+
+
+| cropland_tillage_ipcc |
+1 |
+integer |
+
+
+| database_code |
+base |
+character |
+
+
+| et |
+1460 |
+integer |
+
+
+| farm_code |
+001 |
+character |
+
+
+| farm_name |
+test 3 |
+character |
+
+
+| grassland_implevel |
+Medium |
+character |
+
+
+| grassland_implevel_ipcc |
+1 |
+integer |
+
+
+| grassland_management |
+Nominally managed |
+character |
+
+
+| grassland_management_ipcc |
+1 |
+integer |
+
+
+| grassland_toarable |
+0 |
+integer |
+
+
+| purchased_bedding |
+0 |
+integer |
+
+
+| purchased_compost |
+0 |
+integer |
+
+
+| purchased_manure |
+0 |
+integer |
+
+
+| purchased_organic_n |
+0 |
+integer |
+
+
+| rain_length |
+5 |
+integer |
+
+
+| region |
+AFRICA |
+character |
+
+
+| soil_bulk |
+6 |
+integer |
+
+
+| soil_c |
+12 |
+integer |
+
+
+| soil_clay |
+45 |
+integer |
+
+
+| soil_depth |
+2 |
+integer |
+
+
+| soil_description |
+Lixisol |
+character |
+
+
+| soil_k_value |
+0.25 |
+numeric |
+
+
+| soil_n |
+3.5 |
+numeric |
+
+
+| waste_consume_meat |
+2 |
+integer |
+
+
+| waste_consume_milk |
+2 |
+integer |
+
+
+| waste_distribution_meat |
+3 |
+integer |
+
+
+| waste_distribution_milk |
+3 |
+integer |
+
+
+| waste_processing_meat |
+5 |
+integer |
+
+
+| waste_processing_milk |
+5 |
+integer |
+
+
+| waste_production_meat |
+3 |
+integer |
+
+
+| waste_production_milk |
+3 |
+integer |
+
+
+
+
+
+
Livestock
+
The json_data$livestock of the json list is a data.table
+that contains information about livestock”]] herd structure and
+management, manure management and productivity.
+
+Transposed livestock herd data t(json_data$livestock)
+
+
+
+
+
+
+
+
+
+
+
+| adult_weight |
+800 |
+400 |
+0 |
+
+
+| annual_growth |
+0 |
+0 |
+90 |
+
+
+| annual_milk |
+3000 |
+1500 |
+0 |
+
+
+| annual_wool |
+0 |
+0 |
+0 |
+
+
+| birth_interval |
+1.166667 |
+1.500000 |
+0.000000 |
+
+
+| body_weight |
+600 |
+350 |
+200 |
+
+
+| body_weight_weaning |
+0 |
+0 |
+0 |
+
+
+| body_weight_year_one |
+0 |
+0 |
+0 |
+
+
+| carcass_fraction |
+0.48 |
+0.00 |
+0.48 |
+
+
+| cp_grazing |
+0 |
+3 |
+0 |
+
+
+| cp_growth |
+0.0 |
+0.0 |
+0.4 |
+
+
+| cp_lactation |
+5 |
+2 |
+0 |
+
+
+| cp_lactmilk |
+0.09 |
+0.09 |
+0.00 |
+
+
+| cp_maintenance |
+0.60 |
+0.35 |
+0.20 |
+
+
+| cp_pregnancy |
+12.21 |
+9.64 |
+0.00 |
+
+
+| distance_to_pasture |
+0.0 |
+0.5 |
+0.5 |
+
+
+| energy_eggcontent |
+0 |
+0 |
+0 |
+
+
+| energy_meatcontent |
+2200 |
+2200 |
+2200 |
+
+
+| energy_milkcontent |
+970 |
+970 |
+0 |
+
+
+| fat_content |
+4.3 |
+5.8 |
+0.0 |
+
+
+| grazing_displacement |
+0 |
+2 |
+0 |
+
+
+| herd_composition |
+2 |
+5 |
+0 |
+
+
+| ipcc_ef_category_t1 |
+Dairy cattle |
+Other mature female |
+Other mature female-grazing |
+
+
+| ipcc_ef_category_t2 |
+Dairy cows |
+Dairy cows |
+Non-dairy |
+
+
+| ipcc_meth_man_category |
+Dairy cows |
+Dairy cows |
+Other cattle |
+
+
+| ipcc_n_exc_category |
+Dairy cattle |
+Dairy cattle |
+Other cattle |
+
+
+| lactation_length |
+0 |
+0 |
+0 |
+
+
+| litter_size |
+0 |
+0 |
+0 |
+
+
+| livetype_code |
+2 |
+1 |
+5 |
+
+
+| livetype_desc |
+Cattle - Cows (improved) |
+Cattle - Cows (local) |
+Cattle - Steers/heifers |
+
+
+| lw_gain |
+0 |
+0 |
+0 |
+
+
+| manure_in_field |
+0 |
+0 |
+0 |
+
+
+| manure_in_non_roofed_enclosure |
+0 |
+0 |
+0 |
+
+
+| manure_in_stable |
+1 |
+0 |
+0 |
+
+
+| manure_onfarm_fraction |
+1 |
+0 |
+0 |
+
+
+| manure_sales_fraction |
+0 |
+0 |
+0 |
+
+
+| manureman_non_roofed_enclosure |
+Solid storage |
+Solid storage |
+Solid storage |
+
+
+| manureman_offfarm_grazing |
+Solid storage |
+Solid storage |
+Solid storage |
+
+
+| manureman_onfarm_grazing |
+Solid storage |
+Pasture / range / paddock |
+Solid storage |
+
+
+| manureman_stable |
+Solid storage |
+Solid storage |
+Solid storage |
+
+
+| me_grazing |
+2.0 |
+2.0 |
+1.5 |
+
+
+| me_growth |
+0 |
+0 |
+50 |
+
+
+| me_lactation |
+5 |
+2 |
+0 |
+
+
+| me_lactmilk |
+5.5 |
+5.5 |
+0.0 |
+
+
+| me_maintenance |
+60.61547 |
+40.45955 |
+26.59148 |
+
+
+| me_pregnancy |
+1500 |
+1260 |
+0 |
+
+
+| meat_product |
+beef |
+beef |
+beef |
+
+
+| milk_product |
+cow milk |
+cow milk |
+cow milk |
+
+
+| n_content |
+0.029 |
+0.029 |
+0.029 |
+
+
+| piglets_relying_on_milk |
+0 |
+0 |
+0 |
+
+
+| proportion_growth |
+0 |
+0 |
+0 |
+
+
+| protein_meatcontent |
+26 |
+26 |
+26 |
+
+
+| protein_milkcontent |
+3.7 |
+3.2 |
+0.0 |
+
+
+| time_in_non_roofed_enclosure |
+0 |
+0 |
+0 |
+
+
+| time_in_offfarm_grazing |
+0 |
+0 |
+0 |
+
+
+| time_in_onfarm_grazing |
+0 |
+1 |
+1 |
+
+
+| time_in_stable |
+1 |
+0 |
+0 |
+
+
+| water_requirement |
+140 |
+120 |
+80 |
+
+
+| work_hour |
+0 |
+0 |
+0 |
+
+
+
+
The livestock are linked to the
+feed_basket$feeds tables by the livetype_code
+keyfield.
+
json_data$livestock[,c("livetype_code","livetype_desc")] # Codes in the feed_items table
+
+
+
+
lapply(json_data$feed_basket$feeds,"[[","livestock") # Codes in the feed_basket tables
+
## [[1]]
+## [[1]][[1]]
+## allocation livetype_code
+## 1 40 2
+## 2 17 1
+## 3 40 5
+##
+## [[1]][[2]]
+## allocation livetype_code
+## 1 25 2
+## 2 43 1
+## 3 20 5
+##
+## [[1]][[3]]
+## allocation livetype_code
+## 1 35 2
+## 2 40 1
+## 3 40 5
+##
+##
+## [[2]]
+## [[2]][[1]]
+## allocation livetype_code
+## 1 40 2
+## 2 17 1
+## 3 40 5
+##
+## [[2]][[2]]
+## allocation livetype_code
+## 1 25 2
+## 2 43 1
+## 3 20 5
+##
+## [[2]][[3]]
+## allocation livetype_code
+## 1 35 2
+## 2 40 1
+## 3 40 5
+
+
+
Feed items
+
The json_data$feed_items level of the json list is a
+data.table that contains information about the production management and
+context of feed production.
+
+Transposed feed item data t(json_data$feed_items)
+
+
+
+
+
+
+
+
+
+
+
+| ammonia |
+0 |
+0 |
+0 |
+
+
+| ammonium_nitrate |
+0 |
+0 |
+0 |
+
+
+| ammonium_sulfate |
+0 |
+0 |
+0 |
+
+
+| average_dbh25 |
+0 |
+0 |
+0 |
+
+
+| average_dbh2550 |
+0 |
+0 |
+0 |
+
+
+| average_dbh50 |
+0 |
+0 |
+0 |
+
+
+| category |
+cereal |
+cereal |
+legume |
+
+
+| cp_content |
+13.60 |
+3.85 |
+18.40 |
+
+
+| cultivation_period |
+0 |
+0 |
+0 |
+
+
+| cut_carry_fraction |
+0 |
+0 |
+0 |
+
+
+| dap |
+0 |
+0 |
+0 |
+
+
+| diameter_breast |
+0 |
+0 |
+0 |
+
+
+| dm_content |
+89.00 |
+91.88 |
+90.00 |
+
+
+| dry_yield |
+30 |
+15 |
+8 |
+
+
+| ecosystem_type |
+ |
+ |
+ |
+
+
+| energy |
+0 |
+360 |
+336 |
+
+
+| feed_item_code |
+65 |
+99 |
+18 |
+
+
+| feed_item_name |
+Oats (Avena sativa) - grain IP |
+Rice (Oryza sativa) - straw |
+Cowpea (Vigna unguiculata) - crop residue |
+
+
+| feed_type_code |
+2 |
+45 |
+9 |
+
+
+| feed_type_name |
+Avena sativa |
+Rice |
+Cowpea |
+
+
+| fraction_as_fertilizer |
+1 |
+1 |
+0 |
+
+
+| fraction_as_manure |
+NA |
+NA |
+NA |
+
+
+| grassman |
+1 |
+1 |
+1 |
+
+
+| grassman_change_factor |
+1 |
+1 |
+1 |
+
+
+| grassman_desc |
+Nominally managed |
+Nominally managed |
+Nominally managed |
+
+
+| increase_dbh25 |
+0 |
+0 |
+0 |
+
+
+| increase_dbh2550 |
+0 |
+0 |
+0 |
+
+
+| increase_dbh50 |
+0 |
+0 |
+0 |
+
+
+| intercrop |
+0 |
+0 |
+0 |
+
+
+| intercrop_fraction |
+0 |
+0 |
+0 |
+
+
+| kc_initial |
+0.10 |
+1.05 |
+0.15 |
+
+
+| kc_late |
+0.55 |
+0.75 |
+0.60 |
+
+
+| kc_midseason |
+1.10 |
+1.20 |
+1.05 |
+
+
+| land_cover |
+7 |
+7 |
+1 |
+
+
+| land_cover_desc |
+Cereals |
+Cereals |
+Dense forest |
+
+
+| landcover_c_factor |
+0.150 |
+0.150 |
+0.001 |
+
+
+| main_n |
+0.0176 |
+0.0090 |
+0.0380 |
+
+
+| main_product_removal |
+1 |
+1 |
+0 |
+
+
+| me_content |
+12.267324 |
+5.640000 |
+9.880848 |
+
+
+| n_content |
+0.2 |
+0.2 |
+0.0 |
+
+
+| n_fertilizer |
+NA |
+NA |
+NA |
+
+
+| n_solutions |
+50 |
+300 |
+100 |
+
+
+| npk |
+0 |
+0 |
+0 |
+
+
+| organic_amendment |
+ |
+ |
+ |
+
+
+| residue_burnt |
+0 |
+0 |
+0 |
+
+
+| residue_dry_yield |
+0 |
+0 |
+6 |
+
+
+| residue_n |
+0.0 |
+0.2 |
+0.0 |
+
+
+| residue_removal |
+0.0 |
+0.8 |
+0.0 |
+
+
+| slope |
+1 |
+1 |
+1 |
+
+
+| slope_desc |
+Flat (0-5%) |
+Flat (0-5%) |
+Flat (0-5%) |
+
+
+| slope_length |
+0 |
+0 |
+0 |
+
+
+| slope_p_factor |
+0.11 |
+0.11 |
+0.11 |
+
+
+| source_type |
+Main |
+Residue |
+Main |
+
+
+| time_horizon |
+0 |
+0 |
+0 |
+
+
+| trees_dhb |
+0 |
+0 |
+0 |
+
+
+| trees_growth |
+0 |
+0 |
+0 |
+
+
+| trees_ha |
+0 |
+0 |
+0 |
+
+
+| trees_ha_dbh25 |
+0 |
+0 |
+0 |
+
+
+| trees_ha_dbh2550 |
+0 |
+0 |
+0 |
+
+
+| trees_ha_dbh50 |
+0 |
+0 |
+0 |
+
+
+| trees_removal |
+0 |
+0 |
+0 |
+
+
+| urea |
+400 |
+700 |
+200 |
+
+
+| usda_value |
+0 |
+20450 |
+16062 |
+
+
+| water_content |
+0.00 |
+12.89 |
+11.95 |
+
+
+| water_regime |
+ |
+ |
+ |
+
+
+
+
The feed_items are linked to the
+feed_basket$feeds tables by the feed_item_code
+field.
+
json_data$feed_items[,c("feed_item_code","feed_item_name")] # Codes in the feed_items table
+
+
+
+
lapply(json_data$feed_basket$feeds,"[[","feed_item_code") # Codes in the feed_basket tables
+
## [[1]]
+## [1] "65" "99" "18"
+##
+## [[2]]
+## [1] "65" "99" "18"
+
Other keyfields include feed_type_code and
+land_cover:
+
json_data$feed_items[,c("feed_type_code","feed_type_name","land_cover","land_cover_desc")]
+
+
+
+
+
+
Fertilizer
+
The json_data$fertilizer level of the json list is a
+data.table that contains information about the production management and
+context of feed production.
+
+Fertilizer data input table (json_data$fertilizer)
+
+
+
+
+
+| 4 |
+Ammonium nitrate |
+0 |
+12 |
+
+
+| 6 |
+N solutions |
+0 |
+10 |
+
+
+
+
The values in fertilizer_code field do not appear
+directly correspond to any fields in the feed basket or feed item
+tables. However columns with similar names do appear in the field item
+tables
+
fertilizers<-json_data$fertilizer$fertilizer_desc
+fi_cols<-colnames(json_data$feed_items)
+
+# Reformat fertilizer names to match column names in the feed_items table
+(fertilizers<-gsub(" ","_",tolower(json_data$fertilizer$fertilizer_desc)))
+
## [1] "ammonium_nitrate" "n_solutions"
+
# Find matching columns
+fi_cols[fi_cols %in% fertilizers]
+
## [1] "ammonium_nitrate" "n_solutions"
+
+
+
Seasons
+
The json_data$season level of the input data is 2-column
+table that records the length of each season (adding up to 365 days
+max).
+
+Feed items data input table (json_data$season)
+
+
+
+
+
+| 200 |
+Wet season |
+
+
+| 165 |
+Dry season |
+
+
+
+
The season_name field is the key field that links to the
+feed basket.
+
json_data$feed_basket$season_name
+
## [1] "Wet season" "Dry season"
+
+
+
Feed basket
+
The json_data$feed_basket level of the input data
+contains a futher 2 list levels called feeds and season_name. These
+sub-levels appear to be the same length: feeds = 2, season_name = 2.
+
+
Seasons
+
The json_data$feed_basket$season_name object is simple,
+being a vector containing the names of the seasons:
+
+Feed basket/season data input table (json_data\(feed_basket\)season)
+
+
+
+
+
+| Wet season |
+
+
+| Dry season |
+
+
+
+
+
+
Feed Basket
+
The json_data$feed_basket$feed object is the most
+structurally complex element of the input json data containing several
+levels of nesting.
+
str(json_data$feed_basket$feeds)
+
## List of 2
+## $ :'data.frame': 3 obs. of 3 variables:
+## ..$ feed_item_code: chr [1:3] "65" "99" "18"
+## ..$ feed_type_code: chr [1:3] "2" "45" "9"
+## ..$ livestock :List of 3
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 40 17 40
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 25 43 20
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 35 40 40
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+## $ :'data.frame': 3 obs. of 3 variables:
+## ..$ feed_item_code: chr [1:3] "65" "99" "18"
+## ..$ feed_type_code: chr [1:3] "2" "45" "9"
+## ..$ livestock :List of 3
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 40 17 40
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 25 43 20
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+## .. ..$ :'data.frame': 3 obs. of 2 variables:
+## .. .. ..$ allocation : int [1:3] 35 40 40
+## .. .. ..$ livetype_code: chr [1:3] "2" "1" "5"
+
+
Feeds
+
Each feed basket table (e.g.,
+json_data$feed_basket$feeds[[1]]) is constructed using key
+fields that describe feed items found in the
+json_data$feed_items table, specifically
+feed_item_code and feed_type_code. The feeds
+are then allocated to the herd elements described in the
+json_data$livestock table.
+
+Feed basket/feed data input table tablejson_data\(feed_basket\)feeds[[1]]
+
+
+
+
+
+| 65 |
+2 |
+40, 17, 40, 2 , 1 , 5 |
+
+
+| 99 |
+45 |
+25, 43, 20, 2 , 1 , 5 |
+
+
+| 18 |
+9 |
+35, 40, 40, 2 , 1 , 5 |
+
+
+
+
+
+
Livestock
+
The livestock field in the feed basket table contains a list with 3
+elements, indicating a one-to-many relationship between the diet item
+and elements of the livestock herd. Each feed item represented by a row
+in the feed basket table is allocated to different herd elements, with
+the livetype_code field serving as the key field linking
+the two tables.
+
+
+Feed basket/feed/livestock data input table tablejson_data\(feed_basket\)feeds[[1]]$livestock
+
+
+
+
+
+
+
+
+
+
+| 40 |
+2 |
+
+
+| 17 |
+1 |
+
+
+| 40 |
+5 |
+
+
+
+ |
+
+
+
+
+
+
+
+| 25 |
+2 |
+
+
+| 43 |
+1 |
+
+
+| 20 |
+5 |
+
+
+
+ |
+
+
+
+
+
+
+
+| 35 |
+2 |
+
+
+| 40 |
+1 |
+
+
+| 40 |
+5 |
+
+
+
+ |
+
+
+
+
The first element of the livestock list contains no further
+nesting:
+
str(json_data$feed_basket$feeds[[1]]$livestock[[1]])
+
## 'data.frame': 3 obs. of 2 variables:
+## $ allocation : int 40 17 40
+## $ livetype_code: chr "2" "1" "5"
+
+
+
+
+
+
cleaned cleaned/data .rda files
+
rda_files<-list.files(".rda")
+
+
GHG parameters
+
The ghg para object (cleaned/data/ghg_para.rda) is a
+list of tables that appear to refer to IPCC equations, livestock
+parameters and fertilizers.
+
load("ghg_para.rda")
+
+# Summarize level 1 of the list
+ghg_names<-data.table(field_name=names(ghg_para),
+ dim=sapply(ghg_para,dim))
+
+kable(ghg_names,caption="Tables within ghg_names list")
+
+Tables within ghg_names list
+
+
+
+
+
+| livestock_parameters |
+18, 7 |
+
+
+| Table_10.12 |
+6, 2 |
+
+
+| table_10.17 |
+3, 2 |
+
+
+| table_10.19 |
+12, 3 |
+
+
+| table_10.21 |
+3, 2 |
+
+
+| table_10.22 |
+7, 4 |
+
+
+| table_10A_9 |
+18, 3 |
+
+
+| table_11.1_&_table_11.3 |
+10, 5 |
+
+
+| table_2.5 |
+5, 2 |
+
+
+| fertilizer_table |
+5, 5 |
+
+
+| table_5.11 |
+NULL |
+
+
+| table_5.12 |
+8, 4 |
+
+
+| table_5.13 |
+5, 3 |
+
+
+| table_5.14 |
+6, 2 |
+
+
+
+
The exception is ghg_para$table_5.11 which is a
+list:
+
ghg_para$table_5.11
+
## $baseline_emission_factor
+## [1] 1.3
+##
+## $soil_type_scaling_factor
+## [1] 1
+
+
Livestock_parameters
+
Note there is an invalid character in this table:
+
ghg_para$livestock_parameters$`IPCC Category - methane emissions enteric fermentation - Tier 2`[11]<-"Other Cattle or Buffalo - grazing"
+
kable(ghg_para$livestock_parameters,caption="ghg_para$livestock_parameters")
+
+ghg_para$livestock_parameters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+| Cows (local) |
+0.04 |
+0.08 |
+Other mature female |
+Dairy cattle |
+Dairy cows |
+Dairy cattle |
+
+
+| Cows (improved) |
+0.04 |
+0.08 |
+Dairy cattle |
+Dairy cattle |
+Dairy cows |
+Dairy cattle |
+
+
+| Cows (high productive) |
+0.04 |
+0.08 |
+Dairy cattle |
+Dairy cattle |
+Dairy cows |
+Dairy cattle |
+
+
+| Adult cattle - male |
+0.04 |
+0.08 |
+Other draft bull |
+Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+Other cattle |
+Other cattle |
+
+
+| Steers/heifers |
+0.04 |
+0.08 |
+Other Mature female-grazing |
+Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+Other cattle |
+Other cattle |
+
+
+| Steers/heifers (improved) |
+0.04 |
+0.08 |
+Other Mature female-grazing |
+Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+Other cattle |
+Other cattle |
+
+
+| Calves |
+0.04 |
+0.08 |
+Other young |
+Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+Other cattle |
+Other cattle |
+
+
+| Calves (improved) |
+0.04 |
+0.08 |
+Other young |
+Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+Other cattle |
+Other cattle |
+
+
+| Buffalo (dairy) |
+0.04 |
+0.08 |
+Other draft bull |
+Other Cattle or Buffalo - grazing |
+Buffalo |
+Other cattle |
+
+
+| Buffalo steers/heifers |
+0.04 |
+0.08 |
+Other young |
+Other Cattle or Buffalo - grazing |
+Buffalo |
+Other cattle |
+
+
+| Buffalo calves |
+0.04 |
+0.08 |
+Other young |
+Other Cattle or Buffalo - grazing |
+Buffalo |
+Other cattle |
+
+
+| Sheep/Goats - Ewes/Does |
+0.04 |
+0.08 |
+Goats |
+Sheep |
+Sheep |
+Sheep |
+
+
+| Sheep/Goats - Breeding Rams/Bucks |
+0.04 |
+0.08 |
+Goats |
+Sheep |
+Sheep |
+Sheep |
+
+
+| Sheep/Goats - Fattening Rams/Bucks |
+0.04 |
+0.08 |
+Goats |
+Sheep |
+Sheep |
+sheep |
+
+
+| Sheep/Goats - Lambs/Kids |
+0.04 |
+0.08 |
+Goats |
+lambs (less 1 yr old) |
+Sheep |
+sheep |
+
+
+| Pigs - lactating/pregnant sows |
+0.02 |
+0.08 |
+Pigs |
+N/A |
+Swine |
+pigs |
+
+
+| Pigs - dry sows/boars |
+0.02 |
+0.08 |
+Pigs |
+N/A |
+Swine |
+pigs |
+
+
+| Pigs - growers |
+0.02 |
+0.08 |
+Pigs |
+N/A |
+Swine |
+pigs |
+
+
+
+
+
+
Fertilizer table
+
kable(ghg_para$fertilizer_table,caption="ghg_para$fertilizer_table")
+
+ghg_para$fertilizer_table
+
+
+
+
+
+
+
+
+
+
+
+
+| DAP |
+18 |
+2.80 |
+0.18 |
+0.5040 |
+
+
+| CAN |
+27 |
+8.66 |
+0.27 |
+2.3382 |
+
+
+| Urea |
+NA |
+NA |
+NA |
+0.7850 |
+
+
+| NPK |
+NA |
+NA |
+NA |
+1.2100 |
+
+
+| Lime-application |
+NA |
+NA |
+NA |
+NA |
+
+
+
+
+
+
IPCC Tables
+
+
Table_10.12
+
kable(ghg_para$Table_10.12)
+
+
+
+
+
+
+
+
+
+
+| Dairy cattle |
+6.5 |
+
+
+| Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+6.5 |
+
+
+| Other Cattle or Buffalo - grazing |
+6.5 |
+
+
+| sheep |
+6.5 |
+
+
+| lambs (less 1 yr old) |
+4.5 |
+
+
+| N/A |
+0.0 |
+
+
+
+
+
+
table_10.17
+
kable(ghg_para$table_10.17)
+
+
+
+
+
+
+| Pasture / range / paddock |
+0.015 |
+
+
+| solid storage |
+0.040 |
+
+
+| dry lot |
+0.015 |
+
+
+
+
+
+
table_10.19
+
kable(ghg_para$table_10.19)
+
+
+
+
+
+
+| Dairy cattle |
+LATIN AMERICA |
+0.48 |
+
+
+| Dairy cattle |
+AFRICA |
+0.60 |
+
+
+| Dairy cattle |
+ASIA |
+0.47 |
+
+
+| Other cattle |
+LATIN AMERICA |
+0.37 |
+
+
+| Other cattle |
+AFRICA |
+0.63 |
+
+
+| Other cattle |
+ASIA |
+0.34 |
+
+
+| Sheep |
+LATIN AMERICA |
+1.17 |
+
+
+| Sheep |
+AFRICA |
+1.17 |
+
+
+| Sheep |
+ASIA |
+1.17 |
+
+
+| Pigs |
+LATIN AMERICA |
+1.64 |
+
+
+| Pigs |
+AFRICA |
+1.64 |
+
+
+| Pigs |
+ASIA |
+0.50 |
+
+
+
+
+
+
table_10.21
+
kable(ghg_para$table_10.21)
+
+
+
+
+
+
+| Pasture / range / paddock |
+0.010 |
+
+
+| solid storage |
+0.005 |
+
+
+| dry lot |
+0.020 |
+
+
+
+
+
+
table_10.22
+
kable(ghg_para$table_10.22)
+
+
+
+
+
+
+| Dairy cows |
+pit storage |
+0.28 |
+(10-40) |
+
+
+| Dairy cows |
+dry lot |
+0.20 |
+(10-35) |
+
+
+| Dairy cows |
+solid storage |
+0.30 |
+(10-40) |
+
+
+| Dairy cows |
+daily spread |
+0.07 |
+(5-60) |
+
+
+| Other cattle |
+dry lot |
+0.30 |
+(20-50) |
+
+
+| Other cattle |
+solid storage |
+0.45 |
+(10-65) |
+
+
+| Other cattle |
+deep bedding |
+0.30 |
+(20-40) |
+
+
+
+
+
+
table_10A_9
+
kable(ghg_para$Table_10.12)
+
+
+
+
+
+
+
+
+
+
+| Dairy cattle |
+6.5 |
+
+
+| Other Cattle and Buffaloes that are primarily fed low
+quality crop residues and byproducts |
+6.5 |
+
+
+| Other Cattle or Buffalo - grazing |
+6.5 |
+
+
+| sheep |
+6.5 |
+
+
+| lambs (less 1 yr old) |
+4.5 |
+
+
+| N/A |
+0.0 |
+
+
+
+
+
+
table_11.1_&_table_11.3
+
kable(ghg_para$`table_11.1_&_table_11.3`)
+
+
+
+
+
+
+
+
+
+
+
+
+
+| EF1 |
+kg N2O-N (kg N input)-1 |
+emission factor for N2O emissions from N inputs |
+0.0100 |
+0.003-0.03 |
+
+
+| EF2 |
+kg N2O-N ha-1 yr-1 |
+emission factor for N2O emissions from drained/managed
+organic soils |
+16.0000 |
+5 TO 48 |
+
+
+| EF3PRP-CPP |
+kg N2O-N (kg N input)-1 |
+emission factor for N2O emissions from urine and dung N
+deposited on pasture, range and paddock by grazing animals |
+0.0200 |
+0.007-0.06 |
+
+
+| EF3PRP-SO |
+kg N2O-N (kg N input)-1 |
+emission factor for N2O emissions from urine and dung N
+deposited on pasture, range and paddock by grazing animals |
+0.0100 |
+0.003-0.03 |
+
+
+| EF4 |
+[kg N-N2O (kg NH3-N + NOx-N volatilised)-1] |
+emission factor for N2O emissions from atmospheric
+deposition of N on soils and water surfaces |
+0.0100 |
+0.002-0.05 |
+
+
+| EF5 |
+kg N2O-N (kg N leached and runoff)-1 |
+emission factor for N2O emissions from N leaching and
+runoff |
+0.0075 |
+0.005-0.025 |
+
+
+| EF1R |
+kg N2O-N (kg N input)-1 |
+emission factor for N2O emission from N inputs for
+flooded rice |
+0.0030 |
+0.000 - 0.006 |
+
+
+| FracGASF |
+kg N volatilised (kg of N applied)-1 |
+fraction of synthetic fertilzer N that volatilises as
+NH3 and NOx |
+0.1000 |
+0.03-0.3 |
+
+
+| FracGASM |
+kg N volatilised (kg of N applied or deposited)-1 |
+fraction of applied organic N fertiliser materials
+(FON) and of urine and dung N deposited by grazing animals (FPRP) that
+volatilises as NH3 and NOx |
+0.2000 |
+0.05-0.5 |
+
+
+| FracLEACH-(H) |
+kg N (kg of N additions)-1 |
+fraction of all N added to/mineralised in managed soils
+in regions where leaching/runoff occurs that is lost through leaching
+and runoff |
+0.3000 |
+if sum of rain - sum of PE > soil water holding
+capacity during rainy season |
+
+
+
+
+
+
table_2.5
+
kable(ghg_para$table_2.5)
+
+
+
+
+
+
+| CO2 |
+1515.00 |
+
+
+| CO |
+92.00 |
+
+
+| CH4 |
+2.70 |
+
+
+| N2O |
+0.07 |
+
+
+| Nox |
+2.50 |
+
+
+
+
+
+
table_5.12
+
kable(ghg_para$table_5.12)
+
+
+
+
+
+
+
+
+
+
+
+
+| irrigated |
+Irrigated-Continuously flooded |
+0.78 |
+1.00 |
+
+
+| irrigated |
+intermittently flooded-single aeration |
+0.78 |
+0.60 |
+
+
+| irrigated |
+Intermittently flooded-multiple aeration |
+0.78 |
+0.52 |
+
+
+| Rain fed and deep water |
+Rainfed-regular rainfed |
+0.27 |
+0.28 |
+
+
+| Rain fed and deep water |
+Rainfed-drought prone |
+0.27 |
+0.25 |
+
+
+| Rain fed and deep water |
+Rainfed-deep water |
+0.27 |
+0.31 |
+
+
+| Upland |
+Upland |
+0.00 |
+0.00 |
+
+
+| None |
+None |
+0.00 |
+0.00 |
+
+
+
+
+
+
table_5.13
+
kable(ghg_para$table_5.13)
+
+
+
+
+
+
+
+
+
+
+
+| non-flooded pre-season <180 days( often in double
+cropping of rice) |
+1.22 |
+1.00 |
+
+
+| non-flooded pre-season >180 days (single rice crop
+following a dry fallow period) |
+1.22 |
+0.68 |
+
+
+| flooded pre-season (>30 days) |
+1.22 |
+1.90 |
+
+
+| flooded pre-season (<30 days) |
+1.22 |
+0.00 |
+
+
+| None |
+0.00 |
+0.00 |
+
+
+
+
+
+
table_5.14
+
kable(ghg_para$table_5.14)
+
+
+
+
+
+
+
+
+
+
+| straw incorporated in soil shortly (<30 days) before
+cultivation |
+1.00 |
+
+
+| straw incorporated in soil long (>30 days) before
+cultivation |
+0.29 |
+
+
+| Compost |
+0.05 |
+
+
+| Farm yard manure |
+0.14 |
+
+
+| green manure |
+0.50 |
+
+
+| None |
+0.00 |
+
+
+
+
+
+
+
+
Stock change
+
The stock change object
+(cleaned/data/stock_change_para.rda) is a series of nested
+lists that describe: 1) landuse, management, and input factor_variables
+for grassland; and 2) landuse, tillage, and input input factor_variables
+for cropland.
+
load("stock_change_para.rda")
+str(stock_change_para)
+
## List of 2
+## $ cropland :'data.frame': 1 obs. of 3 variables:
+## ..$ landuse:List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 10 variables:
+## .. .. .. .. ..$ Long term cultivated, temperate/boreal, dry : num 0.8
+## .. .. .. .. ..$ Long term cultivated, temperate/boreal, moist : num 0.69
+## .. .. .. .. ..$ Long term cultivated, tropical, dry : num 0.58
+## .. .. .. .. ..$ Long term cultivated, tropical, moist/wet : num 0.48
+## .. .. .. .. ..$ Long term cultivated, tropical montane, all : num 0.64
+## .. .. .. .. ..$ Paddy rice : num 1.1
+## .. .. .. .. ..$ Perennial/tree crop : int 1
+## .. .. .. .. ..$ Set aside (< 20 years), temperate/boreal and tropical, dry : num 0.93
+## .. .. .. .. ..$ Set aside (< 20 years), temperate/boreal and tropical, moist/wet: num 0.82
+## .. .. .. .. ..$ Set aside (< 20 years),tropical montane, all : num 0.88
+## ..$ tillage:List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 11 variables:
+## .. .. .. .. ..$ Full : int 1
+## .. .. .. .. ..$ Reduced, temperate/boreal, dry : num 1.02
+## .. .. .. .. ..$ Reduced, temperate/boreal, moist: num 1.08
+## .. .. .. .. ..$ Reduced, tropical, dry : num 1.09
+## .. .. .. .. ..$ Reduced, tropical, moist : num 1.15
+## .. .. .. .. ..$ Reduced, tropical montane, all : num 1.09
+## .. .. .. .. ..$ No-till, temperate/boreal, dry : num 1.1
+## .. .. .. .. ..$ No-till, temperate/boreal, moist: num 1.15
+## .. .. .. .. ..$ No-till, tropical, dry : num 1.17
+## .. .. .. .. ..$ No-till, tropical, moist/wet : num 1.22
+## .. .. .. .. ..$ No-till, tropical montane, all : num 1.16
+## ..$ input :List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 12 variables:
+## .. .. .. .. ..$ Low, temperate/boreal, dry : num 0.95
+## .. .. .. .. ..$ Low, temperate/boreal, moist : num 0.92
+## .. .. .. .. ..$ Low, tropical, dry : num 0.95
+## .. .. .. .. ..$ Low, tropical, moist : num 0.92
+## .. .. .. .. ..$ Low, tropical montane, all : num 0.94
+## .. .. .. .. ..$ Medium, all : int 1
+## .. .. .. .. ..$ High w/OUT manure, temperate/boral and tropical, dry : num 1.04
+## .. .. .. .. ..$ High w/OUT manure, temperate/boral and tropical, moist/wet: num 1.11
+## .. .. .. .. ..$ High w/OUT manure, tropical montane : num 1.08
+## .. .. .. .. ..$ High with manure, temperate/boral and tropical, dry : num 1.37
+## .. .. .. .. ..$ High with manure, temperate/boral and tropical, moist/wet : num 1.44
+## .. .. .. .. ..$ High with manure, tropical montane : num 1.41
+## $ grassland:'data.frame': 1 obs. of 3 variables:
+## ..$ landuse :List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. .. .. ..$ All: int 1
+## ..$ management:List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 8 variables:
+## .. .. .. .. ..$ Nominally managed : num 1
+## .. .. .. .. ..$ Moderately degraded grassland, temperate/boreal: num 0.95
+## .. .. .. .. ..$ Moderately degraded grassland, tropical : num 0.97
+## .. .. .. .. ..$ Moderately degraded grassland, tropical montane: num 0.96
+## .. .. .. .. ..$ Severely degraded : num 0.7
+## .. .. .. .. ..$ Improved grassland, temperate/boreal : num 1.14
+## .. .. .. .. ..$ Improved grassland, tropical : num 1.17
+## .. .. .. .. ..$ Improved grassland, tropical montane : num 1.16
+## ..$ input :List of 1
+## .. ..$ :'data.frame': 1 obs. of 1 variable:
+## .. .. ..$ factor_variables:List of 1
+## .. .. .. ..$ :'data.frame': 1 obs. of 3 variables:
+## .. .. .. .. ..$ Medium: int 1
+## .. .. .. .. ..$ High : num 1.11
+## .. .. .. .. ..$ none : int 1
+
+
Grass factor variables
+
Grassland: landuse
+
x<-unlist(stock_change_para$grassland$landuse[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
Grassland: management
+
x<-unlist(stock_change_para$grassland$management[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
+
+
+
+
+| Nominally managed |
+1.00 |
+
+
+| Moderately degraded grassland, temperate/boreal |
+0.95 |
+
+
+| Moderately degraded grassland, tropical |
+0.97 |
+
+
+| Moderately degraded grassland, tropical montane |
+0.96 |
+
+
+| Severely degraded |
+0.70 |
+
+
+| Improved grassland, temperate/boreal |
+1.14 |
+
+
+| Improved grassland, tropical |
+1.17 |
+
+
+| Improved grassland, tropical montane |
+1.16 |
+
+
+
+
Grassland: input
+
x<-unlist(stock_change_para$grassland$input[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
+
+
+
+
+| Medium |
+1.00 |
+
+
+| High |
+1.11 |
+
+
+| none |
+1.00 |
+
+
+
+
+
+
Cropland factor variables
+
Cropland: landuse
+
x<-unlist(stock_change_para$cropland$landuse[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
+
+
+
+
+
+
+
+
+| Long term cultivated, temperate/boreal, dry |
+0.80 |
+
+
+| Long term cultivated, temperate/boreal, moist |
+0.69 |
+
+
+| Long term cultivated, tropical, dry |
+0.58 |
+
+
+| Long term cultivated, tropical, moist/wet |
+0.48 |
+
+
+| Long term cultivated, tropical montane, all |
+0.64 |
+
+
+| Paddy rice |
+1.10 |
+
+
+| Perennial/tree crop |
+1.00 |
+
+
+| Set aside (< 20 years), temperate/boreal and
+tropical, dry |
+0.93 |
+
+
+| Set aside (< 20 years), temperate/boreal and
+tropical, moist/wet |
+0.82 |
+
+
+| Set aside (< 20 years),tropical montane, all |
+0.88 |
+
+
+
+
Cropland: tillage
+
x<-unlist(stock_change_para$cropland$tillage[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
+
+
+
+
+| Full |
+1.00 |
+
+
+| Reduced, temperate/boreal, dry |
+1.02 |
+
+
+| Reduced, temperate/boreal, moist |
+1.08 |
+
+
+| Reduced, tropical, dry |
+1.09 |
+
+
+| Reduced, tropical, moist |
+1.15 |
+
+
+| Reduced, tropical montane, all |
+1.09 |
+
+
+| No-till, temperate/boreal, dry |
+1.10 |
+
+
+| No-till, temperate/boreal, moist |
+1.15 |
+
+
+| No-till, tropical, dry |
+1.17 |
+
+
+| No-till, tropical, moist/wet |
+1.22 |
+
+
+| No-till, tropical montane, all |
+1.16 |
+
+
+
+
Cropland: input
+
x<-unlist(stock_change_para$cropland$input[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+
+
+
+
+
+| Low, temperate/boreal, dry |
+0.95 |
+
+
+| Low, temperate/boreal, moist |
+0.92 |
+
+
+| Low, tropical, dry |
+0.95 |
+
+
+| Low, tropical, moist |
+0.92 |
+
+
+| Low, tropical montane, all |
+0.94 |
+
+
+| Medium, all |
+1.00 |
+
+
+| High w/OUT manure, temperate/boral and tropical,
+dry |
+1.04 |
+
+
+| High w/OUT manure, temperate/boral and tropical,
+moist/wet |
+1.11 |
+
+
+| High w/OUT manure, tropical montane |
+1.08 |
+
+
+| High with manure, temperate/boral and tropical,
+dry |
+1.37 |
+
+
+| High with manure, temperate/boral and tropical,
+moist/wet |
+1.44 |
+
+
+| High with manure, tropical montane |
+1.41 |
+
+
+
+
+
+
+
mufindi
+
The mufindi object (cleaned/data/mufindi.rda) appears to
+be an input dataset similar to the qt_example.json
+file.
+
load("mufindi.rda")
+str(mufindi)
+
## List of 48
+## $ cba_discount_rate : int 0
+## $ cba_years : int 0
+## $ cropland_orgmatter : chr "High w/OUT manure, temperate/boral and tropical, moist/wet"
+## $ cropland_system : chr "Long term cultivated, temperate/boreal, moist"
+## $ cropland_tillage : chr "Reduced, tropical, moist"
+## $ farm_code : chr "ddd"
+## $ farm_name : chr "ooo"
+## $ feed_basket :'data.frame': 2 obs. of 2 variables:
+## ..$ feeds :List of 2
+## .. ..$ :'data.frame': 4 obs. of 3 variables:
+## .. .. ..$ feed_item_code: chr [1:4] "16" "31" "51" "82"
+## .. .. ..$ feed_type_code: chr [1:4] "8" "17" "29" "40"
+## .. .. ..$ livestock :List of 4
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 2 10
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 20 10
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 30 10
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 48 70
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. ..$ :'data.frame': 4 obs. of 3 variables:
+## .. .. ..$ feed_item_code: chr [1:4] "16" "31" "51" "82"
+## .. .. ..$ feed_type_code: chr [1:4] "8" "17" "29" "40"
+## .. .. ..$ livestock :List of 4
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 70 50
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 20 5
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 5 5
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## .. .. .. ..$ :'data.frame': 2 obs. of 2 variables:
+## .. .. .. .. ..$ allocation : int [1:2] 5 40
+## .. .. .. .. ..$ livetype_code: chr [1:2] "3" "6"
+## ..$ season_name: chr [1:2] "Dry season" "Wet season"
+## $ feed_items :'data.frame': 4 obs. of 64 variables:
+## ..$ ammonia : int [1:4] 14 0 0 8
+## ..$ ammonium_nitrate : int [1:4] 11 0 5 0
+## ..$ ammonium_sulfate : int [1:4] 12 6 0 0
+## ..$ c_factor : num [1:4] 0.05 0.117 0.05 0.027
+## ..$ category : chr [1:4] "" "legume" "cereal" "grass"
+## ..$ cp_content : num [1:4] 1.81 16.29 8.9 11
+## ..$ cp_fresh : num [1:4] 1.61 15.17 7.3 1.65
+## ..$ crop_coefficient : num [1:4] 0 0.633 0.533 0.917
+## ..$ cut_carry_fraction : int [1:4] 2 0 0 0
+## ..$ dap : int [1:4] 10 0 0 4
+## ..$ de : num [1:4] 0.71 0.433 0.674 0.652
+## ..$ dm_content : num [1:4] 88.8 93.1 82 15
+## ..$ dry_yield : num [1:4] 5.04 1.16 8.6 6
+## ..$ emission_factor : int [1:4] 0 0 0 0
+## ..$ energy : int [1:4] 160 567 365 0
+## ..$ energy_dm : num [1:4] 397 606 407 0
+## ..$ establishment_cost : int [1:4] 0 0 0 20
+## ..$ establishment_labour : int [1:4] 0 0 0 6
+## ..$ feed_item_code : chr [1:4] "16" "31" "51" "82"
+## ..$ feed_item_name : chr [1:4] "Cassava (Manihot esculenta) - tubers" "Groundnut (Arachis hypogaea) - seed hulls" "Maize (Zea mays) - forage" "Pennisetum purpureum - forage"
+## ..$ feed_type_code : chr [1:4] "8" "17" "29" "40"
+## ..$ feed_type_name : chr [1:4] "Cassava" "Groundnut" "Maize" "Pennisetum purpureum"
+## ..$ fraction_as_fertilizer: int [1:4] 7 1 0 0
+## ..$ fresh_yield : num [1:4] 12.5 1.22 10 20
+## ..$ grassman : chr [1:4] "1" "1" "1" "1"
+## ..$ grassman_change_factor: int [1:4] 1 1 1 1
+## ..$ harvest_index : num [1:4] 0.5 0.29 0.47 0.9
+## ..$ intercrop : int [1:4] 1 0 0 1
+## ..$ intercrop_fraction : int [1:4] 1 0 0 2
+## ..$ kc_initial : num [1:4] 0 0.15 0.15 0.6
+## ..$ kc_late : num [1:4] 0 0.6 0.3 1.05
+## ..$ kc_midseason : num [1:4] 0 1.15 1.15 1.1
+## ..$ land_cover : chr [1:4] "1" "1" "1" "1"
+## ..$ landcover_c_factor : num [1:4] 0.001 0.001 0.001 0.001
+## ..$ main_n : num [1:4] 0.004 0.037 0.017 0.023
+## ..$ main_product_removal : int [1:4] 4 0 0 0
+## ..$ me_content : num [1:4] 10.76 6.56 10.22 9.88
+## ..$ me_fresh : num [1:4] 9.56 6.11 8.38 1.48
+## ..$ n_fertilizer : int [1:4] 15 0 9 0
+## ..$ n_fixation : num [1:4] 0 38.2 0 0
+## ..$ n_solutions : int [1:4] 13 0 7 0
+## ..$ npk : int [1:4] 9 0 3 0
+## ..$ operational_cost : int [1:4] 0 0 0 18
+## ..$ operational_labour : num [1:4] 0 0 0.203 0.5
+## ..$ residue_burnt : int [1:4] 6 0 0 0
+## ..$ residue_dm_content : num [1:4] 0.403 0.935 0.896 0.85
+## ..$ residue_dry_yield : num [1:4] 5.04 2.79 3 0
+## ..$ residue_fresh_yield : num [1:4] 12.5 2.99 3.5 2.22
+## ..$ residue_n : int [1:4] 0 0 0 0
+## ..$ residue_n_dm : num [1:4] 0.003 0.012 0.007 0.023
+## ..$ residue_removal : int [1:4] 5 0 0 0
+## ..$ slope : chr [1:4] "1" "1" "1" "1"
+## ..$ slope_length : int [1:4] 3 0 0 0
+## ..$ slope_p_factor : num [1:4] 0.11 0.11 0.11 0.11
+## ..$ trees_dhb : int [1:4] 0 0 0 0
+## ..$ trees_growth : int [1:4] 0 0 0 0
+## ..$ trees_ha : int [1:4] 0 0 0 0
+## ..$ trees_removal : int [1:4] 0 0 0 0
+## ..$ urea : int [1:4] 8 2 0 0
+## ..$ usda_value : int [1:4] 11134 16067 20314 0
+## ..$ water_content : num [1:4] 59.7 6.5 10.4 0
+## ..$ wfp_blue : num [1:4] 0 0 0.002 0
+## ..$ wfp_green : num [1:4] 0 0 0.199 0
+## ..$ wfp_grey : num [1:4] 0 0 0.002 0
+## $ ferlitizer :'data.frame': 1 obs. of 5 variables:
+## ..$ cost : int 2
+## ..$ fertilizer_code: chr "4"
+## ..$ fertilizer_desc: chr "Ammonium nitrate"
+## ..$ fraction : int 3
+## ..$ quantity : int 1
+## $ grassland_implevel : chr "High"
+## $ grassland_management : chr "Moderately degraded grassland, tropical montane"
+## $ land_oppcost : int 0
+## $ livestock :'data.frame': 2 obs. of 53 variables:
+## ..$ annual_growth : int [1:2] 3 9
+## ..$ annual_milk : int [1:2] 2 10
+## ..$ birth_interval : num [1:2] 1.17 0
+## ..$ body_weight : int [1:2] 600 300
+## ..$ carcass_fraction : num [1:2] 0.45 0.49
+## ..$ cp_grazing : int [1:2] 0 0
+## ..$ cp_growth : num [1:2] 0 0.4
+## ..$ cp_lactation : int [1:2] 0 0
+## ..$ cp_lactmilk : num [1:2] 0.09 0
+## ..$ cp_maintenance : num [1:2] 0.6 0.3
+## ..$ cp_pregnancy : int [1:2] 15 0
+## ..$ distance_to_pasture : int [1:2] 8 4
+## ..$ energy_eggcontent : int [1:2] 0 0
+## ..$ energy_meatcontent : int [1:2] 2200 2200
+## ..$ energy_milkcontent : int [1:2] 970 0
+## ..$ er_grazing : num [1:2] 2 1.5
+## ..$ er_growth : int [1:2] 0 50
+## ..$ er_lactation : int [1:2] 0 0
+## ..$ er_lactmilk : num [1:2] 5.5 0
+## ..$ er_maintenance : num [1:2] 60.6 36
+## ..$ er_pregnancy : int [1:2] 2000 0
+## ..$ fat_content : int [1:2] 4 0
+## ..$ grazing_displacement : int [1:2] 2 2
+## ..$ herd_composition : int [1:2] 1 11
+## ..$ ipcc_meth_ef_t1 : int [1:2] 68 46
+## ..$ ipcc_meth_ef_t2 : num [1:2] 6.5 6.5
+## ..$ ipcc_meth_exc : num [1:2] 0.47 0.34
+## ..$ ipcc_meth_man : int [1:2] 19 1
+## ..$ lactation_length : int [1:2] 0 0
+## ..$ litter_size : int [1:2] 0 0
+## ..$ livetype_code : chr [1:2] "3" "6"
+## ..$ livetype_desc : chr [1:2] "Cows (high productive)" "Steers/heifers (improved)"
+## ..$ lw_gain : int [1:2] 0 0
+## ..$ manure_in_field : int [1:2] 11 1
+## ..$ manure_in_non_roofed_enclosure: int [1:2] 10 2
+## ..$ manure_in_stable : int [1:2] 9 3
+## ..$ meat_price : int [1:2] 23 23
+## ..$ meat_product : chr [1:2] "beef" "beef"
+## ..$ milk_price : num [1:2] 1.04 1.04
+## ..$ milk_product : chr [1:2] "cow milk" "cow milk"
+## ..$ n_content : num [1:2] 0.029 0.029
+## ..$ oneoff_cost : int [1:2] 6400 3450
+## ..$ oneoff_labour : int [1:2] 0 0
+## ..$ operational_cost : int [1:2] 4000 1650
+## ..$ operational_labour : num [1:2] 50.7 7.6
+## ..$ proportion_growth : int [1:2] 0 0
+## ..$ protein_meatcontent : int [1:2] 26 26
+## ..$ protein_milkcontent : num [1:2] 3.7 0
+## ..$ time_in_non_roofed_enclosure : int [1:2] 5 7
+## ..$ time_in_offfarm_grazing : int [1:2] 7 5
+## ..$ time_in_onfarm_grazing : int [1:2] 6 6
+## ..$ time_in_stable : int [1:2] 4 8
+## ..$ water_requirement : int [1:2] 160 100
+## $ manure_onfarm_fraction : int 1
+## $ manure_sales_fraction : int 2
+## $ manureman_pasture : chr "Pasture / range / paddock"
+## $ manureman_stable : chr "Solid storage"
+## $ manureman_yard : chr "Dry slot"
+## $ purchased_bedding : int 6
+## $ purchased_compost : int 4
+## $ purchased_manure : int 3
+## $ purchased_organic_n : int 5
+## $ region : chr "ASIA"
+## $ seasons :'data.frame': 2 obs. of 2 variables:
+## ..$ season_length: int [1:2] 200 165
+## ..$ season_name : chr [1:2] "Dry season" "Wet season"
+## $ txt_annual_prec : int 1
+## $ txt_arable_tograssland : int 16
+## $ txt_cropland_orgmatter_ipcc : num 1.11
+## $ txt_cropland_system_ipcc : num 0.69
+## $ txt_cropland_tillage_ipcc : num 1.15
+## $ txt_et : int 9
+## $ txt_grassland_implevel_ipcc : num 1.11
+## $ txt_grassland_management_ipcc: num 0.96
+## $ txt_grassland_toarable : int 15
+## $ txt_rain_length : int 2
+## $ txt_soil_bulk : int 7
+## $ txt_soil_c : int 5
+## $ txt_soil_clay : int 6
+## $ txt_soil_depth : int 8
+## $ txt_soil_k_value : num 0.25
+## $ txt_soil_n : int 4
+## $ waste_consume_milk : int 0
+## $ waste_distribution_meat : int 0
+## $ waste_distribution_milk : int 0
+## $ waste_processing_meat : int 0
+## $ waste_processing_milk : int 0
+## $ waste_production_meat : int 0
+## $ waste_production_milk : int 0
+
+
+
+
cleaned-desktop cleaned.sqlite file
+
This sqlite database object is found in the qlands/cleaned-desktop
+github it contains several tables of look-up values.
+
+
Load sqlite file into R
+
conn <- dbConnect(RSQLite::SQLite(), "cleaned.sqlite")
+tables <- dbListTables(conn)
+print(tables)
+
## [1] "lkp_climate" "lkp_climate2" "lkp_croplandsystem"
+## [4] "lkp_feeditem" "lkp_feedtype" "lkp_grassinputlevel"
+## [7] "lkp_grasslandman" "lkp_landcover" "lkp_livetype"
+## [10] "lkp_manureman" "lkp_organicmatter" "lkp_orgfertilizer"
+## [13] "lkp_region" "lkp_slope" "lkp_soil"
+## [16] "lkp_tillageregime"
+
sq_tables<-lapply(tables,FUN=function(TAB){
+ query<-paste0("SELECT * FROM ",TAB)
+ data <- dbGetQuery(conn,query)
+ data
+})
+names(sq_tables)<-tables
+
+
Climate
+
+
+
+
+
+
+| Temperate |
+Temperate |
+
+
+| Warm |
+Warm |
+
+
+
+
+
+
Climate2
+
+
+
+
+
+
+| Temperate |
+Warm Temperate Moist |
+Warm Temperate Moist |
+
+
+| Temperate |
+Warm Temperate Dry |
+Warm Temperate Dry |
+
+
+| Warm |
+Tropical Montane |
+Tropical Montane |
+
+
+| Warm |
+Tropical Wet |
+Tropical Wet |
+
+
+| Warm |
+Tropical Moist |
+Tropical Moist |
+
+
+| Warm |
+Tropical Dry |
+Tropical Dry |
+
+
+
+
+
+
Region
+
+
+
+
+
+
+| AFRICA |
+AFRICA |
+
+
+| LATIN |
+LATIN AMERICA |
+
+
+| ASIA |
+ASIA |
+
+
+
+
+
+
Cropland system
+
+
+
+
+
+
+
+
+
+
+
+| 1 |
+Long term cultivated, temperate/boreal, dry |
+0.80 |
+
+
+| 2 |
+Long term cultivated, temperate/boreal, moist |
+0.69 |
+
+
+| 3 |
+Long term cultivated, tropical, dry |
+0.58 |
+
+
+| 4 |
+Long term cultivated, tropical, moist/wet |
+0.48 |
+
+
+| 5 |
+Long term cultivated, tropical montane, all |
+0.64 |
+
+
+| 6 |
+Paddy rice |
+1.10 |
+
+
+| 7 |
+Perennial/tree crop |
+1.00 |
+
+
+| 8 |
+Set aside (< 20 years), temperate/boreal and
+tropical, dry |
+0.93 |
+
+
+| 9 |
+Set aside (< 20 years), temperate/boreal and
+tropical, moist/wet |
+0.82 |
+
+
+| 10 |
+Set aside (< 20 years),tropical montane, all |
+0.88 |
+
+
+
+
+
+
+
+
Grassland management
+
kable(sq_tables$lkp_grasslandman)
+
+
+
+
+
+
+
+
+
+
+
+| 1 |
+Nominally managed |
+1.00 |
+
+
+| 2 |
+Moderately degraded grassland, temperate/boreal |
+0.95 |
+
+
+| 3 |
+Moderately degraded grassland, tropical |
+0.97 |
+
+
+| 4 |
+Moderately degraded grassland, tropical montane |
+0.96 |
+
+
+| 5 |
+Severely degraded |
+0.70 |
+
+
+| 6 |
+Improved grassland, temperate/boreal |
+1.14 |
+
+
+| 7 |
+Improved grassland, tropical |
+1.17 |
+
+
+| 8 |
+Improved grassland, tropical montane |
+1.16 |
+
+
+
+
+
+
Landcover
+
+
+
+
+
+
+| 1 |
+Dense forest |
+0.001 |
+
+
+| 2 |
+Other forest |
+0.050 |
+
+
+| 3 |
+Badlands hard |
+0.050 |
+
+
+| 4 |
+Badlands soft |
+0.400 |
+
+
+| 5 |
+Sorghum |
+0.100 |
+
+
+| 6 |
+Maize |
+0.100 |
+
+
+| 7 |
+Cereals |
+0.150 |
+
+
+| 8 |
+Pulses |
+0.150 |
+
+
+| 9 |
+Dense grass |
+0.010 |
+
+
+| 10 |
+Degraded grass |
+0.050 |
+
+
+| 11 |
+Fallow hard |
+0.050 |
+
+
+| 12 |
+Fallow plouged |
+0.600 |
+
+
+| 13 |
+Ethiopian teff |
+0.250 |
+
+
+| 14 |
+Continuous fallow |
+1.000 |
+
+
+
+
+
+
+
Manure management
+
+
+
+
+
+
+
+
+
+
+
+| pasture |
+Pasture / range / paddock |
+0.010 |
+
+
+| storage |
+Solid storage |
+0.005 |
+
+
+| drylot |
+Dry lot |
+0.020 |
+
+
+| Uncovered anaerobic lagoon |
+Uncovered anaerobic lagoon |
+0.000 |
+
+
+| Liquid/Slurry Pit below animals 1 Month |
+Liquid/Slurry Pit below animals 1 Month |
+0.000 |
+
+
+| Liquid/Slurry Pit below animals 3 Month |
+Liquid/Slurry Pit below animals 3 Month |
+0.000 |
+
+
+| Liquid/Slurry Pit below animals 4 Month |
+Liquid/Slurry Pit below animals 4 Month |
+0.000 |
+
+
+| Liquid/Slurry Pit below animals 6 Month |
+Liquid/Slurry Pit below animals 6 Month |
+0.000 |
+
+
+| Liquid/Slurry Pit below animals 12 Month |
+Liquid/Slurry Pit below animals 12 Month |
+0.000 |
+
+
+| Cattle and swine deep bedding < 1 month |
+Cattle and swine deep bedding < 1 month |
+0.000 |
+
+
+| Cattle and swine deep bedding > 1 month |
+Cattle and swine deep bedding > 1 month |
+0.000 |
+
+
+| Solid storage |
+Solid storage |
+0.000 |
+
+
+| Solid storage - Covered/compacted |
+Solid storage - Covered/compacted |
+0.000 |
+
+
+| Solid storage - Bulking agent addition |
+Solid storage - Bulking agent addition |
+0.000 |
+
+
+| Solid storage - Additives |
+Solid storage - Additives |
+0.000 |
+
+
+| Daily spread |
+Daily spread |
+0.000 |
+
+
+| Composting - In-vessel |
+Composting - In-vessel |
+0.000 |
+
+
+| Composting - Static pile (forced aeration) |
+Composting - Static pile (forced aeration) |
+0.000 |
+
+
+| Composting - Intensive windrow |
+Composting - Intensive windrow |
+0.000 |
+
+
+| Composting - Unfrequent turning |
+Composting - Unfrequent turning |
+0.000 |
+
+
+| Pasture/Range/Paddock |
+Pasture/Range/Paddock |
+0.000 |
+
+
+| Poultry manure with and without litter |
+Poultry manure with and without litter |
+0.000 |
+
+
+| Aerobic treatment |
+Aerobic treatment |
+0.000 |
+
+
+| Burned for fuel |
+Burned for fuel |
+0.000 |
+
+
+| Anaer digester, Low leak, HQ stor, HQ tec. |
+Anaer digester, Low leak, HQ stor, HQ tec. |
+0.000 |
+
+
+| Anaer digester, Low leak, HQ stor, LQ tec |
+Anaer digester, Low leak, HQ stor, LQ tec |
+0.000 |
+
+
+| Anaer digester, Low leak, open stor, HQ tec |
+Anaer digester, Low leak, open stor, HQ tec |
+0.000 |
+
+
+| Anaer digester, High leak, open stor, HQ tec |
+Anaer digester, High leak, open stor, HQ tec |
+0.000 |
+
+
+| Anaer digester, High leak, LQ stor, LQ tec |
+Anaer digester, High leak, LQ stor, LQ tec |
+0.000 |
+
+
+| Anaer digester, High leak, open stor, LQ tec |
+Anaer digester, High leak, open stor, LQ tec |
+0.000 |
+
+
+
+
+
+
Organic matter
+
+
+
+
+
+
+
+
+
+
+
+| 1 |
+Low, temperate/boreal, dry |
+0.95 |
+
+
+| 2 |
+Low, temperate/boreal, moist |
+0.92 |
+
+
+| 3 |
+Low, tropical, dry |
+0.95 |
+
+
+| 4 |
+Low, tropical, moist |
+0.92 |
+
+
+| 5 |
+Low, tropical montane, all |
+0.94 |
+
+
+| 6 |
+Medium, all |
+1.00 |
+
+
+| 7 |
+High w/OUT manure, temperate/boral and tropical,
+dry |
+1.04 |
+
+
+| 8 |
+High w/OUT manure, temperate/boral and tropical,
+moist/wet |
+1.11 |
+
+
+| 9 |
+High w/OUT manure, tropical montane |
+1.08 |
+
+
+| 10 |
+High with manure, temperate/boral and tropical,
+dry |
+1.37 |
+
+
+| 11 |
+High with manure, temperate/boral and tropical,
+moist/wet |
+1.44 |
+
+
+| 12 |
+High with manure, tropical montane |
+1.41 |
+
+
+
+
+
+
Organic fertilizer
+
+
+
+
+
+
+| 1 |
+Urea |
+
+
+| 3 |
+DAP |
+
+
+| 2 |
+NPK |
+
+
+| 4 |
+Ammonium nitrate |
+
+
+| 5 |
+Ammonium sulfate |
+
+
+| 6 |
+N solutions |
+
+
+| 7 |
+Ammonia |
+
+
+| 8 |
+Manure |
+
+
+| 9 |
+Compost |
+
+
+| 10 |
+Other organic N additions |
+
+
+| 11 |
+Bedding material |
+
+
+
+
+
+
Slope
+
+
+
+
+
+
+| 1 |
+Flat (0-5%) |
+0.11 |
+
+
+| 2 |
+Hilly (5-20%) |
+0.13 |
+
+
+| 3 |
+Steep (20-30%) |
+0.22 |
+
+
+| 4 |
+Extremely steep (30%+) |
+0.37 |
+
+
+| 5 |
+Non-agricultural (all slope categories) |
+1.00 |
+
+
+
+
+
+
Soil
+
+
+
+
+
+
+| andosol |
+Andosol |
+0.15 |
+
+
+| cambisol |
+Cambisol |
+0.20 |
+
+
+| lixisol |
+Lixisol |
+0.25 |
+
+
+| fluvisol |
+Fluvisol |
+0.30 |
+
+
+| vertisol |
+Vertisol |
+0.15 |
+
+
+| phaeozem |
+Phaeozem |
+0.20 |
+
+
+| nitosol |
+Nitosol |
+0.25 |
+
+
+| xerosol |
+Xerosol |
+0.30 |
+
+
+
+
+
+
Tillage regime
+
+
+
+
+
+
+| 1 |
+Full |
+1.00 |
+
+
+| 2 |
+Reduced, temperate/boreal, dry |
+1.02 |
+
+
+| 3 |
+Reduced, temperate/boreal, moist |
+1.08 |
+
+
+| 4 |
+Reduced, tropical, dry |
+1.09 |
+
+
+| 5 |
+Reduced, tropical, moist |
+1.15 |
+
+
+| 6 |
+Reduced, tropical montane, all |
+1.09 |
+
+
+| 7 |
+No-till, temperate/boreal, dry |
+1.10 |
+
+
+| 8 |
+No-till, temperate/boreal, moist |
+1.15 |
+
+
+| 9 |
+No-till, tropical, dry |
+1.17 |
+
+
+| 10 |
+No-till, tropical, moist/wet |
+1.22 |
+
+
+| 11 |
+No-till, tropical montane, all |
+1.16 |
+
+
+
+
+
+
+
+
cleaned-desktop energy_parameters.json file
+
The energy_parameters.json object is found in the qlands/cleaned-desktop
+github it contains a single table Table 10.4 that
+does not seem to appear in the cleaned/data/ghg_para.rda
+object.
+
+
Table 10.4
+
json_data2 <- fromJSON("energy_parameters.json")
+names(json_data2)
+
## [1] "Table 10.4"
+
kable(json_data2$`Table 10.4`)
+
+
+
+
+
+
+
+
+
+
+
+| Cattle_Buffalo |
+0.322 |
+All non-lactating cows, steers, heifers and calves |
+
+
+| Cattle_Buffalo_lactating_cows |
+0.386 |
+Maintenance energy requirements are 20% higher during
+lactation |
+
+
+| Cattle_Buffalo_bulls |
+0.370 |
+Maintenance energy requirements are 15% higher for
+intact males than non lactating females |
+
+
+| Sheep_lamb_to _1_year |
+0.236 |
+This value can be increased by 15% for intact
+males |
+
+
+| Sheep_older_than_1_year |
+0.217 |
+This value can be increased by 15% for intact
+males. |
+
+
+| Goats |
+0.315 |
+NA |
+
+
+| Pigs |
+0.440 |
+NA |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/explore_qt_json.pdf b/data/explore_qt_json.pdf
new file mode 100644
index 0000000..d181acc
Binary files /dev/null and b/data/explore_qt_json.pdf differ
diff --git a/data/explore_qt_json.rmd b/data/explore_qt_json.rmd
new file mode 100644
index 0000000..8bd9b5a
--- /dev/null
+++ b/data/explore_qt_json.rmd
@@ -0,0 +1,404 @@
+---
+title: "Exploration of CLEANED input files"
+author: "Peter Steward"
+date: "2024-07-01"
+output:
+ html_document:
+ toc: true
+ toc_float: true
+ toc_depth: 6
+ df_print: paged
+ pdf_document:
+ toc: true
+ toc_depth: 6
+---
+
+```{r setup,echo=F}
+knitr::opts_chunk$set(echo = TRUE)
+
+# Load packages #####
+if (!require("pacman")) {
+ install.packages("pacman")
+ require(pacman)
+}
+
+if (!tinytex::is_tinytex()) {
+ p_load(tinytex)
+ tinytex::install_tinytex()
+}
+
+# Use p_load to install if not present and load the packages
+pacman::p_load(jsonlite,data.table,rmarkdown,knitr,RSQLite)
+```
+
+## Cleaned Data
+### Input data structure
+
+The aim of this markdown document is to summarize the structure of the .json object that is required as an input for the R cleaned packages.
+It also explores any additional datasets that are used as inputs to create this input object, these include `cleaned/data/ghg_para.R`, `cleaned/data/stock_change_para.rda` and `qlands/cleaned-desktop/cleaned.sqlite`.
+
+#### Load input json file into R
+Load the `qt_example.json` example input file stored in `cleaned/data`.
+```{r load data,echo=T}
+# Read in example json file #####
+json_data <- fromJSON("qt_example.json")
+
+# Summarize level 1 of the list
+json_names<-data.table(field_name=names(json_data),
+ class=sapply(json_data,base::class),
+ length=sapply(json_data,length))
+
+kable(json_names, caption = "Summary of Level 1 of the JSON Object")
+```
+
+#### Simple fields
+```{r simple fields,echo=T}
+simple_fields<-json_names[class!="data.frame" & length==1,field_name]
+simple_fields<-json_data[json_names[class!="data.frame" & length==1,field_name]]
+simple_fields<-data.table(field=names(simple_fields),
+ value=unlist(simple_fields),
+ class=json_names[class!="data.frame" & length==1,class])
+```
+
+```{r simple feilds 2,echo=F}
+kable(simple_fields, caption = "Summary of simple fields containing a single value")
+```
+
+#### Livestock
+The `json_data$livestock` of the json list is a data.table that contains information about livestock"]] herd structure and management, manure management and productivity.
+
+```{r livestock 0 ,echo=F}
+livestock<-t(json_data$livestock) # Transpose
+colnames(livestock)<-paste0("livetype_code_",json_data$livestock$livetype_code)
+kable(livestock,caption="Transposed livestock herd data t(json_data$livestock)")
+```
+
+The `livestock` are linked to the `feed_basket$feeds` tables by the `livetype_code` keyfield.
+```{r livestock 1 ,echo=T}
+json_data$livestock[,c("livetype_code","livetype_desc")] # Codes in the feed_items table
+lapply(json_data$feed_basket$feeds,"[[","livestock") # Codes in the feed_basket tables
+```
+
+#### Feed items
+The `json_data$feed_items` level of the json list is a data.table that contains information about the production management and context of feed production.
+
+```{r feed items 0 ,echo=F}
+feed_items<-t(json_data$feed_items) # Transpose
+colnames(feed_items)<-paste0("feed_item_code_",json_data$feed_items$feed_item_code)
+kable(feed_items,caption="Transposed feed item data t(json_data$feed_items)")
+```
+
+The `feed_items` are linked to the `feed_basket$feeds` tables by the `feed_item_code` field.
+```{r feed items 1 ,echo=T}
+json_data$feed_items[,c("feed_item_code","feed_item_name")] # Codes in the feed_items table
+lapply(json_data$feed_basket$feeds,"[[","feed_item_code") # Codes in the feed_basket tables
+```
+
+Other keyfields include `feed_type_code` and `land_cover`:
+```{r feed items 2 ,echo=T}
+json_data$feed_items[,c("feed_type_code","feed_type_name","land_cover","land_cover_desc")]
+```
+
+#### Fertilizer
+The `json_data$fertilizer` level of the json list is a data.table that contains information about the production management and context of feed production.
+
+```{r fertilizer 1,echo=F}
+kable(json_data$fertilizer,caption="Fertilizer data input table (json_data$fertilizer)")
+```
+
+The values in `fertilizer_code` field do not appear directly correspond to any fields in the feed basket or feed item tables. However columns with similar names do appear in the field item tables
+
+```{r fertilizer 2,echo=T}
+fertilizers<-json_data$fertilizer$fertilizer_desc
+fi_cols<-colnames(json_data$feed_items)
+
+# Reformat fertilizer names to match column names in the feed_items table
+(fertilizers<-gsub(" ","_",tolower(json_data$fertilizer$fertilizer_desc)))
+
+# Find matching columns
+fi_cols[fi_cols %in% fertilizers]
+```
+
+#### Seasons
+The `json_data$season` level of the input data is 2-column table that records the length of each season (adding up to 365 days max).
+```{r seasons 1,echo=F}
+kable(json_data$seasons,caption="Feed items data input table (json_data$season)")
+```
+
+The `season_name` field is the key field that links to the feed basket.
+```{r seasons 2 ,echo=T}
+json_data$feed_basket$season_name
+```
+
+#### Feed basket
+The `json_data$feed_basket` level of the input data contains a futher `r length(json_data$feed_basket)` list levels called
+`r paste(names(json_data$feed_basket),collapse=" and ")`. These sub-levels appear to be the same length: `r paste0(names(json_data$feed_basket)," = ", sapply(json_data$feed_basket,length))`.
+
+##### Seasons
+The `json_data$feed_basket$season_name` object is simple, being a vector containing the names of the seasons:
+```{r feed basket seasons,echo=F}
+kable(json_data$feed_basket$season_name,caption="Feed basket/season data input table (json_data$feed_basket$season)")
+```
+
+##### Feed Basket
+The `json_data$feed_basket$feed` object is the most structurally complex element of the input json data containing several levels of nesting.
+```{r feed basket feeds 1 ,echo=T}
+str(json_data$feed_basket$feeds)
+```
+
+###### Feeds
+Each feed basket table (e.g., `json_data$feed_basket$feeds[[1]]`) is constructed using key fields that describe feed items found in the `json_data$feed_items table`, specifically `feed_item_code` and `feed_type_code.` The feeds are then allocated to the herd elements described in the `json_data$livestock table`.
+
+```{r feed basket feeds 0 ,echo=F}
+kable(json_data$feed_basket$feeds[[1]],caption="Feed basket/feed data input table tablejson_data$feed_basket$feeds[[1]]")
+```
+
+###### Livestock
+The livestock field in the feed basket table contains a list with `r length(json_data$feed_basket$feeds[[1]]$livestock)` elements, indicating a one-to-many relationship between the diet item and elements of the livestock herd. Each feed item represented by a row in the feed basket table is allocated to different herd elements, with the `livetype_code` field serving as the key field linking the two tables.
+
+```{r feed basket feeds 2 ,echo=F}
+kable(json_data$feed_basket$feeds[[1]]$livestock,caption="Feed basket/feed/livestock data input table tablejson_data$feed_basket$feeds[[1]]$livestock")
+```
+
+The first element of the livestock list contains no further nesting:
+```{r feed basket feeds 3 ,echo=T}
+str(json_data$feed_basket$feeds[[1]]$livestock[[1]])
+```
+
+### cleaned `cleaned/data .rda` files
+```{r list rda files}
+rda_files<-list.files(".rda")
+```
+
+#### GHG parameters
+The ghg para object (`cleaned/data/ghg_para.rda`) is a list of tables that appear to refer to IPCC equations, livestock parameters and fertilizers.
+```{r ghg_para 1}
+load("ghg_para.rda")
+
+# Summarize level 1 of the list
+ghg_names<-data.table(field_name=names(ghg_para),
+ dim=sapply(ghg_para,dim))
+
+kable(ghg_names,caption="Tables within ghg_names list")
+```
+The exception is `ghg_para$table_5.11` which is a list:
+```{r ghg_para 2}
+ghg_para$table_5.11
+```
+
+##### Livestock_parameters
+Note there is an invalid character in this table:
+```{r ghg_para 3a}
+ghg_para$livestock_parameters$`IPCC Category - methane emissions enteric fermentation - Tier 2`[11]<-"Other Cattle or Buffalo - grazing"
+```
+
+
+```{r ghg_para 3}
+kable(ghg_para$livestock_parameters,caption="ghg_para$livestock_parameters")
+```
+
+##### Fertilizer table
+```{r ghg_para 4}
+kable(ghg_para$fertilizer_table,caption="ghg_para$fertilizer_table")
+```
+
+##### IPCC Tables
+
+###### Table_10.12
+```{r ghg_para Table_10.12}
+kable(ghg_para$Table_10.12)
+```
+
+###### table_10.17
+```{r ghg_para table_10.17}
+kable(ghg_para$table_10.17)
+```
+
+###### table_10.19
+```{r ghg_para table_10.19}
+kable(ghg_para$table_10.19)
+```
+
+###### table_10.21
+```{r ghg_para table_10.21}
+kable(ghg_para$table_10.21)
+```
+
+###### table_10.22
+```{r ghg_para table_10.22}
+kable(ghg_para$table_10.22)
+```
+
+###### table_10A_9
+```{r ghg_para table_10A_9}
+kable(ghg_para$Table_10.12)
+```
+
+###### table_11.1_&_table_11.3
+```{r ghg_para table_11.1_&_table_11.3}
+kable(ghg_para$`table_11.1_&_table_11.3`)
+```
+
+###### table_2.5
+```{r ghg_para table_2.5}
+kable(ghg_para$table_2.5)
+```
+
+###### table_5.12
+```{r ghg_para table_5.12}
+kable(ghg_para$table_5.12)
+```
+
+###### table_5.13
+```{r ghg_para table_5.13}
+kable(ghg_para$table_5.13)
+```
+
+###### table_5.14
+```{r ghg_para table_5.14}
+kable(ghg_para$table_5.14)
+```
+
+#### Stock change
+The stock change object (`cleaned/data/stock_change_para.rda`) is a series of nested lists that describe: 1) landuse, management, and input factor_variables for grassland; and 2) landuse, tillage, and input input factor_variables for cropland.
+
+```{r stock change 1}
+load("stock_change_para.rda")
+str(stock_change_para)
+```
+
+##### Grass factor variables
+**Grassland: landuse**
+```{r stock change grass 1}
+x<-unlist(stock_change_para$grassland$landuse[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+```
+**Grassland: management**
+```{r stock change grass 2}
+x<-unlist(stock_change_para$grassland$management[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+
+```
+**Grassland: input**
+```{r stock change grass 3}
+x<-unlist(stock_change_para$grassland$input[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+```
+
+##### Cropland factor variables
+**Cropland: landuse**
+```{r stock change cropland 1}
+x<-unlist(stock_change_para$cropland$landuse[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+```
+**Cropland: tillage**
+```{r stock change cropland 2}
+x<-unlist(stock_change_para$cropland$tillage[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+```
+**Cropland: input**
+```{r stock change cropland 3}
+x<-unlist(stock_change_para$cropland$input[[1]]$factor_variables)
+kable(data.frame(variable=names(x),value=as.numeric(x)))
+```
+
+#### mufindi
+The mufindi object (`cleaned/data/mufindi.rda`) appears to be an input dataset similar to the `qt_example.json` file.
+```{r mufindi 1}
+load("mufindi.rda")
+str(mufindi)
+```
+
+### cleaned-desktop `cleaned.sqlite` file
+This sqlite database object is found in the [qlands/cleaned-desktop github](https://github.com/qlands/cleaned-desktop/blob/feature/add-comparison/cleaned.sqlite) it contains several tables of look-up values.
+
+#### Load sqlite file into R
+```{r connect sqlite}
+conn <- dbConnect(RSQLite::SQLite(), "cleaned.sqlite")
+tables <- dbListTables(conn)
+print(tables)
+```
+```{r load sqlite,warning=FALSE}
+sq_tables<-lapply(tables,FUN=function(TAB){
+ query<-paste0("SELECT * FROM ",TAB)
+ data <- dbGetQuery(conn,query)
+ data
+})
+names(sq_tables)<-tables
+```
+
+##### Climate
+```{r sqlite climate,echo=F}
+kable(sq_tables$lkp_climate)
+```
+##### Climate2
+```{r sqlite climate 2,echo=F}
+kable(sq_tables$lkp_climate2)
+```
+##### Region
+```{r sqlite region,echo=F}
+kable(sq_tables$lkp_region)
+```
+##### Cropland system
+```{r sqlite cropland,echo=F}
+kable(sq_tables$lkp_croplandsystem)
+```
+##### Feeds
+###### Item
+```{r sqlite feed item,echo=F}
+sq_tables$lkp_feeditem
+```
+###### Type
+```{r sqlite feed type,echo=F}
+sq_tables$lkp_feedtype
+```
+##### Grass input level
+```{r sqlite grass input,echo=F}
+kable(sq_tables$lkp_grassinputlevel)
+```
+##### Grassland management
+```{r sqlite grass management}
+kable(sq_tables$lkp_grasslandman)
+```
+##### Landcover
+```{r sqlite land cover,echo=F}
+kable(sq_tables$lkp_landcover)
+```
+##### Livestock type
+```{r sqlite livestock type,echo=F}
+sq_tables$lkp_livetype
+```
+##### Manure management
+```{r sqlite manure management,echo=F}
+kable(sq_tables$lkp_manureman)
+```
+##### Organic matter
+```{r sqlite organic matter,echo=F}
+kable(sq_tables$lkp_organicmatter)
+```
+##### Organic fertilizer
+```{r sqlite organic fertilizer,echo=F}
+kable(sq_tables$lkp_orgfertilizer)
+```
+##### Slope
+```{r sqlite slope,echo=F}
+kable(sq_tables$lkp_slope)
+```
+##### Soil
+```{r sqlite soil,echo=F}
+kable(sq_tables$lkp_soil)
+```
+##### Tillage regime
+```{r sqlite tillage,echo=F}
+kable(sq_tables$lkp_tillageregime)
+```
+
+### cleaned-desktop `energy_parameters.json` file
+The energy_parameters.json object is found in the [qlands/cleaned-desktop github](https://github.com/qlands/cleaned-desktop/blob/feature/add-comparison/R/energy_parameters.jsone) it contains a single table **Table 10.4** that does not seem to appear in the `cleaned/data/ghg_para.rda` object.
+
+#### Table 10.4
+```{r load energy parameters}
+json_data2 <- fromJSON("energy_parameters.json")
+names(json_data2)
+kable(json_data2$`Table 10.4`)
+```
diff --git a/data/mappings/input_mappings.csv b/data/mappings/input_mappings.csv
new file mode 100644
index 0000000..9c3560e
--- /dev/null
+++ b/data/mappings/input_mappings.csv
@@ -0,0 +1,176 @@
+focal_file,focal_path,focal_class,focal_example_value,focal_type,focal_userselected,focal_free,connected_file,connected_path,focal_keyfield,connected_keyfield
+input_json,annual_prec,integer,1500,,,,,,,
+input_json,arable_tograssland,integer,0,,,,,,,
+input_json,climate_zone,character,Temperate,,,,,,,
+input_json,climate_zone_2,character,Warm Temperate Dry,,,,,,,
+input_json,cropland_orgmatter,character,"Low, temperate/boreal, dry",,,,,,,
+input_json,cropland_orgmatter_ipcc,numeric,0.95,,,,,,,
+input_json,cropland_system,character,"Long term cultivated, temperate/boreal, dry",,,,,,,
+input_json,cropland_system_ipcc,numeric,0.8,,,,,,,
+input_json,cropland_tillage,character,Full,,,,,,,
+input_json,cropland_tillage_ipcc,integer,1,,,,,,,
+input_json,database_code,character,base,,,,,,,
+input_json,et,integer,1460,,,,,,,
+input_json,farm_code,character,001,,,,,,,
+input_json,farm_name,character,test 3,,,,,,,
+input_json,grassland_implevel,character,Medium,,,,,,,
+input_json,grassland_implevel_ipcc,integer,1,,,,,,,
+input_json,grassland_management,character,Nominally managed,,,,,,,
+input_json,grassland_management_ipcc,integer,1,,,,,,,
+input_json,grassland_toarable,integer,0,,,,,,,
+input_json,purchased_bedding,integer,0,,,,,,,
+input_json,purchased_compost,integer,0,,,,,,,
+input_json,purchased_manure,integer,0,,,,,,,
+input_json,purchased_organic_n,integer,0,,,,,,,
+input_json,rain_length,integer,5,,,,,,,
+input_json,region,character,AFRICA,,,,,,,
+input_json,soil_bulk,integer,6,,,,,,,
+input_json,soil_c,integer,12,,,,,,,
+input_json,soil_clay,integer,45,,,,,,,
+input_json,soil_depth,integer,2,,,,,,,
+input_json,soil_description,character,Lixisol,,,,,,,
+input_json,soil_k_value,numeric,0.25,,,,,,,
+input_json,soil_n,numeric,3.5,,,,,,,
+input_json,waste_consume_meat,integer,2,,,,,,,
+input_json,waste_consume_milk,integer,2,,,,,,,
+input_json,waste_distribution_meat,integer,3,,,,,,,
+input_json,waste_distribution_milk,integer,3,,,,,,,
+input_json,waste_processing_meat,integer,5,,,,,,,
+input_json,waste_processing_milk,integer,5,,,,,,,
+input_json,waste_production_meat,integer,3,,,,,,,
+input_json,waste_production_milk,integer,3,,,,,,,
+input_json,feed_items/ammonia,character,0,,,,,,,
+input_json,feed_items/ammonium_nitrate,character,0,,,,,,,
+input_json,feed_items/ammonium_sulfate,character,0,,,,,,,
+input_json,feed_items/average_dbh25,character,0,,,,,,,
+input_json,feed_items/average_dbh2550,character,0,,,,,,,
+input_json,feed_items/average_dbh50,character,0,,,,,,,
+input_json,feed_items/category,character,cereal|legume,,,,,,,
+input_json,feed_items/cp_content,character,13.60| 3.85|18.40,,,,,,,
+input_json,feed_items/cultivation_period,character,0,,,,,,,
+input_json,feed_items/cut_carry_fraction,character,0,,,,,,,
+input_json,feed_items/dap,character,0,,,,,,,
+input_json,feed_items/diameter_breast,character,0,,,,,,,
+input_json,feed_items/dm_content,character,89.00|91.88|90.00,,,,,,,
+input_json,feed_items/dry_yield,character,30|15| 8,,,,,,,
+input_json,feed_items/ecosystem_type,character,"",,,,,,,
+input_json,feed_items/energy,character, 0|360|336,,,,,,,
+input_json,feed_items/feed_item_code,character,65|99|18,,,,,,,
+input_json,feed_items/feed_item_name,character,Oats (Avena sativa) - grain IP|Rice (Oryza sativa) - straw|Cowpea (Vigna unguiculata) - crop residue,,,,,,,
+input_json,feed_items/feed_type_code,character,2|45|9,,,,,,,
+input_json,feed_items/feed_type_name,character,Avena sativa|Rice|Cowpea,,,,,,,
+input_json,feed_items/fraction_as_fertilizer,character,1|0,,,,,,,
+input_json,feed_items/fraction_as_manure,character,NA,,,,,,,
+input_json,feed_items/grassman,character,1,,,,,,,
+input_json,feed_items/grassman_change_factor,character,1,,,,,,,
+input_json,feed_items/grassman_desc,character,Nominally managed,,,,,,,
+input_json,feed_items/increase_dbh25,character,0,,,,,,,
+input_json,feed_items/increase_dbh2550,character,0,,,,,,,
+input_json,feed_items/increase_dbh50,character,0,,,,,,,
+input_json,feed_items/intercrop,character,0,,,,,,,
+input_json,feed_items/intercrop_fraction,character,0,,,,,,,
+input_json,feed_items/kc_initial,character,0.10|1.05|0.15,,,,,,,
+input_json,feed_items/kc_late,character,0.55|0.75|0.60,,,,,,,
+input_json,feed_items/kc_midseason,character,1.10|1.20|1.05,,,,,,,
+input_json,feed_items/land_cover,character,7|1,,,,,,,
+input_json,feed_items/land_cover_desc,character,Cereals|Dense forest,,,,,,,
+input_json,feed_items/landcover_c_factor,character,0.150|0.001,,,,,,,
+input_json,feed_items/main_n,character,0.0176|0.0090|0.0380,,,,,,,
+input_json,feed_items/main_product_removal,character,1|0,,,,,,,
+input_json,feed_items/me_content,character,12.267324| 5.640000| 9.880848,,,,,,,
+input_json,feed_items/n_content,character,0.2|0.0,,,,,,,
+input_json,feed_items/n_fertilizer,character,NA,,,,,,,
+input_json,feed_items/n_solutions,character, 50|300|100,,,,,,,
+input_json,feed_items/npk,character,0,,,,,,,
+input_json,feed_items/organic_amendment,character,"",,,,,,,
+input_json,feed_items/residue_burnt,character,0,,,,,,,
+input_json,feed_items/residue_dry_yield,character,0|6,,,,,,,
+input_json,feed_items/residue_n,character,0.0|0.2,,,,,,,
+input_json,feed_items/residue_removal,character,0.0|0.8,,,,,,,
+input_json,feed_items/slope,character,1,,,,,,,
+input_json,feed_items/slope_desc,character,Flat (0-5%),,,,,,,
+input_json,feed_items/slope_length,character,0,,,,,,,
+input_json,feed_items/slope_p_factor,character,0.11,,,,,,,
+input_json,feed_items/source_type,character,Main|Residue,,,,,,,
+input_json,feed_items/time_horizon,character,0,,,,,,,
+input_json,feed_items/trees_dhb,character,0,,,,,,,
+input_json,feed_items/trees_growth,character,0,,,,,,,
+input_json,feed_items/trees_ha,character,0,,,,,,,
+input_json,feed_items/trees_ha_dbh25,character,0,,,,,,,
+input_json,feed_items/trees_ha_dbh2550,character,0,,,,,,,
+input_json,feed_items/trees_ha_dbh50,character,0,,,,,,,
+input_json,feed_items/trees_removal,character,0,,,,,,,
+input_json,feed_items/urea,character,400|700|200,,,,,,,
+input_json,feed_items/usda_value,character, 0|20450|16062,,,,,,,
+input_json,feed_items/water_content,character, 0.00|12.89|11.95,,,,,,,
+input_json,feed_items/water_regime,character,"",,,,,,,
+input_json,livestock/adult_weight,character,800|400| 0,,,,,,,
+input_json,livestock/annual_growth,character, 0|90,,,,,,,
+input_json,livestock/annual_milk,character,3000|1500| 0,,,,,,,
+input_json,livestock/annual_wool,character,0,,,,,,,
+input_json,livestock/birth_interval,character,1.166667|1.500000|0.000000,,,,,,,
+input_json,livestock/body_weight,character,600|350|200,,,,,,,
+input_json,livestock/body_weight_weaning,character,0,,,,,,,
+input_json,livestock/body_weight_year_one,character,0,,,,,,,
+input_json,livestock/carcass_fraction,character,0.48|0.00,,,,,,,
+input_json,livestock/cp_grazing,character,0|3,,,,,,,
+input_json,livestock/cp_growth,character,0.0|0.4,,,,,,,
+input_json,livestock/cp_lactation,character,5|2|0,,,,,,,
+input_json,livestock/cp_lactmilk,character,0.09|0.00,,,,,,,
+input_json,livestock/cp_maintenance,character,0.60|0.35|0.20,,,,,,,
+input_json,livestock/cp_pregnancy,character,12.21| 9.64| 0.00,,,,,,,
+input_json,livestock/distance_to_pasture,character,0.0|0.5,,,,,,,
+input_json,livestock/energy_eggcontent,character,0,,,,,,,
+input_json,livestock/energy_meatcontent,character,2200,,,,,,,
+input_json,livestock/energy_milkcontent,character,970| 0,,,,,,,
+input_json,livestock/fat_content,character,4.3|5.8|0.0,,,,,,,
+input_json,livestock/grazing_displacement,character,0|2,,,,,,,
+input_json,livestock/herd_composition,character,2|5|0,,,,,,,
+input_json,livestock/ipcc_ef_category_t1,character,Dairy cattle|Other mature female|Other mature female-grazing,,,,,,,
+input_json,livestock/ipcc_ef_category_t2,character,Dairy cows|Non-dairy,,,,,,,
+input_json,livestock/ipcc_meth_man_category,character,Dairy cows|Other cattle,,,,,,,
+input_json,livestock/ipcc_n_exc_category,character,Dairy cattle|Other cattle,,,,,,,
+input_json,livestock/lactation_length,character,0,,,,,,,
+input_json,livestock/litter_size,character,0,,,,,,,
+input_json,livestock/livetype_code,character,2|1|5,,,,,,,
+input_json,livestock/livetype_desc,character,Cattle - Cows (improved)|Cattle - Cows (local)|Cattle - Steers/heifers,,,,,,,
+input_json,livestock/lw_gain,character,0,,,,,,,
+input_json,livestock/manure_in_field,character,0,,,,,,,
+input_json,livestock/manure_in_non_roofed_enclosure,character,0,,,,,,,
+input_json,livestock/manure_in_stable,character,1|0,,,,,,,
+input_json,livestock/manure_onfarm_fraction,character,1|0,,,,,,,
+input_json,livestock/manure_sales_fraction,character,0,,,,,,,
+input_json,livestock/manureman_non_roofed_enclosure,character,Solid storage,,,,,,,
+input_json,livestock/manureman_offfarm_grazing,character,Solid storage,,,,,,,
+input_json,livestock/manureman_onfarm_grazing,character,Solid storage|Pasture / range / paddock,,,,,,,
+input_json,livestock/manureman_stable,character,Solid storage,,,,,,,
+input_json,livestock/me_grazing,character,2.0|1.5,,,,,,,
+input_json,livestock/me_growth,character, 0|50,,,,,,,
+input_json,livestock/me_lactation,character,5|2|0,,,,,,,
+input_json,livestock/me_lactmilk,character,5.5|0.0,,,,,,,
+input_json,livestock/me_maintenance,character,60.61547|40.45955|26.59148,,,,,,,
+input_json,livestock/me_pregnancy,character,1500|1260| 0,,,,,,,
+input_json,livestock/meat_product,character,beef,,,,,,,
+input_json,livestock/milk_product,character,cow milk,,,,,,,
+input_json,livestock/n_content,character,0.029,,,,,,,
+input_json,livestock/piglets_relying_on_milk,character,0,,,,,,,
+input_json,livestock/proportion_growth,character,0,,,,,,,
+input_json,livestock/protein_meatcontent,character,26,,,,,,,
+input_json,livestock/protein_milkcontent,character,3.7|3.2|0.0,,,,,,,
+input_json,livestock/time_in_non_roofed_enclosure,character,0,,,,,,,
+input_json,livestock/time_in_offfarm_grazing,character,0,,,,,,,
+input_json,livestock/time_in_onfarm_grazing,character,0|1,,,,,,,
+input_json,livestock/time_in_stable,character,1|0,,,,,,,
+input_json,livestock/water_requirement,character,140|120| 80,,,,,,,
+input_json,livestock/work_hour,character,0,,,,,,,
+input_json,seasons/season_length,character,200|165,,,,,,,
+input_json,seasons/season_name,character,Wet season|Dry season,,,,,,,
+input_json,feed_basket/season_name,character,Wet season|Dry season,,,,,,,
+input_json,feed_basket/feeds/feed_item_code,character,65|99|18,,,,,,,
+input_json,feed_basket/feeds/feed_type_code,character,2|45|9,,,,,,,
+input_json,feed_basket/feeds/livestock/allocation,character,40|17|25|43|20|35,,,,,,,
+input_json,feed_basket/feeds/livestock/livetype_code,character,2|1|5,,,,,,,
+input_json,fertilizer/fertilizer_code,character,4|6,,,,,,,
+input_json,fertilizer/fertilizer_desc,character,Ammonium nitrate|N solutions,,,,,,,
+input_json,fertilizer/fraction,character,0,,,,,,,
+input_json,fertilizer/percentage_n,character,12|10,,,,,,,
diff --git a/data/mappings/input_mappings_metadata.csv b/data/mappings/input_mappings_metadata.csv
new file mode 100644
index 0000000..34333a4
--- /dev/null
+++ b/data/mappings/input_mappings_metadata.csv
@@ -0,0 +1,21 @@
+field_name,field_type,description
+focal_file,character,The filename of the object containing the focal field
+focal_path,character,The path to the focal field within the focal object
+focal_example_value,character,Example value(s) from the focal field
+focal_class,character,The class of data in the focal field
+focal_type,character,"Enter one these values:
+ 1) standard_parameter - values that cannot be changed by users, for example parameters in IPCC tables. Sometimes referred to has hard_coded values by the team.
+ 2) user_parameter - descriptors of a study area - these filed might be prefilled, but can be changed by users (normally only needs to be done once for a new study area).
+ 3) user_input - user input, to be changed for each livestock enterprise type and scenario."
+focal_userselected,logical,Is the field user selected or entered in the UI (TRUE/FALSE)? FALSE means that the field is auto-populated.
+focal_free,logical,Is the field free-text (TRUE/FALSE)? (i.e. it is entered or selected by the user and there is no lookup field)
+connected_file,character,The filename of the connected object (use when focal_free field is FALSE)
+connected_path,character,The path to the field in the connected object (use when focal_free field is FALSE)
+focal_keyfield,character,"For a field that is autopopulated, what is the path of the key field in the **focal** object that is used to subset the connected table?
+ Use when focal_free field is FALSE AND focal_userselected is FALSE.
+ Example = the soil_k_value (focal_path) in the input_json comes from the sqlite Soil/k_value field (connected_path), the user selected input_json soil_description field (e.g. Lixisol) is used to connect the sqlite Soil/k_value.
+ This means we enter the value soil_description in the focal_keyfield column and the value Soil/soil_desc in the connected_keyfield column."
+connected_keyfield,character,"For a field that is autopopulated, what is the path of the key field in the **connected** table that links to the focal object?
+ Use when focal_free field is FALSE AND focal_userselected is FALSE.
+ Example = the soil_k_value (focal_path) in the input_json comes from the sqlite Soil/k_value field (connected_path), the user selected input_json soil_description field (e.g. Lixisol) is used to connect the sqlite Soil/k_value.
+ This means we enter the value soil_description in the focal_keyfield column and the value Soil/soil_desc in the connected_keyfield column"
diff --git a/data/qt_example.json b/data/qt_example.json
new file mode 100644
index 0000000..49a6ec8
--- /dev/null
+++ b/data/qt_example.json
@@ -0,0 +1,574 @@
+{
+ "annual_prec": 1500,
+ "arable_tograssland": 0,
+ "climate_zone": "Temperate",
+ "climate_zone_2": "Warm Temperate Dry",
+ "cropland_orgmatter": "Low, temperate/boreal, dry",
+ "cropland_orgmatter_ipcc": 0.95,
+ "cropland_system": "Long term cultivated, temperate/boreal, dry",
+ "cropland_system_ipcc": 0.8,
+ "cropland_tillage": "Full",
+ "cropland_tillage_ipcc": 1,
+ "database_code": "base",
+ "et": 1460,
+ "farm_code": "001",
+ "farm_name": "test 3",
+ "feed_basket": [
+ {
+ "feeds": [
+ {
+ "feed_item_code": "65",
+ "feed_type_code": "2",
+ "livestock": [
+ {
+ "allocation": 40,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 17,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "5"
+ }
+ ]
+ },
+ {
+ "feed_item_code": "99",
+ "feed_type_code": "45",
+ "livestock": [
+ {
+ "allocation": 25,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 43,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 20,
+ "livetype_code": "5"
+ }
+ ]
+ },
+ {
+ "feed_item_code": "18",
+ "feed_type_code": "9",
+ "livestock": [
+ {
+ "allocation": 35,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "5"
+ }
+ ]
+ }
+ ],
+ "season_name": "Wet season"
+ },
+ {
+ "feeds": [
+ {
+ "feed_item_code": "65",
+ "feed_type_code": "2",
+ "livestock": [
+ {
+ "allocation": 40,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 17,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "5"
+ }
+ ]
+ },
+ {
+ "feed_item_code": "99",
+ "feed_type_code": "45",
+ "livestock": [
+ {
+ "allocation": 25,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 43,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 20,
+ "livetype_code": "5"
+ }
+ ]
+ },
+ {
+ "feed_item_code": "18",
+ "feed_type_code": "9",
+ "livestock": [
+ {
+ "allocation": 35,
+ "livetype_code": "2"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "1"
+ },
+ {
+ "allocation": 40,
+ "livetype_code": "5"
+ }
+ ]
+ }
+ ],
+ "season_name": "Dry season"
+ }
+ ],
+ "feed_items": [
+ {
+ "ammonia": 0,
+ "ammonium_nitrate": 0,
+ "ammonium_sulfate": 0,
+ "average_dbh25": 0,
+ "average_dbh2550": 0,
+ "average_dbh50": 0,
+ "category": "cereal",
+ "cp_content": 13.6,
+ "cultivation_period": 0,
+ "cut_carry_fraction": 0,
+ "dap": 0,
+ "diameter_breast": 0,
+ "dm_content": 89,
+ "dry_yield": 30,
+ "ecosystem_type": "",
+ "energy": 0,
+ "feed_item_code": "65",
+ "feed_item_name": "Oats (Avena sativa) - grain IP",
+ "feed_type_code": "2",
+ "feed_type_name": "Avena sativa",
+ "fraction_as_fertilizer": 1,
+ "fraction_as_manure": null,
+ "grassman": "1",
+ "grassman_change_factor": 1,
+ "grassman_desc": "Nominally managed",
+ "increase_dbh25": 0,
+ "increase_dbh2550": 0,
+ "increase_dbh50": 0,
+ "intercrop": 0,
+ "intercrop_fraction": 0,
+ "kc_initial": 0.1,
+ "kc_late": 0.55,
+ "kc_midseason": 1.1,
+ "land_cover": "7",
+ "land_cover_desc": "Cereals",
+ "landcover_c_factor": 0.15,
+ "main_n": 0.0176,
+ "main_product_removal": 1,
+ "me_content": 12.267324,
+ "n_content": 0.2,
+ "n_fertilizer": null,
+ "n_solutions": 50,
+ "npk": 0,
+ "organic_amendment": "",
+ "residue_burnt": 0,
+ "residue_dry_yield": 0,
+ "residue_n": 0,
+ "residue_removal": 0,
+ "slope": "1",
+ "slope_desc": "Flat (0-5%)",
+ "slope_length": 0,
+ "slope_p_factor": 0.11,
+ "source_type": "Main",
+ "time_horizon": 0,
+ "trees_dhb": 0,
+ "trees_growth": 0,
+ "trees_ha": 0,
+ "trees_ha_dbh25": 0,
+ "trees_ha_dbh2550": 0,
+ "trees_ha_dbh50": 0,
+ "trees_removal": 0,
+ "urea": 400,
+ "usda_value": 0,
+ "water_content": 0,
+ "water_regime": ""
+ },
+ {
+ "ammonia": 0,
+ "ammonium_nitrate": 0,
+ "ammonium_sulfate": 0,
+ "average_dbh25": 0,
+ "average_dbh2550": 0,
+ "average_dbh50": 0,
+ "category": "cereal",
+ "cp_content": 3.85,
+ "cultivation_period": 0,
+ "cut_carry_fraction": 0,
+ "dap": 0,
+ "diameter_breast": 0,
+ "dm_content": 91.88,
+ "dry_yield": 15,
+ "ecosystem_type": "",
+ "energy": 360,
+ "feed_item_code": "99",
+ "feed_item_name": "Rice (Oryza sativa) - straw",
+ "feed_type_code": "45",
+ "feed_type_name": "Rice",
+ "fraction_as_fertilizer": 1,
+ "fraction_as_manure": null,
+ "grassman": "1",
+ "grassman_change_factor": 1,
+ "grassman_desc": "Nominally managed",
+ "increase_dbh25": 0,
+ "increase_dbh2550": 0,
+ "increase_dbh50": 0,
+ "intercrop": 0,
+ "intercrop_fraction": 0,
+ "kc_initial": 1.05,
+ "kc_late": 0.75,
+ "kc_midseason": 1.2,
+ "land_cover": "7",
+ "land_cover_desc": "Cereals",
+ "landcover_c_factor": 0.15,
+ "main_n": 0.009,
+ "main_product_removal": 1,
+ "me_content": 5.64,
+ "n_content": 0.2,
+ "n_fertilizer": null,
+ "n_solutions": 300,
+ "npk": 0,
+ "organic_amendment": "",
+ "residue_burnt": 0,
+ "residue_dry_yield": 0,
+ "residue_n": 0.2,
+ "residue_removal": 0.8,
+ "slope": "1",
+ "slope_desc": "Flat (0-5%)",
+ "slope_length": 0,
+ "slope_p_factor": 0.11,
+ "source_type": "Residue",
+ "time_horizon": 0,
+ "trees_dhb": 0,
+ "trees_growth": 0,
+ "trees_ha": 0,
+ "trees_ha_dbh25": 0,
+ "trees_ha_dbh2550": 0,
+ "trees_ha_dbh50": 0,
+ "trees_removal": 0,
+ "urea": 700,
+ "usda_value": 20450,
+ "water_content": 12.89,
+ "water_regime": ""
+ },
+ {
+ "ammonia": 0,
+ "ammonium_nitrate": 0,
+ "ammonium_sulfate": 0,
+ "average_dbh25": 0,
+ "average_dbh2550": 0,
+ "average_dbh50": 0,
+ "category": "legume",
+ "cp_content": 18.4,
+ "cultivation_period": 0,
+ "cut_carry_fraction": 0,
+ "dap": 0,
+ "diameter_breast": 0,
+ "dm_content": 90,
+ "dry_yield": 8,
+ "ecosystem_type": "",
+ "energy": 336,
+ "feed_item_code": "18",
+ "feed_item_name": "Cowpea (Vigna unguiculata) - crop residue",
+ "feed_type_code": "9",
+ "feed_type_name": "Cowpea",
+ "fraction_as_fertilizer": 0,
+ "fraction_as_manure": null,
+ "grassman": "1",
+ "grassman_change_factor": 1,
+ "grassman_desc": "Nominally managed",
+ "increase_dbh25": 0,
+ "increase_dbh2550": 0,
+ "increase_dbh50": 0,
+ "intercrop": 0,
+ "intercrop_fraction": 0,
+ "kc_initial": 0.15,
+ "kc_late": 0.6,
+ "kc_midseason": 1.05,
+ "land_cover": "1",
+ "land_cover_desc": "Dense forest",
+ "landcover_c_factor": 0.001,
+ "main_n": 0.038,
+ "main_product_removal": 0,
+ "me_content": 9.880848,
+ "n_content": 0,
+ "n_fertilizer": null,
+ "n_solutions": 100,
+ "npk": 0,
+ "organic_amendment": "",
+ "residue_burnt": 0,
+ "residue_dry_yield": 6,
+ "residue_n": 0,
+ "residue_removal": 0,
+ "slope": "1",
+ "slope_desc": "Flat (0-5%)",
+ "slope_length": 0,
+ "slope_p_factor": 0.11,
+ "source_type": "Main",
+ "time_horizon": 0,
+ "trees_dhb": 0,
+ "trees_growth": 0,
+ "trees_ha": 0,
+ "trees_ha_dbh25": 0,
+ "trees_ha_dbh2550": 0,
+ "trees_ha_dbh50": 0,
+ "trees_removal": 0,
+ "urea": 200,
+ "usda_value": 16062,
+ "water_content": 11.95,
+ "water_regime": ""
+ }
+ ],
+ "fertilizer": [
+ {
+ "fertilizer_code": "4",
+ "fertilizer_desc": "Ammonium nitrate",
+ "fraction": 0,
+ "percentage_n": 12
+ },
+ {
+ "fertilizer_code": "6",
+ "fertilizer_desc": "N solutions",
+ "fraction": 0,
+ "percentage_n": 10
+ }
+ ],
+ "grassland_implevel": "Medium",
+ "grassland_implevel_ipcc": 1,
+ "grassland_management": "Nominally managed",
+ "grassland_management_ipcc": 1,
+ "grassland_toarable": 0,
+ "livestock": [
+ {
+ "adult_weight": 800,
+ "annual_growth": 0,
+ "annual_milk": 3000,
+ "annual_wool": 0,
+ "birth_interval": 1.16666666666667,
+ "body_weight": 600,
+ "body_weight_weaning": 0,
+ "body_weight_year_one": 0,
+ "carcass_fraction": 0.48,
+ "cp_grazing": 0,
+ "cp_growth": 0,
+ "cp_lactation": 5,
+ "cp_lactmilk": 0.09,
+ "cp_maintenance": 0.6,
+ "cp_pregnancy": 12.21,
+ "distance_to_pasture": 0,
+ "energy_eggcontent": 0,
+ "energy_meatcontent": 2200,
+ "energy_milkcontent": 970,
+ "fat_content": 4.3,
+ "grazing_displacement": 0,
+ "herd_composition": 2,
+ "ipcc_ef_category_t1": "Dairy cattle",
+ "ipcc_ef_category_t2": "Dairy cows",
+ "ipcc_meth_man_category": "Dairy cows",
+ "ipcc_n_exc_category": "Dairy cattle",
+ "lactation_length": 0,
+ "litter_size": 0,
+ "livetype_code": "2",
+ "livetype_desc": "Cattle - Cows (improved)",
+ "lw_gain": 0,
+ "manure_in_field": 0,
+ "manure_in_non_roofed_enclosure": 0,
+ "manure_in_stable": 1,
+ "manure_onfarm_fraction": 1,
+ "manure_sales_fraction": 0,
+ "manureman_non_roofed_enclosure": "Solid storage",
+ "manureman_offfarm_grazing": "Solid storage",
+ "manureman_onfarm_grazing": "Solid storage",
+ "manureman_stable": "Solid storage",
+ "me_grazing": 2,
+ "me_growth": 0,
+ "me_lactation": 5,
+ "me_lactmilk": 5.5,
+ "me_maintenance": 60.6154651402987,
+ "me_pregnancy": 1500,
+ "meat_product": "beef",
+ "milk_product": "cow milk",
+ "n_content": 0.029,
+ "piglets_relying_on_milk": 0,
+ "proportion_growth": 0,
+ "protein_meatcontent": 26,
+ "protein_milkcontent": 3.7,
+ "time_in_non_roofed_enclosure": 0,
+ "time_in_offfarm_grazing": 0,
+ "time_in_onfarm_grazing": 0,
+ "time_in_stable": 1,
+ "water_requirement": 140,
+ "work_hour": 0
+ },
+ {
+ "adult_weight": 400,
+ "annual_growth": 0,
+ "annual_milk": 1500,
+ "annual_wool": 0,
+ "birth_interval": 1.5,
+ "body_weight": 350,
+ "body_weight_weaning": 0,
+ "body_weight_year_one": 0,
+ "carcass_fraction": 0,
+ "cp_grazing": 3,
+ "cp_growth": 0,
+ "cp_lactation": 2,
+ "cp_lactmilk": 0.09,
+ "cp_maintenance": 0.35,
+ "cp_pregnancy": 9.64,
+ "distance_to_pasture": 0.5,
+ "energy_eggcontent": 0,
+ "energy_meatcontent": 2200,
+ "energy_milkcontent": 970,
+ "fat_content": 5.8,
+ "grazing_displacement": 2,
+ "herd_composition": 5,
+ "ipcc_ef_category_t1": "Other mature female",
+ "ipcc_ef_category_t2": "Dairy cows",
+ "ipcc_meth_man_category": "Dairy cows",
+ "ipcc_n_exc_category": "Dairy cattle",
+ "lactation_length": 0,
+ "litter_size": 0,
+ "livetype_code": "1",
+ "livetype_desc": "Cattle - Cows (local)",
+ "lw_gain": 0,
+ "manure_in_field": 0,
+ "manure_in_non_roofed_enclosure": 0,
+ "manure_in_stable": 0,
+ "manure_onfarm_fraction": 0,
+ "manure_sales_fraction": 0,
+ "manureman_non_roofed_enclosure": "Solid storage",
+ "manureman_offfarm_grazing": "Solid storage",
+ "manureman_onfarm_grazing": "Pasture / range / paddock",
+ "manureman_stable": "Solid storage",
+ "me_grazing": 2,
+ "me_growth": 0,
+ "me_lactation": 2,
+ "me_lactmilk": 5.5,
+ "me_maintenance": 40.4595490176744,
+ "me_pregnancy": 1260,
+ "meat_product": "beef",
+ "milk_product": "cow milk",
+ "n_content": 0.029,
+ "piglets_relying_on_milk": 0,
+ "proportion_growth": 0,
+ "protein_meatcontent": 26,
+ "protein_milkcontent": 3.2,
+ "time_in_non_roofed_enclosure": 0,
+ "time_in_offfarm_grazing": 0,
+ "time_in_onfarm_grazing": 1,
+ "time_in_stable": 0,
+ "water_requirement": 120,
+ "work_hour": 0
+ },
+ {
+ "adult_weight": 0,
+ "annual_growth": 90,
+ "annual_milk": 0,
+ "annual_wool": 0,
+ "birth_interval": 0,
+ "body_weight": 200,
+ "body_weight_weaning": 0,
+ "body_weight_year_one": 0,
+ "carcass_fraction": 0.48,
+ "cp_grazing": 0,
+ "cp_growth": 0.4,
+ "cp_lactation": 0,
+ "cp_lactmilk": 0,
+ "cp_maintenance": 0.2,
+ "cp_pregnancy": 0,
+ "distance_to_pasture": 0.5,
+ "energy_eggcontent": 0,
+ "energy_meatcontent": 2200,
+ "energy_milkcontent": 0,
+ "fat_content": 0,
+ "grazing_displacement": 0,
+ "herd_composition": 0,
+ "ipcc_ef_category_t1": "Other mature female-grazing",
+ "ipcc_ef_category_t2": "Non-dairy",
+ "ipcc_meth_man_category": "Other cattle",
+ "ipcc_n_exc_category": "Other cattle",
+ "lactation_length": 0,
+ "litter_size": 0,
+ "livetype_code": "5",
+ "livetype_desc": "Cattle - Steers/heifers",
+ "lw_gain": 0,
+ "manure_in_field": 0,
+ "manure_in_non_roofed_enclosure": 0,
+ "manure_in_stable": 0,
+ "manure_onfarm_fraction": 0,
+ "manure_sales_fraction": 0,
+ "manureman_non_roofed_enclosure": "Solid storage",
+ "manureman_offfarm_grazing": "Solid storage",
+ "manureman_onfarm_grazing": "Solid storage",
+ "manureman_stable": "Solid storage",
+ "me_grazing": 1.5,
+ "me_growth": 50,
+ "me_lactation": 0,
+ "me_lactmilk": 0,
+ "me_maintenance": 26.5914794847249,
+ "me_pregnancy": 0,
+ "meat_product": "beef",
+ "milk_product": "cow milk",
+ "n_content": 0.029,
+ "piglets_relying_on_milk": 0,
+ "proportion_growth": 0,
+ "protein_meatcontent": 26,
+ "protein_milkcontent": 0,
+ "time_in_non_roofed_enclosure": 0,
+ "time_in_offfarm_grazing": 0,
+ "time_in_onfarm_grazing": 1,
+ "time_in_stable": 0,
+ "water_requirement": 80,
+ "work_hour": 0
+ }
+ ],
+ "purchased_bedding": 0,
+ "purchased_compost": 0,
+ "purchased_manure": 0,
+ "purchased_organic_n": 0,
+ "rain_length": 5,
+ "region": "AFRICA",
+ "seasons": [
+ {
+ "season_length": 200,
+ "season_name": "Wet season"
+ },
+ {
+ "season_length": 165,
+ "season_name": "Dry season"
+ }
+ ],
+ "soil_bulk": 6,
+ "soil_c": 12,
+ "soil_clay": 45,
+ "soil_depth": 2,
+ "soil_description": "Lixisol",
+ "soil_k_value": 0.25,
+ "soil_n": 3.5,
+ "waste_consume_meat": 2,
+ "waste_consume_milk": 2,
+ "waste_distribution_meat": 3,
+ "waste_distribution_milk": 3,
+ "waste_processing_meat": 5,
+ "waste_processing_milk": 5,
+ "waste_production_meat": 3,
+ "waste_production_milk": 3
+}