Skip to content

Commit

Permalink
Resolving #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKusch committed Jun 25, 2024
1 parent f2d8603 commit 31ae996
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 12 additions & 8 deletions R/CDownloadS.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#' @param TChunkSize Numeric. Number of layers to bundle in each individual download. Default is 6000 to adhere to most restrictive CDS limits: https://cds.climate.copernicus.eu/live/limits.
#' @param Cores Numeric. How many cores to use when carrying out temporal aggregation. Default is 1.
#' @param verbose Logical. Whether to print/message function progress in console or not.
#' @param Keep_Raw Logical. Whether to retain raw downloaded data or not.
#' @param Keep_Raw Logical. Whether to retain raw downloaded data or not. Default is FALSE.
#' @param Save_Final Logical. Whether to write the final SpatRaster to the hard drive. Default is TRUE.
#'
#' @importFrom tools file_path_sans_ext
#' @importFrom terra rast
Expand Down Expand Up @@ -155,7 +156,8 @@ CDownloadS <- function(Variable = NULL, # which variable
TChunkSize = 6000,
Cores = 1, # parallelisation
verbose = TRUE, # verbosity
Keep_Raw = FALSE
Keep_Raw = FALSE,
Save_Final = TRUE
){
## Catching Most Frequent Issues ===============
#--- API Credentials
Expand Down Expand Up @@ -325,12 +327,14 @@ CDownloadS <- function(Variable = NULL, # which variable
terra::metags(CDS_rast) <- Meta_vec

### write file
if(FileExtension == ".tif"){
terra::writeRaster(CDS_rast, filename = file.path(Dir, FileName))
}
if(FileExtension == ".nc"){
CDS_rast <- Meta.NC(NC = CDS_rast, FName = file.path(Dir, FileName),
Attrs = terra::metags(CDS_rast), Write = TRUE)
if(Save_Final){
if(FileExtension == ".tif"){
terra::writeRaster(CDS_rast, filename = file.path(Dir, FileName))
}
if(FileExtension == ".nc"){
CDS_rast <- Meta.NC(NC = CDS_rast, FName = file.path(Dir, FileName),
Attrs = terra::metags(CDS_rast), Write = TRUE)
}
}

### unlink temporary files
Expand Down
7 changes: 5 additions & 2 deletions man/CDownloadS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31ae996

Please sign in to comment.