Skip to content

Single COG / item

Read a single Cloud-Optimized GeoTIFF or the assets of one STAC item at their native grid — no reprojection or mosaicking. Use lazycogs.open for a reprojected mosaic across a whole collection.

Open fetches metadata for the requested assets without decoding pixels. Metadata read-ahead can include compressed tile bytes. sel and isel on the returned lazy array issue no storage requests. Select before loading to limit the spatial window and, for an item, the assets read:

da = lazycogs.open_item(item, bands=["red", "nir"])
window = da.sel(band="nir").isel(y=slice(100, 356), x=slice(200, 456))
pixels = window.load()

Each backend read requests a bounding window of raw, full-resolution pixels. Sparse or strided selections include gaps in that window, and TIFF tile reads can extend beyond it. For a multiband COG, the reader fetches all bands in the window before applying the band selection. open_item requires single-band assets with identical grids and a common dtype that preserves raw values. Use a file:// URI to open a local COG without passing a store.

lazycogs.open_cog

open_cog(
    href: str,
    *,
    store: Store | None = None,
    path_from_href: Callable[[str], str] | None = None,
) -> DataArray

Open one COG at native resolution as an (band, y, x) DataArray.

Reads a single Cloud-Optimized GeoTIFF in place — native CRS, resolution, and shape, no reprojection or mosaicking. Use :func:lazycogs.open for a reprojected mosaic across a STAC/geoparquet collection, or :func:open_item to stack several same-grid assets of one STAC item. Open fetches metadata without decoding pixels. sel and isel do not access storage; loading reads all bands in the bounding window.

Parameters:

Name Type Description Default
href str

COG URL (use a file:// URI for local files). With a custom store, a store-relative object path is also accepted.

required
store Store | None

Pre-configured :class:async_geotiff.Store for all reads.

None
path_from_href Callable[[str], str] | None

Optional callable (href) -> path overriding the default urlparse extraction (see :func:lazycogs.open).

None

Returns:

Type Description
DataArray

DataArray at the COG's native CRS, resolution, and shape. Source

DataArray

nodata is set as _FillValue and any scale/offset as

DataArray

scale_factor/add_offset.

lazycogs.open_item

open_item(
    item: dict[str, Any],
    bands: list[str] | None = None,
    *,
    store: Store | None = None,
    path_from_href: Callable[[str], str] | None = None,
) -> DataArray

Open several same-grid assets of one STAC item as (band, y, x).

Reads the requested single-band assets of one STAC item at their native grid — no reprojection or mosaicking — and stacks them into a single DataArray whose band coordinate is labelled by asset key. All selected assets must share the same CRS, affine transform, and shape, and their dtypes must promote without loss. Open fetches metadata for each requested asset without decoding pixels. sel and isel do not access storage; loading reads the bounding window from only the selected assets. Use :func:lazycogs.open for a reprojected mosaic across a whole collection.

Parameters:

Name Type Description Default
item dict[str, Any]

A STAC item as a dict (e.g. a rustac search result).

required
bands list[str] | None

Asset keys to include, in output order. When None, the item's preferred data assets are used (role "data" or media type image/tiff), matching :func:lazycogs.open.

None
store Store | None

Pre-configured :class:async_geotiff.Store for all reads.

None
path_from_href Callable[[str], str] | None

Optional callable (href) -> path overriding the default urlparse extraction (see :func:lazycogs.open).

None

Returns:

Type Description
DataArray

DataArray at the assets' shared native CRS, resolution, and shape, with

DataArray

the band coordinate labelled by asset key.

Raises:

Type Description
ValueError

If the item has no assets, an asset key or href is missing, an asset is multiband, grids differ, or dtypes cannot be promoted without loss.

lazycogs.open_cog_async async

open_cog_async(
    href: str,
    *,
    store: Store | None = None,
    path_from_href: Callable[[str], str] | None = None,
) -> DataArray

Open one COG at native resolution as an (band, y, x) DataArray.

Async variant of :func:open_cog for use inside a running event loop.

Parameters:

Name Type Description Default
href str

COG URL (use a file:// URI for local files). With a custom store, a store-relative object path is also accepted.

required
store Store | None

Pre-configured :class:async_geotiff.Store for all reads.

None
path_from_href Callable[[str], str] | None

Optional callable (href) -> path overriding the default urlparse extraction (see :func:lazycogs.open).

None

Returns:

Type Description
DataArray

DataArray at the COG's native CRS, resolution, and shape — no

DataArray

reprojection. Values are not masked or scaled. Shared source metadata

DataArray

is exposed as scalar CF attributes.

lazycogs.open_item_async async

open_item_async(
    item: dict[str, Any],
    bands: list[str] | None = None,
    *,
    store: Store | None = None,
    path_from_href: Callable[[str], str] | None = None,
) -> DataArray

Open several same-grid assets of one STAC item as (band, y, x).

Async variant of :func:open_item for use inside a running event loop.

Parameters:

Name Type Description Default
item dict[str, Any]

A STAC item as a dict (e.g. a rustac search result).

required
bands list[str] | None

Asset keys to include, in output order. When None, the item's preferred data assets are used (role "data" or media type image/tiff), matching :func:lazycogs.open.

None
store Store | None

Pre-configured :class:async_geotiff.Store for all reads.

None
path_from_href Callable[[str], str] | None

Optional callable (href) -> path overriding the default urlparse extraction (see :func:lazycogs.open).

None

Returns:

Type Description
DataArray

DataArray at the assets' shared native CRS, resolution, and shape, with

DataArray

the band coordinate labelled by asset key. nodata/scale/

DataArray

offset are read from each asset file and surfaced as scalar CF

DataArray

attrs only when all selected bands agree.

Raises:

Type Description
ValueError

If the item has no assets, an asset key or href is missing, an asset is multiband, grids differ, or dtypes cannot be promoted without loss.