-
Notifications
You must be signed in to change notification settings - Fork 287
LPJ-GUESS restart support: new write_restart, read_restart tweaks & CRU driver hooks #3533
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
Conversation
…g pipeline * implement write_restart.LPJGUESS() with binary-state update * adjust read_restart.LPJGUESS() * extend write.config.LPJGUESS() – CRU bin / misc placeholders (@CLIMATEFILE@, @miscfile@) * split_inputs.LPJGUESS(): bypass *.cru / *.cru.bin files * add template.ins placeholder @miscfile@; update pecan.ins * docs + NAMESPACE entries
mdietze
left a comment
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.
Build is failing on dplyr, so that's the key requested change
| ##' | ||
| ##' @return NONE | ||
| ##' | ||
| ##' @importFrom dplyr %>% |
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.
At this point, I'd recommend shifting to base R pipes, |>, rather than dplyr pipes, %>%, which will eliminate the need to add an additional package dependency
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 have deleted the dplyr cause we don't need it.
| #' @export | ||
| #' @examples | ||
| #' # example code | ||
| #' outdir = "/fs/data2/output//PEcAn_1000010473/out" |
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 recommend putting the example in a "donotrun" block so that the package build doesn't attempt to run this code, which will fail on the Github cloud which doesn't have access to any of these paths and files
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.
Also, the example code doesn't actually show how to call the function, which is what should go in an example
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.
Fixed it.
models/lpjguess/R/read_state.R
Outdated
| #' @param if_else_check Optional. A logical value indicating whether to check for if/else blocks (default is FALSE). | ||
| #' @export | ||
| #' @return A numeric value indicating the line number of the matching closing bracket. | ||
| #' @keywords internal |
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.
Why does this function have the keyword "internal" but also "@export", which makes it an exported (i.e. external) function
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.
Deleted the @keywords internal.
models/lpjguess/R/read_state.R
Outdated
| #' @param ... Parts of a nested list path (e.g., "Gridcell", "Stand", 1, "Patch", 2) | ||
| #' @return A single string key like "Gridcell/Stand/1/Patch/2" | ||
| #' @keywords internal | ||
| make_key <- function(...) paste(..., sep = "/") |
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.
How is this function different from file.path?
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.
Good point. I forgot file.path can also set fsep as "/"
| # when using cru input, lpjguess will not use these clim files | ||
| cru.file <- settings$run$inputs$met$path | ||
| misc.file <- sub("\\.bin$", "misc.bin", cru.file) | ||
| guessins <- gsub("@SOIL_FILE@", cru.file, guessins) |
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.
Why is the met data path being assigned to tag named @SOIL_FILE@? This is very unintuitive and suggests that the guessins template needs updating
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.
This is a legacy from when we used NetCDF input, where met and soil data were separate and @SOIL_FILE@ pointed to the soil input.
Now that we’ve switched to CRU input, the .cru.bin file actually provides both met and soil data, so we reused @SOIL_FILE@ for simplicity.
You're right though — renaming the placeholder to something like @MET_AND_SOIL_FILE@ or @CRU_FILE@ would be more intuitive and better documented. I can update the template accordingly.
| guessins <- gsub("@SOIL_FILE@", soil.file, guessins) | ||
| # # write soil file path | ||
| # # when using cru input, it's also climate file | ||
| # soil.file <- settings$run$inputs$soil$path |
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.
Similarly, curious why the code setting the soils data is commented out. Is this just temporary? Presumably we'll want PEcAn to have the ability to pass in site-specific soil information.
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.
Yes, it's temporary. We’ve switched to CRU input, and the .cru.bin file actually provides both met and soil data.
| file.path(outdir, runid, paste0("lpjguess.", as.Date(start.time), ".out"))) | ||
| system(paste("rm", file.path(rundir, runid, "lpjguess.clim"))) | ||
| } else { | ||
| print(paste("Files not renamed -- Need to rerun timestep", start.time, "before next time step")) |
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.
- this is a surprising flag to post in response to a boolean input flag that is set by the user
- it's also surprising that a flag that tells you to rerun a timestep doesn't stop the code
- error messages should use the PEcAn.logger package
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.
Thanks — you're right that the logic here was misleading. I've replaced the print() with logger.severe() and now explicitly stop() if RENAME == FALSE.
|
|
||
|
|
||
|
|
||
| ## ---- Build PFT parameter table from new.params ---- |
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.
Are these parameters that are needed to be able to write the restart file (e.g. convert new.state to model specific outputs) or just to parameters needed to write the param file? Presumably the latter has not changed from what was written during write.configs. For the former, the custom has been to pass these through new.params. It makes me nervous to see a whole bunch of parameters hard-coded in write_restart
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.
Short-term method for testing.
models/lpjguess/inst/pecan.ins
Outdated
| run_peatland 1 ! whether to simulate peatland (1) or not (0) | ||
|
|
||
| @@@@@ Remove in PalEON version @@@@@ | ||
| ! Remove in PalEON version |
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.
not that write.config is looking for the tag "##### Remove in PalEON version #####" not "! Remove in PalEON version" so I don't think these will be removed
7faa280
Description
This PR completes the restart workflow for the LPJ-GUESS model in PEcAn.
Motivation and Context
Review Time Estimate
Types of changes