gts provides a lightweight workflow for working with gridded
environmental arrays in R, especially data stored in netCDF files. The
package is centred on three complementary object types:
gts: gridded time-series objects;static: time-invariant gridded spatial fields such as bathymetry, shelf break, cell area, or distance to coast;grid: spatial grid objects storing geometry, masks, and associated metadata.
The package aims to make common operations on environmental grids easier and more reproducible inside R: reading and writing netCDF files, inspecting metadata, subsetting in space and time, regridding, filling missing values, computing climatologies and summaries, reshaping to tabular form, and combining point observations with gridded products.
Full documentation is available at https://roliveros-ramos.github.io/gts/.
# CRAN release
install.packages("gts")
# Development version
install.packages("remotes")
remotes::install_github("roliveros-ramos/gts")For most users, the package workflow starts with one of these functions:
read_gts()to read a gridded time-series from a netCDF file;read_static()to read a time-invariant gridded variable from a netCDF file;read_grid()ormake_grid()to import or create a spatial grid.
Lower-level constructors are also available when you already have arrays and metadata in memory:
gts()to build agtsobject from an array or an open netCDF handle;make_grid()to create a regular grid programmatically.
The package includes a few small netCDF files under inst/ncdf. After
installation, you can access them with system.file():
library(gts)
sst_file = system.file("ncdf", "sst.nc4", package = "gts")
bathy_file = system.file("ncdf", "bathymetry.nc", package = "gts")
shelf_file = system.file("ncdf", "shelfbreak.nc", package = "gts")These files are intended as quick examples:
sst.nc4: agtsobject with a time dimension;bathymetry.nc: astaticobject;shelfbreak.nc: astaticobject.
library(gts)
sst_file = system.file("ncdf", "sst.nc4", package = "gts")
bathy_file = system.file("ncdf", "bathymetry.nc", package = "gts")
shelf_file = system.file("ncdf", "shelfbreak.nc", package = "gts")
sst = read_gts(sst_file)
bathy = read_static(bathy_file)
shelfbreak = read_static(shelf_file)
grd = read_grid(sst_file)print(sst)
print(bathy)
resolution(sst)
mask(sst)
longitude(sst)
latitude(sst)# spatial subset
sst_sub = subset(sst, longitude = c(-85, -70), latitude = c(-25, -5))
# regrid to another grid
sst_regrid = regrid(sst_sub, grd)# time-series summaries
sst_t = mean(sst, by = "time")
plot(sst_t)
sst_s = sd(sst, by = "space")
plot(sst_s)
# climatology
sst_clim = climatology(sst, FUN = "mean")
plot(sst_clim, time=3)
# quantiles over time
sst_q = quantile(sst, probs = c(0.1, 0.5, 0.9))
plot(sst_q) # quantile 10% SST# static fields share much of the same interface
print(bathy)
print(shelfbreak)
area(bathy)
plot(bathy)
# arithmetic with gridded time-series objects
sst_adj = drop(sst) / sst_clim
plot(sst_adj)# long-format tables
sst_long = melt(sst)
View(sst_long)write_ncdf(sst, "sst_out.nc")
write_ncdf(bathy, "bathymetry_out.nc")
write_ncdf(grd, "grid_out.nc")- Read and write netCDF-backed gridded data.
- Work with time-varying (
gts) and time-invariant (static) gridded objects. - Store and reuse spatial grid metadata through
gridobjects. - Use familiar time-series generics such as
time(),frequency(),window(), andcycle()on gridded time-series objects. - Regrid, interpolate, subset, and fill environmental grids.
- Compute climatologies, summaries, quantiles, and vertical integrations.
- Reshape gridded objects to tabular form and merge them with point records.
# package introduction
vignette("gts")
# open the pkgdown site
browseURL("https://roliveros-ramos.github.io/gts/")Bug reports, feature requests, and documentation improvements are welcome at https://github.com/roliveros-ramos/gts/issues.
Pull requests are also welcome. Please note that gts is released with
a Contributor Code of Conduct. By contributing to this project, you
agree to abide by its terms.
