feat(data.land): Add fraction_urea_n column to fertilizer_composition_data (#3963)#4047
Open
ANAMASGARD wants to merge 1 commit into
Open
feat(data.land): Add fraction_urea_n column to fertilizer_composition_data (#3963)#4047ANAMASGARD wants to merge 1 commit into
ANAMASGARD wants to merge 1 commit 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
