feat(data.land): Add fraction_urea_n column to fertilizer_composition_data (#3963) - #4047
ANAMASGARD wants to merge 3 commits into
Conversation
- Add fraction_urea_n column (default 0) to the data table - Re-encode urea: move 0.46 from fraction_nh3_n to fraction_urea_n - Re-encode 46_00_00: move 0.46 from fraction_no3_n to fraction_urea_n - Re-encode uan_32: move 0.165 from fraction_organic_n to fraction_urea_n, zero out fraction_c and cn_ratio (urea-C no longer tracked) - Update look_up_fertilizer_components() to return UREA_N - Update documentation and tests - Use distinct(name) to let custom overrides cleanly replace SWAT rows Fixes PecanProject#3963
There was a problem hiding this comment.
DO NOT MERGE BEFORE SEPT 30, 2026 to avoid breaking anything before an important deadline. Or, make sure downstream consumers handle urea correctly.
First priority - decide how PEcAn should handle UREA (I like the idea but want to confirm logic + downstream functionality). Specifically, before merging, write.events.SIPNET needs to be updated to handle this (i.e. by converting it directly to minN). I think that is the only current downstream issue, but it is worth a search.
|
|
||
| convert_swat_fert_table_to_pkg_df <- function() { | ||
| fertilizer.frt <- "https://raw.githubusercontent.com/swat-model/swatplus/refs/heads/main/data/Osu_1hru/fertilizer.frt" | ||
| fertilizer.frt <- "https://raw.githubusercontent.com/swat-model/swatplus/main/refdata/Ames_sub1/fertilizer.frt" |
There was a problem hiding this comment.
what is the rationale for this change? it removes org_compost
| RoxygenNote: 7.3.3 | ||
| X-schema.org-keywords: soil-data, vegetation-data, land-cover | ||
| Config/roxygen2/version: 8.0.0 |
There was a problem hiding this comment.
This change is due to roxygen2 v 8.x changing how it stores Roxygen version metadata.
This is a minor annoyance that causes CI build error.
Easiest, but fragile, fix is to revert this change.
A more robust fix is to install and use roxygen2 v 7.3.3, and pin to this version.
remotes::install_version("roxygen2", version = "7.3.3", upgrade = "never")Currently,
make documentwill fail if the wrong version is installed.devtools::document()outside of make can create a diff like this.
I've proposed adding the installation code to a make document error message in #4108
Fixes #3963
Context
The
fertilizer_composition_datatable lacked a dedicated column for urea nitrogen (urea-N), forcing developers to inconsistently shoehorn urea data into other fields:urea: encoded infraction_nh3_n46_00_00: encoded infraction_no3_nuan_32: encoded infraction_organic_nThis PR establishes consistency by creating a clean
fraction_urea_ncolumn and updating all affected entries without altering the total nitrogen budget per row.🛠️ Changes
1. Data Processing (
data-raw/create_fertilizer_data.R)fraction_urea_n = 0by default inside the SWAT parsing pipeline.tribblematrix with the new column definition.urea,46_00_00, anduan_32rows so their values live insidefraction_urea_n.bind_rows(custom, SWAT) |> distinct(name, .keep_all = TRUE)to guarantee that custom overrides cleanly replace legacy SWAT rows.2. Query Routine (
R/look_up_fertilizer_components.R)UREA_N = round(amount * .data$fraction_urea_n)inside the main lookup path.UREA_N = 0inside fallback return tracks (NN-PP-KK format parser and user-specified organic fraction overrides) to protect backward-compatibility.dplyr::select()strings to map the extra list item.3. Documentation & Tests (
R/data.R,tests/)roxygen2blocks and regenerated package documentation files (.Rd) and the binary data asset (.rda).UREA_N.uan_32and46_00_00.✅ Verification Proof
All 9 local unit tests pass cleanly on Fedora with zero errors or regressions:

Post-Migration Table State:
