Warp imagery with longitude and latitude arrays#
Register coordinate arrays to an image, inspect the proposed destination grid, and warp the image onto it.
Register the coordinate arrays to the image#
Choose paired fields when each grid node has an X and Y coordinate. Choose separable axes when X and Y vary along separate axes. Use GeolocationGrid.from_pair to register a raw pair, supplying the source image’s row and column shape and the coordinate reference system (CRS). Account for the coordinate convention when registering the grid.
For a coarser or offset grid, identify the source sample described by the first coordinate and how many source columns and rows each subsequent coordinate step spans. An explicitly constructed GeolocationGrid accepts offsets, steps, and convention for that registration.
Inspect the destination grid#
Call suggested_output on the registered grid with the destination CRS. Inspect its grid metadata before choosing whether to use the suggested destination.
Warp the scene and check its placement#
This checked per-pixel example uses projected easting and northing in UTM zone 31N, with coordinates in metres. For longitude and latitude arrays, supply their coordinates and CRS in the same registration pattern. The source and destination settings come from cugeo-raster/examples/geolocation_array.py.
import numpy as np
import cupy as cp
from cugeo.raster.geolocation import GeolocationGrid
from cugeo.raster import warp
from cugeo.raster.enums import Resampling
rows, columns = np.indices((7, 13), dtype=np.float64)
x = 500000 + 20 * columns
y = 70 - 10 * rows
source = cp.asarray((5 + 17 * rows + 3 * columns).astype(np.float32)[None])
with GeolocationGrid.from_pair(
x, y, source_shape=(7, 13), crs="EPSG:32631"
) as grid:
print("suggested grid:", grid.suggested_output("EPSG:32631"))
result = warp.reproject(
source,
src_geoloc_array=grid,
dst_crs="EPSG:32631",
resampling=Resampling.bilinear,
return_receipt=True,
)
print("output shape:", result.data.shape)
The checked shape is (1, 4, 14): one band, four rows and fourteen columns. To check placement, compare a sample with an independently known map location against its expected position on the destination grid. If the dimensions match but an area is blank or displaced, trace the affected pixel through grid mapping and effective validity.