-
Notifications
You must be signed in to change notification settings - Fork 244
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
Adding the feature of ERA5 download function using the CDS API #3447
base: develop
Are you sure you want to change the base?
Conversation
…t folder that does the download.
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.
Update bookdown documentation as needed
#' | ||
#' @examples | ||
#' @author Dongchen Zhang | ||
ERA5_cds_annual_download <- function(years, months, days, times, area, variables, outdir, auto.create.key = T) { |
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.
recommend adjusting the function arguments to conform to existing patterns for met download functions. This would mean changing the name to download.ERA5_cds_annual
and changing the order of the arguments to start with outfolder, start_date, end_date
, then the spatial information, then any function-specific arguments, with required arguments coming before optional ones that have defaults.
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.
Similar to my comment on the bounding box, I'd recommend that you internally construct the API's odd format for months, days, time, etc from the start and end times
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.
#' @param months List: a list contains months to be downloaded (e.g., list("01", "02") to download files in Jan and Feb). | ||
#' @param days List: a list contains days to be downloaded (e.g., list("01", "02") to download files in the first and second days). | ||
#' @param times List: a list contains times to be downloaded (e.g., list('00:00','03:00') to download files for the times 12:00 and 3:00 am UTC). | ||
#' @param area Character: a string contains the bounding box (formatted as "North/West/South/East") to be downloaded (e.g., "85/-179/7/-20"). |
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 really odd format. Even if this is what the internal API expects, I think it would be a better design to take the bounding box as a vector of numbers and then format this string inside your 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.
Fixed.
#' @examples | ||
#' @author Dongchen Zhang | ||
ERA5_cds_annual_download <- function(years, months, days, times, area, variables, outdir, auto.create.key = T) { | ||
options(timeout=360000) |
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 make this an optional argument to the function with a default, rather than hard coding.
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.
writeLines(c( | ||
sprintf( | ||
"url: %s", | ||
getPass::getPass(msg = "Enter URL from the following link \n (https://cds.climate.copernicus.eu/api-how-to#install-the-cds-api-key):") |
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.
since getPass is in the suggests, you might add a step in the function that returns an informative error message if it isn't installed
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.
) | ||
# convert grib to nc file. | ||
nc.path <- gsub(".grib", ".nc", fname, fixed = T) | ||
cmd <- paste("grib_to_netcdf", fname, "-o", nc.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.
what ensures that this command line utility exists in the user's system? it's not in the DESCRIPTION file, nor do you seem to provide any check that the command exists or instructions on how to install it. If you add a check, I'd do it early in the function -- would be a pain to have this function fail AFTER you've done the file download.
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.
# remove previous grib file. | ||
unlink(fname) | ||
} | ||
return(nc.paths) |
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.
In keeping with PEcAn met patterns, I recommend returning a more complete results
object. Look at other met download functions to see how these are structured. You may be using this function outside of the PEcAn met workflow, but that doesn't me we want to write it so that it can't be used within the PEcAn met workflow.
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.
Description
Motivation and Context
Review Time Estimate
Types of changes
Checklist: