Skip to content

Commit

Permalink
Get resolution of a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Dec 21, 2023
1 parent 4830c06 commit e13e4a5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(get_downloaded_datasets)
export(get_ice_mask)
export(get_land_mask)
export(get_mis_time_steps)
export(get_resolution)
export(get_time_bp_steps)
export(get_time_ce_steps)
export(get_time_steps)
Expand Down
30 changes: 30 additions & 0 deletions R/get_res.R
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))
}
23 changes: 23 additions & 0 deletions man/get_resolution.Rd

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

7 changes: 7 additions & 0 deletions vignettes/a0_pastclim_overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ and the available time steps can be obtained with:
get_time_bp_steps(dataset = "Example")
```

We can also query the resolution of this dataset:
```{r}
get_resolution(dataset = "Example")
```

so, the *Example" dataset only has a resolution of 1x1 degree.

For *Beyer2020* and *Krapp2021*, you can get a list of available
variables for each dataset with:

Expand Down

0 comments on commit e13e4a5

Please sign in to comment.