API reference¶
GeoArray¶
The grid carrier: a NumPy or JAX array with its stored dims, coordinates, transform, CRS, fill value and attrs. The coordinates are on their own page, the readable types on theirs.
geoarray.GeoArray
dataclass
¶
A georeferenced array whose data is a NumPy or a JAX array.
Every axis has a name (dims); the last two are ("y", "x"). The
first transform.ndim - 1 dims are batch dims, one transform row per
item (patches, or frames with their own grids). Non-spatial dims may
have a coordinate in coords (geoarray.coords: band names and
wavelengths, level values, time stamps).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
|
required |
transform
|
Any
|
The affine transform (a, b, c, d, e, f): an
|
required |
crs
|
CRS | None
|
Anything |
required |
fill_value
|
_FillValue
|
The nodata marker (NaN allowed); |
None
|
attrs
|
FrozenAttrs
|
Whole-carrier metadata, frozen into a hashable |
FrozenAttrs()
|
dims
|
tuple[str, ...]
|
One name per axis, ending in |
cast(Any, None)
|
coords
|
tuple[Coordinate, ...]
|
Coordinates of non-spatial dims, at most one per dim, each with one entry per index of its dim. |
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
X64Error
|
JAX data without |
Example
import numpy as np from geoarray.coords import SpectralAxis swir = SpectralAxis(names=("B11", "B12"), wavelength_nm=(1610.0, 2190.0)) scene = GeoArray( ... np.zeros((2, 600, 600), dtype=np.float32), ... (20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0), ... "EPSG:32613", ... fill_value=np.nan, ... dims=("band", "y", "x"), ... coords=(swir,), ... ) scene.dims, scene.res (('band', 'y', 'x'), (20.0, 20.0)) scene.sel(band="B12").dims ('y', 'x')
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
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 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 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 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 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 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 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 1106 1107 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 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 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 | |
backend
property
¶
"numpy" or "jax".
batch_dims
property
¶
The dims that index transform rows: (), or ("patch",).
batch_shape
property
¶
Leading batch axes: () for one scene, (P,) for P patches.
A batched carrier has one transform per item, (*batch, 6);
batch_dims names those axes.
bounds
property
¶
(x_min, y_min, x_max, y_max) (see Grid.bounds).
count
property
¶
The number of bands: the size of the band dim, or 1 without one.
dtype
property
¶
The data's dtype.
grid
property
¶
The pixel grid (transform, crs, (H, W)) as a hashable Grid.
Raises:
| Type | Description |
|---|---|
GeoArrayTraceError
|
Inside |
height
property
¶
H, the number of rows.
ndim
property
¶
The number of axes (len(dims)).
pixel_grid
property
¶
The y x coordinate: shape and CRS, area convention.
res
property
¶
Pixel size (x, y) in CRS units (see Grid.res).
shape
property
¶
The data's shape, (..., H, W).
sizes
property
¶
Each dim's size: {"band": 2, "y": 600, "x": 600}.
width
property
¶
W, the number of columns.
xp
property
¶
The array module of the data: numpy or jax.numpy.
__array__(dtype=None, copy=None)
¶
The data as a NumPy array, so np.asarray(g) works.
NumPy data is returned as it is (no copy unless copy=True or a
cast). JAX data is copied to the host, eagerly only: inside jit,
grad or vmap the data are tracers, and NumPy code cannot run
on them. pipekit_ops.guard reports each host copy.
Raises:
| Type | Description |
|---|---|
GeoArrayTraceError
|
The data are traced. |
ValueError
|
|
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
__class_getitem__(item)
¶
GeoArray["band y x"]: the carrier annotated with a dims pattern.
An Annotated type carrying a geoarray.types.ReadableType, which
geoarray.types.check_dims checks. The 0.2 array-type parameter
(GeoArray[np.ndarray]) is deprecated and returns the class.
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
__getitem__(key)
¶
Index like NumPy; spatial slices move the transform.
The last two (spatial) axes take slices with positive steps only; the leading axes take anything NumPy indexing allows, with at most one list / array index. An integer drops its dim and that dim's coordinate; other indices slice the coordinate with the data, and indexing the band dim selects the per-band attrs too.
Example
import numpy as np g = GeoArray( ... np.zeros((3, 8, 8)), (20, 0, 600000, 0, -20, 3550000), 32613, ... attrs={"band_names": ["B04", "B08", "B11"]}, dims="band y x", ... ) sub = g[1:, 2:6, ::2] sub.shape, sub.res, sub.attrs["band_names"] ((2, 4, 4), (40.0, 20.0), ('B08', 'B11'))
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
astype(dtype, *, fill_value=INHERIT)
¶
A copy with the data cast to dtype; geometry unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
Any
|
The new dtype. |
required |
fill_value
|
Any
|
The new fill; omitted keeps this carrier's, which
|
INHERIT
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
import numpy as np t = (1, 0, 0, 0, -1, 0) g = GeoArray(np.ones((4, 4)), t, None, np.nan, dims="y x") g.astype(np.uint8, fill_value=255).fill_value 255
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
coord(dim)
¶
The coordinate of dim, or None.
Raises:
| Type | Description |
|---|---|
KeyError
|
|
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
drop_attrs(*keys)
¶
A copy without the given attrs keys (see FrozenAttrs.drop).
expand_dims(axis, dim=None)
¶
Insert a size-1 leading axis at axis, named dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int
|
Where the new axis goes, before the spatial axes. |
required |
dim
|
str | None
|
Its name. Omitted, it is the name the 0.2 layout gives that
position ( |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
from_coords(data, *coords, transform, fill_value=None, attrs=None)
classmethod
¶
A carrier from its coordinates, one per dim in axis order.
Each entry describes the next axis or axes: a 1-D axis
(SpectralAxis, TimeAxis, …) one dim, a dim name ("patch") a
dim without a coordinate, and the last entry a PixelGrid, which
gives y x, the CRS and the expected spatial shape. A
point-convention grid's transform is shifted to the area convention
carriers store (PixelGrid.area_transform).
Raises:
| Type | Description |
|---|---|
TypeError
|
The last entry is not a |
ValueError
|
The data does not fit the coordinates. |
Example
import numpy as np from geoarray.coords import PixelGrid, SpectralAxis, TimeAxis dates = TimeAxis(stamps=["2026-06-01", "2026-06-11"]) swir = SpectralAxis(names=("B11", "B12")) grid = PixelGrid(shape=(4, 4), crs="EPSG:32613") t = (20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0) data = np.zeros((2, 2, 4, 4)) g = GeoArray.from_coords(data, dates, swir, grid, transform=t) g.dims ('time', 'band', 'y', 'x')
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
from_xarray(da)
classmethod
¶
A DataArray on an affine grid as a GeoArray (see to_xarray).
Reads the GeoTransform first, then centre coordinates, then
georeader's attrs["crs"] (deprecated); dask data is computed.
Raises:
| Type | Description |
|---|---|
ImportError
|
xarray is not installed. |
ValueError
|
No grid, or irregular coordinates. |
GridMismatchError
|
Centres disagree with the |
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
identical(other)
¶
Equal data (NaN-aware), transform, dims, coords, CRS, fill and attrs.
Both carriers must be concrete; the backends may differ.
Example
import numpy as np t = (1, 0, 0, 0, -1, 0) g = GeoArray(np.zeros((2, 2)), t, "EPSG:4326", dims="y x") g.identical(g.with_data(np.zeros((2, 2)))) True
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
isel(selection=None, **by_dim)
¶
Index by dim name: g.isel(band=[0, 2], y=slice(0, 100)).
The rules of g[...] apply: y and x take positive-step
slices and move the origin; other dims take ints, slices or
positions, and slice their coordinate. By name, an integer may drop
band from (time, band, y, x): the stored dims say what is
left.
Raises:
| Type | Description |
|---|---|
KeyError
|
A name is not one of this carrier's dims. |
Example
import numpy as np t = (20, 0, 0, 0, -20, 0) g = GeoArray(np.zeros((3, 8, 8)), t, 32613, dims="band y x") g.isel(band=0, x=slice(0, 4)).shape (8, 4)
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
labels(dim)
¶
The exact labels of dim (band names, level values), or None.
load()
¶
map(f)
¶
Apply f to the data and keep the geometry.
f may change the leading axes (a band index collapses bands)
but not the spatial shape. Works inside jit.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
import numpy as np t = (1, 0, 0, 0, -1, 0) g = GeoArray(np.full((2, 2), 9.0), t, None, dims="y x") g.map(np.sqrt).data[0, 0] np.float64(3.0)
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
read_window(window, *, boundless=True)
¶
The pixels of window: geoarray.read_window as a method.
With load, this makes a carrier a RasterSource, so code written
for lazy readers takes a loaded carrier too.
Example
import numpy as np from geoarray import PixelWindow t = (20, 0, 0, 0, -20, 0) g = GeoArray(np.ones((4, 4)), t, 32613, 0.0, dims="y x") window = PixelWindow(col_off=2, row_off=2, width=4, height=4) g.read_window(window).shape (4, 4)
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
replace(**changes)
¶
A copy with fields replaced (data, transform, dims, …).
Example
import numpy as np g = GeoArray(np.zeros((4, 4)), (1, 0, 0, 0, -1, 0), None, dims="y x") g.replace(fill_value=0).fill_value 0
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
sel(selection=None, **by_dim)
¶
Select by exact label: g.sel(band="B12"), g.sel(band=["B8", "B4"]).
One label drops its dim; a list, a tuple or a 1-D array keeps it.
Labels come from the dim's coordinate (labels).
Raises:
| Type | Description |
|---|---|
LabelError
|
The dim has no labels or is spatial, a label is
missing, or the value is a range (a |
KeyError
|
A name is not one of this carrier's dims. |
Example
import numpy as np from geoarray.coords import SpectralAxis bands = SpectralAxis(names=("B4", "B8")) g = GeoArray(np.zeros((2, 4, 4)), (20, 0, 0, 0, -20, 0), 32613, ... dims="band y x", coords=(bands,)) g.sel(band="B8").dims ('y', 'x')
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
shift_origin(delta)
¶
Move the grid by delta = (Δx, Δy) in CRS units: c + Δx, f + Δy.
The pixels do not move; their georeferencing does. Differentiable,
so jax.grad can find a sub-pixel co-registration shift.
Example
import numpy as np t = (20, 0, 600000, 0, -20, 3550000) g = GeoArray(np.zeros((2, 2)), t, 32613, dims="y x") g.shift_origin((7.3, 0.0)).transform[2] np.float64(600007.3)
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
squeeze(axis=None)
¶
Drop size-1 leading axes (all of them when axis is None).
The band axis of a (T, 1, H, W) stack stays unless time goes
too: (T, H, W) would read as (C, H, W).
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
to_jax(device=None)
¶
This carrier with data and transform on a JAX device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Any
|
A |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
JAX is not installed ( |
X64Error
|
|
Example
import jax import numpy as np jax.config.update("jax_enable_x64", True) data = np.zeros((4, 4), np.float32) g = GeoArray(data, (1, 0, 0, 0, -1, 0), None, dims="y x").to_jax() g.backend, str(g.dtype), str(g.transform.dtype) ('jax', 'float32', 'float64')
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
to_numpy()
¶
This carrier with data and transform copied to NumPy on the host.
Raises:
| Type | Description |
|---|---|
GeoArrayTraceError
|
Inside |
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
to_xarray()
¶
This carrier as an xr.DataArray (geotoolz-array[xarray]).
Same dims and values; the CRS and the transform in a CF
spatial_ref coordinate (crs_wkt, GeoTransform), x and y
centre coordinates when axis-aligned, and each coordinate of
geoarray.coords as CF coordinates. from_xarray reads it back
exactly.
Raises:
| Type | Description |
|---|---|
ImportError
|
xarray is not installed. |
ValueError
|
The carrier is batched. |
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
valid_mask(*, keep_time=False)
¶
Which pixels hold data: (H, W) booleans, True where valid.
A pixel is valid when every entry there (over the non-batch,
non-spatial dims) is finite and differs from the fill value (a NaN
fill matches NaN). keep_time=True keeps a time dim,
(T, H, W). Batch axes are kept. Works inside jit.
v_ij = ∧ₖ [isfinite(x_kij) ∧ x_kij ≠ φ]
Example
import numpy as np data = np.array([[[1.0, np.nan]], [[2.0, 3.0]]]) g = GeoArray(data, (1, 0, 0, 0, -1, 0), None, np.nan, dims="band y x") g.valid_mask().tolist() [[True, False]]
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
with_attrs(**items)
¶
A copy with attrs added or replaced (see FrozenAttrs.set).
with_data(data, *, transform=None, fill_value=INHERIT, attrs=None, dims=None, coords=INHERIT)
¶
A carrier with new data on this carrier's grid (or transform).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The new |
required |
transform
|
Any
|
A new transform, for data on a new grid. When omitted,
|
None
|
fill_value
|
Any
|
The new fill; omitted keeps this carrier's. |
INHERIT
|
attrs
|
Any
|
New attrs; omitted keeps this carrier's, without the per-band keys when the band count changed. |
None
|
dims
|
Any
|
The new data's dims; omitted keeps this carrier's when the rank is unchanged, and drops leading dims when it fell. |
None
|
coords
|
Any
|
New coordinates; omitted keeps each of this carrier's whose dim survives with the same size. |
INHERIT
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The spatial shape changed and no |
Example
import numpy as np t = (1, 0, 0, 0, -1, 0) g = GeoArray(np.ones((2, 4, 4)), t, None, dims="band y x") g.with_data(np.zeros((1, 4, 4), dtype=bool), fill_value=False).shape (1, 4, 4)
Source code in packages/geotoolz-array/src/geoarray/_src/array.py
geoarray.SPATIAL_DIMS = ('y', 'x')
module-attribute
¶
geoarray.DIMS = ('time', 'band', 'y', 'x')
module-attribute
¶
GeoSwath and GeoPoints¶
Carriers whose georeference is not an affine grid: per-pixel lat/lon on
row col, and scattered samples on obs.
geoarray.GeoSwath
dataclass
¶
Bases: _Named
Data in sensor geometry: per-pixel lat/lon on the row col dims.
Rows run along track, columns across (EMIT, AVIRIS, TROPOMI L1B/L2).
A model grid with fixed 2-D lat/lon (ORCA) is a swath too
(GeoSwath.from_grid).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
|
required |
lat
|
Any
|
|
required |
lon
|
Any
|
Longitudes, the shape of |
required |
dims
|
tuple[str, ...]
|
One name per axis, ending in |
cast(Any, None)
|
coords
|
tuple[Coordinate, ...]
|
Coordinates of non-spatial dims ( |
()
|
crs
|
CRS | None
|
The CRS of lat/lon; WGS 84 by default. |
cast(Any, _WGS84)
|
fill_value
|
Any
|
The nodata marker. |
None
|
attrs
|
FrozenAttrs
|
Whole-carrier metadata. |
FrozenAttrs()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The dims do not fit, or lat/lon do not match the data's
|
Example
import numpy as np from geoarray.coords import SpectralAxis lat, lon = np.meshgrid(np.linspace(31, 32, 4), np.linspace(-104, -103, 5), ... indexing="ij") swath = GeoSwath(np.zeros((2, 4, 5)), lat, lon, dims="band row col", ... coords=(SpectralAxis(("b1", "b2")),)) swath.isel(row=slice(0, 2)).lat.shape (2, 5)
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
268 269 270 271 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 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 | |
batch_dims
property
¶
The leading dims lat/lon vary along (() for one granule).
__array__(dtype=None, copy=None)
¶
The data as a NumPy array (a host copy for JAX data).
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
__class_getitem__(item)
¶
GeoSwath["band row col"]: the carrier annotated with a dims pattern.
from_grid(data, grid, *, dims, coords=(), fill_value=None, attrs=None)
classmethod
¶
A swath on a fixed curvilinear model grid (ORCA): lat/lon from grid.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
from_xarray(obj)
classmethod
¶
A DataArray with 2-D lat/lon as a GeoSwath (see to_xarray).
identical(other)
¶
Equal data, lat/lon (NaN-aware), dims, coords, CRS, fill and attrs.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
isel(selection=None, **by_dim)
¶
Select by position; lat/lon are sliced with row, col and batch dims.
Raises:
| Type | Description |
|---|---|
IndexError
|
An integer or a list on |
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_jax(device=None)
¶
Data and lat/lon on a JAX device (needs jax_enable_x64).
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_numpy()
¶
Data and lat/lon on the host.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_xarray()
¶
with_data(data, *, dims=None, fill_value=..., attrs=None)
¶
New data on this swath's geolocation (same row, col).
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
geoarray.GeoPoints
dataclass
¶
Bases: _Named
Scattered samples on the obs dim: positions, optional z, time, valid.
- xy —
(obs, 2)positions incrs(lon, lat for WGS 84). - z —
(obs,)vertical positions, described byvertical(height, depth or pressure: never a third column of xy). - time —
(obs,)per-point times, for moving platforms (along-track altimetry, Argo). Shared times are atimedim with aTimeAxisinstead; both together raise. - valid —
(obs,)booleans, False on padding (pad_points).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
|
required |
xy
|
Any
|
|
required |
z
|
Any
|
Optional |
None
|
vertical
|
Vertical | None
|
What |
None
|
time
|
Any
|
Optional |
None
|
valid
|
Any
|
Optional |
None
|
dims
|
tuple[str, ...]
|
One name per axis, ending in |
cast(Any, None)
|
coords
|
tuple[Coordinate, ...]
|
Coordinates of non-spatial dims ( |
()
|
crs
|
CRS | None
|
The CRS of xy; WGS 84 by default. |
cast(Any, _WGS84)
|
fill_value
|
Any
|
The nodata marker. |
None
|
attrs
|
FrozenAttrs
|
Whole-carrier metadata. |
FrozenAttrs()
|
Example
import numpy as np from geoarray.coords import VariableAxis, Vertical depth = Vertical(kind="depth", units="m", positive="down") cycle = GeoPoints( ... np.zeros((2, 3)), xy=np.zeros((3, 2)), z=[5.0, 10.0, 20.0], ... vertical=depth, dims="variable obs", ... coords=(VariableAxis(("temp", "psal"), ("degC", "1")),), ... ) cycle.isel(obs=[2]).z.tolist() [20.0]
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 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 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 | |
batch_dims
property
¶
(): the leaves of a point set do not vary along other dims.
size
property
¶
N, the number of samples.
__array__(dtype=None, copy=None)
¶
The values as a NumPy array (a host copy for JAX data).
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
__class_getitem__(item)
¶
GeoPoints["variable obs"]: the carrier annotated with a dims pattern.
from_xarray(obj)
classmethod
¶
A CF DSG Dataset on obs as a GeoPoints (see to_xarray).
identical(other)
¶
Equal values and leaves (NaN-aware), vertical and static fields.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
isel(selection=None, **by_dim)
¶
Select by position; obs slices xy, z, time and valid together.
Raises:
| Type | Description |
|---|---|
IndexError
|
An integer on |
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_jax(device=None)
¶
Data and leaves on a JAX device; times as int64 ns.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_numpy()
¶
Data and leaves on the host; times as datetime64[ns].
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
to_xarray()
¶
valid_mask()
¶
(obs,) True where a point holds data: valid, finite, not the fill.
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
with_data(data, *, dims=None, fill_value=..., attrs=None)
¶
New values at these samples (same obs).
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
geoarray.pad_points(points, n)
¶
points padded to n samples, with valid=False on the pad.
Pad points sit at the first point's position (finite, so gradients
through a sampling operator stay finite), carry the fill value (NaN for
float data without one) and time / z of the first point. A cost that
masks with valid is then unchanged by the pad length (GA-G16).
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
import numpy as np p = GeoPoints(np.ones(3), xy=np.zeros((3, 2)), dims="obs") padded = pad_points(p, 5) padded.size, padded.valid.tolist() (5, [True, True, True, False, False])
Source code in packages/geotoolz-array/src/geoarray/_src/carriers.py
geoarray.to_geoswath(f, grid, *, crs='EPSG:4326', coords=(), fill_value=None, attrs=None)
¶
A cell-centred model field on a latitude-longitude grid as a GeoSwath.
The grid's y and x become row and col, the ghost ring is
dropped, and every pixel gets the latitude and longitude of its cell
centre, in degrees. The values are not touched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Any
|
A field with |
required |
grid
|
Any
|
The grid of the field: its |
required |
crs
|
Any
|
The CRS of the latitudes and longitudes. |
'EPSG:4326'
|
coords
|
tuple[Coordinate, ...]
|
Coordinates of the other dims of the result. |
()
|
fill_value
|
Any
|
The nodata marker. |
None
|
attrs
|
Any
|
Whole-carrier metadata. |
None
|
Returns:
| Type | Description |
|---|---|
GeoSwath
|
The interior of the field, |
GeoSwath
|
their order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The field is not at the cell centres, has no |
TypeError
|
The grid has no latitudes and longitudes. |
Example
import numpy as np from types import SimpleNamespace y, x = np.deg2rad([9.0, 10.0, 11.0, 12.0]), np.deg2rad([-1.0, 0.0, 1.0]) grid = SimpleNamespace( ... ghost=1, R=6.371e6, coords=lambda axis, at: {"y": y, "x": x}[axis] ... ) h = SimpleNamespace(data=np.ones((4, 3)), dims=("y", "x"), stagger=()) swath = to_geoswath(h, grid) swath.dims, np.round(swath.lat[:, 0], 6).tolist() (('row', 'col'), [10.0, 11.0])
Source code in packages/geotoolz-array/src/geoarray/_src/model.py
Dim-level functions¶
pipekit-array's functions, re-exported: geoarray.isel is
pipekit_array.isel. The named reductions compute, so geoarray does not
re-export them: use geoops.compositing.reduce / argreduce, which leave
nodata out, or pipekit_array.reduce / argreduce as they are (GA-B6). They are documented in pipekit-array; geoarray's
adapters are registered with pipekit at import, and give carriers these
fast paths:
| Function | On a geoarray carrier |
|---|---|
isel(x, **dims), sel(x, **labels) |
slice the data, coordinates and geometry; an index that breaks the grid gives a DimArray |
transpose(x, order) |
a carrier while the spatial dims stay last; else a DimArray |
reduce(x, fn, dim), argreduce(x, fn, dim), take_along(x, index, dim) |
a carrier while the spatial (and batch) dims survive; else a DimArray |
map_over(x, fn, dim) |
one jax.vmap over the data and the matching leaves on JAX; a loop on NumPy |
concat(xs, dim) |
joins coordinates, per-band attrs and, along a batch dim, transforms |
combine(fn, *xs) |
one exact grid, one fill; NumPy inputs join JAX ones (pipekit_ops.guard reports it) |
The named-array adapters¶
geoarray.GeoArrayAdapter
¶
Bases: _SharedMethods
The pipekit_ops.NamedArrayAdapter for GeoArray.
Example
import numpy as np import pipekit_array as pa from geoarray import GeoArray t = (20, 0, 0, 0, -20, 0) g = GeoArray(np.ones((3, 4, 4)), t, 32613, dims="time y x") mean = pa.reduce(g, "mean", "time") type(mean).name, mean.dims ('GeoArray', ('y', 'x')) type(pa.reduce(g, "mean", "y")).name 'DimArray'
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 260 261 262 263 264 265 266 267 268 269 270 271 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 | |
batch_dims(x)
¶
check_compatible(*xs)
¶
The carriers, checked to share one exact grid; use what it returns.
Raises:
| Type | Description |
|---|---|
TypeError
|
One of them is not a |
GridMismatchError
|
CRS, spatial shape, batch shape or transform differ (a traced transform: at run time). |
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
combine(fn, *xs)
¶
geoarray.combine: one grid, one fill, inputs in the first's order.
concat(xs, dim)
¶
data(x)
¶
dims(x)
¶
isel(x, indexers)
¶
Select by position; dropping or picking spatial indices loses the grid.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
labels(x, dim)
¶
The dim's coordinate labels; None for y, x and bare dims.
pipekit-array also reads back the DimArray that rewrap returns
off the grid, so that carrier is read as a DimArray.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
map_over(x, fn, dim)
¶
fn on each item along dim, stacked along dim.
dim comes first, after any batch dims the items keep, so the
transform's batch axes still lead the data. Per-band attrs follow
the items when dim is band. Each item is x without
dim: its own transform row when
dim is a batch dim (patches, per-frame grids), its own stamp
when dim is time. On JAX this is one jax.vmap over the
data and the matching leaves, so 64 patches with 64 transforms are
one trace (GA-G15); on NumPy, a loop.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
rewrap(x, data, dims)
¶
A GeoArray on x's grid while it still describes the data.
That is when dims end in y x with x's spatial shape and
start with x's batch dims and shape. Coordinates and per-band
attrs are kept for dims that survive with their size; a fill the new
dtype cannot hold is dropped. Otherwise a DimArray with the
surviving labels.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
signature(x)
¶
Dims with their sizes, and the dtype's name.
stack(xs, dim)
¶
stack_items(xs, dim)
¶
Items on their own grids along a new batch dim (transform rows).
geoarray.GeoSwathAdapter
¶
Bases: _GeolocatedAdapter
The pipekit_ops.NamedArrayAdapter for GeoSwath: lat/lon must match exactly.
A reduction over row or col (per-column statistics) is a
DimArray.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
geoarray.GeoPointsAdapter
¶
Bases: _GeolocatedAdapter
The pipekit_ops.NamedArrayAdapter for GeoPoints: xy, z, time, valid match.
A reduction over obs is a DimArray.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
geoarray.to_dimarray(g)
¶
A carrier's data, dims and labels as a pipekit_array.DimArray; no grid.
Source code in packages/geotoolz-array/src/geoarray/_src/adapter.py
Coordinates to pixels¶
geoarray.to_pixel(transform, xy)
¶
Map coordinates (x, y) to fractional pixel (row, col), centres at integers.
Inverting the 2 × 2 linear part A = [[a, b], [d, e]] of T,
(j, i)ᵀ = A⁻¹ (x − c, y − f)ᵀ,
and subtracting ½ from both puts integers at pixel centres, so (0, 0) is the centre of the top-left pixel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Any
|
T = (a, b, c, d, e, f), six numbers, NumPy or JAX. |
required |
xy
|
Any
|
The positions (x, y) in the transform's CRS, shape |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The fractional (row, col), shape |
Any
|
the inputs (JAX if either is a JAX array). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If a concrete |
Examples:
>>> import numpy as np
>>> from functax.geometry import to_pixel
>>> north_up = np.array([20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0])
>>> to_pixel(north_up, np.array([[600010.0, 3549990.0]])).tolist()
[[0.0, 0.0]]
>>> to_pixel(north_up, np.array([[600000.0, 3550000.0]])).tolist()
[[-0.5, -0.5]]
Source code in .venv/lib/python3.12/site-packages/functax/_src/geometry/_affine.py
Reading a grid at points, H(x), blends pixels, so it is geoops':
geoops.geom.interp_at.
Grid¶
A pixel grid without data.
geoarray.Grid
dataclass
¶
A pixel grid with no data: transform, CRS and spatial shape.
Hashable, so it can be a warp target, an operator's static config or a
dictionary key. == is exact equality; isclose allows a tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Transform
|
The affine transform (anything |
required |
crs
|
CRS | None
|
The CRS (anything |
required |
shape
|
tuple[int, int]
|
|
required |
Example
transform = (20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0) grid = Grid(transform, "EPSG:32613", (600, 600)) grid.res (20.0, 20.0) grid.bounds (600000.0, 3538000.0, 612000.0, 3550000.0)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
262 263 264 265 266 267 268 269 270 271 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 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 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
affine
property
¶
The transform as an affine.Affine (what rasterio expects).
bounds
property
¶
(x_min, y_min, x_max, y_max) of the grid's outer edges.
height
property
¶
H, the number of rows.
is_axis_aligned
property
¶
Whether the grid has no rotation or shear: b = d = 0.
res
property
¶
Pixel size (x, y) in CRS units, always positive.
For a rotated grid, the lengths of the column and row vectors: (√(a² + d²), √(b² + e²)).
width
property
¶
W, the number of columns.
bounds_of(window)
¶
(x_min, y_min, x_max, y_max) of window on this grid.
The inverse of window for bounds on pixel edges:
grid.bounds_of(grid.window(b)) == b.
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
crop(window)
¶
The grid of window: its origin and its shape.
Example
grid = Grid((20.0, 0.0, 0.0, 0.0, -20.0, 0.0), None, (8, 8)) window = PixelWindow(col_off=3, row_off=2, width=4, height=4) grid.crop(window).transform (20.0, 0.0, 60.0, 0.0, -20.0, -40.0)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
from_affine(affine, crs, shape)
classmethod
¶
A grid from an affine.Affine (or rasterio Affine).
from_bounds(bounds, res, crs, *, atol=1e-06)
classmethod
¶
The north-up grid that covers bounds with square-edged pixels.
The origin is the top-left corner (x_min, y_max); the shape rounds
up to whole pixels, ignoring overshoots below atol pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Sequence[float]
|
|
required |
res
|
float | Sequence[float]
|
Pixel size, one number or |
required |
crs
|
Any
|
The CRS (anything |
required |
atol
|
float
|
Tolerance, in pixels, for a size that is almost whole. |
1e-06
|
Example
Grid.from_bounds((600000, 3538000, 612000, 3550000), 20, 32613).shape (600, 600)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
from_config(config)
classmethod
¶
Rebuild a grid from get_config; from_config(g.get_config()) == g.
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
get_config()
¶
A strict-JSON config: the transform, the CRS string and the shape.
Example
grid = Grid((20.0, 0.0, 0.0, 0.0, -20.0, 0.0), "EPSG:32613", (2, 3)) grid.get_config()["crs"], grid.get_config()["shape"] ('EPSG:32613', [2, 3])
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
isclose(other, atol=1e-06)
¶
Equal CRS and shape, and transforms within atol (map units).
Example
g = Grid((1.0, 0.0, 0.0, 0.0, -1.0, 0.0), None, (2, 2)) g.isclose(g.shift(1e-9, 0.0)) True
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
shift(rows, cols)
¶
The same grid with its origin moved by rows × cols pixels.
c′ = c + a·cols + b·rows, f′ = f + d·cols + e·rows.
Example
grid = Grid((20.0, 0.0, 0.0, 0.0, -20.0, 0.0), None, (4, 4)) grid.shift(1, 2).transform (20.0, 0.0, 40.0, 0.0, -20.0, -20.0)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
to_functax()
¶
This grid as a functax AffineGrid: the transform and the shape.
The CRS stays here, since functax never sees one. The AffineGrid
is an Equinox module, so this needs the functax[jax] extra (JAX
with jax_enable_x64; geotoolz-ops[interp] brings it) and
raises functax's MissingExtraError (an ImportError) without.
Example
grid = Grid((20.0, 0.0, 0.0, 0.0, -20.0, 0.0), "EPSG:32613", (2, 3)) grid.to_functax().shape # doctest: +SKIP (2, 3)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
window(bounds, *, atol=1e-06)
¶
The pixels that cover bounds, rounded outward to whole pixels.
Corners within atol pixels of a pixel edge snap to it, so bounds
on the grid map to exactly the pixels inside them. The window may
extend outside the grid; PixelWindow.intersection clips it. The
kernel is functax's (functax.geometry.window).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Sequence[float]
|
|
required |
atol
|
float
|
Snapping tolerance, in pixels. |
1e-06
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
transform = (20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0) grid = Grid(transform, None, (600, 600)) grid.window((600100, 3549000, 600400, 3549900)) PixelWindow(col_off=5, row_off=5, width=15, height=45)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
PixelWindow¶
A rectangle of pixels.
geoarray.PixelWindow
dataclass
¶
A rectangle of pixels: col_off, row_off, width, height.
rasterio's Window without importing rasterio, with its field order
(columns before rows), so PixelWindow(*rasterio_window.flatten())
is the same rectangle. Offsets may be negative (a window that starts
outside the array); sizes may not.
Example
w = PixelWindow.from_slices(slice(10, 42), slice(5, 37)) w PixelWindow(col_off=5, row_off=10, width=32, height=32) w.to_slices() (slice(10, 42, None), slice(5, 37, None))
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
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 | |
shape
property
¶
(height, width).
from_slices(rows, cols)
classmethod
¶
The window two step-1 slices with explicit bounds select.
Raises:
| Type | Description |
|---|---|
ValueError
|
A slice has a step other than 1 or an open bound. |
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
intersection(other)
¶
The overlap of two windows, or None when they do not overlap.
Example
a = PixelWindow(col_off=0, row_off=0, width=10, height=10) a.intersection(PixelWindow(col_off=5, row_off=5, width=10, height=10)) PixelWindow(col_off=5, row_off=5, width=5, height=5)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
to_slices()
¶
(rows, cols) slices selecting this window.
FrozenAttrs¶
Hashable metadata.
geoarray.FrozenAttrs
¶
Bases: Mapping[str, Any]
An immutable, hashable mapping of string keys to frozen values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Mapping[str, Any] | Any
|
A mapping or iterable of |
None
|
**kwargs
|
Any
|
More items, added after |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
A key is not a string, or a value cannot be frozen. |
Example
import numpy as np wavelengths = np.array([1610.0, 2190.0]) attrs = FrozenAttrs(band_names=["B11", "B12"], wavelengths=wavelengths) attrs["band_names"] ('B11', 'B12') attrs["wavelengths"] (1610.0, 2190.0) attrs.set(sensor="S2A").drop("wavelengths") FrozenAttrs({'band_names': ('B11', 'B12'), 'sensor': 'S2A'})
Source code in packages/geotoolz-array/src/geoarray/_src/attrs.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
drop(*keys)
¶
A copy without keys; missing keys are ignored.
Example
FrozenAttrs(a=1, b=2).drop("b", "c") FrozenAttrs({'a': 1})
Source code in packages/geotoolz-array/src/geoarray/_src/attrs.py
set(**items)
¶
A copy with items added or replaced.
Example
FrozenAttrs(a=1).set(b=2) FrozenAttrs({'a': 1, 'b': 2})
to_dict()
¶
A plain dict; nested FrozenAttrs become dicts, tuples stay tuples.
Example
FrozenAttrs(tags={"AREA_OR_POINT": "Area"}).to_dict() {'tags': {'AREA_OR_POINT': 'Area'}}
Source code in packages/geotoolz-array/src/geoarray/_src/attrs.py
geoarray.PER_BAND_KEYS = ('band_names', 'descriptions', 'bands', 'band_descriptions', 'wavelengths', 'wavelengths_nm')
module-attribute
¶
Geometry¶
Re-index or re-describe pixels without computing new values.
geoarray.crop(g, offset, size)
¶
The size pixels starting at offset, with the matching transform.
offset may be traced (inside jit / vmap); size must be
static. Like jax.lax.dynamic_slice, an offset that would run past
the edge is clamped so the crop fits, and the transform follows the
pixels actually returned, so georeferencing is always right.
x_p = x[..., r₀ : r₀ + h, c₀ : c₀ + w], c′ = c + a·c₀ + b·r₀, f′ = f + d·c₀ + e·r₀.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
The carrier, |
required |
offset
|
Any
|
|
required |
size
|
tuple[int, int]
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
import numpy as np from geoarray import GeoArray g = GeoArray(np.zeros((2, 8, 8)), (20, 0, 600000, 0, -20, 3550000), 32613) patch = crop(g, (2, 4), (4, 4)) patch.shape, patch.bounds[:2] ((2, 4, 4), (600080.0, 3549880.0))
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.read_window(g, window, *, boundless=True, fill_value=INHERIT)
¶
The pixels of window, padding with fill where it leaves the array.
The result's fill value is the padding value, so padded pixels read as
nodata (GeoArray.valid_mask).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
The carrier. |
required |
window
|
PixelWindow
|
The pixels to read; may extend past the edges. |
required |
boundless
|
bool
|
|
True
|
fill_value
|
Any
|
The padding value, and the result's fill; defaults to
|
INHERIT
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
import numpy as np from geoarray import GeoArray, PixelWindow g = GeoArray(np.ones((4, 4)), (20, 0, 0, 0, -20, 0), 32613, fill_value=0.0) window = PixelWindow(col_off=-1, row_off=-1, width=3, height=3) read_window(g, window).data array([[0., 0., 0.], [0., 1., 1.], [0., 1., 1.]])
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.write_window(g, values, window)
¶
A copy of g with values written into window.
The part of window outside the array is ignored, and values
are cast to the carrier's dtype. JAX values promote a NumPy carrier to
JAX (C1), so this works inside jit. JAX data is
immutable, so this always returns a new carrier (the NumPy input is
not modified either).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
The carrier. |
required |
values
|
Any
|
|
required |
window
|
PixelWindow
|
Where to write. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
|
X64Error
|
JAX values for a NumPy carrier, which then moves to JAX, with x64 off. |
Example
import numpy as np from geoarray import GeoArray, PixelWindow g = GeoArray(np.zeros((3, 3)), (20, 0, 0, 0, -20, 0), 32613) window = PixelWindow(col_off=2, row_off=2, width=2, height=2) write_window(g, np.ones((2, 2)), window).data array([[0., 0., 0.], [0., 0., 0.], [0., 0., 1.]])
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.pad(g, pad_width, *, fill_value=INHERIT)
¶
Add fill pixels around the spatial axes; the transform moves with them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
The carrier. |
required |
pad_width
|
Any
|
One int for every side, or |
required |
fill_value
|
Any
|
The value of the new pixels, and the result's fill;
defaults to |
INHERIT
|
Raises:
| Type | Description |
|---|---|
ValueError
|
No fill value, or a NaN fill for integer data. |
Example
import numpy as np from geoarray import GeoArray transform = (20, 0, 600000, 0, -20, 3550000) g = GeoArray(np.ones((1, 2, 2)), transform, 32613, fill_value=0.0) padded = pad(g, ((1, 0), (2, 0))) padded.shape, padded.transform[2], padded.transform[5] ((1, 3, 4), np.float64(599960.0), np.float64(3550020.0))
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.pixel_coords(g, *, center=True)
¶
Map coordinates of every pixel, (2, H, W): x then y.
x_ij = a·(j + ½) + b·(i + ½) + c, y_ij = d·(j + ½) + e·(i + ½) + f
(drop the ½ with center=False for the top-left corners). Runs
inside jit; float64 like the transform.
Raises:
| Type | Description |
|---|---|
ValueError
|
The carrier is batched; use |
Example
import numpy as np from geoarray import GeoArray g = GeoArray(np.zeros((2, 3)), (20, 0, 600000, 0, -20, 3550000), 32613) pixel_coords(g)[:, 0, 0] array([ 600010., 3549990.])
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.footprint(g, crs=None, *, densify=21)
¶
The outline of the carrier's grid as a shapely Polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
The carrier (concrete, not batched). |
required |
crs
|
Any
|
Reproject the outline to this CRS; |
None
|
densify
|
int
|
Points per edge when reprojecting. |
21
|
Raises:
| Type | Description |
|---|---|
ImportError
|
shapely is not installed ( |
ValueError
|
|
Example
import numpy as np from geoarray import GeoArray g = GeoArray(np.zeros((2, 2)), (20, 0, 600000, 0, -20, 3550000), 32613) footprint(g).bounds (600000.0, 3549960.0, 600040.0, 3550000.0)
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
Joining carriers¶
Carriers on one grid: the same CRS, spatial shape and transform
(combine and concat are above).
geoarray.stack(carriers, dim=None, *, axis=None)
¶
Stack carriers on one grid along a new dim.
Three (band, y, x) scenes become one (time, band, y, x) stack.
The new dim goes first, after any batch dims, unless axis puts it
elsewhere; the result keeps the first carrier's coordinates, fill value
and attrs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
carriers
|
Sequence[GeoArray]
|
GeoArrays on one grid with the same dims. |
required |
dim
|
str | None
|
The new dim's name. Omitted (or an int, the 0.2 |
None
|
axis
|
int | None
|
Where the new dim goes; the default is first. |
None
|
Raises:
| Type | Description |
|---|---|
GridMismatchError
|
The grids differ. |
ValueError
|
The fill values differ, the name is taken, or |
Example
import numpy as np from geoarray import GeoArray t = (20, 0, 0, 0, -20, 0) g = GeoArray(np.zeros((2, 4, 4)), t, 32613, dims="band y x") stack([g, g, g], "time").dims ('time', 'band', 'y', 'x')
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
geoarray.concatenate(carriers, axis=-3)
¶
Join carriers on one grid along an existing leading axis, by position.
The 0.2 form of concat: axis picks the dim (−3, the default, is
band in the 0.2 layout). Prefer geoarray.concat(carriers, dim).
Raises:
| Type | Description |
|---|---|
GridMismatchError
|
The grids differ. |
ValueError
|
The fill values differ, or |
Example
import numpy as np from geoarray import GeoArray t = (20, 0, 0, 0, -20, 0) b04 = GeoArray(np.zeros((1, 4, 4)), t, 32613, attrs={"band_names": ["B04"]}, ... dims="band y x") b08 = b04.with_data(np.ones((1, 4, 4)), attrs={"band_names": ["B08"]}) concatenate([b04, b08]).attrs["band_names"] ('B04', 'B08')
Source code in packages/geotoolz-array/src/geoarray/_src/geometry.py
Lazy readers¶
What a reader provides so code can read windows of it on demand; a
GeoArray is one too.
geoarray.RasterSource
¶
Bases: Protocol
A raster whose grid is known and whose pixels are read on demand.
Implemented by every lazy reader of the stack, and by GeoArray
itself (load returns the carrier, read_window slices it).
isinstance(x, RasterSource) checks that the members exist.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
Grid
|
The pixel grid: transform, CRS and |
shape |
tuple[int, ...]
|
|
dtype |
Any
|
The dtype of the pixels. |
fill_value |
Any
|
The nodata value of the pixels read ( |
attrs |
Mapping[str, Any]
|
Metadata every read carries ( |
Example
A function that works on any raster, lazy or loaded::
def corner(source: RasterSource) -> GeoArray:
window = PixelWindow(col_off=0, row_off=0, width=256, height=256)
return source.read_window(window) # (..., 256, 256)
Source code in packages/geotoolz-array/src/geoarray/_src/source.py
load()
¶
read_window(window, *, boundless=True)
¶
The pixels of window as a GeoArray on the window's grid.
boundless=True returns exactly window.shape, filled with
fill_value where the window leaves the grid; False returns
only the part inside.
Source code in packages/geotoolz-array/src/geoarray/_src/source.py
geoarray.AsyncRasterSource
¶
Bases: Protocol
RasterSource with coroutine reads, for sources behind a network.
The metadata members are the same and synchronous; aread_window and
aload are the awaitable reads. An object may implement both
protocols.
Source code in packages/geotoolz-array/src/geoarray/_src/source.py
Backends and interop¶
to_jax() / to_numpy() cross between the backends (see
When to jit). NumPy inputs of a join move to JAX
when another input is on JAX, and np.asarray(g) copies JAX data to the host
(it raises GeoArrayTraceError under a trace). Neither says so, unless
pipekit_ops.guard is on:
geoarray.interop.georeader.from_georeader(gt)
¶
A NumPy GeoArray from a georeader GeoTensor, sharing its memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gt
|
Any
|
A |
required |
Returns:
| Type | Description |
|---|---|
GeoArray
|
The carrier with the same values (no copy), transform, CRS, fill |
value and attrs (frozen
|
lists become tuples). |
Raises:
| Type | Description |
|---|---|
ImportError
|
georeader is not installed. |
TypeError
|
|
Example
import numpy as np from affine import Affine from georeader.geotensor import GeoTensor gt = GeoTensor( ... np.zeros((2, 4, 4), np.float32), Affine(20, 0, 600000, 0, -20, 3550000), ... "EPSG:32613", fill_value_default=np.nan, ... ) g = from_georeader(gt) g.shape, g.grid.bounds[0], np.shares_memory(g.data, gt.values) ((2, 4, 4), 600000.0, True)
Source code in packages/geotoolz-array/src/geoarray/_src/georeader.py
geoarray.interop.georeader.to_georeader(g)
¶
A georeader GeoTensor from a NumPy GeoArray, sharing its memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
GeoArray
|
A NumPy carrier, not batched. Move a JAX carrier to the host
first with |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A |
transform, the CRS as ``"AUTH
|
CODE"`` when that is exact (else |
Any
|
WKT), the fill value ( |
Any
|
of 0 is never assumed) and the attrs as a plain dict. |
Raises:
| Type | Description |
|---|---|
ImportError
|
georeader is not installed. |
TypeError
|
|
ValueError
|
|
Example
import numpy as np from geoarray import GeoArray g = GeoArray(np.ones((4, 4)), (20, 0, 600000, 0, -20, 3550000), 32613) gt = to_georeader(g) gt.crs, gt.transform.c, gt.fill_value_default is None ('EPSG:32613', 600000.0, True)
Source code in packages/geotoolz-array/src/geoarray/_src/georeader.py
geoarray.interop.georeader.source_from_georeader(reader)
¶
A georeader GeoData (or GeoTensor) as a RasterSource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
Any
|
A lazy georeader reader ( |
required |
Returns:
| Type | Description |
|---|---|
RasterSource
|
A |
RasterSource
|
is its |
Raises:
| Type | Description |
|---|---|
ImportError
|
georeader is not installed. |
TypeError
|
|
Example
from georeader.rasterio_reader import RasterioReader # doctest: +SKIP reader = RasterioReader("scene.tif") # doctest: +SKIP source = source_from_georeader(reader) # doctest: +SKIP source.grid.shape, source.read_window(window).shape # doctest: +SKIP
Source code in packages/geotoolz-array/src/geoarray/_src/georeader.py
geoarray.interop.georeader.source_to_georeader(source)
¶
A RasterSource as a georeader GeoData, for georeader's functions.
georeader's read module (read_from_bounds, read_reproject,
…) works on any GeoData; this view lets it read a geotoolz reader
window by window. A GeoArray becomes a GeoTensor
(to_georeader); a source_from_georeader source gives back the
reader it wraps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
RasterSource
|
Any |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A |
Raises:
| Type | Description |
|---|---|
ImportError
|
georeader is not installed. |
TypeError
|
|
Example
from georeader import read # doctest: +SKIP view = source_to_georeader(reader) # doctest: +SKIP tile = read.read_from_bounds(view, bounds) # doctest: +SKIP from_georeader(tile) # doctest: +SKIP
Source code in packages/geotoolz-array/src/geoarray/_src/georeader.py
xarray¶
Lossless converters with a CF spatial_ref and GDAL GeoTransform
(geotoolz-array[xarray]); see Cross to xarray.
geoarray.interop.xarray.to_xarray(carrier)
¶
A carrier as xarray: a DataArray (grid, swath) or a Dataset (points).
Raises:
| Type | Description |
|---|---|
TypeError
|
Not a geoarray carrier. |
ValueError
|
A batched grid (one transform per item). |
GeoArrayTraceError
|
Inside |
Example
import numpy as np from geoarray import GeoArray g = GeoArray(np.zeros((2, 3)), (20, 0, 600000, 0, -20, 3550000), 32613, ... dims="y x") da = to_xarray(g) da.coords["spatial_ref"].attrs["GeoTransform"] '600000.0 20.0 0.0 3550000.0 0.0 -20.0'
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
geoarray.interop.xarray.from_xarray(obj)
¶
A DataArray or a point Dataset as the matching geoarray carrier.
A DataArray with 2-D lat/lon becomes a GeoSwath; one on an
affine grid a GeoArray (its horizontal dims named y x); a
Dataset with an obs dim (a CF DSG) a GeoPoints. Lazy (dask)
data is computed.
Raises:
| Type | Description |
|---|---|
ValueError
|
The object has no georeference geoarray can read, or a grid's coordinates are irregular. |
GridMismatchError
|
Centre coordinates disagree with the
|
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
geoarray.interop.xarray.to_dataset(carriers)
¶
Carriers on one grid as the variables of one Dataset (LL-F3).
Raises:
| Type | Description |
|---|---|
GridMismatchError
|
The carriers are on different grids; use
|
ValueError
|
A shared non-spatial dim has different coordinates
( |
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
geoarray.interop.xarray.from_dataset(ds)
¶
Each grid variable of a Dataset as a GeoArray, by name.
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
geoarray.interop.xarray.to_datatree(groups)
¶
Several grids as one DataTree: one node per grid (LL-F3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
Mapping[str, GeoArray | Mapping[str, GeoArray]]
|
Node name → a carrier (stored under the node's name) or a mapping of carriers on that node's grid. |
required |
Example
import numpy as np from geoarray import GeoArray t10 = (10, 0, 600000, 0, -10, 3550000) t20 = (20, 0, 600000, 0, -20, 3550000) r10 = GeoArray(np.zeros((4, 4)), t10, 32613, dims="y x") r20 = GeoArray(np.zeros((2, 2)), t20, 32613, dims="y x") sorted(to_datatree({"r10m": r10, "r20m": r20}).children) ['r10m', 'r20m']
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
geoarray.interop.xarray.from_datatree(tree)
¶
Every node of a DataTree holding grids: node path → its carriers.
Source code in packages/geotoolz-array/src/geoarray/_src/xarray.py
Coercions¶
Turn transforms and CRSs from other libraries into geoarray's.
geoarray.as_transform(transform)
¶
Coerce a transform to a tuple of six Python floats (a, b, c, d, e, f).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Any
|
An |
required |
Returns:
| Type | Description |
|---|---|
Transform
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The input does not describe an affine transform. |
Example
as_transform(Affine(20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0)) (20.0, 0.0, 600000.0, 0.0, -20.0, 3550000.0)
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
geoarray.as_crs(crs)
¶
Coerce crs to a pyproj.CRS; None stays None.
Accepts anything pyproj.CRS.from_user_input does: "EPSG:32613",
an EPSG integer, WKT, PROJ JSON, or an object with to_wkt() such as
a rasterio CRS.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
as_crs(32613).to_epsg() 32613
Source code in packages/geotoolz-array/src/geoarray/_src/grid.py
Errors¶
Every error geoarray raises on its own account subclasses GeoArrayError.
geoarray.GeoArrayError
¶
geoarray.X64Error
¶
Bases: GeoArrayError, RuntimeError
A JAX carrier needs jax_enable_x64: its transform is float64.
In float32 the spacing of representable numbers is 0.25 m at a UTM northing of 3.55 × 10⁶ m, so a float32 transform silently misplaces pixels. geoarray refuses rather than rounding.
Source code in packages/geotoolz-array/src/geoarray/_src/errors.py
geoarray.GeoArrayTraceError
¶
Bases: GeoArrayError, TypeError
An operation needs concrete values but got JAX tracers.
Inside jit, grad or vmap a GeoArray's data and transform are
tracers. Anything that must read their values on the host (a Grid, a
NumPy function, GeoArray.to_numpy) raises this instead of JAX's
TracerArrayConversionError, naming what to do instead.
Source code in packages/geotoolz-array/src/geoarray/_src/errors.py
geoarray.GridMismatchError
¶
Bases: GeoArrayError, ValueError
Carriers that must share one pixel grid do not.
combine, stack and concatenate need the same CRS, spatial shape,
batch shape and (when concrete) an exactly equal transform. Resample
one carrier onto the other's grid first (geoops.geom).
Source code in packages/geotoolz-array/src/geoarray/_src/errors.py
geoarray.LabelError
¶
Bases: GeoArrayError, KeyError
A selection by label that a carrier cannot do.
GeoArray.sel looks up exact labels of a dim's coordinate (band names,
level values, time stamps). A dim without labels, a label that is not
there, or a range or nearest-neighbour lookup raises this; selection by
value lives in xarray (g.to_xarray().sel(...)).
Source code in packages/geotoolz-array/src/geoarray/_src/errors.py
geoarray.types.DimsError
¶
Bases: GeoArrayError, TypeError
A carrier's dims (or kind) do not fit the readable type a function declares.