raster_tools.Raster#
- class raster_tools.Raster(raster, _fast_path=False)[source]#
Abstraction of georeferenced raster data with lazy function evaluation.
Raster is a wrapper around xarray Datasets and DataArrays. It takes advantage of xarray’s dask integration to allow lazy loading and evaluation. It allows a pipeline of operations on underlying raster sources to be built in a lazy fashion and then evaluated effiently. Most mathematical operations have been overloaded so operations such as
z = x - y
andr = x**2
are possible.All operations on a Raster return a new Raster.
- Parameters
raster (str, Raster, xarray.DataArray, xarray.Dataset, numpy.ndarray) – The raster source to use for this Raster. If raster is a string, it is treated like a path. If raster is a Raster, a copy is made and its raster source is used. If raster is an xarray DataArray, Dataset, or numpy array, it is used as the source. Dataset objects must contain ‘raster’ and ‘mask’ variables. The dimensions of these variables are assumed to be “band”, “y”, “x”, in that order. The ‘mask’ variable must have boolean dtype.
Methods
__init__
(raster[, _fast_path])all
(*args, **kwargs)Reduce the raster to a single dask value by applying all across all bands.
any
(*args, **kwargs)Reduce the raster to a single dask value by applying any across all bands.
astype
(dtype[, warn_about_null_change])Return a copy of the Raster cast to the specified type.
Fill null-masked cells with null value.
chunk
(chunks)Rechunk the underlying raster
close
()Close the underlying source
copy
()Returns a copy of this Raster.
eval
()Compute any applied operations and return the result as new Raster.
explore
(band, *args, **kwargs)Plot the raster band on an interactive
folium
map.get_bands
(bands)Retrieve the specified bands as a new Raster.
get_chunk_bounding_boxes
([include_band])Return GeoDataFrame with the chunk bounding boxes.
Return the underlying data chunks as an array of Rasters.
Get lazy coordinate arrays, in x-y order, chunked to match data.
index
(x, y)Return the (row, col) index of the pixel at (x, y).
load
()Compute delayed operations and load the result into memory.
max
(*args, **kwargs)Reduce the raster to a single dask value by applying max across all bands.
mean
(*args, **kwargs)Reduce the raster to a single dask value by applying mean across all bands.
min
(*args, **kwargs)Reduce the raster to a single dask value by applying min across all bands.
model_predict
(model[, n_outputs])Generate a new raster using the provided model to predict new values.
plot
(*args, **kwargs)Plot the raster.
prod
(*args, **kwargs)Reduce the raster to a single dask value by applying prod across all bands.
reclassify
(remapping[, unmapped_to_null])Reclassify raster values based on a mapping.
remap_range
(mapping[, inclusivity])Remaps values based on a mapping or list of mappings.
replace_null
(value)Replaces null values with value.
reproject
([crs_or_geobox, resample_method, ...])Reproject to a new projection or resolution.
round
([decimals])Evenly round to the given number of decimals
save
(path[, no_data_value])Compute the final raster and save it to the provided location.
set_crs
(crs)Set the CRS for the underlying data.
set_null
(mask_raster)Update the raster's null pixels using the provided mask
set_null_value
(value)Sets or replaces the null value for the raster.
std
(*args, **kwargs)Reduce the raster to a single dask value by applying std across all bands.
sum
(*args, **kwargs)Reduce the raster to a single dask value by applying sum across all bands.
Returns the underlying xarray.Dataset.
Returns a boolean Raster with True at null values and False otherwise.
to_numpy
()Return the raw internal raster as a numpy array.
Convert the raster into a vector where each non-null cell is a point.
to_polygons
([neighbors])Convert the raster to a vector of polygons.
Split the raster into quadrants
to_vector
([as_polygons, neighbors])Convert the raster to a vector.
var
(*args, **kwargs)Reduce the raster to a single dask value by applying var across all bands.
where
(condition, other)Filter elements from this raster according to condition.
xy
(row, col[, offset])Return the (x, y) coordinates of the pixel at (row, col).
Attributes
The affine transformation for the raster data.
The band coordinate values.
Returns an adapter for band-wise operations on this raster
Bounds tuple (minx, miny, maxx, maxy)
The raster's CRS.
The underlying dask array of data
The dtype of the data.
GeoBox object describing the raster's grid.
Produce an array of GeoChunks that correspond to the underlying chunks in the data.
The null value mask as a dask array.
The number of bands.
The raster's null value used to fill missing or invalid entries.
The x and y cell sizes as a tuple.
The shape of the underlying raster.
The number of grid cells across all bands.
The raw internal raster as a numpy array.
The x (horizontal) coordinate values.
The underlying
xarray.DataArray
(read only)The null value mask as an xarray DataArray.
The y (vertical) coordinate values.