Swaths and ocean model grids placed by 2D longitude and latitude, and warped by geolocation arrays.
Satellite swaths, ocean and atmosphere models on rotated or stretched grids: the cells are a regular array in index space, and each cell’s place on the earth is given by 2D longitude and latitude arrays. An affine geotransform cannot describe them.
A model grid in index space
The ROMS-style fixture stores temp on (s_rho, eta_rho, xi_rho), with lon_rho and lat_rho as 2D coordinates. gdalxarray keeps those as coordinates, so xarray’s plotting can place each cell:
The same surface temperature by index (left) and placed by lon_rho/lat_rho (right): the grid fans out from the coast.
The vertical axis is index space too: depths come from the stretching parameters stored beside the data (Vtransform, Cs_r, hc, h, zeta), which gdalxarray reads as ordinary variables.
{k: float(roms[k]) for k in ["Vtransform", "Vstretching", "theta_s", "theta_b", "hc"]}
A EURO-CORDEX-style window: regular in rotated longitude and latitude, with the true lon, lat as 2D coordinates and the rotation recorded in a CF grid_mapping variable.
Near-surface temperature on the rotated grid: a rectangle in rotated coordinates, curved on the earth.
Warping by geolocation arrays
To regrid a curvilinear field, GDAL’s warper can use the 2D longitude and latitude directly (“geolocation arrays”). The recipe is a VRT with a GEOLOCATION metadata domain naming the arrays; gdalxarray.warp then forwards geoloc=True to gdal.WarpOptions.
The swath fixture is 120 x 160 cells with its longitudes and latitudes as two bands of a separate file: