landstac.download

Download helpers for LandsatLook asset HREFs.

This module provides small, focused functions to stream protected assets to disk using an authenticated requests.Session. It does not print or log credentials. Create the session via landstac.auth and pass it in.

Functions

download_asset(href, session, out_path, chunk=1<<20)

Stream one asset to a local GeoTIFF.

download_item_bands(item, session, bands, out_dir)

Download several bands for a single STAC item into a scene folder.

stack_bands_to_geotiff(band_paths, out_path, order=None)

Stack single-band GeoTIFFs into a single multiband GeoTIFF.

Examples

>>> # sess = ers_login_from_file("credentials.json")
>>> # files = download_item_bands(item, sess, ["blue","green","red"], "downloads")
>>> # stack_bands_to_geotiff(files, "downloads/scene_stack.tif", order=["blue","green","red"])

Functions

download_asset(href, session, out_path[, chunk])

Stream an asset to disk using an authenticated session.

download_item_bands(item, session, bands, ...)

Download selected bands for a STAC item.

stack_bands_to_geotiff(band_paths, out_path)

Stack single-band GeoTIFFs into a multiband GeoTIFF.

landstac.download.download_asset(href, session, out_path, chunk=1048576)[source]

Stream an asset to disk using an authenticated session.

Parameters:
  • href (str) – Remote asset URL from item.assets[band].href.

  • session (requests.Session) – Authenticated ERS session. Do not embed credentials in code.

  • out_path (str) – Local GeoTIFF path to write.

  • chunk (int) – Chunk size in bytes for streaming.

Returns:

The local path written.

Return type:

str

Raises:

DownloadError – On HTTP errors or authorization failures.

landstac.download.download_item_bands(item, session, bands, out_dir)[source]

Download selected bands for a STAC item.

Parameters:
  • item (pystac.Item) – STAC item from LandsatLook.

  • session (requests.Session) – Authenticated session to access protected assets.

  • bands (Iterable[str]) – Asset keys to download, for example [“blue”,”green”,”red”,”nir08”].

  • out_dir (str) – Root folder to save files. A per-scene subfolder is created.

Returns:

Mapping {band_name: local_path} for the bands that were downloaded.

Return type:

dict

landstac.download.stack_bands_to_geotiff(band_paths, out_path, order=None)[source]

Stack single-band GeoTIFFs into a multiband GeoTIFF.

All input rasters must share identical CRS, transform, width, and height.

Parameters:
  • band_paths (dict) – Mapping {band_name: local_path} for single-band GeoTIFFs.

  • out_path (str) – Destination path for the stacked GeoTIFF.

  • order (Iterable[str], optional) – Desired band order. Defaults to sorted keys of band_paths.

Returns:

Path to the written multiband GeoTIFF.

Return type:

str

Raises:

ValueError – If georeferencing does not match across inputs.