-
Notifications
You must be signed in to change notification settings - Fork 2
Notebooks for AGU 2025 sims #17
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
base: main
Are you sure you want to change the base?
Changes from all commits
868a7c6
688107e
df1fe80
a30dbf4
4e42a70
2c202ff
b9f7ea1
b8965f2
a937341
b4033e8
0a8fc17
7a926d7
67993c1
57c27c8
b92fdfd
7a4f130
1dd3c83
d0bc0e4
54495e9
5da33a9
a4665d4
dca8445
e354871
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #!/usr/bin/env Rscript | ||
|
|
||
| # Converts ERA5 meteorology data from PEcAn's standard netCDF format | ||
| # to Sipnet `clim` driver files. | ||
|
|
||
| # This is basically a thin wrapper around `met2model.SIPNET()`. | ||
| # Only the filenames are specific to ERA5 by assuming each file is named | ||
| # "ERA5.<ens_id>.<year>nc" with ens_id between 1 and 10. | ||
|
|
||
| ## --------- runtime values: change for your system and simulation --------- | ||
|
|
||
| options <- list( | ||
| optparse::make_option("--site_era5_path", | ||
| default = "data_raw/ERA5_nc", | ||
| help = paste( | ||
| "Path to your existing ERA5 data in PEcAn CF format, organized as", | ||
| "single-site, single-year netcdfs in subdirectories per ensemble member.", | ||
| "Files should be named", | ||
| "'<site_era5_path>/ERA5_<siteid>_<ensid>/ERA5.<ensid>.<year>.nc'" | ||
| ) | ||
| ), | ||
| optparse::make_option("--site_sipnet_met_path", | ||
| default = "data/ERA5_SIPNET", | ||
| help = paste( | ||
| "Output path:", | ||
| "single-site, multi-year Sipnet clim files, one per ensemble member.", | ||
| "Files will be named", | ||
| "<site_sipnet_met_path>/<siteid>/ERA5.<ensid>.<start>.<end>.clim" | ||
| ) | ||
| ), | ||
| optparse::make_option("--site_info_file", | ||
| default = "site_info.csv", | ||
| help = "CSV file with one row per location. Only the `id` column is used", | ||
| ), | ||
| optparse::make_option("--start_date", | ||
| default = "2016-01-01", | ||
| help = "Date to begin clim file", | ||
| ), | ||
| optparse::make_option("--end_date", | ||
| default = "2023-12-31", | ||
| help = "Date to end clim file", | ||
| ), | ||
| optparse::make_option("--n_cores", | ||
| default = 1L, | ||
| help = "number of CPUs to use in parallel", | ||
| ), | ||
| optparse::make_option("--parallel_strategy", | ||
| default = "multisession", | ||
| help = "Strategy for parallel conversion, passed to future::plan()", | ||
| ) | ||
| ) |> | ||
| # Show default values in help message | ||
| purrr::modify(\(x) { | ||
| x@help <- paste(x@help, "[default: %default]") | ||
| x | ||
| }) | ||
|
|
||
| args <- optparse::OptionParser(option_list = options) |> | ||
| optparse::parse_args() | ||
|
|
||
|
|
||
| # ----------- end system-specific --------------------------------- | ||
|
|
||
|
|
||
| future::plan(args$parallel_strategy, workers = args$n_cores) | ||
|
|
||
| site_info <- read.csv(args$site_info_file) | ||
| site_info$start_date <- args$start_date | ||
| site_info$end_date <- args$end_date | ||
|
|
||
|
|
||
| file_info <- site_info |> | ||
| dplyr::rename(site_id = id) |> | ||
| dplyr::cross_join(data.frame(ens_id = 1:10)) | ||
|
|
||
| if (!dir.exists(args$site_sipnet_met_path)) { | ||
| dir.create(args$site_sipnet_met_path, recursive = TRUE) | ||
| } | ||
| furrr::future_pwalk( | ||
| file_info, | ||
| function(site_id, start_date, end_date, ens_id, ...) { | ||
| PEcAn.SIPNET::met2model.SIPNET( | ||
| in.path = file.path( | ||
| args$site_era5_path, | ||
| paste("ERA5", site_id, ens_id, sep = "_") | ||
| ), | ||
| start_date = args$start_date, | ||
| end_date = args$end_date, | ||
|
Comment on lines
+81
to
+88
Contributor
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. function signature binds start_date and end_date from file_info, but lines 87-88 ignore them and use args$start_date / args$end_date instead; this works but is misleading, consider using the function parameter or removing it from the signature. (same pattern exists in 2a_grass/01_ERA5_nc_to_clim.R was this intentionally inherited?) |
||
| in.prefix = paste0("ERA5.", ens_id), | ||
| outfolder = file.path(args$site_sipnet_met_path, site_id) | ||
| ) | ||
| } | ||
| ) | ||
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.
10 met ens is hardcoded here but configurable via
--n_metin03_xml_build.Rconsider adding--n_met_ensoption here for consistencyThere 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 script is specific to ERA5, which always has ten ensemble members. I suppose it's possible someone might want to extract fewer than 10 of them, but I doubt that's common enough to need an extra command-line option.