Heuristics¶
assign_index() automatically detects the affine transform by trying each source in order, using the first one that succeeds:
Priority |
Source |
Location |
Reference |
|---|---|---|---|
1 |
|
CF grid mapping variable (e.g. |
|
2 |
|
DataArray |
|
3 |
|
DataArray |
|
4 |
|
DataArray, data variable, or Dataset |
|
5 |
1D coordinate arrays |
Coordinate variables for x/y dims |
Common in NetCDF |
Grid mapping variable lookup¶
For priority 1, the grid mapping variable is found following CF conventions:
DataArray: looks for a
grid_mappingattribute on the DataArrayDataset: uses the first
grid_mappingattribute found across data variablesFallback: a coordinate variable named
spatial_ref
Zarr spatial convention lookup¶
For priority 4, the convention must be registered in the zarr_conventions attribute (by name spatial: or by UUID); bare spatial: attributes are ignored otherwise. Attributes are looked up on the DataArray for DataArrays, and on each data variable then the Dataset itself for Datasets — array-level attributes take precedence over group-level ones, per the convention.
If a spatial:dimensions attribute is present, it is also used to auto-detect the x/y dimension names when x_dim/y_dim are not passed to assign_index(). The listed names are interpreted as [y, x], following the convention’s examples; spatial:transform uses standard Affine coefficient ordering [a, b, c, d, e, f], mapping (column, row) -> (x, y).
Coordinate array fallback¶
For priority 5, coordinate variables must be 1D with at least 2 values. Pixel spacing is computed as x[1] - x[0] and y[1] - y[0], and coordinates are assumed to be pixel-centered.
Logging¶
Enable trace-level logging to see which source is used:
import logging
from rasterix.lib import TRACE
logging.basicConfig(level=TRACE)
logging.getLogger("rasterix").setLevel(TRACE)