All Projects β†’ r-spatial β†’ Stars

r-spatial / Stars

Licence: apache-2.0
Spatiotemporal Arrays, Raster and Vector Data Cubes

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Stars

GeoArrays.jl
Simple geographical raster interaction built on top of ArchGDAL, GDAL and CoordinateTransformations
Stars: ✭ 42 (-88.43%)
Mutual labels:  raster, spatial
Fasterize
High performance raster conversion for modern spatial data πŸš€πŸŒβ–¦
Stars: ✭ 146 (-59.78%)
Mutual labels:  raster, spatial
belg
Boltzmann entropy of a landscape gradient
Stars: ✭ 14 (-96.14%)
Mutual labels:  raster, spatial
Landscapemetrics
Landscape Metrics for Categorical Map Patterns πŸ—ΊοΈ in R
Stars: ✭ 151 (-58.4%)
Mutual labels:  raster, spatial
spDataLarge
R package with large datasets for spatial analysis
Stars: ✭ 19 (-94.77%)
Mutual labels:  raster, spatial
Spatial pre2021
This repo has been archived. The latest version of the GIS and Spatial Analysis online book is at https://github.com/mgimond/Spatial
Stars: ✭ 88 (-75.76%)
Mutual labels:  spatial
spatialcluster
spatially-constrained clustering in R
Stars: ✭ 25 (-93.11%)
Mutual labels:  spatial
terrain
Generate contours, hillshade, Terrain RGB, slope-angle shading tiles from elevation data.
Stars: ✭ 33 (-90.91%)
Mutual labels:  raster
scanstatistics
An R package for space-time anomaly detection using scan statistics.
Stars: ✭ 41 (-88.71%)
Mutual labels:  spatial
Gdal2tiles Leaflet
Generate raster image tiles for use with leaflet.
Stars: ✭ 338 (-6.89%)
Mutual labels:  raster
XArrayAndRasterio
Experimental code for loading/saving XArray DataArrays to Geographic Rasters using rasterio
Stars: ✭ 21 (-94.21%)
Mutual labels:  raster
st-hadoop
ST-Hadoop is an open-source MapReduce extension of Hadoop designed specially to analyze your spatio-temporal data efficiently
Stars: ✭ 17 (-95.32%)
Mutual labels:  spatial
wxee
A Python interface between Earth Engine and xarray for processing time series data
Stars: ✭ 113 (-68.87%)
Mutual labels:  raster
geoblaze
Blazing Fast JavaScript Raster Processing Engine
Stars: ✭ 80 (-77.96%)
Mutual labels:  raster
malariaAtlas
An R interface to open-access malaria data, hosted by the Malaria Atlas Project.
Stars: ✭ 29 (-92.01%)
Mutual labels:  raster
Grass
GRASS GIS - free and open source Geographic Information System (GIS)
Stars: ✭ 281 (-22.59%)
Mutual labels:  raster
wdpar
Interface to the World Database on Protected Areas
Stars: ✭ 27 (-92.56%)
Mutual labels:  spatial
NLMR
πŸ“¦ R package to simulate neutral landscape models πŸ”
Stars: ✭ 57 (-84.3%)
Mutual labels:  spatial
geowombat
GeoWombat: Utilities for geospatial data
Stars: ✭ 34 (-90.63%)
Mutual labels:  raster
pixelscan
A Python library that provides functions to scan pixels on a grid in a variety of spatial patterns.
Stars: ✭ 23 (-93.66%)
Mutual labels:  spatial

Spatiotemporal Arrays: Raster and Vector Datacubes

tic codecov CRAN cran checks Downloads status

Spatiotemporal data often comes in the form of dense arrays, with space and time being array dimensions. Examples include

  • socio-economic or demographic data,
  • environmental variables monitored at fixed stations,
  • raster maps
  • time series of satellite images with multiple spectral bands,
  • spatial simulations, and
  • climate or weather model output.

This R package provides classes and methods for reading, manipulating, plotting and writing such data cubes, to the extent that there are proper formats for doing so.

Raster and vector data cubes

The canonical data cube most of us have in mind is that where two dimensions represent spatial raster dimensions, and the third time (or band), as e.g. shown here:

By data cubes however we also consider higher-dimensional cubes (hypercubes) such as a five-dimensional cube where in addition to time, spectral band and sensor form dimensions:

or lower-dimensional cubes such as a raster image:

suppressPackageStartupMessages(library(dplyr))
library(stars)
# Loading required package: abind
# Loading required package: sf
# Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
tif = system.file("tif/L7_ETMs.tif", package = "stars")
read_stars(tif) %>%
  slice(index = 1, along = "band") %>%
  plot()

Raster data do not need to be regular and aligned with North/East, and package stars supports besides regular also rotated, sheared, rectilinear and curvilinear rasters:

Vector data cubes arise when we do not have two regularly discretized spatial dimensions, but a single dimension that points to distinct spatial feature geometries, such as polygons (e.g. denoting administrative regions):

or points (e.g. denoting sensor locations):

NetCDF’s CF-convention calls this a discrete axis.

NetCDF, GDAL

stars provides two functions to read data: read_ncdf and read_stars, where the latter reads through GDAL. (In the future, both will be integrated in read_stars.) For reading NetCDF files, package RNetCDF is used, for reading through GDAL, package sf provides the binary linking to GDAL.

For vector and raster operations, stars uses as much as possible the routines available in GDAL and PROJ (e.g. st_transform, rasterize, polygonize, warp). Read more about this in the vignette on vector-raster conversions, reprojection, warping.

Out-of-memory (on-disk) rasters

Package stars provides stars_proxy objects (currently only when read through GDAL), which contain only the dimensions metadata and pointers to the files on disk. These objects work lazily: reading and processing data is postponed to the moment that pixels are really needed (at plot time, or when writing to disk), and is done at the lowest spatial resolution possible that still fulfills the resolution of the graphics device. More details are found in the stars proxy vignette.

The following methods are currently available for stars_proxy objects:

methods(class = "stars_proxy")
#  [1] [              adrop          aggregate      aperm          as.data.frame 
#  [6] c              coerce         dim            droplevels     filter        
# [11] initialize     Math           merge          mutate         Ops           
# [16] plot           predict        print          pull           select        
# [21] show           slice          slotsFromS3    split          st_apply      
# [26] st_as_stars    st_crop        st_mosaic      st_redimension st_sample     
# [31] st_set_bbox    transmute      write_stars   
# see '?methods' for accessing help and source code

Raster and vector time series analysis example

In the following, a curvilinear grid with hourly precipitation values of a hurricane is imported and the first 12 time steps are plotted:

prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars")
(prec = read_ncdf(prec_file, curvilinear = c("lon", "lat"), ignore_bounds = TRUE))
# no 'var' specified, using Total_precipitation_surface_1_Hour_Accumulation
# other available variables:
#  time_bounds, lon, lat, time
# No projection information found in nc file. 
#  Coordinate variable units found to be degrees, 
#  assuming WGS84 Lat/Lon.
# stars object with 3 dimensions and 1 attribute
# attribute(s):
#  Total_precipitation_surface_1_Hour_Accumulation [kg/m^2]
#  Min.   :  0.000                                         
#  1st Qu.:  0.000                                         
#  Median :  0.750                                         
#  Mean   :  4.143                                         
#  3rd Qu.:  4.630                                         
#  Max.   :163.750                                         
# dimension(s):
#      from  to                  offset   delta  refsys point
# x       1  87                      NA      NA  WGS 84    NA
# y       1 118                      NA      NA  WGS 84    NA
# time    1  23 2018-09-13 18:30:00 UTC 1 hours POSIXct    NA
#                              values x/y
# x    [87x118] -80.6113,...,-74.8822 [x]
# y      [87x118] 32.4413,...,37.6193 [y]
# time                           NULL    
# curvilinear grid
sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"), "nc.gpkg") %>%
  st_transform(st_crs(prec)) -> nc # transform from NAD27 to WGS84
nc_outline = st_union(st_geometry(nc))
# although coordinates are longitude/latitude, st_union assumes that they are planar
plot_hook = function() plot(nc_outline, border = 'red', add = TRUE)
prec %>%
  slice(index = 1:12, along = "time") %>%
  plot(downsample = c(5, 5, 1), hook = plot_hook)

and next, intersected with with the counties of North Carolina, where the maximum precipitation intensity was obtained per county, and plotted:

a = aggregate(prec, by = nc, FUN = max)
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
plot(a, max.plot = 23, border = 'grey', lwd = .5)

We can integrate over (reduce) time, for instance to find out when the maximum precipitation occurred. The following code finds the time index, and then the corresponding time value:

index_max = function(x) ifelse(all(is.na(x)), NA, which.max(x))
st_apply(a, "geom", index_max) %>%
  mutate(when = st_get_dimension_values(a, "time")[.$index_max]) %>%
  select(when) %>%
  plot(key.pos = 1, main = "time of maximum precipitation")

Other packages for data cubes

gdalcubes

Package gdalcubes can be used to create data cubes (or functions from them) from image collections, sets of multi-band images with varying

  • spatial resolution
  • spatial extent
  • coordinate reference systems (e.g., spread over multiple UTM zones)
  • observation times

and does this by resampling and/or aggregating over space and/or time. It reuses GDAL VRT’s and gdalwarp for spatial resampling and/or warping, and handles temporal resampling or aggregation itself.

ncdfgeom

ncdfgeom reads and writes vector data cubes from and to netcdf files in a standards-compliant way.

raster

Package raster is a powerful package for handling raster maps and stacks of raster maps both in memory and on disk, but does not address

  • non-raster time series,
  • multi-attribute rasters time series
  • rasters with mixed type attributes (e.g., numeric, logical, factor, POSIXct)
  • rectilinear or curvilinear rasters

A list of stars commands matching existing raster commands is found in this wiki. A list of translations in the opposite direction (from stars to raster) still needs to be made.

Other stars resources:

Acknowledgment

This project has been realized with financial support from the

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].