-
Notifications
You must be signed in to change notification settings - Fork 315
make workflow configs parseable outside R and resolve input paths from env #4082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
divine7022
wants to merge
13
commits into
PecanProject:develop
Choose a base branch
from
divine7022:n_ncc_tweaks
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b64316c
drop !expr and make input paths relative to a data root
divine7022 2b8f3bd
resolve paths from the environment and log what resolved
divine7022 9e1543f
resolve the output dir from the environment
divine7022 4bbd444
resolve the output dir from the environment
divine7022 b87a8bd
resolve the output dir from the environment
divine7022 3694b92
document running with a different data root
divine7022 0747299
drop !expr and make input paths relative to a data root
divine7022 31eb4bc
resolve paths from the environment and log what resolved
divine7022 55ce063
resolve the output dir from the environment
divine7022 1b0fa5d
resolve the output dir from the environment
divine7022 df395b5
resolve the output dir from the environment
divine7022 15b280a
document running with a different data root
divine7022 b23474e
catch try-error in the shard write guard
divine7022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,9 @@ Source: California Department of Water Resources. (2016-2023). Statewide Crop Ma | |
|
|
||
| Configuration parameters live in `config.yml`. Most setups only need: | ||
|
|
||
| - `crops_path`: the harmonized CADWR Land Use crops parquet. Override with `CCMMF_CROPS_PATH` | ||
| - `phen_dir`: the gap-filled LandIQ to MSLSP match directory, the same product the ncc workflow reads. Override with `CCMMF_PHEN_DIR` | ||
| - `ccmmf_dir`: data root the input paths are relative to. Override with `CCMMF_DIR` | ||
| - `crops_path`: gap-filled LandIQ crops table. Override with `CCMMF_CROPS_PATH` | ||
| - `phen_dir`: gap-filled LandIQ to MSLSP match. Override with `CCMMF_PHEN_DIR` | ||
| - `phen_glob`: file glob under `phen_dir` (default `assigned_year=*_gapfilled.parquet`). Override with `CCMMF_PHEN_GLOB` | ||
| - `pft_lookup_path`: crop code to PFT table, the same one the monitoring products use. Override with `CCMMF_PFT_LOOKUP` | ||
| - `pft_anchor`: phenology transition used as the anchor, per PFT. See Application timing | ||
|
|
@@ -68,6 +69,42 @@ schedule. | |
| - Only crop codes present in the crosswalk resolve to an N rate envelope. Cycles whose | ||
| code does not resolve are dropped and reported at run time. | ||
|
|
||
| # Running outside the BU cluster | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit this header to something more generic like "Config file". |
||
|
|
||
| `config.yml` is plain YAML with no R expressions, so any parser can read it. Input paths | ||
| are relative to `ccmmf_dir` and are resolved at run time; `01` logs every resolved path, | ||
| so a run's log records the configuration it actually used. | ||
|
|
||
| Three inputs are needed. They are monitoring products, not distributed with this repo: | ||
|
|
||
| | config key | what it is | | ||
| |---|---| | ||
| | `crops_path` | gap-filled LandIQ crops table, one row per parcel, year and season | | ||
| | `phen_dir` | gap-filled LandIQ to MSLSP phenology match, keyed the same way | | ||
| | `pft_lookup_path` | crop code to PFT table | | ||
|
|
||
| If they sit under one directory in the layout `config.yml` describes, point `CCMMF_DIR` at | ||
| it and nothing else changes: | ||
|
|
||
| ``` | ||
| CCMMF_DIR=/my/ccmmf FERT_PROJECT=all bash workflows/fertilization-statewide/run-statewide.sh | ||
| ``` | ||
|
|
||
| If the layout differs, override paths individually. These take precedence over | ||
| `ccmmf_dir`: | ||
|
|
||
| ``` | ||
| CCMMF_CROPS_PATH=/data/crops_all_years.parq \ | ||
| CCMMF_PHEN_DIR=/data/phenology \ | ||
| CCMMF_PFT_LOOKUP=/data/LandIQ_cropCode_lookup_table.csv \ | ||
| CCMMF_FERT_OUT=/data/events \ | ||
| FERT_PROJECT=all bash workflows/fertilization-statewide/run-statewide.sh | ||
| ``` | ||
|
|
||
| `phen_glob` can be overridden with `CCMMF_PHEN_GLOB` if the phenology files are named | ||
| differently. Inputs are required rather than optional: if one does not resolve, the run | ||
| stops and names the variable to set. | ||
|
|
||
| # Output | ||
|
|
||
| Parcel range sharded parquet at `<output_dir>/`. Columns: `parcel_id`, `ens_id` (`ens_NNN`, shared with ncc workflow), `date`, `nh4_n_kg_m2`, `no3_n_kg_m2`, `org_c_kg_m2` (zero), `org_n_kg_m2` (zero), `crop_code`. | ||
|
|
||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to check in on the second assumption above -- from a design perspective, why would we prioritize values set from the environment over values within the file. Also, why would doing so somehow make the code more portable, since you just need other code to set all those environment variables to local values, which means that you now have two different files trying to set the same configs (config.yml and the script setting the env variables). This seems redundant, confusing, and error prone. There's also no reason a config file can't have the user define a root directory as an absolute path and then define other paths as relative paths based on that root (or even to detect whether the other path is absolute or relative)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a related discussion with @hdpriest-ui yesterday - setting values in config is preferred over using environment variables for portability and reproducibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the use of environmental variables is widespread in the code so it isn't necessary or prudent to force refactoring working code in the short term.