Geometry¶
Grid, projection and tiling operators, plus swath / sensor-geometry
corrections and image registration. Coregistration operators for
multi-source matchups live in the geom.coregister subnamespace
(below).
- Projection / resampling:
Reproject,ReprojectLike,Resample,ResampleLike,Resize - Shape:
CropTo,CropToBounds,PadTo - Tiling:
Tile,SlidingWindow,Stitch,Mosaic - Vector ↔ raster:
Rasterize,RasterizeLike,Vectorize - Swath / sensor geometry:
Georeference(GLT),SegmentStitch,BowtieCorrection,AntimeridianSplit,GeostationaryParallaxCorrect - Sampling at points:
interp_at(function, underjit/grad),InterpAt(operator): H(x), a grid read atGeoPoints - Registration:
PhaseAlign(phase cross-correlation),OpticalFlowILK,OpticalFlowTVL1 - Diagnostic calculus:
Gradient1D/2D/3D,Divergence1D/2D/3D,Curl2D/3D,Laplacian1D/2D/3D(operators);gradient_1d,divergence_2d,curl_3d, … and theiradaptive_*twins (arrays);difference,adaptive_difference,difference_offsets,difference_coeffs,nonuniform_coeffs(stencils)
Projection operator choices¶
Reprojectchanges CRS and optionally resolution, or warps onto atargetgrid.engine="gdal"(the default) runs georeader on NumPy;engine="interp"(the[interp]extra) warps ontotargetthrough a functax plan, on NumPy and on JAX underjit, withnearest,bilinear,cubicorcubic_spline.ReprojectLikematches anotherGeoArray's CRS, transform, and shape.ResampleLikeis the same grid-matching surface for resolution/alignment work where the CRS is already compatible.CropToBoundsdelegates togeoreader.read.read_from_bounds(..., boundless=False): the pixel window is rounded outward, so every pixel the bounds touch (even partially) is kept, and the result is clipped to the carrier.
Diagnostic calculus¶
The calculus family has three levels, and each level is built from the one below.
The operators read the geometry from the carrier: they map pixel derivatives to the CRS's axes through the transform, and on a geographic CRS they use the CRS ellipsoid's radii, so horizontal results are per CRS unit (per metre on a geographic CRS).
The array primitives take the steps (dz, dy, dx) or the level positions (z=, coords=) instead, so the same maths runs on bare NumPy or JAX arrays inside a jitted cost.
Both rest on difference and adaptive_difference, whose stencils come from difference_offsets and difference_coeffs, or from nonuniform_coeffs on an unevenly spaced axis.
Each name carries its dimension:
- the 2-D operators (
Gradient2D,Divergence2D,Curl2D,Laplacian2D) work overy x; - the 3-D ones (
Gradient3D,Divergence3D,Curl3D,Laplacian3D) add theleveldim, spaced by itsVerticalAxis(depths, heights or pressures, unevenly spaced or not);Gradient3DandCurl3Dreturn acomponentdim holding(z, y, x); - the 1-D ones (
Gradient1D,Divergence1D,Laplacian1D) work along one dim named byalong:"x"or"y"(on an axis-aligned grid),"level", or"time"(per second, from theTimeAxis).
A curl needs two dimensions, so there is no Curl1D.
The calculus operators expect collocated fields, all on one grid of cell centres.
Ocean and atmosphere models often write staggered (Arakawa C-grid) output, with u on x-faces and v on y-faces.
Collocate such output in the model library before calling an operator here, for example with finitevolX's Interpolation2D, or use finitevolX's own C-grid operators when you need model-grade differences.
xrtoolz follows the same rule (its decision D14).
Pick nan_policy="adaptive" when the field has a mask that matters, such as a coastline: each derivative then uses the widest stencil that fits on valid data, so the cells next to land keep a value and only the masked cells are NaN.
The default, "propagate", uses the plain stencil, and a masked cell costs a halo of about accuracy cells.
import numpy as np
from geoarray import GeoArray
import geoops as gz
rows, cols = np.mgrid[0:7, 0:9] + 0.5
x, y = 10.0 * cols, -10.0 * rows # (7, 9) metres
transform = (10.0, 0.0, 0.0, 0.0, -10.0, 0.0)
u = GeoArray(-y, transform, "EPSG:32613", dims=("y", "x")) # (7, 9) float64
v = GeoArray(x, transform, "EPSG:32613", dims=("y", "x")) # (7, 9) float64
land = np.zeros((7, 9), dtype=bool) # (7, 9) bool, True drops
land[:, 4] = True
zeta = gz.Curl2D(nan_policy="adaptive")(u, v, land) # (7, 9), 2.0 off the wall
div = gz.Divergence2D()(u, v) # (7, 9), 0.0 everywhere
same = gz.geom.adaptive_curl_2d(-y, x, -10.0, 10.0, mask=land) # (7, 9) ndarray
depth = np.array([0.0, 5.0, 15.0, 30.0]) # (4,) uneven levels, m
dtdz = gz.geom.gradient_1d(depth**2, coords=depth) # (4,) per metre
lap = gz.geom.laplacian_3d(np.zeros((4, 7, 9)), z=depth) # (4, 7, 9) float64
Sampling at points¶
interp_at reads a grid at the positions of a geoarray.GeoPoints: the
observation operator H(x) of data assimilation. Bilinear weights blend the
four pixels around each point (InterpAt declares it spatial, reach 1);
"nearest" reads one. A point off the grid or on nodata is NaN and
invalid, and a padded point gives 0, so a masked cost and its gradient do
not depend on the padding. It runs on NumPy and under jax.jit /
jax.grad; InterpAt is the same function as an operator, with the
points as its second input. It moved here from geoarray (GA-B6), which
keeps geoarray.to_pixel for the coordinate maths.
InterpAt.plan(grid, points) returns that plan, H, built once per grid and points: plan.adjoint(r) and plan.operator().transpose() send point residuals back onto the grid as Hᵀ r.
The stencil is a functax plan (functax.interp.Linear or Nearest on the grid's AffineGrid, with extent="cells" and boundary="edge"), so H has a tested adjoint, and both need the [interp] extra; a NumPy grid is read on JAX in 64-bit mode and comes back as NumPy.
geoops.geom
¶
Geometry, projection, tiling, mosaicking, rasterization, and vectorization.
Cross-modality coregistration operators (raster↔raster grid alignment,
swath↔grid, raster↔points, point-cloud↔raster, vector-with-aggregation)
live in the coregister subnamespace (and at the top level) — see
docs/catalog/design/query-matchup.md §5 for the design.
AntimeridianSplit
¶
Bases: Operator
Split a geographic swath at a longitude wrap.
Longitudes are read from gt.attrs["lons"] / gt.attrs["lon"] /
gt.attrs["longitude"] when present -- one value per column (a 1-D
tuple) or one per pixel (nested (H, W) tuples such as
lons.tolist(); attrs cannot hold a 2-D array) -- otherwise they are
derived from the affine grid for geographic CRSs. If no jump larger
than tolerance_deg is found, the output is a single-item list
containing the input unchanged.
Each part carries its normalised longitudes (in [-180, 180)) under
attrs["lons"], in the form they were read: per column when the
input gave one value per column (or the grid-derived longitudes are
constant along rows), else per pixel as nested tuples.
Geo-dependent: requires a georeferenced GeoArray input (attrs /
geographic grid); plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
str
|
Geographic CRS used to interpret longitudes. |
'EPSG:4326'
|
tolerance_deg
|
float
|
Absolute longitude jump threshold in degrees. |
90.0
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 | |
BowtieCorrection
¶
Bases: Operator
Remove whiskbroom bowtie overlap by resampling each scan along track.
A whiskbroom scanner (MODIS, VIIRS) images N detector rows per
mirror scan. The along-track footprint of a detector grows with scan
angle θ, while the satellite advances by the same distance every scan,
so consecutive scans overlap along track towards the swath edges: the
same ground appears in the last rows of scan j and the first rows of
scan j + 1 (the "bowtie" effect). This operator removes that
duplication, per column, from the scan geometry alone.
Geometry (spherical Earth, radius R; altitude h; see
radiomax.geometry.scan_pixel_growth)::
β(θ) = arcsin(((R + h)/R)·sin θ) − θ Earth central angle
s(θ) = (R + h)·cos θ − √(R² − (R + h)²·sin² θ) slant range
g(θ) = s / (h·cos β) along-track growth
g is the along-track size of a detector, measured in orbit angle
(the coordinate in which every scan advances by the same amount),
relative to nadir; g(0) = 1 and the flat-Earth limit is
1 / cos θ. The column scan angles θ_c follow the constant
mirror rate (see radiomax.geometry.scan_angles),
including VIIRS along-scan aggregation when aggregation_zones is
given.
De-overlap. In units of one nadir detector, scans are contiguous
at nadir (scan j spans rows j·N … j·N + N − 1) and detector
k of scan j lies at y = j·N + (N − 1)/2 + (k − (N − 1)/2)·g.
Output row r = j·N + m is the ground at y = r — a uniform
along-track grid, identical to the input grid at nadir — sampled from
the scan whose centre is nearest (scan j) at fractional detector
k₀ = (N − 1)/2 + (m − (N − 1)/2)/g (nearest or linear in k).
Each scan is therefore shrunk about its centre by 1/g so the rows
it shares with a neighbour are taken once, from the nearer scan. If
that sample is nodata, the overlapping neighbour scan j ± 1 is
used instead when its footprint covers y = r; otherwise the output
is fill.
Output grid. Same shape, transform and CRS as the input; only
along-track values change. Columns are never moved (cross-track pixel
growth is left for a swath-to-grid resampler: grid the corrected swath
with :class:~geoops.geom.coregister.SwathToGrid) and the along-track
extent is conserved.
Assumptions / limitations. Spherical Earth, circular orbit at a
constant altitude, no terrain; scans exactly contiguous at nadir;
detectors equally spaced along track (first order in the detector
angle, error ~ (N·IFOV)² ≈ 10⁻⁴ of a row); the along-track shift of a
scan line caused by satellite motion and Earth rotation during a scan
is common to all scans of a column and does not change the overlap, so
it is ignored. Input rows must be whole scans (H % N == 0) with
row 0 the first detector of a scan.
VIIRS. On-board aggregation makes the columns non-uniform in angle;
pass aggregation_zones (the viirs preset does). On-board
bowtie deletion (1 row per scan edge in the 2-sample zone, 2 in the
unaggregated zone, M-band; doubled for I-bands) delivers the duplicated
rows as fill: they are nodata here, so the neighbouring scan's copy of
that ground is used and no gap remains.
Nodata: a pixel is invalid when any band is non-finite or equals the
carrier's fill; invalid samples never contribute to an output pixel,
and output pixels without a valid source hold the output's fill
(carried_fill: the input's fill for "nearest"; NaN for
"linear" on integer input, which is promoted to float).
(T, C, H, W) stacks are corrected frame by frame.
Pixel-space resampling (driven entirely by the scan-geometry
constructor arguments): both GeoArray and plain np.ndarray
inputs are supported and returned in kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detectors_per_scan
|
int
|
Detector rows per scan |
required |
max_scan_angle_deg
|
float
|
Scan-edge angle |
required |
altitude_km
|
float
|
Orbit altitude |
required |
earth_radius_km
|
float
|
Earth radius |
_EARTH_MEAN_RADIUS_KM
|
aggregation_zones
|
Sequence[Sequence[int]] | None
|
Optional along-scan aggregation table,
|
None
|
method
|
str
|
|
'nearest'
|
Examples:
>>> import geoops as gz
>>> debowtie = gz.geom.BowtieCorrection.modis() # 1 km bands
>>> viirs = gz.geom.BowtieCorrection.viirs(band="M", method="linear")
>>> custom = gz.geom.BowtieCorrection(
... detectors_per_scan=10, max_scan_angle_deg=55.0, altitude_km=705.0
... )
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 | |
modis(resolution_m=1000, *, method='nearest')
classmethod
¶
MODIS (Terra / Aqua) preset.
10 / 20 / 40 detectors per scan at 1 km / 500 m / 250 m, ±55°, 705 km (Barnes et al. 1998; Wolfe et al. 2002).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution_m
|
int
|
Band resolution: |
1000
|
method
|
str
|
|
'nearest'
|
Returns:
| Type | Description |
|---|---|
BowtieCorrection
|
The configured operator. |
Examples:
>>> BowtieCorrection.modis().detectors_per_scan
10
>>> BowtieCorrection.modis(250).detectors_per_scan
40
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
viirs(band='M', *, method='nearest')
classmethod
¶
VIIRS (S-NPP / JPSS) preset for aggregated SDR swaths.
16 M-band (3200 columns) or 32 I-band (6400 columns) detectors per scan, ±56.28°, 824 km, with the three on-board aggregation zones (NOAA NESDIS 142, VIIRS SDR User's Guide). Bowtie-deleted rows are expected as fill and are refilled from the overlapping scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
str
|
|
'M'
|
method
|
str
|
|
'nearest'
|
Returns:
| Type | Description |
|---|---|
BowtieCorrection
|
The configured operator. |
Examples:
>>> BowtieCorrection.viirs().detectors_per_scan
16
>>> BowtieCorrection.viirs("I").aggregation_zones[0]
(3552, 3)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
CropTo
¶
Bases: Operator
Crop a GeoArray to a target spatial shape.
Anchors either at the centre (default) or upper-left corner of the
input. The affine transform is updated by slicing the GeoArray, so
the geographic extent of the surviving pixels is preserved.
Pixel-space cropping: plain np.ndarray inputs are supported
(sliced and returned as plain arrays); the transform bookkeeping
only happens for GeoArray input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
Target spatial shape |
required |
anchor
|
str
|
|
'center'
|
Examples:
>>> import geoops as gz
>>> # Centre-crop a 1024×1024 scene to a 512×512 chip.
>>> chip = gz.geom.CropTo(shape=(512, 512))(scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
CropToBounds
¶
Bases: Operator
Crop a GeoArray to a geographic bounding box.
Thin wrapper over :func:georeader.read.read_from_bounds with
boundless=False: bounds are reprojected into the carrier's
CRS if crs differs from it, the pixel window is rounded
outward (every pixel the bounds touch, even partially, is kept —
matching georeader's readers), and the intersection with the carrier
is read. Non-intersecting bounds raise
:class:rasterio.windows.WindowError.
Geo-dependent: requires a georeferenced GeoArray input
(transform + CRS); plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float]
|
|
required |
crs
|
str | None
|
CRS of |
None
|
Examples:
>>> import geoops as gz
>>> # Crop a global mosaic to a small AOI in geographic coords.
>>> aoi = gz.geom.CropToBounds(
... bounds=(-10.0, 35.0, -8.0, 36.5), crs="EPSG:4326"
... )
>>> patch = aoi(global_scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | |
Curl2D
¶
Bases: Operator
Curl (relative vorticity) of a gridded 2-D vector field in map axes.
.. math::
\zeta = \frac{\partial v}{\partial x} - \frac{\partial u}{\partial y}
Inputs, geometry, masks and outputs as :class:Divergence2D. On a
geographic CRS, with the CRS ellipsoid's radii,
.. math::
\zeta = \frac{1}{N \cos\varphi} \frac{\partial v}{\partial \lambda}
- \frac{1}{M N \cos\varphi}
\frac{\partial (N \cos\varphi\, u)}{\partial \varphi}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> zeta = gz.Curl2D()(u, v) # (y, x)
>>> zeta = gz.Curl2D(nan_policy="adaptive")(u, v, land) # up to the coast
>>> zeta = gz.geom.curl_2d(u, v, dy, dx) # arrays only, jittable
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Curl3D
¶
Bases: Operator
Curl (vorticity vector) of a gridded 3-D vector field on vertical levels.
.. math::
\omega_z = \partial_x v - \partial_y u, \quad
\omega_y = \partial_z u - \partial_x w, \quad
\omega_x = \partial_y w - \partial_z v
:math:\omega_z is :class:Curl2D's relative vorticity; the horizontal
derivatives of w are :class:Gradient2D's (thin-shell on a
geographic CRS), and ∂/∂z runs along the level dim with its
VerticalAxis spacing. z is the level coordinate as stored and
w its component: on a positive="down" axis (depth, pressure)
(x, y, z) is left-handed, so :math:\omega_y and :math:\omega_x
have the opposite sign of the curl in upward height. The result gains a
component dim before y x holding (ω_z, ω_y, ω_x), in axis
order as :class:Gradient3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> omega = gz.Curl3D()(u, v, w) # (level, component, y, x)
>>> omega = gz.geom.curl_3d(u, v, w, dz, dy, dx, z=height) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Divergence1D
¶
Bases: Operator
Divergence of a flux along one dim, :math:\partial u / \partial s.
In one dimension the divergence of a flux is its derivative, so this is
:class:Gradient1D read as a conservation term: ∂F/∂z of a vertical
flux on "level", ∂q/∂x along a channel. along, spacing, masks
and outputs as :class:Gradient1D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
along
|
str
|
|
'x'
|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic
|
bool
|
The dim wraps. |
False
|
Examples:
>>> import geoops as gz
>>> heating = gz.Divergence1D(along="level")(heat_flux) # (level, y, x)
>>> ddiv = gz.geom.divergence_1d(flux, coords=depth, axis=-3) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Divergence2D
¶
Bases: Operator
Divergence of a gridded 2-D vector field in map axes, NaN- and mask-aware.
.. math::
\nabla \cdot \mathbf{u} = \frac{\partial u}{\partial x}
+ \frac{\partial v}{\partial y}
u and v are two positional carriers on one grid, the components
along the CRS's x and y (eastward and northward on a geographic
CRS). The geometry, nan_policy and mask follow :class:Gradient2D:
pixel derivatives map to map axes through the transform's Jacobian, so
north-up, flipped and rotated grids are exact for a linear field. On a
geographic CRS the divergence uses the CRS ellipsoid's radii
:math:M(\varphi) and :math:N(\varphi), as Gradient2D does,
.. math::
\nabla \cdot \mathbf{u} = \frac{1}{N \cos\varphi}
\frac{\partial u}{\partial \lambda}
+ \frac{1}{M N \cos\varphi}
\frac{\partial (N \cos\varphi\, v)}{\partial \varphi},
which is the spherical form on a sphere (:math:M = N = R). A cell is
dropped where either component is nodata (non-finite, or its carrier's
fill) or mask is True. The result is on the input grid, per CRS
unit (per metre on a geographic CRS), with fill_value=NaN. A plain
array is differentiated in pixel units, rows then columns; a
DataArray is refused (lift it with xrops.lift, or call
:func:geoops.geom.divergence_2d with coordinate spacings).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> div = gz.Divergence2D()(u, v) # (y, x)
>>> div = gz.Divergence2D(nan_policy="adaptive")(u, v, land) # keeps the coast
>>> div = gz.geom.adaptive_divergence_2d(u, v, dy, dx, mask=land) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 | |
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Divergence3D
¶
Bases: Operator
Divergence of a gridded 3-D vector field on vertical levels.
.. math::
\nabla \cdot \mathbf{u} = \nabla_h \cdot \mathbf{u}_h
+ \frac{\partial w}{\partial z}
The horizontal part as :class:Divergence2D (the ellipsoid's flux form on
a geographic CRS, thin-shell), plus ∂w/∂z along the level dim with
its VerticalAxis spacing. w is the component along increasing
level values, so on pressure levels this is the pressure-coordinate
divergence with :math:\omega in w; on depth levels w points
down. u, v and w are three positional carriers with one grid
and one level axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> div = gz.Divergence3D()(u, v, omega) # (level, y, x)
>>> div = gz.geom.divergence_3d(u, v, w, dz, dy, dx, z=depth) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Georeference
¶
Bases: Operator
Georeference swath data using a GLT (geolocation lookup table) GeoArray.
Thin wrapper around :func:georeader.griddata.georreference (note
the upstream spelling), called through the engine boundary. The GLT (Geolocation Lookup Table) maps
output-grid pixels to source-sensor pixels for fast, exact
orthorectification with no resampling artifacts.
The input is sensor-space swath data, so plain np.ndarray input
is accepted alongside GeoArray; the output is always a
georeferenced GeoArray whose geometry comes from the GLT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
glt
|
GeoArray
|
GLT |
required |
valid_glt
|
ndarray | None
|
Optional boolean mask of valid GLT pixels. |
None
|
Note
Carries a concrete GeoArray and (optionally) a numpy array
reference, so flagged forbid_in_yaml = True.
Examples:
>>> import geoops as gz
>>> # Orthorectify a hyperspectral scene predicted in sensor space.
>>> ortho = gz.geom.Georeference(glt=glt)(prediction_swath)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
GeostationaryParallaxCorrect
¶
Bases: Operator
Shift pixels from apparent geostationary view position to nadir.
For each output ground pixel, the operator finds where an elevated target
would appear to a geostationary satellite, on the ellipsoid
(radiomax.geometry.apparent_position), and samples the input there,
treating each input value as located at its pixel centre.
target_height_m=0 is an exact identity. Pixels without an apparent
position (the target is above the limb or behind it) are filled with
gt.fill_value (0 when it is None).
Geo-dependent: requires a georeferenced GeoArray input on an
EPSG:4326 grid; plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
satellite_lon_deg
|
float
|
Sub-satellite longitude. |
required |
satellite_height_m
|
float
|
Satellite height above the equator. |
35786023.0
|
target_height_m
|
float | ndarray | GeoArray
|
Scalar height, same-grid array, or same-grid GeoArray. |
0.0
|
earth_radius_m
|
float | None
|
Radius of a spherical Earth; |
None
|
method
|
str
|
|
'bilinear'
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 | |
Gradient1D
¶
Bases: Operator
Derivative of a gridded field along one dim, NaN- and mask-aware.
along names the dim, and its spacing comes from the carrier:
"x"or"y": the transform's column or row step, on a grid whose rows and columns follow the CRS's axes (a rotated or sheared grid raises, naming :class:Reproject;NaNunderjax.jit). On a geographic CRS the derivative is per metre of arc on the CRS ellipsoid, eastward along a parallel or northward along a meridian, as :class:Gradient2D's components are;"level": theVerticalAxisvalues on theleveldim, unevenly spaced or not (depth or height in metres, pressure in its units);"time": theTimeAxisstamps, per second.
Masks, nodata and outputs as :class:Gradient2D, on the input's dims; a
plain array is differentiated in pixel units along "x" (its last
axis) or "y".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
along
|
str
|
|
'x'
|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic
|
bool
|
The dim wraps ( |
False
|
Examples:
>>> import geoops as gz
>>> dtdz = gz.Gradient1D(along="level")(temperature) # (level, y, x), per metre
>>> dfdt = gz.Gradient1D(along="time")(ssh_series) # per second
>>> dfdx = gz.geom.gradient_1d(f, dx) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Gradient2D
¶
Bases: Operator
Diagnostic gradient of a gridded field in map axes, NaN- and mask-aware (OP-O7).
Masks. nan_policy decides what a masked cell costs:
"propagate"(default): the plain stencil; a masked cell (non-finite, the carrier's fill, orTrueinmask) makes every derivative whose stencil reads itNaN, a halo of aboutaccuracycells;"adaptive": per point, the widest stencil lying wholly on valid data (central, then forward, then backward, at decreasing accuracy), so valid cells next to land keep a one-order-lower estimate and only masked cells areNaN.
The arithmetic is the public L1 primitives, so the same maths is
available without a carrier: :func:geoops.geom.gradient_2d /
:func:geoops.geom.adaptive_gradient_2d over :func:geoops.geom.difference
/ :func:geoops.geom.adaptive_difference, whose stencils come from
:func:geoops.geom.difference_offsets and :func:geoops.geom.difference_coeffs.
Geometry, derived from the carrier. The row and column derivatives
map to the CRS's x and y through the transform's Jacobian
(:math:x = a\,j + b\,i + c,\; y = d\,j + e\,i + f),
.. math::
\begin{pmatrix} \partial_x f \\ \partial_y f \end{pmatrix}
= \frac{1}{ae - bd}
\begin{pmatrix} e & -d \\ -b & a \end{pmatrix}
\begin{pmatrix} \partial_j f \\ \partial_i f \end{pmatrix},
exact for a linear field on north-up, flipped and rotated grids. On a
geographic CRS its angular unit (degrees, grads) becomes metres on the CRS's ellipsoid at each
pixel's latitude :math:\varphi:
:math:\partial_{\mathrm{north}} f = \partial_\varphi f / (M(\varphi)\,\pi/180),
:math:\partial_{\mathrm{east}} f = \partial_\lambda f / (N(\varphi)\cos\varphi\,\pi/180),
with :math:M, :math:N the meridional and prime-vertical radii.
The result gains a component dim just before y x holding
(∂f/∂y, ∂f/∂x), per CRS unit (per metre on a geographic CRS), and
declares fill_value=NaN. A plain array is differentiated in pixel
units, rows then columns. A diagnostic: model-grade calculus on
staggered grids stays in finitevolX. A geometry operator, so a
DataArray is refused: lift it with xrops.lift, or call the L1
primitives with coordinate spacings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils (the centred one
is one order higher); |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> grad = gz.Gradient2D()(ssh_map) # (component, y, x)
>>> grad = gz.Gradient2D(nan_policy="adaptive")(ssh_map, land) # keeps the coast
>>> step = jax.jit(gz.Gradient2D()) # one trace across transforms
>>> d_y, d_x = gz.geom.adaptive_gradient_2d(ssh, dy, dx, mask=land) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 | |
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Gradient3D
¶
Bases: Operator
Gradient of a gridded field on vertical levels, NaN- and mask-aware.
(∂f/∂z, ∂f/∂y, ∂f/∂x): the horizontal components as
:class:Gradient2D (map axes, the ellipsoid on a geographic CRS), and
the vertical one along the carrier's level dim with the spacing of its
VerticalAxis, unevenly spaced levels included. z is the level
coordinate as stored (depth, height or pressure), so ∂f/∂z is per
unit of it. On a geographic CRS this is the thin-shell form: the
horizontal metric does not change with height.
The result gains a component dim before y x holding
(∂f/∂z, ∂f/∂y, ∂f/∂x), with fill_value=NaN. A plain array is
differentiated in pixel units over its last three axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> grad = gz.Gradient3D()(temperature) # (level, component, y, x)
>>> grad = gz.Gradient3D(nan_policy="adaptive")(temperature, seabed)
>>> d_z, d_y, d_x = gz.geom.gradient_3d(t, dz, dy, dx, z=depth) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
InterpAt
¶
Bases: Operator
H(x): a grid read at the positions of points, as an operator.
geoops.geom.interp_at in a pipeline: InterpAt()(grid, points)
returns a geoarray.GeoPoints with the grid's values at the points
(bilinear or nearest), valid=False and NaN off the grid or on
nodata, and 0 on padded points so a masked cost stays finite. The
points are the second positional input, so a pipekit_ops.Graph wires
them from their own Input. Unlike the function, the operator never
moves a NumPy grid to JAX for JAX points: pipekit refuses mixed
backends, so call grid.to_jax() first.
The declared coupling (spatial, reach 1) is bilinear's; "nearest"
reads one pixel, so for it the declaration is an upper bound.
plan(grid, points) returns the functax plan H the operator reads
with: H(y) on the grid flattened to (..., N) gives the values at
the points, and H.adjoint(r) (or H.operator().transpose()) sends
point residuals back onto the grid, Hᵀ r. The operator builds a plan
once per (grid, points) on concrete inputs and reuses it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['bilinear', 'nearest']
|
|
'bilinear'
|
along
|
str
|
The dim a per-point |
'time'
|
Example
import numpy as np from geoarray import GeoArray, GeoPoints import geoops as gz t = (1.0, 0.0, 0.0, 0.0, -1.0, 4.0) g = GeoArray(np.arange(16.0).reshape(4, 4), t, None, dims="y x") p = GeoPoints(np.zeros(1), xy=np.array([[1.0, 3.0]]), dims="obs", crs=None) gz.InterpAt()(g, p).data.tolist() [2.5]
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 | |
plan(grid, points)
¶
H, the functax plan this operator reads grid at points with.
f̂ = H y for y the grid flattened row-major to (..., N), N = H·W,
with NaN at points off the grid; plan.adjoint(r) is Hᵀ r, and
plan.operator() is H as an (M, N) lineax operator (its
transpose() is (N, M)). Padded or non-finite points read
nothing. The nodata rule is the operator's, not the plan's: calling
the operator also masks points that read nodata.
Built once per (grid, points) and cached (the 16 most recent) when
both are concrete and it is built outside a trace; under jit it
is built in the trace and not kept. A plan
on a NumPy grid is built in JAX's 64-bit mode and holds float64
weights, so apply it with jax_enable_x64 on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
GeoArray
|
The carrier |
required |
points
|
GeoPoints
|
Where to read, in |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A |
Raises:
| Type | Description |
|---|---|
ImportError
|
functax's plans are missing (the |
Example
import numpy as np from geoarray import GeoArray, GeoPoints import geoops as gz t = (1.0, 0.0, 0.0, 0.0, -1.0, 4.0) g = GeoArray(np.arange(16.0).reshape(4, 4), t, None, dims="y x") p = GeoPoints(np.zeros(1), xy=np.array([[1.0, 3.0]]), dims="obs", crs=None) H = gz.InterpAt().plan(g, p) # (1, 16) np.asarray(H(g.data.reshape(-1))).tolist() # doctest: +SKIP [2.5]
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
Laplacian1D
¶
Bases: Operator
Second derivative of a gridded field along one dim, NaN- and mask-aware.
:math:\partial^2 f / \partial s^2 with second-derivative stencils;
along, spacing, masks and outputs as :class:Gradient1D. On a
geographic CRS it is per square metre of arc: along a parallel
:math:f_{\lambda\lambda} / (N \cos\varphi)^2, along a meridian
:math:f_{\varphi\varphi} / M^2 - M' f_\varphi / M^3 (the meridian's
radius of curvature changes with latitude).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
along
|
str
|
|
'x'
|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic
|
bool
|
The dim wraps. |
False
|
Examples:
>>> import geoops as gz
>>> curvature = gz.Laplacian1D(along="level")(temperature) # per m²
>>> d2f = gz.geom.laplacian_1d(f, coords=depth, axis=-3) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Laplacian2D
¶
Bases: Operator
Laplacian of a gridded field in 2-D map axes, NaN- and mask-aware.
.. math::
\nabla^2 f = \frac{\partial^2 f}{\partial x^2}
+ \frac{\partial^2 f}{\partial y^2}
Second-derivative stencils (derivative=2) along the pixel axes. The
Laplacian is rotation-invariant, so on a grid with perpendicular axes
(north-up, flipped or rotated) it is
:math:f_{jj} / |\mathbf{a}_j|^2 + f_{ii} / |\mathbf{a}_i|^2, with
:math:\mathbf{a}_j = (a, d) and :math:\mathbf{a}_i = (b, e) the
column and row steps; a quadratic stays exact up to the edges. On a
geographic CRS (rows and columns along latitude and longitude), with the
CRS ellipsoid's radii :math:M(\varphi) and :math:N(\varphi),
.. math::
\nabla^2 f = \frac{1}{N^2 \cos^2\varphi}
\frac{\partial^2 f}{\partial \lambda^2}
+ \frac{1}{M^2} \frac{\partial^2 f}{\partial \varphi^2}
+ \frac{1}{M N \cos\varphi}
\frac{d}{d\varphi}\!\left(\frac{N \cos\varphi}{M}\right)
\frac{\partial f}{\partial \varphi},
which on a sphere has the last term :math:-\tan\varphi / R^2\,
\partial f / \partial \varphi. A sheared grid (or a rotated geographic
one) raises, naming :class:Reproject; under jax.jit, where the
transform is traced, such a grid gives NaN instead. Units per CRS
unit squared (per square metre on a geographic CRS); masks, nodata and
carriers as :class:Gradient2D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> lap = gz.Laplacian2D()(ssh_map) # (y, x)
>>> lap = gz.Laplacian2D(nan_policy="adaptive")(ssh_map, land)
>>> lap = gz.geom.laplacian_2d(ssh, dy, dx) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 | |
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Laplacian3D
¶
Bases: Operator
Laplacian of a gridded field on vertical levels, NaN- and mask-aware.
.. math::
\nabla^2 f = \nabla_h^2 f + \frac{\partial^2 f}{\partial z^2}
The horizontal part as :class:Laplacian2D (its grid conditions and the
ellipsoid's metric, thin-shell), plus the second derivative along the
level dim with its VerticalAxis spacing, unevenly spaced levels
included. Units: the horizontal part per CRS unit squared (per square
metre on a geographic CRS), the vertical one per level unit squared, so
mix them only where those agree (heights or depths in metres).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
int
|
Accuracy order of the one-sided stencils. |
1
|
nan_policy
|
str
|
|
'propagate'
|
periodic_x
|
bool
|
The columns wrap, for a global longitude grid. |
False
|
Examples:
>>> import geoops as gz
>>> lap = gz.Laplacian3D()(temperature) # (level, y, x)
>>> lap = gz.geom.laplacian_3d(t, dz, dy, dx, z=depth) # arrays only
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: the widest stencil the mask-aware policy may use; None when x is periodic.
Mosaic
¶
Bases: Operator
Mosaic multiple GeoArrays onto a single grid.
For method="first" this is a thin wrapper around
:func:georeader.mosaic.spatial_mosaic: rasters are processed in
order and the first valid pixel wins. For all other methods the
frame is the union of the input bounds on the first raster's pixel
grid (its CRS / dtype), every input is reprojected onto that frame
(its fill sentinel becoming NaN) and the per-pixel reduction is
applied:
.. math::
\hat{x}_{ij} \;=\; \mathrm{agg}\!\left(
\{ x^{(k)}_{ij} \;|\; x^{(k)}_{ij} \neq \text{fill} \}
\right)
with agg chosen from mean, median, max, min.
Pixels no input covers get the first raster's fill_value;
when that is None they get NaN (float dtypes) or 0 (integer
dtypes), and "first" also takes this stacked path because
spatial_mosaic cannot pad fill-less inputs.
Geo-dependent: every input must be a georeferenced GeoArray
(transform + CRS drive the mosaic frame); plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
|
'first'
|
resampling
|
str
|
Resampling mode used for reprojection onto the mosaic frame. |
'bilinear'
|
Examples:
>>> import geoops as gz
>>> # Median-composite a stack of overlapping S2 scenes.
>>> composite = gz.geom.Mosaic(method="median")(s2_scene_list)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 | |
OpticalFlowILK
¶
Bases: OpticalFlowTVL1
Dense per-pixel displacement via iterative Lucas-Kanade optical flow.
Same contract as :class:OpticalFlowTVL1 (both carriers supported),
delegating to :func:skimage.registration.optical_flow_ilk.
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
OpticalFlowTVL1
¶
Bases: Operator
Dense per-pixel displacement via TV-L1 optical flow.
Wraps :func:skimage.registration.optical_flow_tvl1 on the selected
registration band. The output is a (2, H, W) displacement field
([dy, dx] per pixel) on the input's carrier: pixel-space math,
so both GeoArray and plain np.ndarray inputs are supported
and returned in kind. Pixels that are nodata in either scene are
NaN (fill_value=NaN). Inputs are (H, W) or
(C, H, W); a 4-D (T, C, H, W) stack raises ValueError
(compute the flow of each frame separately).
Called as op(moving, reference): reference is the fixed scene
the input is registered against, on the input's pixel grid
(ValueError otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
int
|
Band index (along the band axis) used for registration on 3-D inputs. |
0
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
PadTo
¶
Bases: Operator
Pad a GeoArray up to a target spatial shape.
Pads the spatial axes ("y", "x") symmetrically so the output
has at least shape pixels along each spatial axis. If the
input already exceeds the target on an axis, that axis is left
alone (no truncation — pair with :class:CropTo for that).
The affine transform is re-based (geoarray.pad for a constant
pad with the carrier's own fill) so the geographic position of the
existing data does not move; new rows appear to the top/bottom and
new columns to the left/right. The output keeps the input's
fill_value.
Pixel-space padding: plain np.ndarray inputs are supported and
padded with :func:numpy.pad (returned as plain arrays); the
transform bookkeeping only happens for GeoArray input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
Target minimum spatial shape |
required |
mode
|
str
|
Numpy pad mode. |
'constant'
|
fill_value
|
float | None
|
Constant value when |
None
|
Examples:
>>> import geoops as gz
>>> # Pad to a multiple of 256 before tiling.
>>> snug = gz.geom.PadTo(shape=(2048, 2048), fill_value=0)(scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
PhaseAlign
¶
Bases: Operator
Sub-pixel image registration via phase cross-correlation.
Arrays are interpreted as (H, W) or channel-first (C, H, W);
the selected registration band is taken from the band axis (-3).
A 4-D (T, C, H, W) stack raises ValueError: register each
frame separately. The estimated
(dy, dx) shift (nodata pixels of either registration band set to
that band's valid mean, so a fill value never drives the
correlation) is applied with linear interpolation
(scipy.ndimage.shift) when apply=True.
The registration math is pixel-space, so plain np.ndarray inputs
are supported: they come back as plain shifted arrays. For
GeoArray input the shifted array keeps the input's affine
transform (which must share the reference's grid), so a feature at
pixel (r, c) of the output sits at the same world coordinate as
pixel (r, c) of the reference. Nodata pixels (fill or
non-finite) are shifted as nodata, and edge pixels the shift uncovers
have no data either: every output pixel interpolated from one holds
the input's fill value (NaN for a fill-less float input), so a
sub-pixel shift grows a nodata region by up to one pixel. An integer
input without a fill_value cannot mark nodata; its
uncovered edge repeats the nearest edge pixel.
Called as op(moving, reference): reference is the fixed scene
the input is registered against, on the input's pixel grid
(ValueError otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upsample_factor
|
int
|
Sub-pixel upsampling factor passed to
:func: |
10
|
band
|
int
|
Band index (along the band axis) used for registration on 3-D inputs. |
0
|
apply
|
bool
|
If |
True
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
Rasterize
¶
Bases: Operator
Rasterize geometries onto the input GeoArray's grid.
Burns geometries into a fresh array aligned with the input's
CRS and transform. Accepts either:
- a
listof shapely geometries (each gets value1); or - a :class:
geopandas.GeoDataFrame(thecolumnargument selects which attribute supplies the burn-in value; without one every geometry burns1, as for a list).
Delegates to :func:georeader.rasterize.rasterize_geopandas_like
or :func:georeader.rasterize.rasterize_geometry_like.
Geo-dependent: requires a georeferenced GeoArray input (its
transform + CRS define the burn grid); plain arrays raise
TypeError.
The output is one (H, W) raster whatever the input's rank: every
band and every frame of a (T, C, H, W) stack share the grid, so
one burn serves them all. Its fill_value is fill_value
in the output dtype (0 for the default uint8 burn), and
pixels that are nodata in the input (in any band or frame) hold it.
Note
Carries Python-level geometry objects (shapely / geopandas),
so flagged forbid_in_yaml = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometries
|
list[BaseGeometry] | GeoDataFrame
|
Shapely geometries or a |
required |
column
|
str | None
|
For |
None
|
all_touched
|
bool
|
Whether to mark every pixel the geometry touches (vs. only those whose centre is inside). |
False
|
fill_value
|
float
|
Background value. Default |
0.0
|
Examples:
>>> import geoops as gz
>>> from shapely.geometry import box
>>> aoi_mask = gz.geom.Rasterize(geometries=[box(*aoi_bounds)])(scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 | |
RasterizeLike
¶
Bases: Operator
Rasterize geometries onto a stored reference grid.
Same as :class:Rasterize but the reference grid is pinned at
construction (like) rather than supplied per call. The
operator takes no positional input (it is a producer) -- useful as
the head of a Sequential pipeline that consumes the burned mask --
or a GeoArray on like's grid (ValueError otherwise), whose
nodata pixels then hold the fill as in :class:Rasterize (like
only supplies the grid). The output is one (H, W) raster whatever
the input's rank.
Note
Flagged forbid_in_yaml = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
like
|
GeoArray
|
Reference |
required |
geometries
|
GeoDataFrame
|
Shapely geometries or a |
required |
column
|
str | None
|
Attribute column for the burn-in value, or |
None
|
all_touched
|
bool
|
As in :class: |
False
|
fill_value
|
float
|
Background value. |
0.0
|
Examples:
>>> import geoops as gz
>>> burner = gz.geom.RasterizeLike(
... like=ref_scene, geometries=polygons_gdf, column="class_id"
... )
>>> labels = burner()
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 | |
Reproject
¶
Bases: Operator
Reproject a GeoArray to a destination CRS or onto a target grid.
Two engines. engine="gdal" (the default) wraps
:func:georeader.read.read_to_crs: the destination grid is anchored to
the input's bounding box reprojected into dst_crs, and the
resolution defaults to the input's pixel size expressed in the
destination CRS; it runs on NumPy only (a JAX carrier goes to the host
and back, and a trace is refused). engine="interp" warps onto target
through a functax plan (the [interp] extra): the target pixel
centres go through pyproj to the source CRS once, a scheme plans the
read-out H on the source grid, and every frame and band is H y. It runs
on NumPy and on JAX, under jax.jit / eqx.filter_jit too, and the
centres are computed once per source CRS and reused.
Geo-dependent: requires a georeferenced GeoArray input
(transform + CRS); plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst_crs
|
str | None
|
Target CRS as a string (EPSG code, WKT, PROJ string, or
anything :class: |
None
|
resolution
|
tuple[float, float] | None
|
Optional |
None
|
resampling
|
str
|
One of |
'bilinear'
|
engine
|
Literal['gdal', 'interp']
|
|
'gdal'
|
target
|
Grid | Mapping[str, Any] | None
|
The output grid (a hashable |
None
|
Examples:
>>> import geoops as gz
>>> # Reproject a UTM scene into geographic coords for plotting.
>>> reproj = gz.geom.Reproject(
... dst_crs="EPSG:4326", resampling="bilinear"
... )
>>> geographic = reproj(utm_scene)
>>> # The same warp onto a fixed grid, on JAX and under jit.
>>> import equinox as eqx
>>> import geoarray as ga
>>> target = ga.Grid((0.001, 0.0, -104.0, 0.0, -0.001, 32.0), "EPSG:4326", (500, 500))
>>> warp = eqx.filter_jit(
... gz.geom.Reproject(target=target, resampling="bilinear", engine="interp")
... )
>>> frames = warp(utm_scene.to_jax()) # (T, C, H, W) -> (T, C, 500, 500)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
ReprojectLike
¶
Bases: Operator
Reproject a GeoArray onto another GeoArray's CRS + grid.
Wraps :func:georeader.read.read_reproject_like: the output has the
same CRS, transform, and spatial shape as like. Useful for
aligning auxiliary data (DEMs, masks, predictions from another
sensor) onto a reference scene grid before downstream pipelines.
Geo-dependent: requires a georeferenced GeoArray input
(transform + CRS); plain arrays raise TypeError.
Note
like is a concrete GeoArray, so this Operator is
flagged forbid_in_yaml = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
like
|
GeoArray
|
The reference |
required |
resampling
|
str
|
See :class: |
'bilinear'
|
Examples:
>>> import geoops as gz
>>> # Align a coarse cloud mask onto the scene grid.
>>> aligned_mask = gz.geom.ReprojectLike(
... like=scene, resampling="nearest"
... )(coarse_mask)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
Resample
¶
Bases: Operator
Resample a GeoArray to a target spatial resolution.
The output shape is derived per axis from the ratio of the input
pixel size to the requested resolution,
(round(H * res_y / dst_y), round(W * res_x / dst_x)), and the
resize is delegated to georeader's GeoTensor.resize (through the
engine boundary).
The geographic extent is preserved, so the achieved pixel size
matches resolution exactly only when it divides the extent.
Geo-dependent: the target resolution is expressed in CRS units, so
a georeferenced GeoArray input is required; plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
tuple[float, float]
|
Target |
required |
resampling
|
str
|
Interpolation mode. Default |
'bilinear'
|
anti_aliasing
|
bool
|
Whether to anti-alias before downscaling.
Default |
True
|
Examples:
>>> import geoops as gz
>>> # Downsample a 10 m raster to 30 m.
>>> coarse = gz.geom.Resample(resolution=(30.0, 30.0))(fine_10m)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
ResampleLike
¶
Bases: ReprojectLike
Resample a GeoArray onto another GeoArray's spatial grid.
Alias of :class:ReprojectLike. The intent of the rename is purely
pipeline-readability: in workflows where both inputs already share a
CRS, ResampleLike reads as "match this grid" rather than
"warp into a new projection".
Examples:
>>> import geoops as gz
>>> # Downsample a 10 m S2 band onto a 20 m reference grid.
>>> rs = gz.geom.ResampleLike(like=s2_20m, resampling="average")
>>> b04_20m = rs(b04_10m)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
Resize
¶
Bases: Operator
Resize a GeoArray to a target spatial shape.
Delegates to georeader's GeoTensor.resize (through the engine
boundary), re-basing the affine transform so the geographic extent is preserved
while the pixel grid is densified or coarsened. anti_aliasing
applies a Gaussian pre-filter when downscaling (recommended).
Geo-dependent (transform-updating): requires a georeferenced
GeoArray input; plain arrays raise TypeError.
Note
The interpolation name is mapped onto
:func:skimage.transform.resize's conventions
("bilinear", "bicubic", "nearest").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
Target spatial shape |
required |
anti_aliasing
|
bool
|
Whether to anti-alias before downscaling.
Default |
True
|
resampling
|
str
|
Interpolation mode. Default |
'bilinear'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
SegmentStitch
¶
Bases: Operator
Assemble indexed sensor segments into one contiguous GeoArray.
Segment order is read from each input's
attrs["__geotoolz_segment_meta__"] mapping (a nested dict, frozen
by the carrier) with segment_index and n_segments keys. Both zero-based
(0..n_segments-1) and one-based (1..n_segments) indexing are
accepted. One-based indexing is selected only when an index equal to
n_segments is present; ambiguous missing-edge cases default to
zero-based. Missing segments are filled with fill_value.
Geo-dependent: every segment must be a georeferenced GeoArray
(attrs metadata + transform bookkeeping); plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
str
|
Stitching direction: |
'scan'
|
fill_value
|
float | None
|
Value used for missing segments. |
None
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 | |
SlidingWindow
¶
Bases: Tile
Split a GeoArray into overlapping sliding-window tiles.
Convenience subclass of :class:Tile that takes a scalar
overlap (in pixels) and derives the stride. Equivalent to
Tile(size=size, stride=(size[0] - overlap, size[1] - overlap)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple[int, int]
|
Tile spatial shape |
required |
overlap
|
int
|
Overlap in pixels along both axes. Default |
0
|
Examples:
>>> import geoops as gz
>>> # 256x256 tiles, 32-pixel overlap on every side.
>>> tiles = gz.geom.SlidingWindow(size=(256, 256), overlap=32)(scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
Stitch
¶
Bases: Operator
Stitch georeferenced tiles back into one GeoArray.
Blends a list[GeoArray] (typically the output of :class:Tile)
onto a unioning north-up grid, masking out the
fill_value sentinels that :class:Tile introduces
along the bottom / right edges with boundless=True.
Supported blend modes:
"average"— unweighted mean of overlapping pixels."feather"— overlap-add with triangular edge weights, kernel from :func:geoops.geom._src.array.feather_weights."first"— first tile wins on overlap."max"— element-wise maximum across overlapping tiles.
The mathematical model for "average" / "feather" is the
standard overlap-add reconstruction:
.. math::
\hat{x}_{ij} \;=\; \frac{\sum_k w_k(i, j)\, m_k(i, j)\, x_k(i, j)}
{\sum_k w_k(i, j)\, m_k(i, j)}
where m_k is the validity mask of tile k and w_k is the
weight kernel (1 everywhere for "average", the feather kernel
otherwise). Pixels with no valid contributor are filled with
fill_value (default: the first tile's fill_value).
Unless target_shape is pinned, trailing bottom rows / right
columns with no valid contributor (the sentinel padding
:class:Tile adds to its edge tiles) are cropped off, so a
Tile → Stitch round trip recovers the source extent. Pin
target_shape to keep them.
Geo-dependent: every tile must be a georeferenced GeoArray —
the tile transforms place each tile on the output grid. Plain-array
tiles raise TypeError. Every tile must be north-up
(b == d == 0, a > 0, e < 0) and share the first tile's
pixel size; otherwise ValueError is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blend
|
str
|
Blend mode (see above). Default |
'average'
|
feather_width
|
int
|
Pixel ramp width for |
16
|
target_shape
|
tuple[int, int] | None
|
Optional |
None
|
target_transform
|
Affine | Sequence[float] | None
|
Optional :class: |
None
|
target_crs
|
str | None
|
Optional CRS override for the output. Defaults to the first tile's CRS. |
None
|
fill_value
|
float | int | None
|
Output fill value. |
None
|
Examples:
>>> import geoops as gz
>>> # Round-trip a tiled inference pipeline.
>>> tiles = gz.geom.Tile(size=(256, 256))(scene)
>>> predictions = [model(tile) for tile in tiles]
>>> stitched = gz.geom.Stitch(blend="feather", feather_width=16)(
... predictions
... )
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 | |
Tile
¶
Bases: Operator
Split a GeoArray into spatial tiles.
Wraps :func:georeader.slices.create_windows (with
trim_incomplete=False) and then reads each window with
boundless=True so the trailing-edge tiles match size
exactly. Out-of-bounds areas are padded with the carrier's
fill_value; use :func:Stitch (which masks the
sentinel) to recover the original extent. A GeoArray with
fill_value=None is zero-padded instead — Stitch
cannot tell that padding from data, so pin its target_shape /
target_transform to the source grid to drop it.
Pixel-space tiling: plain np.ndarray inputs are supported and
yield a list of plain arrays (out-of-bounds areas zero-padded, since
a plain array carries no fill_value). Note that
:class:Stitch cannot reassemble plain-array tiles — it needs each
tile's transform to place it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple[int, int]
|
Tile spatial shape |
required |
stride
|
tuple[int, int] | None
|
Step between consecutive tile origins |
None
|
include_incomplete
|
bool
|
Whether to keep edge tiles that don't fully
fit (still emitted at |
True
|
Examples:
>>> import geoops as gz
>>> # 512x512 tiles with 64-pixel overlap.
>>> tiles = gz.geom.Tile(size=(512, 512), stride=(448, 448))(scene)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | |
Vectorize
¶
Bases: Operator
Vectorize non-zero regions of a mask GeoArray into polygons.
Wraps :func:georeader.vectorize.get_polygons. The carrier's
transform is used to express polygons in geographic coordinates.
Polygons with area below min_area_px (in square pixels of the
mask) are dropped.
Geo-dependent: requires a georeferenced GeoArray input (the
transform maps pixels to polygon coordinates); plain arrays raise
TypeError. The mask must be single-band, (H, W) or
(1, H, W); other shapes raise ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_area_px
|
float
|
Minimum polygon area in square pixels. Default
|
25.5
|
simplify_tolerance
|
float | None
|
Optional post-hoc :meth: |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/geom/_src/operators.py
adaptive_curl_2d(u, v, dy=1.0, dx=1.0, *, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware curl: :func:adaptive_difference for each derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch h w']
|
The component along rows. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
mask
|
Bool[ndarray, '*batch h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The curl, |
Example
y, x = np.mgrid[0:5, 0:6].astype(float) wall = x == 2 zeta = adaptive_curl_2d(-y, x, mask=wall) int(np.isnan(zeta).sum()), float(np.nanmax(np.abs(zeta - 2.0))) (5, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_curl_3d(u, v, w, dz=1.0, dy=1.0, dx=1.0, *, z=None, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware 3-D curl: :func:adaptive_difference for each derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch d h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch d h w']
|
The component along rows. |
required |
w
|
Float[ndarray, '*batch d h w']
|
The component along levels. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions; replaces |
None
|
mask
|
Bool[ndarray, '*batch d h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '3 *batch d h w']
|
|
Example
z, y, x = np.mgrid[0:4, 0:5, 0:6].astype(float) rock = (z == 2) & (y == 2) & (x == 3) zeta_z = adaptive_curl_3d(-y, x, 0.0 * z, mask=rock)[0] int(np.isnan(zeta_z).sum()), float(np.nanmax(np.abs(zeta_z - 2.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_difference(f, *, mask=None, axis=-1, step=1.0, coords=None, derivative=1, accuracy=1, periodic=False)
¶
Mask-aware finite difference: the widest stencil that fits on valid data.
Near a mask (land, a swath edge, a cloud) the centred stencil reads a
masked cell and :func:difference loses the valid cells next to it.
This keeps, per point, the first finite result among the central,
forward and backward stencils at accuracy, then at each lower
accuracy down to 1, so a narrow channel still gets a first-order
estimate. Recovered cells carry one order less than the interior.
NaN is its own support detector: a stencil that reads a masked cell
returns NaN (0 * nan is nan), so the selection needs no mask
arithmetic (xrtoolz docs/design/xrgrad-nan-masks.md, where it beat
fill-then-differentiate by ~90x at the coast). Every candidate is
computed, so the call costs 3 * accuracy stencils and runs under
jax.jit. Masked cells are NaN in the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
mask
|
Bool[ndarray, '*shape'] | None
|
|
None
|
axis
|
int
|
The axis to differentiate. |
-1
|
step
|
Float[ndarray, '*shape'] | float
|
The signed step between centres along |
1.0
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
derivative
|
int
|
The derivative order. |
1
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
The derivative, |
Float[ndarray, '*shape']
|
stencil fits on valid data. |
Example
f = np.array([0.0, 1.0, 2.0, np.nan, 4.0, 5.0, 6.0]) # f = x difference(f) array([ 1., 1., nan, nan, nan, 1., 1.]) adaptive_difference(f) array([ 1., 1., 1., nan, 1., 1., 1.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
adaptive_divergence_1d(u, step=1.0, *, axis=-1, coords=None, mask=None, accuracy=1, periodic=False)
¶
Mask-aware 1-D divergence: :func:adaptive_difference of u.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*shape']
|
The flux component along |
required |
step
|
Float[ndarray, '*shape'] | float
|
The signed step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
mask
|
Bool[ndarray, '*shape'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
The divergence, |
Example
adaptive_divergence_1d(np.array([0.0, 2.0, np.nan, 6.0, 8.0]), 2.0) array([ 1., 1., nan, 1., 1.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_divergence_2d(u, v, dy=1.0, dx=1.0, *, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware divergence: :func:adaptive_difference for each derivative.
Each term uses, per point, the widest stencil lying on valid data, so a
linear field stays exact up to the coast. A cell is NaN where mask
drops it or either component is non-finite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch h w']
|
The component along rows. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
mask
|
Bool[ndarray, '*batch h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The divergence, |
Example
y, x = np.mgrid[0:5, 0:6].astype(float) land = (y == 2) & (x == 3) div = adaptive_divergence_2d(x, y, mask=land) int(np.isnan(div).sum()), float(np.nanmax(np.abs(div - 2.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_divergence_3d(u, v, w, dz=1.0, dy=1.0, dx=1.0, *, z=None, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware 3-D divergence: :func:adaptive_difference for each term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch d h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch d h w']
|
The component along rows. |
required |
w
|
Float[ndarray, '*batch d h w']
|
The component along levels. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions; replaces |
None
|
mask
|
Bool[ndarray, '*batch d h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch d h w']
|
The divergence, |
Example
z, y, x = np.mgrid[0:5, 0:5, 0:6].astype(float) rock = (z == 2) & (y == 2) & (x == 3) # off every edge div = adaptive_divergence_3d(x, y, z, mask=rock) int(np.isnan(div).sum()), float(np.nanmax(np.abs(div - 3.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_gradient_1d(f, step=1.0, *, axis=-1, coords=None, mask=None, accuracy=1, periodic=False)
¶
Mask-aware ∂f/∂s along one axis: :func:adaptive_difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
step
|
Float[ndarray, '*shape'] | float
|
The signed step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
mask
|
Bool[ndarray, '*shape'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
The derivative, |
Example
adaptive_gradient_1d(np.array([0.0, 1.0, np.nan, 3.0, 4.0])) array([ 1., 1., nan, 1., 1.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_gradient_2d(f, dy=1.0, dx=1.0, *, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware (∂f/∂y, ∂f/∂x): :func:adaptive_difference on both axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch h w']
|
The field, rows and columns last. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
mask
|
Bool[ndarray, '*batch h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '2 *batch h w']
|
|
Float[ndarray, '2 *batch h w']
|
cells only (a linear field stays exact up to the coast). |
Example
y, x = np.mgrid[0:4, 0:5].astype(float) land = (y == 1) & (x == 2) d_y, d_x = adaptive_gradient_2d(y + x, mask=land) int(np.isnan(d_x).sum()), float(np.nanmax(np.abs(d_x - 1.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_gradient_3d(f, dz=1.0, dy=1.0, dx=1.0, *, z=None, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware (∂f/∂z, ∂f/∂y, ∂f/∂x): :func:adaptive_difference per axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch d h w']
|
The field, levels, rows and columns last. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions; replaces |
None
|
mask
|
Bool[ndarray, '*batch d h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '3 *batch d h w']
|
The three components stacked on a new leading axis. |
Example
z, y, x = np.mgrid[0:4, 0:4, 0:5].astype(float) seabed = (z == 3) & (x == 2) d_z, _, _ = adaptive_gradient_3d(z + y + x, mask=seabed) int(np.isnan(d_z).sum()), float(np.nanmax(np.abs(d_z - 1.0))) (4, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_laplacian_1d(f, step=1.0, *, axis=-1, coords=None, mask=None, accuracy=1, periodic=False)
¶
Mask-aware ∂²f/∂s² along one axis: :func:adaptive_difference of order 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
step
|
Float[ndarray, '*shape'] | float
|
The step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
mask
|
Bool[ndarray, '*shape'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
The second derivative, |
Example
s = np.arange(8.0) f = s**2 f[3] = np.nan adaptive_laplacian_1d(f) array([ 2., 2., 2., nan, 2., 2., 2., 2.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_laplacian_2d(f, dy=1.0, dx=1.0, *, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware Laplacian: :func:adaptive_difference of second order on each axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch h w']
|
The field, rows and columns last. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The step between column centres. |
1.0
|
mask
|
Bool[ndarray, '*batch h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The Laplacian, |
Example
y, x = np.mgrid[0:7, 0:8].astype(float) island = (y == 3) & (x == 4) # two cells from every edge lap = adaptive_laplacian_2d(x2 + y2, mask=island) int(np.isnan(lap).sum()), float(np.nanmax(np.abs(lap - 4.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
adaptive_laplacian_3d(f, dz=1.0, dy=1.0, dx=1.0, *, z=None, mask=None, accuracy=1, periodic_x=False)
¶
Mask-aware 3-D Laplacian: :func:adaptive_difference of order 2 per axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch d h w']
|
The field, levels, rows and columns last. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions; replaces |
None
|
mask
|
Bool[ndarray, '*batch d h w'] | None
|
|
None
|
accuracy
|
int
|
The highest accuracy order to try. |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch d h w']
|
The Laplacian, |
Example
z, y, x = np.mgrid[0:7, 0:7, 0:8].astype(float) rock = (z == 3) & (y == 3) & (x == 4) lap = adaptive_laplacian_3d(x2 + y2 + z**2, mask=rock) int(np.isnan(lap).sum()), float(np.nanmax(np.abs(lap - 6.0))) (1, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
curl_2d(u, v, dy=1.0, dx=1.0, *, accuracy=1, periodic_x=False)
¶
Curl2D (relative vorticity) ∂v/∂x − ∂u/∂y over the last two axes.
.. math::
\zeta = \frac{\partial v}{\partial x} - \frac{\partial u}{\partial y}
A NaN propagates through the stencils that read it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch h w']
|
The component along columns, rows and columns last. |
required |
v
|
Float[ndarray, '*batch h w']
|
The component along rows, on |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres, a scalar or |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres, a scalar or |
1.0
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap (a global longitude). |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The curl, |
Examples:
>>> y, x = np.mgrid[0:4, 0:5].astype(float)
>>> float(curl_2d(-y, x).min()), float(curl_2d(-y, x).max()) # solid-body rotation
(2.0, 2.0)
>>> float(np.abs(curl_2d(x, y)).max()) # an irrotational expansion
0.0
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
curl_3d(u, v, w, dz=1.0, dy=1.0, dx=1.0, *, z=None, accuracy=1, periodic_x=False)
¶
Curl (vorticity vector) over the last three axes; a NaN propagates.
.. math::
\boldsymbol{\omega} = \nabla \times \mathbf{u}, \quad
\omega_z = \partial_x v - \partial_y u, \;
\omega_y = \partial_z u - \partial_x w, \;
\omega_x = \partial_y w - \partial_z v
Components in axis order, (ω_z, ω_y, ω_x), as :func:gradient_3d.
The curl is right-handed in (x, y, z) with z the level
coordinate as stored and w along increasing z: on a
positive="down" axis (depth, pressure) that system is left-handed, so
ω_y and ω_x have the opposite sign of the curl in upward height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch d h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch d h w']
|
The component along rows. |
required |
w
|
Float[ndarray, '*batch d h w']
|
The component along levels. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions for uneven levels; replaces |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '3 *batch d h w']
|
|
Example
z, y, x = np.mgrid[0:3, 0:4, 0:5].astype(float) zeta_z, zeta_y, zeta_x = curl_3d(-y, x, 0.0 * z) # rotation about z float(zeta_z.min()), float(np.abs(zeta_y).max()), float(np.abs(zeta_x).max()) (2.0, 0.0, 0.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
difference(f, *, axis=-1, step=1.0, coords=None, derivative=1, accuracy=1, method='central', periodic=False)
¶
Finite-difference derivative along one axis; a NaN propagates.
The plain stencil, finitediffx's difference on any backend: with
method="central" the centred stencil of order accuracy + 1 inside
and forward / backward stencils of order accuracy on the edges,
nothing wrapping around (accuracy=1 is numpy.gradient's
scheme). "forward" / "backward" use that stencil everywhere it
fits and the other one-sided stencil where it does not.
A stencil that reads a NaN returns NaN, so a masked cell costs a halo of
about accuracy cells; :func:adaptive_difference recovers them.
.. math::
\partial^n_s f(x_i) \approx h^{-n} \sum_k c_k\, f(x_{i + s_k})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
axis
|
int
|
The axis to differentiate. |
-1
|
step
|
Float[ndarray, '*shape'] | float
|
The signed step :math: |
1.0
|
coords
|
Float[ndarray, ' n'] | None
|
The positions of the centres along |
None
|
derivative
|
int
|
The derivative order :math: |
1
|
accuracy
|
int
|
The accuracy order of the one-sided stencils. |
1
|
method
|
Method
|
|
'central'
|
periodic
|
bool
|
The axis wraps (a global longitude): every point uses the
|
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
math: |
Raises:
| Type | Description |
|---|---|
ValueError
|
The axis is shorter than the stencil needs, |
Examples:
>>> f = np.array([0.0, 1.0, 4.0, 9.0, 16.0]) # x², x = 0…4
>>> difference(f)
array([1., 2., 4., 6., 7.])
>>> difference(f, accuracy=2)
array([0., 2., 4., 6., 8.])
>>> difference(f, derivative=2)
array([2., 2., 2., 2., 2.])
>>> z = np.array([0.0, 1.0, 3.0, 7.0, 15.0]) # uneven levels
>>> difference(z**2, coords=z, derivative=2) # exact for a quadratic
array([2., 2., 2., 2., 2.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
difference_coeffs(offsets, derivative=1)
cached
¶
The coefficients of a stencil on offsets, from the Taylor conditions.
Solves :math:\sum_k c_k s_k^m = n!\,\delta_{mn} for
:math:m = 0, \dots, K - 1 in float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offsets
|
tuple[int, ...]
|
The stencil's integer offsets, distinct. |
required |
derivative
|
int
|
The derivative order; fewer than |
1
|
Returns:
| Type | Description |
|---|---|
One coefficient per offset;
|
math:`f^{(n)}(x) \approx h^{-n} \sum_k |
...
|
c_k f(x + s_k h)`. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Too few offsets for the derivative. |
Examples:
>>> difference_coeffs((-1, 0, 1), derivative=2)
(1.0, -2.0, 1.0)
>>> [round(c, 6) for c in difference_coeffs((0, 1, 2), derivative=1)]
[-1.5, 2.0, -0.5]
Source code in packages/geotoolz-ops/src/geoops/geom/_src/stencils.py
difference_offsets(*, derivative=1, accuracy=1, method='central')
cached
¶
The offsets of one stencil, finitediffx's rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
derivative
|
int
|
The derivative order, at least 1. |
1
|
accuracy
|
int
|
The accuracy order, at least 1. A central stencil is built
at |
1
|
method
|
Method
|
|
'central'
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
The integer offsets, ascending. |
Raises:
| Type | Description |
|---|---|
ValueError
|
An order below 1, or an unknown method. |
Examples:
>>> difference_offsets(derivative=1, accuracy=2, method="forward")
(0, 1, 2)
>>> difference_offsets(derivative=2, accuracy=1, method="central")
(-1, 0, 1)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/stencils.py
divergence_1d(u, step=1.0, *, axis=-1, coords=None, accuracy=1, periodic=False)
¶
The 1-D divergence ∂u/∂s of a flux along one axis; a NaN propagates.
In one dimension the divergence of a flux is its derivative, so this is
:func:gradient_1d read as a conservation term (∂F/∂z of a vertical
flux, ∂q/∂x along a channel).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*shape']
|
The flux component along |
required |
step
|
Float[ndarray, '*shape'] | float
|
The signed step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
math: |
Example
divergence_1d(np.array([0.0, 1.0, 4.0, 9.0])) # u = s², s = 0…3 array([1., 2., 4., 5.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
divergence_2d(u, v, dy=1.0, dx=1.0, *, accuracy=1, periodic_x=False)
¶
Divergence ∂u/∂x + ∂v/∂y over the last two axes; a NaN propagates.
.. math::
\nabla \cdot \mathbf{u} = \frac{\partial u}{\partial x}
+ \frac{\partial v}{\partial y}
:func:difference of u along columns (axis=-1, step dx) plus
that of v along rows (axis=-2, step dy), so a uniform-grid
field needs no carrier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch h w']
|
The component along columns, rows and columns last. |
required |
v
|
Float[ndarray, '*batch h w']
|
The component along rows, on |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres, a scalar or |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres, a scalar or |
1.0
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap (a global longitude). |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The divergence, |
Examples:
>>> y, x = np.mgrid[0:4, 0:5].astype(float)
>>> float(np.abs(divergence_2d(-y, x)).max()) # solid-body rotation
0.0
>>> float(divergence_2d(x, y).min()) # a uniform expansion
2.0
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
divergence_3d(u, v, w, dz=1.0, dy=1.0, dx=1.0, *, z=None, accuracy=1, periodic_x=False)
¶
Divergence ∂u/∂x + ∂v/∂y + ∂w/∂z over the last three axes.
.. math::
\nabla \cdot \mathbf{u} = \frac{\partial u}{\partial x}
+ \frac{\partial v}{\partial y} + \frac{\partial w}{\partial z}
w is the component along increasing z (the level coordinate as
stored), so on pressure levels this is the pressure-coordinate divergence
with :math:\omega in w. A NaN propagates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[ndarray, '*batch d h w']
|
The component along columns. |
required |
v
|
Float[ndarray, '*batch d h w']
|
The component along rows. |
required |
w
|
Float[ndarray, '*batch d h w']
|
The component along levels. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions for uneven levels; replaces |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch d h w']
|
The divergence, |
Example
z, y, x = np.mgrid[0:3, 0:4, 0:5].astype(float) float(divergence_3d(x, y, -2.0 * z).max()) # incompressible 0.0
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
gradient_1d(f, step=1.0, *, axis=-1, coords=None, accuracy=1, periodic=False)
¶
∂f/∂s along one axis; a NaN propagates.
:func:difference of first order, named for the calculus family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
step
|
Float[ndarray, '*shape'] | float
|
The signed step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
math: |
Examples:
>>> gradient_1d(np.array([0.0, 2.0, 4.0, 6.0]), 2.0)
array([1., 1., 1., 1.])
>>> z = np.array([0.0, 10.0, 30.0, 70.0]) # uneven levels
>>> gradient_1d(3.0 * z, coords=z)
array([3., 3., 3., 3.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
gradient_2d(f, dy=1.0, dx=1.0, *, accuracy=1, periodic_x=False)
¶
(∂f/∂y, ∂f/∂x) over the last two axes; a NaN propagates.
:func:difference along rows (axis=-2, step dy) and columns
(axis=-1, step dx). At accuracy=1: second-order centred
differences inside, first-order one-sided on the edges, exact for a
linear field everywhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch h w']
|
The field, rows and columns last; leading axes are mapped. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres, a scalar or |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres, a scalar or |
1.0
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap (a global longitude). |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '2 *batch h w']
|
|
Example
y, x = np.mgrid[0:3, 0:4].astype(float) d_y, d_x = gradient_2d(2.0 * y + 3.0 * x) float(d_y.min()), float(d_y.max()), float(d_x.min()), float(d_x.max()) (2.0, 2.0, 3.0, 3.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
gradient_3d(f, dz=1.0, dy=1.0, dx=1.0, *, z=None, accuracy=1, periodic_x=False)
¶
(∂f/∂z, ∂f/∂y, ∂f/∂x) over the last three axes; a NaN propagates.
The components follow the axes, levels (axis=-3) then rows then
columns, as :func:gradient_2d gives rows then columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch d h w']
|
The field, levels, rows and columns last. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The signed step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The signed step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The signed step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions for uneven levels; replaces |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap (a global longitude). |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '3 *batch d h w']
|
|
Example
z, y, x = np.mgrid[0:3, 0:4, 0:5].astype(float) tuple(float(d.max()) for d in gradient_3d(4.0 * z + 2.0 * y + x)) (4.0, 2.0, 1.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
interp_at(grid, points, method='bilinear', *, frame=None, along='time')
¶
H(x): grid read at the positions of points.
The read-out is a functax plan on the grid (functax.interp.Linear or
Nearest). A point is inside when its fractional pixel position lies in
[−½, R − ½] × [−½, C − ½] (extent="cells"), and taps past the last
row or column read the edge pixel (boundary="edge"), so the half
pixel at the border takes the edge value. Nearest-neighbour ties (a
position exactly half way between two pixel centres) go to the lower
pixel, as functax's Nearest does. A point outside the grid's
extent, at a non-finite position, or reading a nodata pixel (non-finite
or the grid's fill, in any band, with a non-zero weight) gives NaN and
valid=False; nodata never blends into a value. A padded point
(valid=False on points) gives 0 and stays invalid, so a masked
cost and its gradient are finite and unchanged by the padding (GA-G16).
JAX points read a NumPy grid on JAX (a constant under jit), so the
values can be differentiated with respect to the positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
GeoArray
|
A carrier |
required |
points
|
GeoPoints
|
Where to read, in |
required |
method
|
str
|
|
'bilinear'
|
frame
|
Any
|
Optional |
None
|
along
|
str
|
The dim |
'time'
|
Returns:
| Type | Description |
|---|---|
GeoPoints
|
A |
GeoPoints
|
points' validity and being inside the grid, and the grid's leading |
dims and coordinates
|
a |
GeoPoints
|
stations is a |
Raises:
| Type | Description |
|---|---|
ValueError
|
The CRSs differ, the grid is batched, or |
ImportError
|
functax's plans are missing (the |
Example
import numpy as np from geoarray import GeoArray, GeoPoints from geoops.geom import interp_at t = (1.0, 0.0, 0.0, 0.0, -1.0, 4.0) g = GeoArray(np.arange(16.0).reshape(4, 4), t, None, dims="y x") p = GeoPoints(np.zeros(2), xy=np.array([[0.5, 3.5], [9.0, 9.0]]), ... dims="obs", crs=None) out = interp_at(g, p) out.data.tolist(), out.valid.tolist() ([0.0, nan], [True, False])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/sampling.py
laplacian_1d(f, step=1.0, *, axis=-1, coords=None, accuracy=1, periodic=False)
¶
∂²f/∂s² along one axis, a second-derivative stencil; a NaN propagates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*shape']
|
The field; any shape. |
required |
step
|
Float[ndarray, '*shape'] | float
|
The step between centres along |
1.0
|
axis
|
int
|
The axis to differentiate. |
-1
|
coords
|
Float[ndarray, ' n'] | None
|
The centres' positions along |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic
|
bool
|
The axis wraps. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*shape']
|
math: |
Examples:
>>> laplacian_1d(np.array([0.0, 1.0, 4.0, 9.0])) # f = s²
array([2., 2., 2., 2.])
>>> z = np.array([0.0, 5.0, 15.0, 30.0]) # uneven levels
>>> laplacian_1d(z**2, coords=z)
array([2., 2., 2., 2.])
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
laplacian_2d(f, dy=1.0, dx=1.0, *, accuracy=1, periodic_x=False)
¶
Laplacian ∂²f/∂x² + ∂²f/∂y² over the last two axes; a NaN propagates.
.. math::
\nabla^2 f = \frac{\partial^2 f}{\partial x^2}
+ \frac{\partial^2 f}{\partial y^2}
Second-derivative stencils (derivative=2), not two first derivatives:
the 3-point centred stencil inside and 3-point one-sided ones on the edges
at accuracy=1, all exact for a quadratic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch h w']
|
The field, rows and columns last; leading axes are mapped. |
required |
dy
|
Float[ndarray, 'h w'] | float
|
The step between row centres, a scalar or |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The step between column centres, a scalar or |
1.0
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap (a global longitude). |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
The Laplacian, |
Examples:
>>> y, x = np.mgrid[0:4, 0:5].astype(float)
>>> lap = laplacian_2d(x**2 + y**2)
>>> float(lap.min()), float(lap.max()) # exact, edges included
(4.0, 4.0)
>>> float(laplacian_2d(x**2, dx=0.5).max()) # steps in coordinate units
8.0
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
laplacian_3d(f, dz=1.0, dy=1.0, dx=1.0, *, z=None, accuracy=1, periodic_x=False)
¶
Laplacian ∂²f/∂x² + ∂²f/∂y² + ∂²f/∂z², second-derivative stencils.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[ndarray, '*batch d h w']
|
The field, levels, rows and columns last. |
required |
dz
|
Float[ndarray, 'd h w'] | float
|
The step between level centres. |
1.0
|
dy
|
Float[ndarray, 'h w'] | float
|
The step between row centres. |
1.0
|
dx
|
Float[ndarray, 'h w'] | float
|
The step between column centres. |
1.0
|
z
|
Float[ndarray, ' d'] | None
|
The level centres' positions for uneven levels; replaces |
None
|
accuracy
|
int
|
The accuracy order (see :func: |
1
|
periodic_x
|
bool
|
The columns wrap. |
False
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch d h w']
|
The Laplacian, |
Example
z, y, x = np.mgrid[0:3, 0:4, 0:5].astype(float) lap = laplacian_3d(x2 + y2 + z**2) float(lap.min()), float(lap.max()) # exact, edges included (6.0, 6.0)
Source code in packages/geotoolz-ops/src/geoops/geom/_src/array.py
nonuniform_coeffs(dz, derivative=1)
¶
Stencil coefficients for points at arbitrary distances, on any backend.
The non-uniform form of :func:difference_coeffs: for each point, the
weights :math:c_k with :math:f^{(n)}(z) \approx \sum_k c_k f(z + \delta_k)
solve the Taylor conditions :math:\sum_k c_k \delta_k^m / m! = \delta_{mn}
for :math:m = 0, \dots, K - 1, so the stencil is exact for polynomials of
degree :math:K - 1. Each row is solved in units of its own widest
distance, which keeps the system well conditioned for coordinates in
metres or pascals. Written on the array namespace, so traced distances
(a TimeAxis under jax.jit) work too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dz
|
Any
|
|
required |
derivative
|
int
|
The derivative order :math: |
1
|
Returns:
| Type | Description |
|---|---|
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Too few points for the derivative. |
Examples:
>>> nonuniform_coeffs(np.array([-1.0, 0.0, 1.0])) # the uniform stencil
array([-0.5, 0. , 0.5])
>>> # uneven levels at 0, 1 and 3 m: still exact for a quadratic
>>> c = nonuniform_coeffs(np.array([-1.0, 0.0, 2.0]), derivative=2)
>>> float(c @ np.array([-1.0, 0.0, 2.0]) ** 2)
2.0
Source code in packages/geotoolz-ops/src/geoops/geom/_src/stencils.py
Coregistration¶
geom.coregister aligns one source onto another's support — the
coregistration callables for geopatcher.matched.MatchedField:
RasterToRasterLike, RasterToPoints / PointsToRaster ([vector-cube]
extra), RasterToPointCloud / PointCloudToRaster, VectorToRasterAgg, and
SwathToGrid(target=grid), which grids a GeoSwath onto a geoarray.Grid
(pass raster.grid to match a raster). The IDW and
nearest paths run on functax plans ([interp] extra).
geoops.geom.coregister
¶
geoops.geom.coregister — cross-modality coregistration operators.
Public re-exports of the operators implemented in
geoops.geom._src.coregister. The subnamespace lives under geom
because these are genuine geometric operations — the same module that
owns Reproject / Resample / Rasterize. Like every public
operator, each is also re-exported at the top level
(gz.RasterToRasterLike, ...).
See docs/catalog/design/query-matchup.md §5.
PointCloudToRaster
¶
Bases: Operator
Rasterize a point cloud onto a target grid.
Numpy-first counterpart to PointsToRaster. The cloud input is
a tuple (xy_array, values_array) so callers don't need to
wrap their raw arrays in a GeoDataFrame.
Geo-dependent: like must be a georeferenced GeoArray
(its transform defines the target grid); plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['binned_stat', 'idw']
|
|
'binned_stat'
|
stat
|
Literal['mean', 'median', 'sum', 'count', 'max', 'min']
|
For |
'mean'
|
power
|
float
|
For |
2.0
|
k
|
int
|
For |
8
|
max_radius
|
float | None
|
For |
None
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
PointsToRaster
¶
Bases: Operator
Bin a vector cube of point measurements onto a target raster grid.
"binned_stat" uses scipy.stats.binned_statistic_2d with the
like raster's pixel-edge grid as bins. "idw" takes, at each
pixel centre, the inverse-distance weighted mean of the k nearest
points (functax.interp.InverseDistance, the [interp] extra),
as PointCloudToRaster does; a pixel centre on a point takes that
point's value.
The points input accepts:
- a
geopandas.GeoSeries/GeoDataFrame(uses.geometry; requires theattributeargument naming the column to bin). - an
xarray.DataArraywith an xvec geometry index (values taken from the array itself, noattributeneeded).
A bare (geoms, values) form is not supported — wrap in
a GeoDataFrame or DataArray upfront. Like RasterToPoints,
only Point geometries are accepted; non-axis-aligned target
rasters are rejected.
Geo-dependent: like must be a georeferenced GeoArray
(its transform defines the bin grid); plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['binned_stat', 'idw']
|
Reduction strategy — |
'binned_stat'
|
stat
|
Literal['mean', 'median', 'sum', 'count', 'max', 'min']
|
For |
'mean'
|
attribute
|
str | None
|
For GeoDataFrame inputs, the column to bin. Required for GeoDataFrame; ignored for xvec-indexed DataArray. |
None
|
power
|
float
|
For |
2.0
|
k
|
int
|
For |
8
|
max_radius
|
float | None
|
For |
None
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
RasterToPointCloud
¶
Bases: Operator
Sample raster values onto each node of a point cloud.
A point cloud here is an (N, 2) numpy array of XY coordinates
in the raster's CRS (Z columns, if present, are ignored —
sampling is 2-D). For shapely-Point inputs use RasterToPoints;
the distinction is the input form, not the underlying op.
Geo-dependent: the raster must be a georeferenced GeoArray
(transform + CRS); plain raster arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of nearest pixels per point. |
1
|
max_radius
|
float | None
|
Optional distance ceiling in CRS units. Points
farther than this from any pixel center get |
None
|
method
|
Literal['nearest', 'bilinear', 'idw']
|
|
'nearest'
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
RasterToPoints
¶
Bases: Operator
Extract raster values at a vector cube of points.
Requires the [vector-cube] extra (xvec).
The points input accepts three forms:
- a sequence of
shapely.Point(or any iterable of shapely geometries), - a
geopandas.GeoSeries/GeoDataFrame(uses.geometry), - an
xarray.DataArraywith an xvec geometry index (uses.xvec.geom_coords).
The return value is an xarray.DataArray indexed by a
geometry dim, with the raster's values sampled at each
point. For 3-D (C, H, W) rasters the result carries an
additional band dim.
Geo-dependent: the raster must be a georeferenced GeoArray
(transform + CRS); plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extract
|
Literal['nearest', 'bilinear']
|
Interpolation mode — |
'nearest'
|
out_var
|
str
|
Name attached to the output DataArray. |
'value'
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
RasterToRasterLike
¶
Bases: Operator
Align one raster onto another's CRS + grid in a single op.
Thin binary wrapper around geom.ReprojectLike — the underlying
rasterio warp handles both CRS reprojection and target-grid
resampling in one pass. The wrapper exists because
ReprojectLike pins like at construction (unary call),
whereas matchup coregistration needs both inputs at call time
to match the (secondary_raw, primary_patch) -> aligned_secondary
shape of MatchedField.coreg.
Useful as a default in MatchedField.coreg for raster↔raster
pairs where the secondary needs to be coregistered to the
primary's grid before stacking.
Geo-dependent: both inputs must be georeferenced GeoArrays
(transform + CRS); plain arrays raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resampling
|
str
|
One of |
'bilinear'
|
Examples:
>>> import geoops as gz
>>> coreg = gz.geom.coregister.RasterToRasterLike(resampling="bilinear")
>>> aligned_s2 = coreg(s2_chip, modis_chip)
>>> # `aligned_s2` has MODIS's CRS, transform, and spatial shape.
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
SwathToGrid
¶
Bases: Operator
Grid a swath onto a target grid by inverse-distance weighting.
# Shapes: C bands; Nr × Nc swath (row, col); Ny′ × Nx′ target grid; Q = k
to_grid = SwathToGrid(target=grid, method="idw", k=4, power=2.0)
# f̂(x*) = ∑ⱼ wⱼ yⱼ over the Q nearest valid swath pixels, wⱼ ∝ max(dⱼ, ε)⁻ᵖ
gridded = to_grid(swath) # (C, Nr, Nc) -> (C, Ny′, Nx′)
Each swath pixel is a source at its geolocation (swath.lon,
swath.lat, transformed from swath.crs into target.crs); each
target is a pixel centre of target. One plan,
functax.interp.InverseDistance(k, power).plan(sources, targets)
(the [interp] extra), reads every band, with distances measured in
the target CRS's units (ε = 10⁻¹², so a pixel centre on a swath
pixel takes its value). "nearest" is the k = 1 case.
Nodata: a swath pixel that is invalid in any band (non-finite or the
swath's fill) or has a non-finite geolocation is skipped, so its
targets read their k nearest valid pixels instead. A target
whose nearest valid pixel is farther than max_radius is NaN,
the output's fill.
The output's grid (transform, CRS, (y, x) shape) is target; its
leading dims, their coordinates and its attrs are the swath's. To grid
onto a raster's grid, pass target=raster.grid.
This is the cross-track resampler BowtieCorrection leaves to a
later step: grid its output with this operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Grid | Mapping[str, Any]
|
The output grid, a |
required |
method
|
Literal['idw', 'nearest']
|
|
'idw'
|
k
|
int
|
For |
4
|
power
|
float
|
For |
2.0
|
max_radius
|
float | None
|
Distance ceiling in the target CRS's units, or |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
An unknown |
TypeError
|
|
ImportError
|
Without the |
Examples:
>>> grid = ga.Grid((10.0, 0.0, 500000.0, 0.0, -10.0, 4e6), "EPSG:32629", (8, 10))
>>> to_grid = gz.geom.coregister.SwathToGrid(target=grid, method="idw", k=4)
>>> gridded = to_grid(swath) # GeoArray on grid
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
VectorToRasterAgg
¶
Bases: Operator
Rasterize a vector layer with an aggregation policy for overlaps.
Extends geom.Rasterize (which burns features in order and lets
later ones overwrite earlier ones) with a per-pixel aggregation
when multiple features overlap a pixel — useful for mean of an
attribute, count of features per pixel, etc.
Implementation strategy: rasterize each feature separately to a boolean mask (O(H*W) per feature, single accumulator pass) and update a running aggregator. This is more memory-friendly than stacking N feature rasters and reducing.
Geo-dependent: like must be a georeferenced GeoArray
(its transform defines the burn grid); plain arrays raise
TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agg
|
Literal['mean', 'majority', 'count', 'sum', 'max', 'min', 'first', 'last']
|
One of |
'mean'
|
attribute
|
str | None
|
Column name to aggregate. Required for
|
None
|
all_touched
|
bool
|
If |
False
|
Source code in packages/geotoolz-ops/src/geoops/geom/_src/coregister/operators.py
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |