mirrorworld.satellite: Satellite imagery (STAC)

Imagery from STAC catalogues, read from cloud-optimized GeoTIFFs for just the requested box. Searching is sync and async; reading uses GDAL and is sync only. Needs pip install mirrorworld[raster]. Scenes default to the newest acquisition covering the box; Sentinel-2 and Landsat additionally check the cloud mask inside the box itself (max_local_cloud).

Generic STAC

search(endpoint, collections, north, west, south, east, start=None, end=None, max_cloud_cover=None, query=None, limit=100, session=None)[source]

Searches a STAC API for items intersecting a bounding box, newest first.

Parameters:
  • endpoint (str) – STAC API root, e.g. EARTH_SEARCH or PLANETARY_COMPUTER.

  • collections (str | Sequence[str]) – Collection ID(s).

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition.

  • max_cloud_cover (float | None) – (optional) Maximum eo:cloud_cover in percent.

  • query (dict | None) – (optional) Further STAC query conditions, e.g. {"sat:orbit_state": {"eq": "ascending"}}.

  • limit (int) – (optional) Maximum number of items. Defaults to 100.

  • session (Session) – (optional) A requests session.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async search_async(endpoint, collections, north, west, south, east, session, start=None, end=None, max_cloud_cover=None, query=None, limit=100)[source]
Parameters:
Return type:

List[Scene]

read(scenes, assets, north, west, south, east, resolution=None, crs=None, resampling='nearest', dtype=None)[source]

Reads assets of one or more items for a bounding box onto a common grid.

With several items (e.g. adjacent tiles of one pass, or a time series to composite), the first item with data at a pixel wins, so pass them in order of preference.

Parameters:
  • scenes (Scene | Sequence[Scene]) – A Scene or a list of Scenes.

  • assets (Sequence[str]) – Asset names, e.g. ["red", "green", "blue", "nir"]. Multi-band assets (e.g. NAIP’s image) contribute all their bands.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • resolution (float | None) – (optional) Pixel size in units of crs. Defaults to the first asset’s native size.

  • crs (str | None) – (optional) Output CRS. Defaults to the first asset’s native CRS.

  • resampling (str) – (optional) nearest, bilinear, cubic, average, … Defaults to nearest.

  • dtype (str | None) – (optional) Output data type. Defaults to the first asset’s.

Returns:

A Raster with one band per asset band; metadata lists the item IDs, dates and scale/offset of each band where the catalogue gives them.

Return type:

Raster

pick_scenes(scenes, north, west, south, east)[source]

Picks the newest acquisition date that covers the box, returning all items of that date (adjacent tiles of one pass) with the least cloudy first. Falls back to the newest scene.

Parameters:
Return type:

List[Scene]

pick_clear_scenes(scenes, north, west, south, east, mask_asset, is_cloud, max_fraction, max_checks=15)[source]

Picks the newest scene whose cloud mask shows at most max_fraction cloud inside the box. Scene-level cloud cover says little about a small area, so the mask band is read for the box itself (cheap: one band, a few kilobytes). Falls back to the clearest scene checked.

Parameters:
  • scenes (Sequence[Scene]) – Candidate scenes, newest first.

  • mask_asset (str) – Name of the cloud/quality mask asset, e.g. scl or qa_pixel.

  • is_cloud (Callable[[ndarray], ndarray]) – Function mapping mask values to a boolean cloud array.

  • max_fraction (float) – Largest acceptable cloudy fraction, 0..1.

  • max_checks (int) – (optional) Number of candidate scenes to check. Defaults to 15.

  • north (float)

  • west (float)

  • south (float)

  • east (float)

Returns:

A list with the chosen scene.

Return type:

List[Scene]

sign_href(scene, href)[source]

Makes an asset URL readable. Items from Microsoft Planetary Computer need a short-lived SAS token, fetched anonymously from its token API and cached per collection; other URLs are returned unchanged.

Parameters:
Return type:

str

Usage sample:

from mirrorworld.satellite import stac

scenes = stac.search(stac.PLANETARY_COMPUTER, "io-lulc-annual-v02", 47.615, -122.345, 47.600, -122.325)
raster = stac.read(scenes[0], ["data"], 47.615, -122.345, 47.600, -122.325)
class Scene(id, collection, datetime, bbox, endpoint, cloud_cover=None, assets=<factory>, properties=<factory>)[source]

One item of a STAC catalogue, e.g. a satellite scene or an aerial survey tile.

Parameters:
id: str

Item ID.

collection: str

Collection ID, e.g. sentinel-2-l2a.

datetime: datetime | None

Acquisition time (UTC).

bbox: Tuple[float, float, float, float]

Footprint bounding box as (west, south, east, north).

endpoint: str

STAC API the item came from.

cloud_cover: float | None = None

Cloud cover in percent, for optical scenes.

assets: Dict[str, dict]

Asset name -> STAC asset (href, type, eo:bands, raster:bands, …).

properties: dict

All item properties.

covers(north, west, south, east)[source]

Whether the footprint’s bounding box contains a bounding box.

Parameters:
Return type:

bool

Sentinel-2 (10 m multispectral)

find_scenes(north, west, south, east, start=None, end=None, max_cloud_cover=20, limit=50)[source]

Finds Sentinel-2 scenes intersecting a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition date, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition date (inclusive).

  • max_cloud_cover (float | None) – (optional) Maximum cloud cover in percent. Defaults to 20.

  • limit (int) – (optional) Maximum number of scenes. Defaults to 50.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async find_scenes_async(north, west, south, east, session, start=None, end=None, max_cloud_cover=20, limit=50)[source]
Parameters:
Return type:

List[Scene]

get_raster(north, west, south, east, scenes=None, bands=('red', 'green', 'blue', 'nir'), resolution=10.0, crs=None, start=None, end=None, max_cloud_cover=20, resampling='nearest', max_local_cloud=0.1)[source]

Reads Sentinel-2 bands for a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • scenes (Scene | Sequence[Scene] | None) – (optional) Scene(s) from find_scenes(). Defaults to the newest acquisition covering the box within start/end and under max_cloud_cover.

  • bands (Sequence[str]) – (optional) Band names, e.g. nir and red for NDVI or scl for the cloud mask. Defaults to ("red", "green", "blue", "nir").

  • resolution (float | None) – (optional) Pixel size in meters. Defaults to 10 (the native resolution of the visible and near-infrared bands).

  • crs (str | None) – (optional) Output CRS. Defaults to the scene’s native CRS (UTM).

  • start (str | datetime | None) – (optional) Earliest acquisition date when choosing a scene.

  • end (str | datetime | None) – (optional) Latest acquisition date when choosing a scene.

  • max_cloud_cover (float | None) – (optional) Maximum cloud cover in percent. Defaults to 20.

  • resampling (str) – (optional) Resampling method. Defaults to nearest.

  • max_local_cloud (float) – (optional) When choosing a scene, the largest cloudy fraction (0..1) allowed inside the box itself, judged from the scene classification classes 3 (cloud shadow), 8-9 (cloud) and 10 (cirrus). Defaults to 0.1.

Returns:

A Raster; metadata names the scenes and any scale/offset per band.

Return type:

Raster

download_raster(north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (.tif keeps all bands and values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.satellite import sentinel2

r = sentinel2.get_raster(47.615, -122.345, 47.600, -122.325, bands=("red", "nir"),
                         start="2025-06-01", end="2025-09-30")
red, nir = (r.band(b) * 0.0001 - 0.1 for b in ("red", "nir"))   # scale/offset from r.metadata["band_info"]
ndvi = (nir - red) / (nir + red)

Sentinel-1 (10 m radar)

find_scenes(north, west, south, east, start=None, end=None, limit=50)[source]

Finds Sentinel-1 RTC scenes intersecting a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition date, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition date (inclusive).

  • limit (int) – (optional) Maximum number of scenes. Defaults to 50.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async find_scenes_async(north, west, south, east, session, start=None, end=None, limit=50)[source]
Parameters:
Return type:

List[Scene]

get_raster(north, west, south, east, scenes=None, bands=('vv', 'vh'), resolution=10.0, crs=None, start=None, end=None, resampling='bilinear')[source]

Reads Sentinel-1 backscatter for a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • scenes (Scene | Sequence[Scene] | None) – (optional) Scene(s) from find_scenes(). Defaults to the newest acquisition covering the box within start/end.

  • bands (Sequence[str]) – (optional) vv and/or vh. Defaults to ("vv", "vh").

  • resolution (float | None) – (optional) Pixel size in meters. Defaults to 10.

  • crs (str | None) – (optional) Output CRS. Defaults to the scene’s native CRS (UTM).

  • start (str | datetime | None) – (optional) Earliest acquisition date when choosing a scene.

  • end (str | datetime | None) – (optional) Latest acquisition date when choosing a scene.

  • resampling (str) – (optional) Resampling method. Defaults to bilinear.

Returns:

A Raster; metadata names the scenes and any scale/offset per band.

Return type:

Raster

download_raster(north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (.tif keeps all bands and values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.satellite import sentinel1

sentinel1.download_raster(47.615, -122.345, 47.600, -122.325, "s1.tif", start="2025-07-01", end="2025-07-31")

Landsat (30 m multispectral and thermal)

find_scenes(north, west, south, east, start=None, end=None, max_cloud_cover=20, limit=50)[source]

Finds Landsat scenes intersecting a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition date, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition date (inclusive).

  • max_cloud_cover (float | None) – (optional) Maximum cloud cover in percent. Defaults to 20.

  • limit (int) – (optional) Maximum number of scenes. Defaults to 50.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async find_scenes_async(north, west, south, east, session, start=None, end=None, max_cloud_cover=20, limit=50)[source]
Parameters:
Return type:

List[Scene]

get_raster(north, west, south, east, scenes=None, bands=('red', 'green', 'blue', 'nir08'), resolution=30.0, crs=None, start=None, end=None, max_cloud_cover=20, resampling='nearest', max_local_cloud=0.1)[source]

Reads Landsat bands for a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • scenes (Scene | Sequence[Scene] | None) – (optional) Scene(s) from find_scenes(). Defaults to the newest acquisition covering the box within start/end and under max_cloud_cover.

  • bands (Sequence[str]) – (optional) Band names, e.g. lwir11 for surface temperature. Defaults to ("red", "green", "blue", "nir08").

  • resolution (float | None) – (optional) Pixel size in meters. Defaults to 30.

  • crs (str | None) – (optional) Output CRS. Defaults to the scene’s native CRS (UTM).

  • start (str | datetime | None) – (optional) Earliest acquisition date when choosing a scene.

  • end (str | datetime | None) – (optional) Latest acquisition date when choosing a scene.

  • max_cloud_cover (float | None) – (optional) Maximum cloud cover in percent. Defaults to 20.

  • resampling (str) – (optional) Resampling method. Defaults to nearest.

  • max_local_cloud (float) – (optional) When choosing a scene, the largest cloudy fraction (0..1) allowed inside the box itself, judged from the QA_PIXEL bits 1-4 (dilated cloud, cirrus, cloud, cloud shadow). Defaults to 0.1.

Returns:

A Raster; metadata names the scenes and any scale/offset per band.

Return type:

Raster

download_raster(north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (.tif keeps all bands and values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.satellite import landsat

landsat.download_raster(47.615, -122.345, 47.600, -122.325, "lst.tif", bands=("lwir11",),
                        start="2025-06-01", end="2025-09-30")

NAIP (0.6 m RGB + near-infrared, US)

find_scenes(north, west, south, east, start=None, end=None, limit=50)[source]

Finds NAIP tiles intersecting a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition date, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition date (inclusive).

  • limit (int) – (optional) Maximum number of scenes. Defaults to 50.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async find_scenes_async(north, west, south, east, session, start=None, end=None, limit=50)[source]
Parameters:
Return type:

List[Scene]

get_raster(north, west, south, east, scenes=None, bands=('image',), resolution=None, crs=None, start=None, end=None, resampling='nearest')[source]

Reads NAIP imagery (red, green, blue, nir) for a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • scenes (Scene | Sequence[Scene] | None) – (optional) Scene(s) from find_scenes(). Defaults to the newest acquisition covering the box within start/end.

  • bands (Sequence[str]) – (optional) Asset names; image holds all four bands. Defaults to ("image",).

  • resolution (float | None) – (optional) Pixel size in meters. Defaults to the native resolution (0.6 m for recent years).

  • crs (str | None) – (optional) Output CRS. Defaults to the scene’s native CRS (UTM, NAD83).

  • start (str | datetime | None) – (optional) Earliest acquisition date when choosing a scene.

  • end (str | datetime | None) – (optional) Latest acquisition date when choosing a scene.

  • resampling (str) – (optional) Resampling method. Defaults to nearest.

Returns:

A Raster; metadata names the scenes and any scale/offset per band.

Return type:

Raster

download_raster(north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (.tif keeps all bands and values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.satellite import naip

naip.download_raster(47.615, -122.345, 47.600, -122.325, "naip.tif")

ESA WorldCover (10 m land cover)

find_scenes(north, west, south, east, start=None, end=None, limit=50)[source]

Finds WorldCover tiles intersecting a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • start (str | datetime | None) – (optional) Earliest acquisition date, e.g. "2024-06-01".

  • end (str | datetime | None) – (optional) Latest acquisition date (inclusive).

  • limit (int) – (optional) Maximum number of scenes. Defaults to 50.

Returns:

A list of Scene objects.

Return type:

List[Scene]

async find_scenes_async(north, west, south, east, session, start=None, end=None, limit=50)[source]
Parameters:
Return type:

List[Scene]

get_raster(north, west, south, east, scenes=None, bands=('map',), resolution=None, crs=None, start=None, end=None, resampling='nearest')[source]

Reads WorldCover land cover classes for a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • scenes (Scene | Sequence[Scene] | None) – (optional) Scene(s) from find_scenes(). Defaults to the newest acquisition covering the box within start/end.

  • bands (Sequence[str]) – (optional) Asset names; map holds the classes. Defaults to ("map",).

  • resolution (float | None) – (optional) Pixel size in meters. Defaults to the native resolution (10 m in degrees, EPSG:4326).

  • crs (str | None) – (optional) Output CRS. Defaults to the scene’s native CRS (EPSG:4326).

  • start (str | datetime | None) – (optional) Earliest acquisition date when choosing a scene.

  • end (str | datetime | None) – (optional) Latest acquisition date when choosing a scene.

  • resampling (str) – (optional) Resampling method. Defaults to nearest.

Returns:

A Raster; metadata names the scenes and any scale/offset per band.

Return type:

Raster

download_raster(north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (.tif keeps all bands and values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.satellite import worldcover

r = worldcover.get_raster(47.615, -122.345, 47.600, -122.325)
print(worldcover.CLASSES)