astrovision.data

Contents

astrovision.data#

Data module.

Submodules#

Classes#

SatelliteImage

Wrapper class for a satellite image.

SegmentationLabeledSatelliteImage

Class for satellite images with a semantic segmentation label.

DetectionLabeledSatelliteImage

Class for satellite images with an object detection label.

ClassificationLabeledSatelliteImage

Class for satellite images with 0-1 classification label.

Package Contents#

class astrovision.data.SatelliteImage(array: numpy.array, crs: str, bounds: Tuple, transform: affine.Affine, dep: Literal[astrovision.data.constants.DEPARTMENTS_LIST] | None = None, date: SatelliteImage.__init__.date | None = None)#

Wrapper class for a satellite image.

array#
crs#
bounds#
transform#
dep#
date#
split(tile_length: int) List[SatelliteImage]#

Split the SatelliteImage into square tiles of side tile_length.

Args:

tile_length (int): Side of of tiles.

Returns:

List[SatelliteImage]: List of tiles.

to_tensor(bands_indices: List[int] | None = None) torch.Tensor#

Return SatelliteImage array as a torch.Tensor.

Args:
bands_indices (List): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

Returns:

torch.Tensor: Image tensor.

normalize(quantile: float = 0.97) SatelliteImage#

Normalize array values with min-max normalization after clipping at quantiles.

Args:

quantile (float): Normalize an array.

Returns:

SatelliteImage: Normalized image.

copy() SatelliteImage#

Deep copy a satellite image.

Returns:

SatelliteImage: Copied image.

plot(bands_indices: List[int])#

Plot a subset of bands from a 3D array as an image.

Args:
bands_indices (List[int]): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

static from_raster(file_path: str, dep: Literal[astrovision.data.constants.DEPARTMENTS_LIST] | None = None, date: SatelliteImage.from_raster.date | None = None, n_bands: int = 3, channels_first: bool = True, cast_to_float: bool = False) SatelliteImage#

Factory method to create a Satellite image from a raster file.

Args:

file_path (str): File path. dep (Optional[Literal[DEPARTMENTS_LIST]]): Département. date (Optional[date]): Date. Defaults to None. n_bands (int): Number of bands. channels_first (bool): True if channels should be moved

to first axis.

cast_to_float (bool): True to cast array to float.

Returns:

SatelliteImage: Satellite image.

to_raster(file_path: str) None#

Save a SatelliteImage to a raster file according to the raster type desired (.tif or .jp2).

Args:

file_path (str): File path.

to_raster_jp2(file_path: str)#

Save a SatelliteImage to a .jp2 raster file.

Args:

file_path (str): File path.

to_raster_tif(file_path: str) None#

Save a SatelliteImage to a .tif raster file.

Args:

file_path (str): File path.

intersects_box(box_bounds: Tuple, crs: str) bool#

Return True if image intersects a bounding box specified by box_bounds and a crs.

Args:

box_bounds (Tuple): Box bounds. crs (str): Projection system.

Returns:

bool: Boolean.

intersects_polygon(polygon_geometry: shapely.geometry.Polygon, crs: str) bool#

Return True if image intersects a polygon.

Args:

polygon_geometry (Polygon): Polygon geometry. crs (str): Projection system.

Returns:

bool: Boolean.

contains(coordinates: Tuple, crs: str) bool#

Return True if image contains a point specified by coordinates

Args:

coordinates (Tuple): Coordinates. crs (str): Projection system.

Returns:

bool: Boolean.

class astrovision.data.SegmentationLabeledSatelliteImage(satellite_image: astrovision.data.satellite_image.SatelliteImage, label: numpy.array, source: Literal['RIL', 'BDTOPO'] | None = None, labeling_date: datetime.datetime | None = None)#

Class for satellite images with a semantic segmentation label. The segmentation label supports n classes.

satellite_image#
label#
source#
labeling_date#
split(tile_length: int) List[SegmentationLabeledSatelliteImage]#

Split the SegmentationLabeledSatelliteImage into labeled tiles of dimension (tile_length x tile_length).

Args:

tile_length (int): Dimension of tiles

Returns:

List[SegmentationLabeledSatelliteImage]: Labeled tiles.

plot(bands_indices: List[int], alpha: float = 0.3, colormap: str = 'tab20', class_labels: List[str] | None = None)#

Plot a subset of bands of the satellite image and its corresponding labels on the same plot.

Args:
bands_indices (List): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

alpha (float, optional): The transparency of the label

image when overlaid on the satellite image. A value of 0 means fully transparent and a value of 1 means fully opaque. The default value is 0.3.

colormap (str, optional): Matplotlib colormap for the labels. class_labels (Optional[List[str]], optional): List of class labels for the legend.

If not provided, it assumes a binary classification.

plot_label_next_to_image(bands_indices: List[int], colormap: str = 'tab20', class_labels: List[str] | None = None)#

Plot a subset of bands from a satellite image and its corresponding label on the side.

Args:
bands_indices (List[int]): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

colormap (str, optional): Matplotlib colormap for the labels. class_labels (Optional[List[str]], optional): List of class labels for the legend.

If not provided, it assumes a binary classification.

to_classification_labeled_image(aggregation_method: str = 'any') ClassificationLabeledSatelliteImage#

Return a ClassificationLabeledSatelliteImage.

Args:
aggregation_method (str): Method to aggregate pixel labels to a single class.

Options: ‘any’ (default), ‘majority’, ‘weighted’.

Returns:

ClassificationLabeledSatelliteImage: Image with a single class label.

class astrovision.data.DetectionLabeledSatelliteImage(satellite_image: astrovision.data.satellite_image.SatelliteImage, label: List[Tuple[int]], source: Literal['RIL', 'BDTOPO'] | None = None, labeling_date: datetime.datetime | None = None)#

Class for satellite images with an object detection label. The segmentation label is a List of box coordinates indicating the coordinates of buildings on the image. TODO: generalize to n classes ?

satellite_image#
label#
source#
labeling_date#
abstract split(nfolds: int) List[DetectionLabeledSatelliteImage]#

Split the DetectionLabeledSatelliteImage into labeled tiles of dimension (tile_length x tile_length).

Args:

tile_length (int): Dimension of tiles

Returns:

List[DetectionLabeledSatelliteImage]: Labeled tiles.

plot(bands_indices: List[int])#

Plot a subset of bands from the satellite image with its corresponding label.

Args:
bands_indices (List[int]): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

to_classification_labeled_image() ClassificationLabeledSatelliteImage#

Return a ClassificationLabeledSatelliteImage.

class astrovision.data.ClassificationLabeledSatelliteImage(satellite_image: astrovision.data.satellite_image.SatelliteImage, label: int, source: Literal['RIL', 'BDTOPO'] | None = None, labeling_date: datetime.datetime | None = None)#

Class for satellite images with 0-1 classification label.

satellite_image#
label#
source#
labeling_date#
plot(bands_indices: List[int], alpha: float = 0.2)#

Plot a subset of bands of the satellite image with a green or red overlay depending on whether it is labeled 1 or 0.

Args:
bands_indices (List): List of indices of bands to plot.

The indices should be integers between 0 and the number of bands - 1.

alpha (float, optional): The transparency of the label

color when overlaid on the satellite image. A value of 0 means fully transparent and a value of 1 means fully opaque. The default value is 0.2.