Skip to content

Commit 6788ce4

Browse files
authored
Merge branch 'develop' into automated-reporting-and-visualization
2 parents 92604f8 + 065d7fc commit 6788ce4

30 files changed

Lines changed: 872 additions & 313 deletions

docker/depends/pecan_package_dependencies.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@
496496
"rcrossref","*","base/db","Suggests",FALSE
497497
"readr","*","models/ldndc","Imports",FALSE
498498
"readr","*","modules/assim.sequential","Suggests",FALSE
499+
"readr","*","modules/data.land","Suggests",FALSE
499500
"REddyProc","*","modules/data.atmosphere","Imports",FALSE
500501
"redland","*","modules/data.land","Suggests",FALSE
501502
"reshape","*","modules/data.remote","Suggests",FALSE
@@ -701,6 +702,7 @@
701702
"units","*","modules/data.atmosphere","Imports",FALSE
702703
"units",">= 0.8.7","base/utils","Imports",FALSE
703704
"urltools","*","base/remote","Imports",FALSE
705+
"usethis","*","modules/data.land","Suggests",FALSE
704706
"utils","*","base/all","Imports",FALSE
705707
"utils","*","base/logger","Imports",FALSE
706708
"utils","*","models/ed","Imports",FALSE

modules/data.land/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ Suggests:
7171
PEcAn.settings,
7272
PEcAn.visualization,
7373
raster,
74+
readr,
7475
redland,
7576
reticulate,
7677
rjags,
7778
sirt,
7879
sp,
7980
testthat (>= 3.1.0),
8081
traits,
82+
usethis,
8183
withr
8284
Remotes:
8385
github::ropensci/traits

modules/data.land/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export(get_veg_module)
4646
export(ic_process)
4747
export(id_resolveable)
4848
export(load_veg)
49-
export(look_up_ca_compost_amendment)
5049
export(look_up_ca_n_rate)
50+
export(look_up_ca_organic_amendment)
5151
export(look_up_fertilizer_components)
5252
export(matchInventoryRings)
5353
export(match_pft)

modules/data.land/NEWS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
* Datasets
1313
* `landiq_crop_mapping_codes` dataset mapping LandIQ crop classification codes to human-readable crop names.
1414
* `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.
15-
* `ca_n_application_rate` dataset with recommended N application rates (g N/m2) for 33 California crops from CDFA-FREP and UC ANR sources.
16-
* `ca_compost_amendment` dataset with C:N ratios, carbon, nitrogen, and PAN (g/m2) for 32 organic amendment materials.
15+
* `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.
16+
* `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).
17+
* `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`.
1718
* Functions
1819
* `look_up_ca_n_rate()` for looking up crop-specific N application rates by name (exact match first, partial match suggestions on miss).
19-
* `look_up_ca_compost_amendment()` for looking up organic amendment properties by material name.
20+
* `look_up_ca_organic_amendment()` for looking up organic amendment properties by material name.
2021
* `to_co2e()` for converting SOC change, CH4, and N2O to CO2-equivalent emissions using IPCC Global Warming Potential values.
2122

2223
## Changed

modules/data.land/R/data.R

Lines changed: 84 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -209,84 +209,108 @@
209209

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

247-
#' California organic amendment (compost) properties
246+
#' California organic amendment properties
248247
#'
249-
#' Properties of organic amendment materials used in California agriculture,
250-
#' including C:N ratios, carbon and nitrogen content, plant-available nitrogen
251-
#' (PAN), and application rates. Some materials appear in multiple rows when
252-
#' values are reported by different sources (e.g. Corn stalks, Cow manure,
253-
#' Vegetable waste). The \code{source} column disambiguates these.
248+
#' Properties of organic amendment materials used in California
249+
#' agriculture: C:N ratio range, total N, plant available N at 4 weeks
250+
#' (PAN), and CalRecycle feedstock class (14 CCR section 17852).
251+
#' Materials reported by more than one source appear once per source;
252+
#' the \code{source} column disambiguates. Application rates live in
253+
#' \code{\link{ca_organic_amendment_app_rate}} and join on
254+
#' \code{material}.
254255
#'
255-
#' @format A tibble with 32 rows and the following columns:
256+
#' @format A tibble with 32 rows and the columns:
256257
#' \describe{
257-
#' \item{material}{\code{character}. Amendment material name.}
258-
#' \item{cn_min, cn_max, cn_avg}{\code{numeric}. Carbon-to-nitrogen ratio
259-
#' range and average.}
260-
#' \item{c_pct}{\code{numeric}. Assumed carbon content (percent).}
261-
#' \item{n_pct}{\code{numeric}. Total nitrogen content (percent).}
262-
#' \item{pan_pct}{\code{numeric}. Plant-available nitrogen after 4 weeks
263-
#' (percent). Negative values indicate N immobilization.}
264-
#' \item{n_class}{\code{character}. "LOWER" or "HIGHER" N content class.}
265-
#' \item{app_rate_min, app_rate_max}{\code{numeric}. Application rate range
266-
#' (lbs/acre).}
267-
#' \item{total_c_min_lbs_acre, total_c_max_lbs_acre}{\code{numeric}.
268-
#' Total carbon applied (lbs C/acre).}
269-
#' \item{total_n_min_lbs_acre, total_n_max_lbs_acre}{\code{numeric}.
270-
#' Total nitrogen applied (lbs N/acre).}
271-
#' \item{total_c_min_g_m2, total_c_max_g_m2}{\code{numeric}.
272-
#' Total carbon in SI units (g C/m\eqn{^2}).}
273-
#' \item{total_n_min_g_m2, total_n_max_g_m2}{\code{numeric}.
274-
#' Total nitrogen in SI units (g N/m\eqn{^2}).}
275-
#' \item{source}{\code{character}. Short citation for the data source.}
258+
#' \item{material}{Material name.}
259+
#' \item{material_class}{CalRecycle feedstock class
260+
#' (14 CCR section 17852): one of \code{"ag"}, \code{"food"},
261+
#' \code{"green"}, \code{"wood"}, \code{"yard"}, \code{"biosolids"}.}
262+
#' \item{cn_min, cn_max, cn_avg}{C:N ratio range.}
263+
#' \item{n_pct}{Total N (percent of dry mass).}
264+
#' \item{pan_pct}{Plant available N at 4 weeks (percent of total N).
265+
#' Negative values indicate net immobilization.}
266+
#' \item{n_class}{N tier reported in the source (\code{"LOWER"} or
267+
#' \code{"HIGHER"}).}
268+
#' \item{source}{Short citation.}
276269
#' }
277270
#'
278271
#' @source Eghball, B. Composting Manure and Other Organic Residues.
279-
#' University of Nebraska-Lincoln Extension, Publication G2222.
272+
#' University of Nebraska Lincoln Extension, Publication G2222.
280273
#' \url{https://extensionpubs.unl.edu/publication/g2222/na/html/view}
281274
#' @source Rynk, R. (ed.) Compost Production and Use in Sustainable
282275
#' Farming Systems. NC State Extension.
283276
#' \url{https://content.ces.ncsu.edu/compost-production-and-use-in-sustainable-farming-systems}
284277
#'
285-
#' @seealso \code{\link{look_up_ca_compost_amendment}} for looking up
286-
#' amendments by material name.
287-
#' \code{\link{look_up_fertilizer_components}} for fertilizer nutrient
288-
#' composition (N/C fractions) from the SWAT/DayCent database.
289-
"ca_compost_amendment"
278+
#' @seealso \code{\link{ca_organic_amendment_app_rate}}.
279+
#' \code{\link{look_up_ca_organic_amendment}}.
280+
"ca_organic_amendment_properties"
281+
282+
#' California organic amendment application rates
283+
#'
284+
#' Recommended application rates for each material in
285+
#' \code{\link{ca_organic_amendment_properties}}, broken out by crop
286+
#' structure (row crops vs orchards). The two rate sets are identical
287+
#' for most materials in the source, but a handful of N rich materials
288+
#' (Blood meal, poultry manure) differ between row and tree applications.
289+
#'
290+
#' @format A tibble with 64 rows (32 materials x 2 crop structures) and
291+
#' the columns:
292+
#' \describe{
293+
#' \item{material}{Material name. Joins to
294+
#' \code{\link{ca_organic_amendment_properties}}.}
295+
#' \item{crop_structure}{\code{"rows"} for annual row crops,
296+
#' \code{"trees"} for perennial orchards.}
297+
#' \item{app_rate_min, app_rate_max}{Amendment application rate range
298+
#' (lbs of amendment / acre).}
299+
#' \item{total_n_min_lbs_acre, total_n_max_lbs_acre}{Total N delivered
300+
#' at those rates (lbs N / acre).}
301+
#' \item{source}{Short citation.}
302+
#' \item{total_n_min_g_m2, total_n_max_g_m2}{Same N range in SI units
303+
#' (g N / m\eqn{^2}).}
304+
#' }
305+
#'
306+
#' @source Eghball, B. Composting Manure and Other Organic Residues.
307+
#' University of Nebraska Lincoln Extension, Publication G2222.
308+
#' @source Rynk, R. (ed.) Compost Production and Use in Sustainable
309+
#' Farming Systems. NC State Extension.
310+
#'
311+
#' @seealso \code{\link{ca_organic_amendment_properties}}.
312+
#' \code{\link{look_up_ca_organic_amendment}}.
313+
"ca_organic_amendment_app_rate"
290314

291315
#' Crop-specific rooting depths and water-depletion thresholds
292316
#'

modules/data.land/R/look_up_ca_n_rate.R

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' way forward. California Agriculture, 67(1).
2323
#' \url{https://escholarship.org/uc/item/5mk2q1sm}
2424
#' @source Meyer, R. D., Marcum, D. B., Orloff, S. B., & Schmierer, J. L.
25-
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8296.
25+
#' (2007). Alfalfa fertilization strategies. UC ANR Publication 8292.
2626
#'
2727
#' @seealso [look_up_fertilizer_components()] for fertilizer nutrient
2828
#' composition (N/C fractions) from the SWAT/DayCent database.
@@ -100,10 +100,12 @@ look_up_ca_n_rate <- function(
100100
}
101101

102102

103-
#' Look up California compost amendment properties
103+
#' Look up California organic amendment properties
104104
#'
105105
#' Returns properties of organic amendment materials including carbon and
106106
#' nitrogen content, C:N ratio, and plant-available nitrogen (PAN).
107+
#' Application rates live in
108+
#' \code{\link{ca_organic_amendment_app_rate}}; join on \code{material}.
107109
#'
108110
#' Matching is case-insensitive. Exact matches are returned directly.
109111
#' If no exact match is found, partial matching suggests possible materials.
@@ -117,10 +119,8 @@ look_up_ca_n_rate <- function(
117119
#' @param aggregate Character, one of "none" (default) or "mean".
118120
#' If "mean", rows for the same material are averaged into a single row.
119121
#'
120-
#' @return A tibble with columns: `material`, `cn_min`, `cn_max`,
121-
#' `cn_avg`, `c_pct`, `n_pct`, `pan_pct`, `n_class`,
122-
#' `total_c_min_g_m2`, `total_c_max_g_m2`,
123-
#' `total_n_min_g_m2`, `total_n_max_g_m2`, `source`.
122+
#' @return A tibble with columns: `material`, `material_class`,
123+
#' `cn_min`, `cn_max`, `cn_avg`, `n_pct`, `pan_pct`, `n_class`, `source`.
124124
#' Returns an empty tibble (with a warning) if no match is found.
125125
#'
126126
#' @source Eghball, B. Composting Manure and Other Organic Residues.
@@ -132,21 +132,22 @@ look_up_ca_n_rate <- function(
132132
#'
133133
#' @seealso [look_up_fertilizer_components()] for fertilizer nutrient
134134
#' composition (N/C fractions) from the SWAT/DayCent database.
135-
#' [ca_compost_amendment] for the underlying dataset.
135+
#' [ca_organic_amendment_properties] for the underlying dataset.
136+
#' [ca_organic_amendment_app_rate] for the matching application rates.
136137
#'
137138
#' @examples
138-
#' look_up_ca_compost_amendment("Cow manure")
139-
#' look_up_ca_compost_amendment("Cow manure", aggregate = "mean")
140-
#' look_up_ca_compost_amendment("Poultry litter", n_class = "LOWER")
139+
#' look_up_ca_organic_amendment("Cow manure")
140+
#' look_up_ca_organic_amendment("Cow manure", aggregate = "mean")
141+
#' look_up_ca_organic_amendment("Poultry litter", n_class = "LOWER")
141142
#'
142143
#' @export
143-
look_up_ca_compost_amendment <- function(
144+
look_up_ca_organic_amendment <- function(
144145
material,
145146
n_class = NULL,
146147
aggregate = c("none", "mean")
147148
) {
148149
aggregate <- match.arg(aggregate)
149-
dat <- PEcAn.data.land::ca_compost_amendment
150+
dat <- PEcAn.data.land::ca_organic_amendment_properties
150151

151152
if (!is.null(n_class)) {
152153
dat <- dat |>
@@ -170,37 +171,33 @@ look_up_ca_compost_amendment <- function(
170171
)
171172
} else {
172173
PEcAn.logger::logger.warn(
173-
"No compost amendment found for material '", material, "'"
174+
"No organic amendment found for material '", material, "'"
174175
)
175176
}
176177
return(dplyr::tibble(
177-
material = character(), cn_min = numeric(), cn_max = numeric(),
178-
cn_avg = numeric(), c_pct = numeric(),
178+
material = character(), material_class = character(),
179+
cn_min = numeric(), cn_max = numeric(), cn_avg = numeric(),
179180
n_pct = numeric(), pan_pct = numeric(), n_class = character(),
180-
total_c_min_g_m2 = numeric(), total_c_max_g_m2 = numeric(),
181-
total_n_min_g_m2 = numeric(), total_n_max_g_m2 = numeric(),
182181
source = character()
183182
))
184183
}
185184

186185
out <- result |>
187186
dplyr::select(
188-
"material", "cn_min", "cn_max", "cn_avg",
189-
"c_pct", "n_pct", "pan_pct", "n_class",
190-
"total_c_min_g_m2", "total_c_max_g_m2",
191-
"total_n_min_g_m2", "total_n_max_g_m2",
187+
"material", "material_class",
188+
"cn_min", "cn_max", "cn_avg",
189+
"n_pct", "pan_pct", "n_class",
192190
"source"
193191
)
194192

195193
if (aggregate == "mean" && nrow(out) > 1) {
196194
numeric_cols <- c(
197-
"cn_min", "cn_max", "cn_avg", "c_pct", "n_pct", "pan_pct",
198-
"total_c_min_g_m2", "total_c_max_g_m2",
199-
"total_n_min_g_m2", "total_n_max_g_m2"
195+
"cn_min", "cn_max", "cn_avg", "n_pct", "pan_pct"
200196
)
201197
out <- out |>
202198
dplyr::summarize(
203199
dplyr::across(dplyr::all_of(numeric_cols), mean),
200+
material_class = dplyr::first(.data$material_class),
204201
n_class = dplyr::first(.data$n_class),
205202
source = paste(unique(.data$source), collapse = "; "),
206203
.by = "material"

0 commit comments

Comments
 (0)