Skip to content

Tillage scripts to build transition matrices - #4049

Open
ananyak534 wants to merge 2 commits into
PecanProject:developfrom
ananyak534:tillage_scripts
Open

Tillage scripts to build transition matrices#4049
ananyak534 wants to merge 2 commits into
PecanProject:developfrom
ananyak534:tillage_scripts

Conversation

@ananyak534

Copy link
Copy Markdown
Contributor

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.

library(data.table)
library(arrow)

setwd("/projectnb/dietzelab/ananyak")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants