as_cubble: Coerce foreign objects into a cubble object

View source: R/as-cubble.R

as_cubbleR 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 'data.frame'
as_cubble(data, key, index, coords, ...)

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

## 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.

crs

used in as_cubble.tbl_df() to set the crs. the data to read in as_cubble.netcdf().

dimensions

used when creating a cubble from a stars object

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

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(index = band)

## 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)

cubble documentation built on Sept. 11, 2024, 7:19 p.m.