-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Get resolution of a given dataset | ||
#' | ||
#' Get the resolution of a given dataset. | ||
#' | ||
#' @param dataset string defining dataset to be downloaded (a list of possible | ||
#' values can be obtained with [list_available_datasets()]). If set to | ||
#' "custom", then a single nc file is used from "path_to_nc" | ||
#' @param path_to_nc the path to the custom nc file containing the palaeoclimate | ||
#' reconstructions. All the variables of interest need to be included in | ||
#' this file. | ||
#' @returns a vector of resolution in the x and y axes | ||
#' | ||
#' @export | ||
|
||
get_resolution <- function(dataset, path_to_nc = NULL) { | ||
check_dataset_path(dataset = dataset, path_to_nc = path_to_nc) | ||
|
||
if (is.null(path_to_nc)) { | ||
possible_files <- dataset_list_included$file_name[dataset_list_included$dataset == dataset] | ||
possible_files <- possible_files[possible_files %in% list.files(get_data_path())] | ||
# check that at least one file is available | ||
if (length(possible_files) == 0) { | ||
stop("no variable has been downloaded for this dataset yet") | ||
} | ||
path_to_nc <- file.path(get_data_path(), possible_files[1]) | ||
} | ||
|
||
climate_nc <- terra::rast(path_to_nc, subds = 1) | ||
return(terra::res(climate_nc)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters