Tillage scripts to build transition matrices - #4049
Conversation
| library(data.table) | ||
| library(arrow) | ||
|
|
||
| setwd("/projectnb/dietzelab/ananyak") |
There was a problem hiding this comment.
I'd either drop this from the committed code, or comment it out and add a comment about where this script is assumed to be run from. Ideally, the code should use global paths, not local paths, so it shouldn't matter what the pwd is set to.
| setwd("/projectnb/dietzelab/ananyak") | ||
|
|
||
| #functions to make consistent transition matrices and formats | ||
| source("/projectnb/dietzelab/ananyak/transition_functions.R") |
There was a problem hiding this comment.
Is this script part of pecan or just local on the SCC? If local, it needs to be in the PR. If it's already in PEcAn, then update the "source" to point to where it is in the PEcAn hierarchy (to do so you may need to either use system.file [preferred] or define a user-specified file path variable for where their local pecan install is located).
| #functions to make consistent transition matrices and formats | ||
| source("/projectnb/dietzelab/ananyak/transition_functions.R") | ||
|
|
||
| ##directories to load full data files |
There was a problem hiding this comment.
needs more documentation of what these are and how a user should set them if they're not running locally
|
|
||
| setorder(tillage, parcel_id, year) | ||
|
|
||
| tillage[, till_class := fifelse( ndti_pct_change >= 0 & ndti_pct_change < 30, "no_till", |
There was a problem hiding this comment.
I'd recommend setting the thresholds as variables earlier in the code, rather than hard coding them here
| states_all = states, | ||
| group_cols = c("county")) | ||
|
|
||
| dir.create("county_till_matrices", showWarnings = FALSE) |
There was a problem hiding this comment.
I'd switch "county_till_matrices" to a variable (e.g. outdir) that's defined earlier in the script where you're setting other paths and then use that variable here and in the write.csv below. User should be able to save these outputs wherever they want
The file 'tillage.R' loads the data from the event files and creates simple 3x3 till class transition matrices for each county. The till classes are separated into 0-30 = no till, 30-69 = low till, 70+ = high till. The transition matrices are then used in the add_transition_matrix branch to predict future till classes with the magic scenario sheets.