Skip to content

feat(data.land): Add fraction_urea_n column to fertilizer_composition_data (#3963)#4047

Open
ANAMASGARD wants to merge 1 commit into
PecanProject:developfrom
ANAMASGARD:feature/add-fraction-urea-n
Open

feat(data.land): Add fraction_urea_n column to fertilizer_composition_data (#3963)#4047
ANAMASGARD wants to merge 1 commit into
PecanProject:developfrom
ANAMASGARD:feature/add-fraction-urea-n

Conversation

@ANAMASGARD

Copy link
Copy Markdown
Contributor

Fixes #3963

Context

The fertilizer_composition_data table lacked a dedicated column for urea nitrogen (urea-N), forcing developers to inconsistently shoehorn urea data into other fields:

  • urea: encoded in fraction_nh3_n
  • 46_00_00: encoded in fraction_no3_n
  • uan_32: encoded in fraction_organic_n

This PR establishes consistency by creating a clean fraction_urea_n column and updating all affected entries without altering the total nitrogen budget per row.


🛠️ Changes

1. Data Processing (data-raw/create_fertilizer_data.R)

  • Added fraction_urea_n = 0 by default inside the SWAT parsing pipeline.
  • Expanded the custom fertilizer tribble matrix with the new column definition.
  • Re-encoded urea, 46_00_00, and uan_32 rows so their values live inside fraction_urea_n.
  • Used bind_rows(custom, SWAT) |> distinct(name, .keep_all = TRUE) to guarantee that custom overrides cleanly replace legacy SWAT rows.
  • Patched an out-of-date remote SWAT URL pointing to a 404 resource.

2. Query Routine (R/look_up_fertilizer_components.R)

  • Added UREA_N = round(amount * .data$fraction_urea_n) inside the main lookup path.
  • Set UREA_N = 0 inside fallback return tracks (NN-PP-KK format parser and user-specified organic fraction overrides) to protect backward-compatibility.
  • Updated internal dplyr::select() strings to map the extra list item.

3. Documentation & Tests (R/data.R, tests/)

  • Updated roxygen2 blocks and regenerated package documentation files (.Rd) and the binary data asset (.rda).
  • Updated legacy test blocks to expect the new 6-element list layout containing UREA_N.
  • Appended explicit unit test contexts verifying component data splits for uan_32 and 46_00_00.

✅ Verification Proof

All 9 local unit tests pass cleanly on Fedora with zero errors or regressions:
image

Post-Migration Table State:
image

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant