Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
5b609f9
rewrite create_n_rate_data data raw script
divine7022 May 18, 2026
af7171a
refresh n_application_rates csv
divine7022 May 18, 2026
9079a65
rebuild ca_n_application_rate rda
divine7022 May 18, 2026
4ba0b09
add oz_per_tree_to_lb_per_acre helper
divine7022 May 18, 2026
4da526e
add doc for oz_per_tree_to_lb_per_acre
divine7022 May 18, 2026
00a4ce8
add tpa_lookup helper
divine7022 May 18, 2026
b738e65
add doc for tpa_lookup
divine7022 May 18, 2026
70f56c8
rewrite create_compost_data with material class
divine7022 May 18, 2026
ef7d28c
refresh compost_amendments csv
divine7022 May 18, 2026
1b96343
rebuild ca_compost_amendment rda
divine7022 May 18, 2026
36ed147
update doc for ca_compost_amendment
divine7022 May 18, 2026
3598750
add create_ca_compost_distributions data raw script
divine7022 May 18, 2026
adc5190
add ca_compost_pct_c_distribution rda
divine7022 May 18, 2026
9a15db8
add ca_compost_cn_distribution rda
divine7022 May 18, 2026
e850cee
add ca_compost_app_rate_envelope rda
divine7022 May 18, 2026
c5cb2ad
add ca_compost_calendar_window rda
divine7022 May 18, 2026
5e2fff3
add ca_compost_material_whitelist rda
divine7022 May 18, 2026
e41539f
add doc for ca_compost_pct_c_distribution
divine7022 May 18, 2026
de0bb71
add doc for ca_compost_cn_distribution
divine7022 May 18, 2026
9b22635
add doc for ca_compost_app_rate_envelope
divine7022 May 18, 2026
4dfed63
add doc for ca_compost_calendar_window
divine7022 May 18, 2026
56a95f6
add doc for ca_compost_material_whitelist
divine7022 May 18, 2026
ee1ef5e
add sample_ca_compost functions
divine7022 May 18, 2026
d858456
add doc for sample_ca_compost_pct_c
divine7022 May 18, 2026
c5d72f0
add doc for sample_ca_compost_cn
divine7022 May 18, 2026
c353ef5
add doc for sample_ca_compost_app_rate
divine7022 May 18, 2026
1d24977
add doc for sample_ca_compost_date_offset
divine7022 May 18, 2026
a71ef65
add doc for sample_ca_compost_material
divine7022 May 18, 2026
5f5172c
add tests for sample_ca_compost
divine7022 May 18, 2026
f52c1c3
update bundled dataset docs
divine7022 May 18, 2026
955e7f1
export new helpers and samplers
divine7022 May 18, 2026
30e620d
add ncc event type to events schema
divine7022 May 18, 2026
d0c79ef
update doc for ca_n_application_rate
divine7022 May 18, 2026
0974b36
update dataset docs
divine7022 May 18, 2026
d0844c9
update create_compost_data
divine7022 May 18, 2026
0bd71d9
Merge branch 'develop' into ncc-compost
dlebauer May 20, 2026
246fb5b
revert events schema additions; drop ncc as a seperate event
divine7022 May 23, 2026
f503d37
drop sample_ca_compost functions
divine7022 May 23, 2026
3fbfcec
drop sample_ca_compost tests
divine7022 May 23, 2026
81864e8
drop compost distributions build script
divine7022 May 23, 2026
0b71a7e
drop ca_compost_pct_c_distribution rda
divine7022 May 23, 2026
daf20d8
drop ca_compost_cn_distribution rda
divine7022 May 23, 2026
bb138b0
drop ca_compost_app_rate_envelope rda
divine7022 May 23, 2026
93c7456
drop ca_compost_calendar_window rda
divine7022 May 23, 2026
eb461d3
drop ca_compost_material_whitelist rda
divine7022 May 23, 2026
5d4070a
drop doc for ca_compost_pct_c_distribution
divine7022 May 23, 2026
aec34bf
drop doc for ca_compost_cn_distribution
divine7022 May 23, 2026
d4567f0
drop doc for ca_compost_app_rate_envelope
divine7022 May 23, 2026
34a4068
drop doc for ca_compost_calendar_window
divine7022 May 23, 2026
9a9dcf0
drop doc for ca_compost_material_whitelist
divine7022 May 23, 2026
7ee162b
drop doc for sample_ca_compost_pct_c
divine7022 May 23, 2026
6d943fb
drop doc for sample_ca_compost_cn
divine7022 May 23, 2026
3da67e0
drop doc for sample_ca_compost_app_rate
divine7022 May 23, 2026
6e025b4
drop doc for sample_ca_compost_date_offset
divine7022 May 23, 2026
9433f59
drop doc for sample_ca_compost_material
divine7022 May 23, 2026
0a715a6
drop oz_per_tree_to_lb_per_acre helper
divine7022 May 23, 2026
2467216
drop doc for oz_per_tree_to_lb_per_acre
divine7022 May 23, 2026
1e5dbe5
drop tpa_lookup helper
divine7022 May 23, 2026
aa60cf2
drop doc for tpa_lookup
divine7022 May 23, 2026
6d3850c
drop docs for removed compost distribution datasets
divine7022 May 23, 2026
b5c658b
drop namespace exports for removed functions
divine7022 May 23, 2026
1bc7c15
update look_up_ca_compost_amendment for new column set
divine7022 May 23, 2026
740cc8c
regen doc for look_up_ca_compost_amendment
divine7022 May 23, 2026
4150ede
update lookup tests for recovered crops and new compost columns
divine7022 May 23, 2026
7a59c49
add raw compost tsv to data-raw
divine7022 May 23, 2026
229b2ac
add raw n fertilization tsv to data-raw
divine7022 May 23, 2026
ca51a68
read raw compost tsv from data-raw and use ud_convert
divine7022 May 23, 2026
39ce033
read raw n tsv from data-raw and use ud_convert
divine7022 May 23, 2026
50c2ffa
rebuild ca_compost_amendment rda
divine7022 May 23, 2026
0cc6cdf
rebuild ca_n_application_rate rda
divine7022 May 23, 2026
7b3dd3b
Merge remote-tracking branch 'origin/develop' into ncc-compost
divine7022 May 23, 2026
76455c1
update news entry to match new compost and n rate columns
divine7022 May 23, 2026
335031c
update ca_compost_amendment doc to mention material_class
divine7022 May 23, 2026
fc67a4e
regen doc for ca_compost_amendment
divine7022 May 23, 2026
b7d07e3
Merge branch 'ncc-compost' of github.com:divine7022/pecan into ncc-co…
divine7022 May 23, 2026
e721e3f
add harmonized ca_n_application_rate csv
divine7022 Jun 9, 2026
aadf430
add harmonized ca_organic_amendment_properties csv
divine7022 Jun 9, 2026
3f7592e
add harmonized ca_organic_amendment_app_rate csv
divine7022 Jun 9, 2026
37a7245
add create script for ca_n_application_rate
divine7022 Jun 9, 2026
3fcaab0
add create script for organic amendment tables
divine7022 Jun 9, 2026
702cf07
build ca_organic_amendment_properties rda
divine7022 Jun 9, 2026
6ac9e51
build ca_organic_amendment_app_rate rda
divine7022 Jun 9, 2026
b5aa883
rebuild ca_n_application_rate rda from harmonized csv
divine7022 Jun 9, 2026
c56a21c
rename look_up_ca_compost_amendment to look_up_ca_organic_amendment
divine7022 Jun 9, 2026
e8752f6
rewrite dataset docs for split amendment tables
divine7022 Jun 9, 2026
db4b6b1
update exports for renamed lookup function
divine7022 Jun 9, 2026
d7b4391
add doc for ca_organic_amendment_properties
divine7022 Jun 9, 2026
2044ea3
add doc for ca_organic_amendment_app_rate
divine7022 Jun 9, 2026
1a4a05a
add doc for look_up_ca_organic_amendment
divine7022 Jun 9, 2026
95165aa
regen doc for ca_n_application_rate
divine7022 Jun 9, 2026
2ad6403
update lookup tests for split tables
divine7022 Jun 9, 2026
d58ca09
document fertilization datasets in data-raw readme
divine7022 Jun 9, 2026
6b95f43
add news entries for ca fertilization datasets
divine7022 Jun 9, 2026
7d7ae2f
drop raw compost tsv superseded by harmonized csv
divine7022 Jun 9, 2026
5d60c92
drop raw n fertilization tsv superseded by harmonized csv
divine7022 Jun 9, 2026
24f9212
drop old compost build script
divine7022 Jun 9, 2026
b7ee992
drop old n rate build script
divine7022 Jun 9, 2026
84cda6f
drop ca_compost_amendment rda replaced by split tables
divine7022 Jun 9, 2026
40d6d5b
drop doc for ca_compost_amendment
divine7022 Jun 9, 2026
a9e4e10
drop doc for look_up_ca_compost_amendment
divine7022 Jun 9, 2026
71cbc05
add ca fertilization n rate raw data from cornell curation
divine7022 Jul 19, 2026
38a0166
use brown 2020 nbmp almond rates, drop the oz/tree rows
divine7022 Jul 19, 2026
6c3f8ec
add potato n rate from lazicki 2016
divine7022 Jul 19, 2026
e992699
drop peach bell and chili, they were copies of pepper
divine7022 Jul 19, 2026
3aaffc7
add ca organic amendment raw data
divine7022 Jul 19, 2026
4e0717c
add build script to harmonize the raw tsvs into the ca datasets
divine7022 Jul 19, 2026
8af6f8b
move readr and usethis to suggests
divine7022 Jul 19, 2026
b3fb473
add invariant checks for the ca fertilization datasets
divine7022 Jul 19, 2026
0eef397
document the fertilization data sources and update flow
divine7022 Jul 19, 2026
c9a888e
fix the alfalfa pub number in the n rate source
divine7022 Jul 19, 2026
b3d637a
fix grapevine n rate source, was a mislabeled alfalfa pub
divine7022 Jul 19, 2026
1169691
rebuild ca_n_application_rate csv
divine7022 Jul 19, 2026
d9f3fb6
rebuild ca_n_application_rate rda from csv
divine7022 Jul 19, 2026
69f4e2e
correct the grapevine source note in the readme
divine7022 Jul 19, 2026
bb862f8
fix the alfalfa pub number in the dataset docs
divine7022 Jul 19, 2026
4ece99f
regenerate package dependencies for data.land
divine7022 Jul 19, 2026
c346eb3
Merge branch 'develop' into ncc-compost
dlebauer Jul 29, 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
2 changes: 2 additions & 0 deletions docker/depends/pecan_package_dependencies.csv
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@
"rcrossref","*","base/db","Suggests",FALSE
"readr","*","models/ldndc","Imports",FALSE
"readr","*","modules/assim.sequential","Suggests",FALSE
"readr","*","modules/data.land","Suggests",FALSE
"REddyProc","*","modules/data.atmosphere","Imports",FALSE
"redland","*","modules/data.land","Suggests",FALSE
"reshape","*","modules/data.remote","Suggests",FALSE
Expand Down Expand Up @@ -700,6 +701,7 @@
"units","*","modules/data.atmosphere","Imports",FALSE
"units",">= 0.8.7","base/utils","Imports",FALSE
"urltools","*","base/remote","Imports",FALSE
"usethis","*","modules/data.land","Suggests",FALSE
"utils","*","base/all","Imports",FALSE
"utils","*","base/logger","Imports",FALSE
"utils","*","models/ed","Imports",FALSE
Expand Down
2 changes: 2 additions & 0 deletions modules/data.land/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ Suggests:
PEcAn.settings,
PEcAn.visualization,
raster,
readr,
redland,
reticulate,
rjags,
sirt,
sp,
testthat (>= 3.1.0),
traits,
usethis,
withr
Remotes:
github::ropensci/traits
Expand Down
2 changes: 1 addition & 1 deletion modules/data.land/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export(get_veg_module)
export(ic_process)
export(id_resolveable)
export(load_veg)
export(look_up_ca_compost_amendment)
export(look_up_ca_n_rate)
export(look_up_ca_organic_amendment)
export(look_up_fertilizer_components)
export(matchInventoryRings)
export(match_pft)
Expand Down
7 changes: 4 additions & 3 deletions modules/data.land/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* Datasets
* `landiq_crop_mapping_codes` dataset mapping LandIQ crop classification codes to human-readable crop names.
* `bism_kc_by_crop` dataset containing BISm crop coefficient schedules and stage timing references for use in ET estimation, including columns that map to LandIQ class and subclass.
* `ca_n_application_rate` dataset with recommended N application rates (g N/m2) for 33 California crops from CDFA-FREP and UC ANR sources.
* `ca_compost_amendment` dataset with C:N ratios, carbon, nitrogen, and PAN (g/m2) for 32 organic amendment materials.
* `ca_n_application_rate` dataset with recommended N application rates (g N/m2) for 40 California crops from CDFA-FREP, UC ANR, Rosenstock 2013, Brown 2020 NBMP (Almonds age stages) and Lazicki 2016 (Potato) sources.
* `ca_organic_amendment_properties` dataset with C:N ratios, nitrogen, and PAN for 32 organic amendment materials, plus a `material_class` column mapping each material to the CalRecycle taxonomy (14 CCR section 17852).
* `ca_organic_amendment_app_rate` dataset with row-crop and orchard application rate envelopes (64 rows = 32 materials x 2 crop structures) that joins to `ca_organic_amendment_properties` on `material`.
* Functions
* `look_up_ca_n_rate()` for looking up crop-specific N application rates by name (exact match first, partial match suggestions on miss).
* `look_up_ca_compost_amendment()` for looking up organic amendment properties by material name.
* `look_up_ca_organic_amendment()` for looking up organic amendment properties by material name.
* `to_co2e()` for converting SOC change, CH4, and N2O to CO2-equivalent emissions using IPCC Global Warming Potential values.

## Changed
Expand Down
144 changes: 84 additions & 60 deletions modules/data.land/R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,84 +209,108 @@

#' California recommended N application rates by crop
#'
#' Crop-specific recommended nitrogen fertilizer application rates for
#' California agriculture. Contains total-season rates (not per-stage
#' breakdowns). When multiple sources report rates for the same crop,
#' the rate represents the envelope (min of minimums, max of maximums)
#' across sources.
#'
#' @format A tibble with one row per crop and the following columns:
#' Recommended nitrogen fertilizer application rates for California crops.
#' When multiple sources report rates for the same crop the value is the
#' envelope across sources. Crops reported only as within year stages
#' (Barley, Beans, Cauliflower, Melons) have stages summed to an annual
#' total. Crops reported only by age (Almonds) get the envelope across
#' ages.
#'
#' @format A tibble with one row per crop and the columns:
#' \describe{
#' \item{pft_group}{\code{character}. Plant functional type group
#' (e.g. "row", "woody", "rice").}
#' \item{crop}{\code{character}. Crop name as given in the source.}
#' \item{min_n_lbs_acre}{\code{numeric}. Minimum recommended N rate
#' (lbs N/acre).}
#' \item{max_n_lbs_acre}{\code{numeric}. Maximum recommended N rate
#' (lbs N/acre).}
#' \item{source}{\code{character}. Short citation for the source(s).
#' Multiple sources are separated by "; ".}
#' \item{min_n_g_m2}{\code{numeric}. Minimum N rate in SI units
#' (g N/m\eqn{^2}). Conversion: 1 lb/acre = 0.112085 g/m\eqn{^2}.}
#' \item{max_n_g_m2}{\code{numeric}. Maximum N rate in SI units
#' (g N/m\eqn{^2}).}
#' \item{pft_group}{Plant functional type group: \code{"row"},
#' \code{"woody"}, or \code{"rice"}.}
#' \item{crop}{Crop name as given in the source.}
#' \item{min_n_lbs_acre, max_n_lbs_acre}{Recommended N rate range
#' (lbs N / acre).}
#' \item{source}{Short citation. Multiple sources are joined with
#' \code{"; "}.}
#' \item{min_n_g_m2, max_n_g_m2}{Same range in SI units (g N / m\eqn{^2}).}
#' }
#'
#' @source Rosenstock, T. S., Liptzin, D., Six, J., & Tomich, T. P. (2013).
#' @source Rosenstock, T. S., Liptzin, D., Six, J., Tomich, T. P. (2013).
#' Nitrogen fertilizer use in California: Assessing the data, trends and a
#' way forward. California Agriculture, 67(1).
#' way forward. California Agriculture 67(1).
#' \url{https://escholarship.org/uc/item/5mk2q1sm}
#' @source Meyer, R. D., Marcum, D. B., Orloff, S. B., & Schmierer, J. L.
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8296.
#'
#' @seealso \code{\link{look_up_ca_n_rate}} for looking up rates by crop name.
#' \code{\link{look_up_fertilizer_components}} for fertilizer nutrient
#' composition (N/C fractions) from the SWAT/DayCent database.
#' @source Meyer, R. D., Marcum, D. B., Orloff, S. B., Schmierer, J. L.
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8292.
#' @source Brown, P. H. et al. (2020). Nitrogen Best Management Practices
#' for Almonds. Almond Board of California. Source for Almonds rates by
#' age.
#' @source Lazicki, P., Geisseler, D., Horwath, W. R. (2016). Potato
#' Production in California. CDFA FREP / UC Davis. Source for Potato.
#'
#' @seealso \code{\link{look_up_ca_n_rate}}.
"ca_n_application_rate"

#' California organic amendment (compost) properties
#' California organic amendment properties
#'
#' Properties of organic amendment materials used in California agriculture,
#' including C:N ratios, carbon and nitrogen content, plant-available nitrogen
#' (PAN), and application rates. Some materials appear in multiple rows when
#' values are reported by different sources (e.g. Corn stalks, Cow manure,
#' Vegetable waste). The \code{source} column disambiguates these.
#' Properties of organic amendment materials used in California
#' agriculture: C:N ratio range, total N, plant available N at 4 weeks
#' (PAN), and CalRecycle feedstock class (14 CCR section 17852).
#' Materials reported by more than one source appear once per source;
#' the \code{source} column disambiguates. Application rates live in
#' \code{\link{ca_organic_amendment_app_rate}} and join on
#' \code{material}.
#'
#' @format A tibble with 32 rows and the following columns:
#' @format A tibble with 32 rows and the columns:
#' \describe{
#' \item{material}{\code{character}. Amendment material name.}
#' \item{cn_min, cn_max, cn_avg}{\code{numeric}. Carbon-to-nitrogen ratio
#' range and average.}
#' \item{c_pct}{\code{numeric}. Assumed carbon content (percent).}
#' \item{n_pct}{\code{numeric}. Total nitrogen content (percent).}
#' \item{pan_pct}{\code{numeric}. Plant-available nitrogen after 4 weeks
#' (percent). Negative values indicate N immobilization.}
#' \item{n_class}{\code{character}. "LOWER" or "HIGHER" N content class.}
#' \item{app_rate_min, app_rate_max}{\code{numeric}. Application rate range
#' (lbs/acre).}
#' \item{total_c_min_lbs_acre, total_c_max_lbs_acre}{\code{numeric}.
#' Total carbon applied (lbs C/acre).}
#' \item{total_n_min_lbs_acre, total_n_max_lbs_acre}{\code{numeric}.
#' Total nitrogen applied (lbs N/acre).}
#' \item{total_c_min_g_m2, total_c_max_g_m2}{\code{numeric}.
#' Total carbon in SI units (g C/m\eqn{^2}).}
#' \item{total_n_min_g_m2, total_n_max_g_m2}{\code{numeric}.
#' Total nitrogen in SI units (g N/m\eqn{^2}).}
#' \item{source}{\code{character}. Short citation for the data source.}
#' \item{material}{Material name.}
#' \item{material_class}{CalRecycle feedstock class
#' (14 CCR section 17852): one of \code{"ag"}, \code{"food"},
#' \code{"green"}, \code{"wood"}, \code{"yard"}, \code{"biosolids"}.}
#' \item{cn_min, cn_max, cn_avg}{C:N ratio range.}
#' \item{n_pct}{Total N (percent of dry mass).}
#' \item{pan_pct}{Plant available N at 4 weeks (percent of total N).
#' Negative values indicate net immobilization.}
#' \item{n_class}{N tier reported in the source (\code{"LOWER"} or
#' \code{"HIGHER"}).}
#' \item{source}{Short citation.}
#' }
#'
#' @source Eghball, B. Composting Manure and Other Organic Residues.
#' University of Nebraska-Lincoln Extension, Publication G2222.
#' University of Nebraska Lincoln Extension, Publication G2222.
#' \url{https://extensionpubs.unl.edu/publication/g2222/na/html/view}
#' @source Rynk, R. (ed.) Compost Production and Use in Sustainable
#' Farming Systems. NC State Extension.
#' \url{https://content.ces.ncsu.edu/compost-production-and-use-in-sustainable-farming-systems}
#'
#' @seealso \code{\link{look_up_ca_compost_amendment}} for looking up
#' amendments by material name.
#' \code{\link{look_up_fertilizer_components}} for fertilizer nutrient
#' composition (N/C fractions) from the SWAT/DayCent database.
"ca_compost_amendment"
#' @seealso \code{\link{ca_organic_amendment_app_rate}}.
#' \code{\link{look_up_ca_organic_amendment}}.
"ca_organic_amendment_properties"

#' California organic amendment application rates
#'
#' Recommended application rates for each material in
#' \code{\link{ca_organic_amendment_properties}}, broken out by crop
#' structure (row crops vs orchards). The two rate sets are identical
#' for most materials in the source, but a handful of N rich materials
#' (Blood meal, poultry manure) differ between row and tree applications.
#'
#' @format A tibble with 64 rows (32 materials x 2 crop structures) and
#' the columns:
#' \describe{
#' \item{material}{Material name. Joins to
#' \code{\link{ca_organic_amendment_properties}}.}
#' \item{crop_structure}{\code{"rows"} for annual row crops,
#' \code{"trees"} for perennial orchards.}
#' \item{app_rate_min, app_rate_max}{Amendment application rate range
#' (lbs of amendment / acre).}
#' \item{total_n_min_lbs_acre, total_n_max_lbs_acre}{Total N delivered
#' at those rates (lbs N / acre).}
#' \item{source}{Short citation.}
#' \item{total_n_min_g_m2, total_n_max_g_m2}{Same N range in SI units
#' (g N / m\eqn{^2}).}
#' }
#'
#' @source Eghball, B. Composting Manure and Other Organic Residues.
#' University of Nebraska Lincoln Extension, Publication G2222.
#' @source Rynk, R. (ed.) Compost Production and Use in Sustainable
#' Farming Systems. NC State Extension.
#'
#' @seealso \code{\link{ca_organic_amendment_properties}}.
#' \code{\link{look_up_ca_organic_amendment}}.
"ca_organic_amendment_app_rate"

#' Crop-specific rooting depths and water-depletion thresholds
#'
Expand Down
45 changes: 21 additions & 24 deletions modules/data.land/R/look_up_ca_n_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' way forward. California Agriculture, 67(1).
#' \url{https://escholarship.org/uc/item/5mk2q1sm}
#' @source Meyer, R. D., Marcum, D. B., Orloff, S. B., & Schmierer, J. L.
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8296.
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8292.
#'
#' @seealso [look_up_fertilizer_components()] for fertilizer nutrient
#' composition (N/C fractions) from the SWAT/DayCent database.
Expand Down Expand Up @@ -100,10 +100,12 @@ look_up_ca_n_rate <- function(
}


#' Look up California compost amendment properties
#' Look up California organic amendment properties
#'
#' Returns properties of organic amendment materials including carbon and
#' nitrogen content, C:N ratio, and plant-available nitrogen (PAN).
#' Application rates live in
#' \code{\link{ca_organic_amendment_app_rate}}; join on \code{material}.
#'
#' Matching is case-insensitive. Exact matches are returned directly.
#' If no exact match is found, partial matching suggests possible materials.
Expand All @@ -117,10 +119,8 @@ look_up_ca_n_rate <- function(
#' @param aggregate Character, one of "none" (default) or "mean".
#' If "mean", rows for the same material are averaged into a single row.
#'
#' @return A tibble with columns: `material`, `cn_min`, `cn_max`,
#' `cn_avg`, `c_pct`, `n_pct`, `pan_pct`, `n_class`,
#' `total_c_min_g_m2`, `total_c_max_g_m2`,
#' `total_n_min_g_m2`, `total_n_max_g_m2`, `source`.
#' @return A tibble with columns: `material`, `material_class`,
#' `cn_min`, `cn_max`, `cn_avg`, `n_pct`, `pan_pct`, `n_class`, `source`.
#' Returns an empty tibble (with a warning) if no match is found.
#'
#' @source Eghball, B. Composting Manure and Other Organic Residues.
Expand All @@ -132,21 +132,22 @@ look_up_ca_n_rate <- function(
#'
#' @seealso [look_up_fertilizer_components()] for fertilizer nutrient
#' composition (N/C fractions) from the SWAT/DayCent database.
#' [ca_compost_amendment] for the underlying dataset.
#' [ca_organic_amendment_properties] for the underlying dataset.
#' [ca_organic_amendment_app_rate] for the matching application rates.
#'
#' @examples
#' look_up_ca_compost_amendment("Cow manure")
#' look_up_ca_compost_amendment("Cow manure", aggregate = "mean")
#' look_up_ca_compost_amendment("Poultry litter", n_class = "LOWER")
#' look_up_ca_organic_amendment("Cow manure")
#' look_up_ca_organic_amendment("Cow manure", aggregate = "mean")
#' look_up_ca_organic_amendment("Poultry litter", n_class = "LOWER")
#'
#' @export
look_up_ca_compost_amendment <- function(
look_up_ca_organic_amendment <- function(
material,
n_class = NULL,
aggregate = c("none", "mean")
) {
aggregate <- match.arg(aggregate)
dat <- PEcAn.data.land::ca_compost_amendment
dat <- PEcAn.data.land::ca_organic_amendment_properties

if (!is.null(n_class)) {
dat <- dat |>
Expand All @@ -170,37 +171,33 @@ look_up_ca_compost_amendment <- function(
)
} else {
PEcAn.logger::logger.warn(
"No compost amendment found for material '", material, "'"
"No organic amendment found for material '", material, "'"
)
}
return(dplyr::tibble(
material = character(), cn_min = numeric(), cn_max = numeric(),
cn_avg = numeric(), c_pct = numeric(),
material = character(), material_class = character(),
cn_min = numeric(), cn_max = numeric(), cn_avg = numeric(),
n_pct = numeric(), pan_pct = numeric(), n_class = character(),
total_c_min_g_m2 = numeric(), total_c_max_g_m2 = numeric(),
total_n_min_g_m2 = numeric(), total_n_max_g_m2 = numeric(),
source = character()
))
}

out <- result |>
dplyr::select(
"material", "cn_min", "cn_max", "cn_avg",
"c_pct", "n_pct", "pan_pct", "n_class",
"total_c_min_g_m2", "total_c_max_g_m2",
"total_n_min_g_m2", "total_n_max_g_m2",
"material", "material_class",
"cn_min", "cn_max", "cn_avg",
"n_pct", "pan_pct", "n_class",
"source"
)

if (aggregate == "mean" && nrow(out) > 1) {
numeric_cols <- c(
"cn_min", "cn_max", "cn_avg", "c_pct", "n_pct", "pan_pct",
"total_c_min_g_m2", "total_c_max_g_m2",
"total_n_min_g_m2", "total_n_max_g_m2"
"cn_min", "cn_max", "cn_avg", "n_pct", "pan_pct"
)
out <- out |>
dplyr::summarize(
dplyr::across(dplyr::all_of(numeric_cols), mean),
material_class = dplyr::first(.data$material_class),
n_class = dplyr::first(.data$n_class),
source = paste(unique(.data$source), collapse = "; "),
.by = "material"
Expand Down
Loading
Loading