Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e517787
Refactored manure and lactation CP functions, updated variable names
M-Emmanuel Jan 7, 2026
215fc3e
minor parenthesis check
M-Emmanuel Jan 8, 2026
de1e456
minor parentheses check
M-Emmanuel Jan 8, 2026
7d75ef4
Update README.md
M-Emmanuel Jan 27, 2026
8f75cda
Create CITATION.cff
M-Emmanuel Jan 29, 2026
0291184
Update README.md
M-Emmanuel Jan 29, 2026
599978f
Update README.md
M-Emmanuel Jan 29, 2026
47a0d2f
fixing land_productivity outputs
M-Emmanuel Feb 19, 2026
d95c966
Update productivity outputs
M-Emmanuel Feb 24, 2026
4c44dc9
fix livetype_name handling & update livestock productivity outputs
M-Emmanuel Feb 24, 2026
b27962d
Align ghg_emission with V2 logic
M-Emmanuel Mar 5, 2026
9f801bf
Updating climate picker tables
M-Emmanuel Mar 16, 2026
98b1c75
update climate picker
M-Emmanuel Mar 16, 2026
7fabb39
update climate picker
M-Emmanuel Mar 16, 2026
c5734c8
update climate picker
M-Emmanuel Mar 17, 2026
a23abd9
update climate picker
M-Emmanuel Mar 17, 2026
4c6fa8b
productivity picker issue
M-Emmanuel Mar 17, 2026
fc1aeaf
fix SOC parameter lookup with dynamic extraction
M-Emmanuel Mar 24, 2026
0d42050
add helper to debug case sensitive text
M-Emmanuel Mar 24, 2026
6f07d0d
assign correct input to ghg_emissions
M-Emmanuel Mar 25, 2026
a0482e0
remove whitespace in lambs
M-Emmanuel Mar 25, 2026
5b6db80
add energy_required in the pipeline
M-Emmanuel Mar 25, 2026
c6b1168
solve cbind errors
M-Emmanuel Mar 26, 2026
1c4dc9c
align with pipeline
M-Emmanuel Mar 26, 2026
6188364
pipeline fix
M-Emmanuel Mar 26, 2026
e33b2b0
fix pipeline breaks
M-Emmanuel Mar 26, 2026
2f80d25
fix pipeline input-output logic
M-Emmanuel Mar 26, 2026
a3f4990
fix pipeline
M-Emmanuel Mar 26, 2026
5367f19
fix pipeline
M-Emmanuel Mar 26, 2026
acba3cf
fix pipeline
M-Emmanuel Mar 26, 2026
fc64da4
fix pipeline
M-Emmanuel Mar 26, 2026
0602537
fix pipeline
M-Emmanuel Mar 26, 2026
fa1fc50
fix pipeline
M-Emmanuel Mar 26, 2026
29e9eae
fix ghg summary
M-Emmanuel Mar 30, 2026
0783ae3
fixing fertilizer quantity
M-Emmanuel Mar 30, 2026
f770d78
fixing ghg summary
M-Emmanuel Mar 30, 2026
0e51365
fix duplicate livetypes when merging
M-Emmanuel Apr 13, 2026
a5f52eb
add DE fallback in Ym selection
M-Emmanuel Jun 17, 2026
85afea9
align outputs for merging
M-Emmanuel Jun 18, 2026
e62f073
re-order plotting fields & batch output tables
M-Emmanuel Jun 18, 2026
3094225
fix parentheses
M-Emmanuel Jun 24, 2026
88e5905
Make CLEANED outputs compatible with app and batch workflows
M-Emmanuel Jul 13, 2026
b565c15
Merge branch 'feature/ghg-v2-align' of https://github.com/M-Emmanuel/…
M-Emmanuel Jul 13, 2026
ebdd1bd
Merge pull request #1 from M-Emmanuel/feature/ghg-v2-align
M-Emmanuel Jul 13, 2026
a879c68
Merge pull request #2 from M-Emmanuel/feature/correct-functions
M-Emmanuel Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cff-version: 1.2.0
title: "CIAT/Cleaned_batch-2: CLEANED Development Changes (2025)"
message: "If you use this software, please cite it as below."
type: software

authors:
- family-names: Mwema
given-names: Emmanuel
affiliation: "Alliance Bioversity International - CIAT"

- family-names: Steward
given-names: Pete
affiliation: "Alliance Bioversity International - CIAT"

- family-names: "Van der Hoek"
given-names: Rein
affiliation: "Alliance Bioversity International - CIAT"

- family-names: Notenbaert
given-names: An
affiliation: "Alliance Bioversity International - CIAT"

repository-code: https://github.com/M-Emmanuel/cleaned-staging-v2
version: "2025.1"
date-released: 2026-01-27
2 changes: 1 addition & 1 deletion R/biomass_calculation.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ biomass_calculation <- function(para, land_required){
summarise(area_feed = sum(area_feed))

# add feed category
feed_production <- unnest(para[["feed_items"]], cols = c(feed_type_name))
feed_production <- unnest(para[["feed_items"]], cols = c(crop_name))

# Changes in dplyr caused an error running the section below
# feed_production <- na_if(feed_production, "NA") %>%
Expand Down
531 changes: 397 additions & 134 deletions R/differences.R

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions R/energy_requirement.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ energy_requirement <- function(para, feed_basket_quality,energy_parameters){

#Lactation energy
lactation_er <- growth_er%>%
mutate(ev = ifelse(livestock_category_name %in% Cattle_n_Buffalo_lactating_cows, 1.47+(0.40*fat_content),
mutate(ev = ifelse(livestock_category_name %in% Cattle_n_Buffalo_lactating_cows, 1.47+(0.40*fat_milkcontent),
ifelse(livestock_category_name == "Sheep - Ewes",4.6,
ifelse(livestock_category_name == "Goats - Does",3,0))),
er_lact = ifelse(livestock_category_name%in%c("Sheep - Ewes","Goats - Does") & annual_milk == 0,5*(body_weight_weaning/no_days)*ev, #equation 10.10
ifelse(livestock_category_name=="Pigs - lactating/pregnant sows",(((piglets_relying_on_milk/100)*lactation_length*((6.83*litter_size*lw_gain)-(0.125*litter_size)))*4.2)/no_days/birth_interval, #not from the ipcc
ifelse(livestock_category_name=="Pigs - lactating/pregnant sows",(((piglets_relying_on_milk/100)*lactation_length*((6.83*litter_size*lw_gain_piglets)-(0.125*litter_size)))*4.2)/no_days/birth_interval, #NRC 1998
(annual_milk*ev)/no_days)), #equation 10.8 & equation 10.9
er_lactation = ifelse(!is.finite(er_lact),0,er_lact))

Expand All @@ -128,14 +128,20 @@ energy_requirement <- function(para, feed_basket_quality,energy_parameters){
er_wool = ifelse(!is.finite(er_wool),0,er_wool))

#Computing Gross Energy and DMI
#calculate lactation cp for small ruminants and pigs
lactation_cp <- wool_er %>%
mutate(cp_lactation = ifelse(livestock_category_name %in% c("Sheep - Ewes", "Goats - Does"), cp_maintenance * 2 * lactation_length, # NRC 2007
ifelse(livestock_category_name == "Pigs - lactating/pregnant sows", (1.1 * 0.022 * lw_gain_piglets * litter_size - 0.0064) * lactation_length * proportion_growth_piglets_milk, # NRC 1998
0 )),
cp_lactation = ifelse(!is.finite(cp_lactation), 0, cp_lactation))

#Compute annual energy and protein required
annual_requirement <- wool_er%>%
annual_requirement <- lactation_cp%>%
mutate(energy_required_annually=(er_maintenance+er_activity+er_growth+er_lactation+er_pregnancy+er_work+er_wool)*no_days*herd_composition,
protein_required_annually =((cp_maintenance*no_days)+(cp_grazing*grazing_displacement*no_days)+
ifelse(!is.finite(((cp_pregnancy/(no_days*birth_interval))*no_days)),0,((cp_pregnancy/(no_days*birth_interval))*no_days))+
protein_required_annually =((cp_maintenance*no_days)+
ifelse(!is.finite(((cp_lys_pregnancy/(no_days*birth_interval))*no_days)),0,((cp_lys_pregnancy/(no_days*birth_interval))*no_days))+
ifelse(!is.finite(((cp_lactation/(no_days*birth_interval))*no_days)),0,((cp_lactation/(no_days*birth_interval))*no_days))+
(annual_milk*cp_lactmilk)+(annual_growth*cp_growth))*herd_composition)
(annual_milk*cp_lactmilk)+(annual_growth*cp_lys_growth))*herd_composition)

#get livestock energy and protein requirement per season
for (i in 1:nrow(seasons)) {
Expand Down Expand Up @@ -198,11 +204,11 @@ energy_requirement <- function(para, feed_basket_quality,energy_parameters){
daily_manure_produced = annual_manure_produced/365)%>%
left_join(livestock, by = "livestock_category_code")%>%
mutate(manure_onfarm_grazing = (annual_manure_produced*time_in_onfarm_grazing)-(annual_manure_produced*time_in_onfarm_grazing*manure_in_field),
n_content_manure_grazing = manure_onfarm_grazing*n_content,
n_content_manure_grazing = manure_onfarm_grazing*n_manure_content,
manure_collected = annual_manure_produced*((time_in_stable*manure_in_stable)+
(time_in_non_roofed_enclosure*manure_in_non_roofed_enclosure)+
(time_in_onfarm_grazing*manure_in_field))*manure_onfarm_fraction,
n_content_manure_collected = manure_collected*n_content,
n_content_manure_collected = manure_collected*n_manure_content,
n_content_manure_total = n_content_manure_grazing+n_content_manure_collected,
manure_exported = manure_collected*manure_sales_fraction)%>%
select(livestock_category_code,me_intake,dmi_tot,de_intake,ge_intake,annual_manure_produced,daily_manure_produced,manure_onfarm_grazing,
Expand Down
10 changes: 5 additions & 5 deletions R/feed_quality.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ feed_quality <- function(para) {

for (season in 1:nrow(seasons)) {

feed_production <- unnest(para[["feed_items"]], cols = c(feed_type_name))
feed_production <- unnest(para[["feed_items"]], cols = c(crop_name))

feed_types <- unique(feed_production$feed_type_name)
feed_types <- unique(feed_production$crop_name)

feed_allocation <- list()

for (i in 1:length(feed_types)) {
feed_selected <- feed_production %>% dplyr::filter(feed_type_name %in% feed_types[i])
feed_selected <- feed_production %>% dplyr::filter(crop_name %in% feed_types[i])

#feed_item <- as.data.frame(feed_selected[["feed_items"]])

Expand All @@ -71,7 +71,7 @@ feed_quality <- function(para) {

feeding_seasons <- unnest(para[["feed_basket"]],
cols = c(feeds)) %>% dplyr::filter(season_name %in%
seasons$season_name[season])
seasons$season_name[season])

feed_item_selected <- feeding_seasons %>%
dplyr::filter(feed_item_code %in% feed_selected[["feed_item_code"]])
Expand Down Expand Up @@ -154,4 +154,4 @@ feed_quality <- function(para) {

return(livestock_feed_allocation)

}
}
Loading