Landsat#

class torchgeo.datasets.Landsat(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: RasterDataset, ABC

Abstract base class for all Landsat datasets.

Landsat is a joint NASA/USGS program, providing the longest continuous space-based record of Earth’s land in existence.

If you use this dataset in your research, please cite it using the following format:

If you use any of the following Level-2 products, there may be additional citation requirements, including papers you can cite. See the “Citation Information” section of the following pages:

filename_regex = '\n        ^L\n        (?P<sensor>[COTEM])\n        (?P<satellite>\\d{2})\n        _(?P<processing_correction_level>[A-Z0-9]{4})\n        _(?P<wrs_path>\\d{3})\n        (?P<wrs_row>\\d{3})\n        _(?P<date>\\d{8})\n        _(?P<processing_date>\\d{8})\n        _(?P<collection_number>\\d{2})\n        _(?P<collection_category>[A-Z0-9]{2})\n        _(?P<band>[A-Z0-9_]+)\n        \\.\n    '#

Regular expression used to extract date from filename.

The expression should use named groups. The expression may contain any number of groups. The following groups are specifically searched for by the base class:

  • date: used to calculate mint and maxt for index insertion

  • start: used to calculate mint for index insertion

  • stop: used to calculate maxt for index insertion

When separate_files is True, the following additional groups are searched for to find other files:

  • band: replaced with requested band name

separate_files = True#

True if data is stored in a separate file for each band, else False.

abstract property default_bands: tuple[str, ...]#

Bands to load by default.

__init__(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Initialize a new Dataset instance.

Parameters:
  • paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search or files to load

  • crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)

  • res (float | tuple[float, float] | None) – resolution of the dataset in units of CRS in (xres, yres) format. If a single float is provided, it is used for both the x and y resolution. (defaults to the resolution of the first file found)

  • bands (Sequence[str] | None) – bands to return (defaults to all bands)

  • transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – a function/transform that takes an input sample and returns a transformed version

  • cache (bool) – if True, cache file handle to speed up repeated sampling

  • time_series (bool) – if True, stack data along the time series dimension [T, C, H, W]. If False, merge data into a [C, H, W] mosaic.

Raises:

DatasetNotFoundError – If dataset is not found and download is False.

Added in version 0.9: The time_series parameter.

Changed in version 0.5: root was renamed to paths.

plot(sample, show_titles=True, suptitle=None)[source]#

Plot a sample from the dataset.

Parameters:
  • sample (dict[str, Any]) – a sample returned by RasterDataset.__getitem__()

  • show_titles (bool) – flag indicating whether to show titles above each panel

  • suptitle (str | None) – optional string to use as a suptitle

Returns:

a matplotlib Figure with the rendered sample

Raises:

RGBBandsMissingError – If bands does not include all RGB bands.

Return type:

Figure

Changed in version 0.3: Method now takes a sample dict, not a Tensor. Additionally, possible to show subplot titles and/or use a custom suptitle.

__annotate_func__()#

The type of the None singleton.

class torchgeo.datasets.Landsat9(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat8

Landsat 9 Operational Land Imager (OLI-2) and Thermal Infrared Sensor (TIRS-2).

filename_glob = 'LC09_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

class torchgeo.datasets.Landsat8(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat

Landsat 8 Operational Land Imager (OLI) and Thermal Infrared Sensor (TIRS).

filename_glob = 'LC08_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

rgb_bands: tuple[str, ...] = ('SR_B4', 'SR_B3', 'SR_B2')#

Names of RGB bands in the dataset, used for plotting

class torchgeo.datasets.Landsat7(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat

Landsat 7 Enhanced Thematic Mapper Plus (ETM+).

filename_glob = 'LE07_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

rgb_bands: tuple[str, ...] = ('SR_B3', 'SR_B2', 'SR_B1')#

Names of RGB bands in the dataset, used for plotting

class torchgeo.datasets.Landsat5TM(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat4TM

Landsat 5 Thematic Mapper (TM).

filename_glob = 'LT05_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

class torchgeo.datasets.Landsat5MSS(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat4MSS

Landsat 4 Multispectral Scanner (MSS).

filename_glob = 'LM04_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

class torchgeo.datasets.Landsat4TM(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat

Landsat 4 Thematic Mapper (TM).

filename_glob = 'LT04_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

rgb_bands: tuple[str, ...] = ('SR_B3', 'SR_B2', 'SR_B1')#

Names of RGB bands in the dataset, used for plotting

class torchgeo.datasets.Landsat4MSS(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat

Landsat 4 Multispectral Scanner (MSS).

filename_glob = 'LM04_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

rgb_bands: tuple[str, ...] = ('B3', 'B2', 'B1')#

Names of RGB bands in the dataset, used for plotting

class torchgeo.datasets.Landsat3(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat1

Landsat 3 Multispectral Scanner (MSS).

filename_glob = 'LM03_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

class torchgeo.datasets.Landsat2(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat1

Landsat 2 Multispectral Scanner (MSS).

filename_glob = 'LM02_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

class torchgeo.datasets.Landsat1(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#

Bases: Landsat

Landsat 1 Multispectral Scanner (MSS).

filename_glob = 'LM01_*_{}.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

rgb_bands: tuple[str, ...] = ('B6', 'B5', 'B4')#

Names of RGB bands in the dataset, used for plotting