-
Notifications
You must be signed in to change notification settings - Fork 307
SIPNET workflow for restarting with events #3919
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
ashiklom
wants to merge
77
commits into
PecanProject:develop
Choose a base branch
from
ashiklom:sipnet-restart-workflow
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
77 commits
Select commit
Hold shift + click to select a range
9fe0165
first draft of fn to parse restart dates out of event files
infotroph 4708176
Update modules/data.land/tests/testthat/test-events_to_crop_cycle_sta…
infotroph d8df7d0
require crop id in planting and harvest; add docs on event properties
infotroph 24db912
right, we said optional for harvest
infotroph 7d145c8
changelog
infotroph 67e055d
WIP changes
ashiklom dac5a9e
split prepare events from run workflow
ashiklom 175f15a
wip changes
ashiklom a97a946
remove .Renviron
ashiklom 4174200
sipnet output workaround
ashiklom 236fb4a
pixi dependencies
ashiklom b093d75
crop --> crop_code for parsing crop cycles
ashiklom c47817c
working run-sipnet workflow
ashiklom 4bf352f
add cdo and r-stars to pixi environment
ashiklom fc55b75
workflow runs with outputs concatenated
ashiklom c33de6c
fix syntax for model restarts
ashiklom a68f8cd
working restart workflow
ashiklom 964b174
WIP PFT configuration
ashiklom 0cf8782
ensemble restart workflow
ashiklom 3cc9171
move to root workflows dir
ashiklom 5e8a404
refactor settings creation into own file
ashiklom f0b07c7
pull run_sipnet_segmented into own function
ashiklom 0df2bbc
update plotting code
ashiklom 2b4bf9e
support event ensembles
ashiklom e3cf5fb
add README
ashiklom 1505297
sipnet: make sure trait.values is a list
ashiklom f33d822
sipnet: coerce start/end time to datetime
ashiklom 0e4cb63
use real harvest events
ashiklom d155df7
allow prepare-events to work without irrigation
ashiklom cb5cc1c
update met paths to use xxN_yy.yE -type naming
ashiklom 22bc879
put all settings logic into prepare-settings
ashiklom d1d8252
better plotting
ashiklom 4f9781c
bugfix handling of trait.values
ashiklom 2c9521d
pixi updates + script to find winter crops
ashiklom 959ed7b
better variable list handling in plots
ashiklom f2d384d
fix start/end handling & interaction with segments
ashiklom 9a378cb
simplify crew config
ashiklom 67b1039
add `combine_sipnet_out`; document new split funcs
ashiklom df8f712
write new job.sh instead of actually doing runs
ashiklom b7fac24
bugfix model2netcdf.sipnet
ashiklom 546ee44
complete more pecanic workflow
ashiklom c0317a4
grepv --> grep(..., values = TRUE)
ashiklom 390e5d8
bugfix: seq_along --> seq_len
ashiklom ea4ca66
typo extra file.path
ashiklom dc4e8bb
More robust segment logic
ashiklom 8ab19bd
crop -> crop_code in tests
ashiklom 7f03d04
outpath should be NULL, not FALSE
ashiklom 10eec01
better docs + warnings for sipnet trait.values
ashiklom c31c63b
comment about file sorting
ashiklom d6555db
warn on non-alternating harvest-planting cycles
ashiklom 2173db9
remove pixi and WIP files
ashiklom 11fa863
better combine_sipnet_out docs
ashiklom 2ce339e
add todo for crop2pft
ashiklom 3843f12
option to force reruns of segments (default=FALSE)
ashiklom 2756786
set pft_dir for BU SCC
ashiklom 61aa302
Merge branch 'develop' into sipnet-restart-workflow
ashiklom f720c3d
Merge remote-tracking branch 'origin/develop' into sipnet-restart-wor…
ashiklom 3ea3b2b
drop "sipnet only takes one PFT" from warning
ashiklom 53f2516
update sipnet configs docs
ashiklom 0b3ac45
split inputs consistently is < end.time, not <=
ashiklom 3ab8def
downgrade datetime coercion message to debug
ashiklom 691e7d5
change inputs -> results to avoid confusion
ashiklom 617b2fe
various R CMD check fixes
ashiklom e49e7e8
fix split inputs tests with new structure
ashiklom 79952c4
fix events_to_crop_cycle_starts tests
ashiklom 3f6ea0d
fix sipnet split_input tests
ashiklom 464acf7
more rcheck fixes
ashiklom 7456de0
revert setting default ensemble method
ashiklom a40d0b2
add tests for splitting sipnet events
ashiklom 0abbbf7
fix: write_events.SIPNET actually sorts by date
ashiklom f061e09
continue runs to end of year
ashiklom 6554a6b
!(length > 0) --> length == 0
ashiklom d5c359e
run in whole-year chunks
ashiklom 453fc3b
generate dependencies (unrelated - data.atmosphere)
ashiklom 7702281
remove warning for duplicate harvest/planting
ashiklom a5dae48
Revert temp changes to data.atmosphere DESCRIPTION
ashiklom 81e49dc
.data predicate in crop cycle starts
ashiklom 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
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env Rscript | ||
|
|
||
| #' Combine a bunch of `sipnet.out` files into a single file | ||
| #' | ||
| #' @param directory Parent directory to search for `sipnet.out` files. You must | ||
| #' provide either this or an explicit vector of `files`. | ||
| #' @param outfile File to which combined `sipnet.out` will be written | ||
| #' @param files Optional vector of paths to files to combine. All must be | ||
| #' readable with [read_sipnet_out()]. If `NULL` (default), looks for files | ||
| #' named `sipnet.out` in `directory` and its subdirectories, recursively. | ||
| #' | ||
| #' @return `outfile` (path to output file), invisibly | ||
| #' @export | ||
| combine_sipnet_out <- function(directory, outfile, files = NULL) { | ||
| if (missing(directory) && is.null(files)) { | ||
| PEcAn.logger::logger.severe("Must provide either `directory` or `files`") | ||
| } | ||
| if (is.null(files)) { | ||
| # NOTE that this expects file paths (including parent directories) to be | ||
| # lexicographically sorted. For the common case of segmented SIPNET runs, | ||
| # the parent directories are named `segment_001`, `segment_002`, etc., so | ||
| # this will work automatically. | ||
| # If you don't want to make this assumption, or have a custom sort order, | ||
| # pass `files` directly to this function. | ||
| files <- sort(list.files(directory, "sipnet\\.out", full.names = TRUE, recursive = TRUE)) | ||
| } | ||
| if (length(files) == 0) { | ||
| PEcAn.logger::logger.severe("No files provided; nothing to combine.") | ||
| } | ||
| flist <- lapply(files, read_sipnet_out) | ||
| combined <- do.call(rbind.data.frame, flist) | ||
|
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. Potential FUTURE enhancement: Provide an option to add a column with a filename or other source identifier, so that we could pipe output from directories full of sipnet.out straight into a multi-site/run netCDF without needing to write the plaintext back out in between. |
||
| # Mimic the SIPNET fixed-width right-aligned format | ||
| combined_fwf <- format(combined, justify = "right") | ||
| utils::write.table(combined_fwf, outfile, row.names = FALSE, col.names = TRUE, quote = FALSE, sep = " ") | ||
| invisible(outfile) | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #' Read `sipnet.out` file to `data.frame` | ||
| #' | ||
| #' @param sipnet_out_file Path to `sipnet.out` file | ||
| #' | ||
| #' @return `data.frame` of SIPNET output | ||
| read_sipnet_out <- function(sipnet_out_file) { | ||
| # SIPNET v1 had a "Notes" comment line before the header; v2 removed it. | ||
| # if the first line starts with "year", there is no Notes line. | ||
| first_line <- readLines(sipnet_out_file, n = 1) | ||
| skip_n <- if (grepl("^year", first_line)) 0 else 1 | ||
| # Temporary workaround until | ||
| # https://github.com/PecanProject/sipnet/issues/304 is resolved. | ||
| sipnet_output <- tryCatch({ | ||
| utils::read.table(sipnet_out_file, header = TRUE, skip = skip_n, sep = "") | ||
| }, error = function(err) { | ||
| PEcAn.logger::logger.warn( | ||
| "Failed to read using `read.table`. ", | ||
| "Trying to parse output manually." | ||
| ) | ||
| raw_lines <- readLines(sipnet_out_file) | ||
| raw_header <- raw_lines[[1 + skip_n]] | ||
| raw_body <- utils::tail(raw_lines, -(1 + skip_n)) | ||
| # SIPNET output is right-aligned with the column names in the header. | ||
| # We use this to figure out where the numbers end if there are no spaces. | ||
| token_matches <- gregexpr("\\S+", raw_header, perl = TRUE) | ||
| proc_header <- regmatches(raw_header, token_matches)[[1]] | ||
| col_ends <- token_matches[[1]] + attr(token_matches[[1]], "match.length") - 1 | ||
| col_starts <- c(1, utils::head(col_ends, -1) + 1) | ||
| col_widths <- col_ends - col_starts + 1 | ||
| result <- utils::read.fwf( | ||
| textConnection(raw_body), | ||
| widths = col_widths, | ||
| col.names = proc_header, | ||
| na.strings = c("nan", "-nan") | ||
| ) | ||
| result[] <- lapply(result, as.numeric) | ||
| result | ||
| }) | ||
| sipnet_output | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.