rasterix.lib

Shared library utilities for rasterix.

Module Contents

rasterix.lib.TRACE = 5[source]
class rasterix.lib.TraceLogger(name, level=NOTSET)[source]

Bases: logging.Logger

Logger with trace level support.

trace(message, *args, **kwargs)[source]

Log a message with severity ‘TRACE’.

rasterix.lib.logger[source]
rasterix.lib.affine_from_tiepoint_and_scale(tiepoint, scale)[source]

Create an Affine transform from GeoTIFF tiepoint and pixel scale.

Parameters:
tiepointlist or tuple

GeoTIFF model tiepoint in format [I, J, K, X, Y, Z] where (I, J, K) are pixel coords and (X, Y, Z) are world coords.

scalelist or tuple

GeoTIFF model pixel scale in format [ScaleX, ScaleY, ScaleZ].

Returns:
Affine

Affine transformation matrix.

Raises:
AssertionError

If ScaleZ is not 0 (only 2D rasters are supported).

Examples

>>> tiepoint = [0.0, 0.0, 0.0, 323400.0, 4265400.0, 0.0]
>>> scale = [30.0, 30.0, 0.0]
>>> affine = affine_from_tiepoint_and_scale(tiepoint, scale)
rasterix.lib.affine_from_stac_proj_metadata(metadata)[source]

Extract Affine transform from STAC projection metadata.

Parameters:
metadatadict

Dictionary containing STAC metadata. Should contain a ‘proj:transform’ key.

Returns:
Affine or None

Affine transformation matrix if ‘proj:transform’ is found, None otherwise.

Examples

>>> metadata = {"proj:transform": [30.0, 0.0, 323400.0, 0.0, 30.0, 4268400.0]}
>>> affine = affine_from_stac_proj_metadata(metadata)
rasterix.lib.affine_from_spatial_zarr_convention(metadata)[source]

Extract Affine transform from Zarr spatial convention metadata.

See https://github.com/zarr-conventions/spatial for the full specification.

Parameters:
metadatadict

Dictionary containing Zarr spatial convention metadata.

Returns:
Affine or None

Affine transformation matrix if minimal Zarr spatial metadata is found, None otherwise.

Examples

>>> ds: xr.Dataset = ...
>>> affine = affine_from_spatial_zarr_convention(ds.attrs)
rasterix.lib.spatial_dims_from_zarr_convention(metadata)[source]

Extract spatial dimension names from Zarr spatial convention metadata.

See https://github.com/zarr-conventions/spatial for the full specification.

Parameters:
metadatadict

Dictionary containing Zarr spatial convention metadata.

Returns:
(x_dim, y_dim) or None

Dimension names from spatial:dimensions, interpreted as [y, x] following the convention’s examples. None if the convention is not registered or spatial:dimensions is absent.