XarraySource#
- class XarraySource[source]#
Bases:
RasterSource
A RasterSource for reading an Xarry DataArray.
Attributes
Bounding box applied to the source imagery.
Associated
CRSTransformer
.numpy.dtype
of the chips read from this source.Extent of the
RasterSource
.Number of channels in the chips read from this source.
Shape of the raster as a (height, width, num_channels) tuple.
- __init__(data_array: DataArray, crs_transformer: CRSTransformer, raster_transformers: list['RasterTransformer'] = [], channel_order: Optional[Sequence[int]] = None, bbox: rastervision.core.box.Box | None = None, temporal: bool = False)[source]#
Constructor.
- Parameters:
uris – One or more URIs of images. If more than one, the images will be mosaiced together using GDAL.
crs_transformer (CRSTransformer) – A CRSTransformer defining the mapping between pixel and map coords.
raster_transformers (list['RasterTransformer']) – RasterTransformers to use to transform chips after they are read.
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 toNone
.bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If
None
, the full extent available in the source file is used.temporal (bool) – If
True
, data_array is expected to have a “time” dimension and the chips returned will be of shape (T, H, W, C).data_array (DataArray) –
Methods
__init__
(data_array, crs_transformer[, ...])Constructor.
from_stac
(item_or_item_collection[, ...])Construct an
XarraySource
from a STAC Item or ItemCollection.get_chip
(window[, bands, time, out_shape])Read a chip specified by a window from the file.
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.
- __init__(data_array: DataArray, crs_transformer: CRSTransformer, raster_transformers: list['RasterTransformer'] = [], channel_order: Optional[Sequence[int]] = None, bbox: rastervision.core.box.Box | None = None, temporal: bool = False)[source]#
Constructor.
- Parameters:
uris – One or more URIs of images. If more than one, the images will be mosaiced together using GDAL.
crs_transformer (CRSTransformer) – A CRSTransformer defining the mapping between pixel and map coords.
raster_transformers (list['RasterTransformer']) – RasterTransformers to use to transform chips after they are read.
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 toNone
.bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If
None
, the full extent available in the source file is used.temporal (bool) – If
True
, data_array is expected to have a “time” dimension and the chips returned will be of shape (T, H, W, C).data_array (DataArray) –
- classmethod from_stac(item_or_item_collection: Item | ItemCollection, 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, temporal: bool = False, allow_streaming: bool = False, stackstac_args: dict = {'rescale': False}) XarraySource [source]#
Construct an
XarraySource
from a STAC Item or ItemCollection.- Parameters:
item_or_item_collection (Item | ItemCollection) – STAC Item or ItemCollection.
raster_transformers (list['RasterTransformer']) – RasterTransformers to use to transform chips after they are read.
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
Box
or (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
Box
or (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
.temporal (bool) – If True, data_array is expected to have a “time” dimension and the chips returned will be of shape (T, H, W, C).
allow_streaming (bool) – If False, load the entire DataArray into memory. Defaults to True.
stackstac_args (dict) – Optional arguments to pass to stackstac.stack().
- Return type:
- get_chip(window: Box, bands: Optional[Union[int, Sequence[int], slice]] = None, time: Union[int, Sequence[int], slice] = slice(None, None, None), out_shape: tuple[int, ...] | None = None) ndarray [source]#
Read a chip specified by a window from the file.
- Parameters:
window (Box) – Bounding box of chip in pixel coordinates.
bands (Optional[Union[int, Sequence[int], slice]]) – Subset of bands to read. Note that this will be applied on top of the
channel_order
(if specified). So if this is an RGB image andchannel_order=[2, 1, 0]
, then usingbands=[0]
will return the B-channel. Defaults toNone
.out_shape (tuple[int, ...] | None) – (height, width) of the output chip. If
None
, no resizing is done. Defaults toNone
.
- Returns:
A chip of shape (height, width, channels).
- Return type:
np.ndarray
- 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
- property crs_transformer: RasterioCRSTransformer#
Associated
CRSTransformer
.