-
Notifications
You must be signed in to change notification settings - Fork 242
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
initial revisions to write_params_ctsm function #2365
Conversation
@dlebauer why does this function name use underscores instead of periods? |
@KristinaRiemer Apologies if someone already answered this offline, and additional apologies for the long-winded answer, but... R uses dots in function names as part of its S3 method system, which allows functions of the same name to do different things for different objects. For example, seq(1, 5)
#> [1] 1 2 3 4 5
seq(as.Date("2010-01-01"), as.Date("2010-02-01"), by = "3 days")
#> [1] "2010-01-01" "2010-01-04" "2010-01-07" "2010-01-10" "2010-01-13"
#> [6] "2010-01-16" "2010-01-19" "2010-01-22" "2010-01-25" "2010-01-28"
#> [11] "2010-01-31" ...because under the hood, it calls In general, the S3 method system uses the naming convention Unfortunately, in what I think is arguably the single worst design decision in R, this only happens when methods have been registered; otherwise, R will let you put as many dots in object names as you want. This can lead to ambiguity; for instance, is data <- function(...) UseMethod("data")
x <- structure(list(x = 1, y = 2), class = "frame")
class(x)
#> [1] "frame"
data(x)
#> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors): cannot coerce class '"frame"' to a data.frame
t <- function(...) UseMethod("t")
y <- structure(5, class = "test")
t(y)
#> Error in t.test.default(y): not enough 'x' observations In both cases, we end up unintentionally calling So, in general, that's why we avoid dots in function names. |
@ashiklom that's a great explanation, thanks for taking the time! I think I knew vaguely that using dots when naming functions was tricky, but I didn't know why. As a followup that, some of the Pecan functions have dots in them. Are they using the S3 system? All of the models in Pecan have write.config functions. So for write.config.ED2, is ED2 the class and write.config the function? |
No, those aren't S3 methods, but rather a legacy of sloppy development. We've kept them around as long as we have for backwards compatibility -- i.e. to avoid breaking all the external custom scripts people have written that use those functions. In fact, replacing In the meantime, trying to change these names may get you yelled at by your supervisor 😜 |
Gotcha! Okay, that really addresses my confusion about the inconsistency with using dots vs underscores. And now I know more about how/when to use dots. Thank so much! |
Looking for feedback on this function now. A couple of things to pay attention to:
|
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.
Looks OK to me, but I haven't actually tested it. Might not be a bad idea for someone with more knowledge of CTSM to take a look.
Eventually, it would be good to add a unit test for this, but that shouldn't hold up this PR.
|
||
write_params_ctsm <- | ||
function(defaults = system.file('clm5_params.c171117_0001.nc', package = 'PEcAn.CTSM'), |
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 would instead advocate that we use a refrun script, like the one I wrote for the Docker, that places the clm param file in the refrun directory such that we have the correct version in the refrun directory. Then we grab the default file from that directory instead of the pecan package directory
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.
where we would have something like:
export CLM_PARAM_FILE_PATH={path to cesm datasets/lnd/clm2/}
export CLM_PARAM_FILE=clm5_params.c171117_0001.nc /new/run/dir
in the create refrun script for the Docker image and then the param file will be in that dir on the host machine
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.
@serbinsh I don't think I quite understand this. I've looked over your example, but that is part of creating a case for a CLM run, which is not what we want to do here?
So we want to have a shell script with the two export
lines (in models/ctsm?). This will indicate where the initial CLM parameter file is, which will not be in the Pecan repository but will only exists as a host machine file? Will it be an "inputs"-type file like in Bety? And will that shell script then be run by a Dockerfile? Which one?
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.
@KristinaRiemer please move shawn's suggestions to new PR and then this can be merged
|
||
## Copy and open default parameter files | ||
ctsm.param.default <- | ||
system.file('clm5_params.c171117_0001.nc', package = 'PEcAn.CTSM') |
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.
so we would update this as well
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.
See comments in line
Moving refrun directory conversation over to a new issue #2388. |
@serbinsh have your requested changes been addressed? |
Great, thanks @KristinaRiemer |
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 think this looks OK but need to actually try and run it with a ctsm model soon to confirm its giving us what we need! We will also need to replace the defaults netCDF with one that comes with CTSM
#' @param settings | ||
#' @param run.id | ||
#' @param local.rundir location to store copied parameter file | ||
#' @param leafC |
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 this here? copy and past issue?
Ready to merge
references #2301
Review Time Estimate
Types of changes
Checklist: