Skip to content

rasteret.types

Data types and dataclasses used across Rasteret.

types

Classes

CogMetadata dataclass

CogMetadata(
    width: int,
    height: int,
    tile_width: int,
    tile_height: int,
    dtype: dtype | DataType,
    crs: int | None,
    predictor: int | None = None,
    transform: list[float] | None = None,
    compression: int | None = None,
    tile_offsets: list[int] | None = None,
    tile_byte_counts: list[int] | None = None,
    pixel_scale: tuple[float, ...] | None = None,
    tiepoint: tuple[float, ...] | None = None,
    nodata: float | int | None = None,
    samples_per_pixel: int = 1,
    planar_configuration: int = 1,
    photometric: int | None = None,
    extra_samples: tuple[int, ...] | None = None,
)

Metadata for a tiled GeoTIFF (including COGs).

New fields added for correctness (nodata, samples_per_pixel, planar_configuration, photometric, extra_samples) have defaults so existing Parquet files missing them load without error.

Functions
from_dict classmethod
from_dict(
    raw: dict[str, Any],
    *,
    crs: int | None = None,
    transform_override: list[float] | None = None,
) -> CogMetadata

Build from a raw metadata dict (as stored in the Parquet table).

Parameters:

Name Type Description Default
raw dict

The {band}_metadata dict from the collection schema.

required
crs int

EPSG code to use (overrides any value in raw).

None
transform_override list[float]

Pre-normalized transform. When None, raw["transform"] is used as-is.

None
Source code in src/rasteret/types.py
@classmethod
def from_dict(
    cls,
    raw: dict[str, Any],
    *,
    crs: int | None = None,
    transform_override: list[float] | None = None,
) -> CogMetadata:
    """Build from a raw metadata dict (as stored in the Parquet table).

    Parameters
    ----------
    raw : dict
        The ``{band}_metadata`` dict from the collection schema.
    crs : int, optional
        EPSG code to use (overrides any value in *raw*).
    transform_override : list[float], optional
        Pre-normalized transform.  When ``None``, ``raw["transform"]``
        is used as-is.
    """
    # Parse nodata: stored as float64 in Parquet, may be NaN or None.
    raw_nodata = raw.get("nodata")
    nodata = None
    if raw_nodata is not None:
        fval = float(raw_nodata)
        if fval != fval:  # NaN sentinel
            nodata = float("nan")
        else:
            int_val = int(fval)
            nodata = int_val if float(int_val) == fval else fval

    extra = raw.get("extra_samples")

    return cls(
        width=raw.get("image_width", raw.get("width")),
        height=raw.get("image_height", raw.get("height")),
        tile_width=raw["tile_width"],
        tile_height=raw["tile_height"],
        dtype=np.dtype(raw["dtype"]),
        transform=transform_override
        if transform_override is not None
        else raw.get("transform"),
        crs=crs,
        tile_offsets=raw["tile_offsets"],
        tile_byte_counts=raw["tile_byte_counts"],
        predictor=raw.get("predictor"),
        compression=raw.get("compression"),
        pixel_scale=raw.get("pixel_scale"),
        tiepoint=raw.get("tiepoint"),
        nodata=nodata,
        samples_per_pixel=raw.get("samples_per_pixel", 1),
        planar_configuration=raw.get("planar_configuration", 1),
        photometric=raw.get("photometric"),
        extra_samples=tuple(extra) if extra is not None else None,
    )

RasterInfo dataclass

RasterInfo(
    id: str,
    datetime: datetime,
    bbox: list[float],
    footprint: Any,
    crs: int | None,
    cloud_cover: float,
    assets: dict[str, Any],
    band_metadata: dict[str, Any],
    collection: str,
)

Metadata for a single raster record (Parquet row).

Each row in a Rasteret Collection Parquet becomes a RasterInfo that is then used to construct a :class:~rasteret.core.raster_accessor.RasterAccessor.

Parameters:

Name Type Description Default
id str

Unique record identifier.

required
datetime datetime

Acquisition / observation time.

required
bbox list of float

Bounding box [minx, miny, maxx, maxy].

required
footprint object

Footprint geometry (Shapely Polygon or WKB bytes).

required
crs int or None

EPSG code for the record's native CRS.

required
cloud_cover float

Cloud cover percentage (0--100).

required
assets dict

Mapping of band code to asset dict (href, raster:bands, etc.).

required
band_metadata dict

Per-band COG metadata dicts keyed by {band}_metadata.

required
collection str

Parent collection identifier.

required