Raster Objects#

Constructing Rasters#

Raster(raster[, _fast_path])

Abstraction of georeferenced raster data with lazy function evaluation.

Properties#

Raster.dtype

The dtype of the data.

Raster.shape

The shape of the underlying raster.

Raster.nbands

The number of bands.

Raster.null_value

The raster's null value used to fill missing or invalid entries.

Raster.values

The raw internal raster as a numpy array.

Raster.data

The underlying dask array of data

Raster.xdata

The underlying xarray.DataArray (read only)

Raster.mask

The null value mask as a dask array.

Raster.xmask

The null value mask as an xarray DataArray.

Raster.x

The x (horizontal) coordinate values.

Raster.y

The y (vertical) coordinate values.

Raster.crs

The raster's CRS.

Raster.affine

The affine transformation for the raster data.

Raster.resolution

The x and y cell sizes as a tuple.

Raster.bounds

Bounds tuple (minx, miny, maxx, maxy)

Raster.bandwise

Returns an adapter for band-wise operations on this raster

Deprecated Properties#

Raster.pxrs

Raster.xrs

Operations#

Arithmetic and Comparison Operations#

Raster objects support all arithmetic (+, -, *, /, //, %, divmod(), **, <<, >>, &, ^, |, ~), bitwise/logical operators (&, |, ^, ~), and comparison operations (==, <, >, <=, >=, !=). Because of this, they can be used like regular scalar variables. Some examples:

  • Addition and subtraction: rs4 = rs1 + rs2 - rs3

  • Floor division: rs3 = rs1 // rs2

  • With scalars: rs3 = 1.5 * (rs1 ** (-rs2 - 2))

  • divmod: rs_div, rs_mod = divmod(rs1, rs2)

  • Bit shifting: rs2 = rs1 << 1

  • Bitwise and: rs3 = rs1 & rs2

  • Bitwise complement: rs2 = ~rs1

  • Comparison: rs_bool = rs1 >= rs2

General#

Raster.round([decimals])

Evenly round to the given number of decimals

Reductions#

Raster.all(*args, **kwargs)

Reduce the raster to a single dask value by applying all across all bands.

Raster.any(*args, **kwargs)

Reduce the raster to a single dask value by applying any across all bands.

Raster.max(*args, **kwargs)

Reduce the raster to a single dask value by applying max across all bands.

Raster.mean(*args, **kwargs)

Reduce the raster to a single dask value by applying mean across all bands.

Raster.min(*args, **kwargs)

Reduce the raster to a single dask value by applying min across all bands.

Raster.prod(*args, **kwargs)

Reduce the raster to a single dask value by applying prod across all bands.

Raster.std(*args, **kwargs)

Reduce the raster to a single dask value by applying std across all bands.

Raster.sum(*args, **kwargs)

Reduce the raster to a single dask value by applying sum across all bands.

Raster.var(*args, **kwargs)

Reduce the raster to a single dask value by applying var across all bands.

Methods#

Reorganizing#

Raster.chunk(chunks)

Rechunk the underlying raster

Extracting#

Raster.get_bands(bands)

Retrieve the specified bands as a new Raster.

Raster.get_chunk_rasters()

Return the underlying data chunks as an array of Rasters.

Raster.to_quadrants()

Split the raster into quadrants

Null Data and Remapping#

Raster.burn_mask()

Fill null-masked cells with null value.

Raster.reclassify(remapping[, unmapped_to_null])

Reclassify raster values based on a mapping.

Raster.replace_null(value)

Replaces null values with value.

Raster.remap_range(mapping[, inclusivity])

Remaps values based on a mapping or list of mappings.

Raster.set_null_value(value)

Sets or replaces the null value for the raster.

Raster.set_null(mask_raster)

Update the raster's null pixels using the provided mask

Raster.to_null_mask()

Returns a boolean Raster with True at null values and False otherwise.

Raster.where(condition, other)

Filter elements from this raster according to condition.

Contents / Conversion#

Raster.astype(dtype[, warn_about_null_change])

Return a copy of the Raster cast to the specified type.

Raster.copy()

Returns a copy of this Raster.

Raster.to_dataset()

Returns the underlying xarray.Dataset.

Raster.to_numpy()

Return the raw internal raster as a numpy array.

Raster.to_vector([as_polygons, neighbors])

Convert the raster to a vector.

Georeferencing#

Raster.index(x, y)

Return the (row, col) index of the pixel at (x, y).

Raster.set_crs(crs)

Set the CRS for the underlying data.

Raster.xy(row, col[, offset])

Return the (x, y) coordinates of the pixel at (row, col).

Warping#

Raster.reproject([crs_or_geobox, ...])

Reproject to a new projection or resolution.

Raster IO#

Raster.close()

Close the underlying source

Raster.eval()

Compute any applied operations and return the result as new Raster.

Raster.load()

Compute delayed operations and load the result into memory.

Raster.save(path[, no_data_value])

Compute the final raster and save it to the provided location.

Plotting#

Raster.explore(band, *args, **kwargs)

Plot the raster band on an interactive folium map.

Raster.plot(*args, **kwargs)

Plot the raster.

Miscellaneous#

Raster.get_chunk_bounding_boxes([include_band])

Return GeoDataFrame with the chunk bounding boxes.

Raster.get_chunked_coords()

Get lazy coordinate arrays, in x-y order, chunked to match data.

Raster.model_predict(model[, n_outputs])

Generate a new raster using the provided model to predict new values.