as_cubble {cubble}R Documentation

Coerce foreign objects into a cubble object

Description

Coerce foreign objects into a cubble object

Usage

as_cubble(data, key, index, coords, ...)

## S3 method for class 'tbl_df'
as_cubble(data, key, index, coords, ...)

## S3 method for class 'sf'
as_cubble(data, key, index, ...)

## S3 method for class 'ncdf4'
as_cubble(
  data,
  key,
  index,
  coords,
  vars,
  lat_range = NULL,
  long_range = NULL,
  ...
)

## S3 method for class 'stars'
as_cubble(data, key, index, coords, ...)

## S3 method for class 'sftime'
as_cubble(data, key, index, coords, ...)

Arguments

data

an object to be converted into an cubble object. Currently support objects of classes tibble, ncdf4, stars, and sftime.

key

a character (symbol), the spatial identifier, see make_cubble()

index

a character (symbol), the temporal identifier, see make_cubble().

coords

a vector of character (symbol) of length 2, see make_cubble().

...

other arguments.

vars

a vector of variables to read in (with quote), used in as_cubble.netcdf() to select the variable to read in.

lat_range, long_range

in the syntax of seq(FROM, TO, BY) to downsample the data to read in as_cubble.netcdf().

Value

a cubble object

Examples

climate_flat %>% as_cubble(key = id, index = date, coords = c(long, lat))

# only need `coords` if create from a tsibble
dt <- climate_flat %>%  tsibble::as_tsibble(key = id, index = date)
dt %>%  as_cubble(coords = c(long, lat))

# netcdf
path <- system.file("ncdf/era5-pressure.nc", package = "cubble")
raw <- ncdf4::nc_open(path)
dt <- as_cubble(raw)
# subset degree
dt <- as_cubble(raw,vars = c("q", "z"),
                long_range = seq(113, 153, 3),
                lat_range = seq(-53, -12, 3))

## Not run: 
# stars - take a few seconds to run
tif <- system.file("tif/L7_ETMs.tif", package = "stars")
x <-  stars::read_stars(tif)
x %>% as_cubble()

## End(Not run)

# don't have to supply coords if create from a sftime
dt <- climate_flat %>%
  sf::st_as_sf(coords = c("long", "lat"), crs = sf::st_crs("OGC:CRS84")) %>%
  sftime::st_as_sftime()
dt %>% as_cubble(key = id, index = date)

[Package cubble version 0.3.0 Index]