envir_downANDextract: Download environmental data from Copernicus services, extract...

View source: R/envir_downANDextract.R

envir_downANDextractR Documentation

Download environmental data from Copernicus services, extract variables and values, and then add them to a set of coordinates.

Description

This function takes a table of coordinates-date and makes a selectively download of data (by now, from Copernicus server). Then it adds the dowloaded values to the original table. The selectively process implies that the environmental data will be downloaded for each date (day) just for a section 'around' the coordinates. How 'around' will depend on the user (by default, it is set in 2 degrees grid).

Usage

envir_downANDextract(
  pts,
  credentials,
  datasetID,
  datasetVersion = NULL,
  service = NULL,
  vars,
  depth_range = c(5, 10),
  dx = 2,
  download = FALSE,
  outDir = "./",
  outSufix = "mercator",
  quite = FALSE,
  compression = FALSE,
  extract_method = "simple"
)

Arguments

pts

data.frame or tibble of coordinates where the user wants to add the environmental variables. See Details.

credentials

A 2-length character list or vector with credentials (user and password) to access Copernicus server.

datasetID

The dataset ID as it is specified in the Copernicus website.

datasetVersion

The dataset version as it is specified in the Copernicus website.

service

one of the available services using the service name among ['arco-geo-series', 'arco-time-series', 'omi-arco', 'static-arco', 'opendap', 'motu'] or its short name among ['geoseries', 'timeseries', 'omi-arco', 'static-arco', 'opendap', 'motu'].

vars

character vector with the names of the variables that will be accessed and added to pts.

depth_range

2-length numeric vector with the range of depths the user wants to download environmental data.

dx

numeric vector with the Size of the grid that will be used to download environmental data selectively.

download

logical if TRUE, allows to download and save the environmental data. Otherwise, each file will be downloaded as temporal file and will be deleted then.

outDir

character with the directory path where the data will be downloaded. Omitted if download=FALSE.

outSufix

character with the suffix that will be added to downloaded files. Omitted if download=FALSE.

quite

logical if TRUE, the function will return progress messages.

compression

Specify a compression level to apply on the NetCDF output file. A value of 0 means no compression, and 9 is the highest level of compression available. See Details.

extract_method

character. Method for extracting values with points ("simple" or "bilinear"). With "simple" values for the cell a point falls in are returned. With "bilinear" the returned values are interpolated from the values of the four nearest raster cells. This argument will be transmitted to extract[terra] function (method argument).

Details

pts needs to have at least three columns called lon, lat and date. date values have to be of class Date or POSIX, lon and lat must be numeric.

The environmental data will be downloaded always (so it is important to have a stable internet connection), but the user can decide whether to keep or not the files (by the use of download, outDir and outSufix arguments. If download=TRUE, the file names will preserve the ranges of the downloaded data (date, lon, lat and depth).

If service = NULL, the function will let copernicusmarine choose the default value. Usually, it should be arco-time-series but it could depend on the version.

Value

The pts object with extra columns corresponding to the selected variables.

Examples

n <- 20

set.seed(123)

pts1 <- data.frame(lon = runif(n = n, min = 53, max = 98),
                  lat = runif(n = n, min = -32, max = -2),
                  date = as.Date("2010-1-1"))

pts2 <- data.frame(lon = runif(n = n, min = 53, max = 98),
                  lat = runif(n = n, min = -32, max = -2),
                  date = seq(from = as.Date("2010-1-1"),
                             to = as.Date("2010-1-1"),
                             by = "day")[as.integer(runif(n = n, min = 1, max = 10))])

outs <- downloadEnvir(pts = pts,
                      credentials = list(username = "USERNAME", password = "PASSWORD"),
                      datasetID = "cmems_mod_glo_phy_my_0.083deg_P1D-m",
                      service = "arco-time-series",
                      vars = c("thetao", "zos"))

LuisLauM/ruisu documentation built on March 26, 2024, 8:23 a.m.