MultiRasterSource#
- class MultiRasterSource[source]#
Bases:
RasterSourceMerge multiple
RasterSourcesby concatenating along the channel dim.Attributes
Bounding box applied to the source imagery.
Associated
CRSTransformer.numpy.dtypeof the chips read from this source.Extent of the
RasterSource.Number of channels in the chips read from this source.
Primary sub-
RasterSourceShape of the raster as a (..., H, W, C) tuple.
- __init__(raster_sources: Sequence[RasterSource], primary_source_idx: int = 0, channel_order: Optional[Sequence[int]] = None, raster_transformers: Sequence[RasterTransformer] = [], bbox: rastervision.core.box.Box | None = None)[source]#
Constructor.
- Parameters
raster_sources (Sequence[RasterSource]) – Sequence of RasterSources.
primary_source_idx (int) – Index of the raster source whose CRS, dtype, and other attributes will override those of the other raster sources.
channel_order (Optional[Sequence[int]]) – Channel ordering that will be used by
MultiRasterSource.get_chip(). Defaults toNone.raster_transformers (Sequence[RasterTransformer]) – List of transformers. Defaults to
[].bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If specified, the primary raster source’s bbox is set to this. If
None, the full extent available in the source file of the primary raster source is used.
Methods
__init__(raster_sources[, ...])Constructor.
from_stac(item, assets[, ...])Construct a
MultiRasterSourcefrom a STAC Item.get_chip(window[, out_shape])Return the transformed chip in the window.
get_chip_by_map_window(window_map_coords, ...)Same as get_chip(), but input is a window in map coords.
get_raw_chip(window[, out_shape])Return raw chip without applying channel_order or transforms.
resize(chip[, out_shape])set_bbox(bbox)Set self.bbox to the given value.
Validate sub-
RasterSources.- __init__(raster_sources: Sequence[RasterSource], primary_source_idx: int = 0, channel_order: Optional[Sequence[int]] = None, raster_transformers: Sequence[RasterTransformer] = [], bbox: rastervision.core.box.Box | None = None)[source]#
Constructor.
- Parameters
raster_sources (Sequence[RasterSource]) – Sequence of RasterSources.
primary_source_idx (int) – Index of the raster source whose CRS, dtype, and other attributes will override those of the other raster sources.
channel_order (Optional[Sequence[int]]) – Channel ordering that will be used by
MultiRasterSource.get_chip(). Defaults toNone.raster_transformers (Sequence[RasterTransformer]) – List of transformers. Defaults to
[].bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If specified, the primary raster source’s bbox is set to this. If
None, the full extent available in the source file of the primary raster source is used.
- classmethod from_stac(item: Item, assets: list[str] | None, primary_source_idx: int = 0, raster_transformers: list['RasterTransformer'] = [], channel_order: Optional[Sequence[int]] = None, bbox: rastervision.core.box.Box | tuple[int, int, int, int] | None = None, bbox_map_coords: rastervision.core.box.Box | tuple[int, int, int, int] | None = None, allow_streaming: bool = False) Self[source]#
Construct a
MultiRasterSourcefrom a STAC Item.This creates a
RasterioSourcefor each asset and puts all the raster sources together into aMultiRasterSource. Ifassetsis not specified, all the assets in the STAC item are used.Only assets that are readable by rasterio are supported.
- Parameters
item (Item) – STAC Item.
assets (list[str] | None) – List of names of assets to use. If
None, all assets present in the item will be used. Defaults toNone.primary_source_idx (int) – Index of the raster source whose CRS, dtype, and other attributes will override those of the other raster sources.
raster_transformers (list['RasterTransformer']) – RasterTransformers to use to transform chips after they are read. Defaults to
[].channel_order (Optional[Sequence[int]]) – List of indices of channels to extract from raw imagery. Can be a subset of the available channels. If None, all channels available in the image will be read. Defaults to None.
bbox (rastervision.core.box.Box | tuple[int, int, int, int] | None) – User-specified crop of the extent. Can be
Boxor (ymin, xmin, ymax, xmax) tuple. If None, the full extent available in the source file is used. Mutually exclusive withbbox_map_coords. Defaults toNone.bbox_map_coords (rastervision.core.box.Box | tuple[int, int, int, int] | None) – User-specified bbox in EPSG:4326 coords. Can be
Boxor (ymin, xmin, ymax, xmax) tuple. Useful for cropping the raster source so that only part of the raster is read from. Mutually exclusive withbbox. Defaults toNone.allow_streaming (bool) – Passed to
RasterioSource. IfFalse, assets will be downloaded. Defaults toTrue.
- Return type
Self
- get_chip(window: Box, out_shape: tuple[int, int] | None = None) ndarray[source]#
Return the transformed chip in the window.
Get processed chips from sub raster sources (with their respective channel orders and transformations applied), concatenate them along the channel dimension, apply channel_order, followed by transformations.
- get_chip_by_map_window(window_map_coords: Box, *args, **kwargs) ndarray#
Same as get_chip(), but input is a window in map coords.
- get_raw_chip(window: Box, out_shape: tuple[int, int] | None = None) ndarray#
Return raw chip without applying channel_order or transforms.
- set_bbox(bbox: Box) None#
Set self.bbox to the given value.
Note
This method is idempotent.
- Parameters
bbox (Box) – User-specified bbox in pixel coordinates.
- Return type
None
- validate_raster_sources() None[source]#
Validate sub-
RasterSources.Checks if all raster sources have the same dtype.
- Return type
None
- property crs_transformer: CRSTransformer#
Associated
CRSTransformer.
- property primary_source: RasterSource#
Primary sub-
RasterSource