Description Usage Arguments Value Examples
[
allows to subset an xarray
object by its dimensions (see dim()
)
[[
allows to subset an xarray
object by measurements/variables (e.g. spectral band), either named (character) or indexed (numeric).
xar_sel_time()
allows to subset an xarray
object by a character vector of dates/times.
[[<-
allows to assign a measurement/variable (e.g. spectral band), either named (character) or indexed (numeric), to an existing xarray
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## S3 method for class 'xarray.core.dataset.Dataset'
x[i = NULL, j = NULL, k = NULL, ...]
## S3 method for class 'xarray.core.dataarray.DataArray'
x[i = NULL, j = NULL, k = NULL, ...]
## S3 method for class 'xarray.core.dataset.Dataset'
x[[...]]
## S3 method for class 'xarray.core.dataarray.DataArray'
x[[...]]
xar_sel_time(x, query, exact_match = T)
## S3 replacement method for class 'xarray.core.dataset.Dataset'
x[[...]] <- value
## S3 replacement method for class 'xarray.core.dataset.Dataset'
x$... <- value
|
x |
|
i |
numeric, first dimension index |
j |
numeric, second dimension index |
k |
numeric, third dimension index |
... |
numeric or character, index or indices by which to extract/assign (additional) elements |
query |
character vector, one or more time/date character vectors in the format of the time dimension of |
exact_match |
logical, whether to return only exact matches (default) or to search for closest elements to each element in |
value |
|
Subsetted xarray
object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | ## Not run:
library(odcr)
# connect to a database, store the Daatcube connection internally (default and recommended)
database_connect(app = "Sentinel_2")
# build a query list
lat <- 22.821
lon <- 28.518
buffer <- 0.05
query <- list(
'time' = c('2020-01', '2020-03'),
'x' = c(lon - buffer, lon + buffer),
'y' = c(lat + buffer, lat - buffer),
'output_crs' = 'epsg:6933',
'resolution' = c(-20,20)
)
# load data and return an xarray object for a query
ds <- dc_load(query = c(product = "s2_l2a", dask_chunks = dict(), query))
# return dimensions of ds
dim(ds)
# subset/index ds by time, x, y
ds[13, 11:20, 21:30]
# subset/index ds by time
ds[13,,]
# subset/index ds by variable/measurement
ds[[2]]
# or do the same with a named variable or alias
ds[["nir"]]
# subset/index by exact time vectors
xar_sel_time(ds, c("2020-01-02", "2020-01-07"))
# or find closest times/date subsets by time vectors
xar_sel_time(ds, c("2020-01-01", "2020-01-07"), exact_match = F)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.