One georeferenced array for NumPy and JAX. A
GeoArrayholds the array, its affine transform, CRS, fill value and metadata, and knows which pixel sits where — imported asgeoarray.
Where it comes from¶
A raster is an array plus where its pixels are. Keep the two apart and every function has to carry both; keep them together by subclassing the array type, and the first operation from another array library loses the georeferencing. JAX arrays cannot be subclassed at all.
GeoArray holds its array instead, so one carrier works on NumPy and on
JAX. It is a JAX pytree: the data and a float64 transform are leaves, which
jit, grad and vmap trace, and the stored dims, coordinates, CRS, fill
value and attrs are static.
A new transform (another scene, another patch) reuses compiled code, and
gradients reach the georeferencing.

Install¶
pip install geotoolz-array # NumPy carriers, Grid, PixelWindow
pip install 'geotoolz-array[jax]' # + JAX carriers and the pytree
pip install 'geotoolz-array[vector]' # + footprint as a shapely polygon
pip install 'geotoolz-array[georeader]' # + GeoTensor <-> GeoArray
pip install 'geotoolz-array[xarray]' # + to_xarray / from_xarray (CF spatial_ref)| Extra | Pulls in | Needed for |
|---|---|---|
| (base) | numpy, pyproj, affine, pipekit, pipekit-array | GeoArray, GeoSwath, GeoPoints on NumPy data, geoarray.coords, geoarray.types, the dim-level functions, Grid, PixelWindow, FrozenAttrs |
[jax] | jax | JAX data, GeoArray.to_jax, jit / grad / vmap over carriers |
[vector] | shapely | footprint |
[georeader] | georeader-spaceml | geoarray.interop.georeader (from_georeader, to_georeader) |
[xarray] | xarray | to_xarray / from_xarray, to_dataset, to_datatree; readable types on DataArrays |
A JAX carrier keeps its transform in float64, so it needs
jax.config.update("jax_enable_x64", True). The data keeps its own dtype.
Quickstart¶
Wrap a Sentinel-2 chip in UTM 13N, read its grid, then move it to JAX and jit a function of it.
import jax
import numpy as np
from geoarray import GeoArray, Grid
from geoarray.coords import SpectralAxis
jax.config.update("jax_enable_x64", True)
# Shapes: C = 2 bands (B11, B12), H × W = 600 × 600 pixels of 20 m
chip: GeoArray = GeoArray(
np.zeros((2, 600, 600), dtype=np.float32), # (C, H, W) float32
(20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0), # (a, b, c, d, e, f)
"EPSG:32613",
fill_value=np.nan,
dims=("band", "y", "x"),
coords=(SpectralAxis(names=("B11", "B12"), wavelength_nm=(1610.0, 2190.0)),),
)
b12: GeoArray = chip.sel(band="B12") # (H, W) float32: dims y x
grid: Grid = chip.grid # transform, CRS, (600, 600)
grid.bounds # (600000.0, 3538000.0, 612000.0, 3550000.0)
on_device: GeoArray = chip.to_jax() # (C, H, W) float32 · transform float64
total = jax.jit(lambda g: g.data.sum())(on_device) # () float32Slice it, cut a window by map bounds, and crop patches inside vmap:
each result carries the transform of the pixels it holds.
import jax
import jax.numpy as jnp
import numpy as np
from geoarray import GeoArray, PixelWindow, crop, read_window
jax.config.update("jax_enable_x64", True)
# Shapes: C = 2 bands, H × W = 600 × 600 pixels of 20 m
scene: GeoArray = GeoArray(
np.zeros((2, 600, 600), dtype=np.float32), # (C, H, W) float32
(20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0), # (a, b, c, d, e, f)
"EPSG:32613",
fill_value=np.nan,
dims=("band", "y", "x"),
).to_jax()
sub: GeoArray = scene[..., 100:356, 200:456] # (C, 256, 256): the origin moves
window: PixelWindow = scene.grid.window((604000.0, 3542880.0, 609120.0, 3548000.0))
same: GeoArray = read_window(scene, window) # the same pixels as sub
offsets = jnp.array([[0, 0], [256, 256], [344, 344]]) # (N, 2) int
patches: GeoArray = jax.jit(jax.vmap(lambda o: crop(scene, o, (256, 256))))(offsets)
patches.batch_shape # (3,): (N, C, 256, 256) data, one (6,) transform per patch
valid = scene.valid_mask() # (H, W) bool: every band finite and not the fillBackends and georeader¶
NumPy and JAX carriers mix eagerly, as NumPy and jnp arrays do. Inside
jit, grad or vmap the data are tracers, and NumPy code on them raises
GeoArrayTraceError instead of JAX’s generic error.
| Call | NumPy carrier | JAX carrier |
|---|---|---|
np.asarray(g) | the data, no copy | a host copy; raises under a trace; pipekit_ops.guard reports it |
combine, stack, concatenate, write_window with mixed inputs | — | NumPy inputs move to JAX (needs x64) |
from_georeader(gt) / to_georeader(g) | GeoTensor ↔ GeoArray, sharing memory | to_georeader needs g.to_numpy() first |
import numpy as np
from affine import Affine
from georeader.geotensor import GeoTensor
from geoarray import GeoArray
from geoarray.interop.georeader import from_georeader, to_georeader
gt: GeoTensor = GeoTensor(
np.zeros((2, 600, 600), dtype=np.float32), # (C, H, W) float32
Affine(20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0),
"EPSG:32613",
fill_value_default=np.nan,
)
g: GeoArray = from_georeader(gt) # (C, H, W) float32, the same memory
back: GeoTensor = to_georeader(g[..., :256, :256]) # (C, 256, 256), origin keptWhat’s inside¶
| Name | Use it to… | Guide |
|---|---|---|
GeoArray | carry data with its stored dims, coordinates, transform, CRS, fill value and attrs; sel / isel by name, grid, with_data, to_jax, to_numpy, from_coords | Concepts |
GeoSwath, GeoPoints, pad_points, to_geoswath | carry swaths in sensor geometry (lat/lon leaves), point sets (xy, z, time, valid) and model fields on a lat-lon grid | Tutorial |
geoarray.coords | say what a dim means: SpectralAxis, VariableAxis, VerticalAxis, TimeAxis, PixelGrid, … | Reference |
geoarray.types | name common shapes (GeoImage, GeoMapSeries, GeoTracks, …) and check them with check_dims | Reference |
isel, sel, reduce, map_over, concat, combine, … | pipekit-array’s dim-level functions, on every named carrier; a pipekit-array KernelOp runs on carriers too | Concepts |
to_pixel | map coordinates to fractional pixels (functax’s kernel, re-exported); H(x) itself is geoops.geom.interp_at | When to jit |
to_xarray, from_xarray, to_dataset, to_datatree | cross to xarray losslessly ([xarray]) | Cross to xarray |
Grid | describe a pixel grid without data: bounds, res, shift, crop, from_bounds, isclose, get_config | Reference |
PixelWindow | name a rectangle of pixels, rasterio’s Window without rasterio; Grid.window / Grid.bounds_of convert to and from map bounds | Reference |
g[...], isel | slice with the transform following; select bands with their per-band attrs | Reference |
map, shift_origin, squeeze, expand_dims | change the data on the same grid, move the georeferencing, add or drop leading axes | Reference |
crop, read_window, write_window, pad | cut, read past the edges, write and pad pixels; crop inside jit / vmap | Reference |
valid_mask, pixel_coords, footprint | find the pixels that hold data, their map coordinates, the outline ([vector]) | Reference |
stack, concatenate | join carriers that share a grid (stack(gs, "time"); concatenate is concat by position) | Reference |
FrozenAttrs | keep metadata hashable, so it can key a compiled function | Reference |
RasterSource, AsyncRasterSource | describe a lazy reader: its grid, and reads that return a GeoArray (read_window, load); a GeoArray is one | Reference |
from_georeader, to_georeader | bridge to georeader’s GeoTensor, zero-copy, and (source_from_georeader / source_to_georeader) its lazy readers ([georeader]) | Reference |
as_transform, as_crs | coerce an affine.Affine, six numbers, an EPSG code or WKT | Reference |
Next steps¶
Concepts: carriers, static or leaf, the shared functions, readable types, moving from 0.2.
How-to: When to jit, Cross to xarray.
Tutorial: Swaths and averaging kernels.
The design, its decisions and its roadmap: geoarray: one NumPy/JAX carrier for geotoolz.