rio_tiler.models
rio_tiler.models ¶
rio-tiler models.
BandStatistics ¶
Bases: BaseModel
Band statistics
Bounds ¶
Bases: BaseModel
Dataset Bounding box
ImageData ¶
Image Data class.
Attributes:
-
array(MaskedArray) –image values.
-
dimensions(list[str]) –list of dimension names corresponding to the array.
-
band_names(list or dict) –name of each band. Defaults to
["b1", "b2", "b3"]for 3 bands image. -
band_descriptions(list or dict) –description of each band. Defaults to
["b1", "b2", "b3"]for 3 bands image. -
bounds(BoundingBox) –bounding box of the data.
-
crs(CRS) –Coordinates Reference System of the bounds.
-
assets(list) –list of assets used to construct the data values.
-
metadata(dict) –Additional metadata. Defaults to
{}. -
nodata(NoData) –nodata value for the data.
-
dataset_statistics(list) –dataset statistics
[(min, max), (min, max)] -
cutline_mask(ndarray) –Cutline mask for the image.
-
alpha_mask(ndarray) –Alpha mask for the image.
Note: mask should be considered as PER_BAND so shape should be similar as the data
is_nd
property
¶
is_nd: bool
Return True if data has more than 3 dimensions (*leading, height, width).
_as_3d ¶
_as_3d(array: ndarray) -> ndarray
Return a flattened version of the data array.
(*leading, height, width) -> (prod(leading), height, width)
_check_alpha_mask ¶
_check_alpha_mask(attribute, value)
Make sure alpha mask has valid shape and datatype.
_default_dimensions ¶
_default_dimensions()
Return default dimensions based on the array shape.
By definition, the last two dimensions are assumed to be spatial (y, x).
apply_color_formula ¶
apply_color_formula(color_formula: str | None) -> Self
Apply color-operations formula in place.
apply_colormap ¶
apply_colormap(colormap: ColorMapType) -> ImageData
Apply colormap to the image data.
apply_expression ¶
apply_expression(expression: str) -> ImageData
Apply expression to the image data.
create_from_list
classmethod
¶
Create ImageData from a sequence of ImageData objects.
Parameters:
-
data(sequence) –sequence of ImageData.
-
stack_on_dim(str, default:None) –Stack the data along a new leading dimension with this name, instead of concatenating them along the first dimension.
data_as_image ¶
data_as_image() -> ndarray
Return the data array reshaped into an image processing/visualization software friendly order.
(bands, rows, columns) -> (rows, columns, bands).
from_bytes
classmethod
¶
from_bytes(data: bytes) -> ImageData
Create ImageData from bytes.
Parameters:
-
data(bytes) –raster dataset as bytes.
get_coverage_array ¶
get_coverage_array(shape: dict, shape_crs: CRS = WGS84_CRS, cover_scale: int = 10) -> NDArray[floating]
Get Coverage array for a Geometry.
Parameters:
-
shape(Dict) –GeoJSON geometry or Feature.
-
shape_crs(CRS, default:WGS84_CRS) –Coordinates Reference System of shape.
-
cover_scale(int, default:10) –Scale used when generating coverage estimates of each raster cell by vector feature. Coverage is generated by rasterizing the feature at a finer resolution than the raster then using a summation to aggregate to the raster resolution and dividing by the square of cover_scale to get coverage value for each cell. Increasing cover_scale will increase the accuracy of coverage values; three orders magnitude finer resolution (cover_scale=1000) is usually enough to get coverage estimates with <1% error in individual edge cells coverage estimates, though much smaller values (e.g., cover_scale=10) are often sufficient (<10% error) and require less memory.
Returns:
-
NDArray[floating]–numpy.array: percent coverage.
Note: code adapted from perrygeo/python-rasterstats!136 by @sgoodm
post_process ¶
post_process(in_range: Sequence[IntervalTuple] | None = None, out_dtype: str | number = 'uint8', color_formula: str | None = None, **kwargs: Any) -> ImageData
Post-process image data.
Parameters:
-
in_range(tuple, default:None) –input min/max bounds value to rescale from.
-
out_dtype(str, default:'uint8') –output datatype after rescaling. Defaults to
uint8. -
color_formula(str, default:None) –color-ops formula (see: vincentsarago/color-ops).
-
kwargs(optional, default:{}) –keyword arguments to forward to
rio_tiler.utils.linear_rescale.
Returns:
-
ImageData(ImageData) –new ImageData object with the updated data.
Examples:
>>> img.post_process(in_range=((0, 16000), ))
>>> img.post_process(color_formula="Gamma RGB 4.1")
reduce ¶
reduce(dim: str, func: Callable[..., MaskedArray]) -> ImageData
Reduce data along a non-spatial dimension.
Parameters:
-
dim(str) –non-spatial dimension name to reduce.
-
func(callable) –reducer function called as
func(array, axis=axis)(e.gnumpy.ma.mean).
Returns:
-
ImageData(ImageData) –data with
dimremoved (or of length 1 ifdimwas the only non-spatial dimension).
render ¶
render(add_mask: bool = True, img_format: str = 'PNG', colormap: ColorMapType | None = None, **kwargs) -> bytes
Render data to image blob.
Parameters:
-
add_mask(bool, default:True) –add mask to output image. Defaults to
True. -
img_format(str, default:'PNG') –output image format. Defaults to
PNG. -
colormap(dict or sequence, default:None) –RGBA Color Table dictionary or sequence.
-
kwargs(optional, default:{}) –keyword arguments to forward to
rio_tiler.utils.render.
Returns:
-
bytes(bytes) –image.
reproject ¶
reproject(dst_crs: CRS, resolution: tuple[float, float] | None = None, reproject_method: WarpResampling = 'nearest') -> ImageData
Reproject data and mask.
rescale ¶
rescale(in_range: Sequence[IntervalTuple], out_range: Sequence[IntervalTuple] = ((0, 255),), out_dtype: str | number = 'uint8') -> Self
Rescale data in place.
resize ¶
resize(height: int, width: int, resampling_method: RIOResampling = 'nearest') -> ImageData
Resize data and mask.
statistics ¶
statistics(categorical: bool = False, categories: list[float] | None = None, percentiles: list[int] | None = None, hist_options: dict | None = None, coverage: ndarray | None = None) -> dict[str, BandStatistics]
Return statistics from ImageData.
to_raster ¶
to_raster(dst_path: str, *, driver: str = 'GTIFF', **kwargs: Any) -> None
Save ImageData array to file.
PointData ¶
Point Data class.
Attributes:
-
array(MaskedArray) –pixel values.
-
dimensions(list[str]) –list of dimension names corresponding to the array.
-
band_names(list or dict) –name of each band. Defaults to
["b1", "b2", "b3"]for 3 bands image. -
band_descriptions(list or dict) –description of each band. Defaults to
["b1", "b2", "b3"]for 3 bands image. -
coordinates(tuple) –Point's coordinates.
-
crs(CRS) –Coordinates Reference System of the bounds.
-
assets(list) –list of assets used to construct the data values.
-
metadata(dict) –Additional metadata. Defaults to
{}. -
nodata(NoData) –nodata value for the data.
-
pixel_location(tuple) –Pixel location (row, column) within the original dataset.
apply_expression ¶
apply_expression(expression: str) -> PointData
Apply expression to the image data.
create_from_list
classmethod
¶
Create PointData from a sequence of PointsData objects.
Parameters:
-
data(sequence) –sequence of PointData.
-
stack_on_dim(str, default:None) –Stack the data along a new leading dimension with this name, instead of concatenating them along the first dimension.
reduce ¶
reduce(dim: str, func: Callable[..., MaskedArray]) -> PointData
Reduce data along a dimension.
Parameters:
-
dim(str) –dimension name to reduce.
-
func(callable) –reducer function called as
func(array, axis=axis)(e.gnumpy.ma.mean).
Returns:
-
PointData(PointData) –data with
dimremoved (or of length 1 ifdimwas the only dimension).
_reduce_band_metadata ¶
_reduce_band_metadata(meta: list[str] | dict[str, list[str]], dim: str, dims: list[str]) -> list[str] | dict[str, list[str]] | None
Remove dim from band metadata, dims being the remaining non-spatial dimensions.
Returns None when the metadata should be set to the default values.
rescale_image ¶
rescale_image(array: MaskedArray, in_range: Sequence[IntervalTuple], out_range: Sequence[IntervalTuple] = ((0, 255),), out_dtype: str | number = 'uint8') -> MaskedArray
Rescale image data in-place.