Map grids#

Georeferenced products are in sensor (swath) geometry: (lines, samples) pixels, each with its own latitude and longitude. hypso.grid puts them on map grids.

Regridding#

Product.regrid() returns the same product, at the same level, on a map grid:

import hypso

l1c = hypso.open("HYPSO2_HSI.20250304T103805.aeronetvenice.L1C.nc")
g = l1c.regrid()                      # capture's UTM zone, its own resolution
g.grid                                # "utm33n_876m"
g.write()                             # ....L1C.utm33n_876m.nc

l1c.regrid(resolution=300)            # UTM, 300 m
l1c.regrid("EPSG:4326", resolution=0.005)
other.regrid(g)                       # onto g's grid: pixel-by-pixel comparable
l1c.regrid(area_def)                  # any pyresample AreaDefinition
l1c.regrid(resolution=3000, method="average")   # 3 km cell means

Grids are snapped to whole multiples of the pixel size, so two captures regridded to the same CRS and resolution share pixel boundaries.

target

"utm" (default; the WGS84 UTM zone of the scene centre), any CRS pyproj accepts, a pyresample AreaDefinition, or a gridded Product.

resolution

Pixel size in the CRS’s units. The default is the product’s resolution (the coarser of its along- and across-track pixel spacing), so nothing is oversampled. HYPSO pixels are far from square (the wide capture used in the tests: about 876 m along-track, 108 m across-track), so a finer grid is a deliberate choice. max_gb (default 4) refuses grids whose cube would be larger.

method

"nearest" (default): every grid pixel holds one measured spectrum, unmixed. "bilinear" blends neighbouring pixels’ spectra, on request. "average": for grids at least as coarse as the product, each cell is the mean of the swath pixels whose centres fall in it (NaN ignored per band), and a source_pixel_count variable says how many that was. It is an unweighted approximation of area-weighted averaging, close when the pixels are much smaller than the cells.

Per variable: the product cube and float variables use method; azimuth angles too, but bilinear and average work on their sine and cosine to avoid 0/360 artefacts. Integer variables are nearest neighbour, except bit flags with "average", which are OR-ed over the cell: a cell is flagged land or cloud if any of its pixels is. pixel_flags gains an outside_swath flag for grid pixels the capture does not cover (their spectra are NaN). *_direct geolocation and angles are dropped. The method, CRS, resolution and coverage are recorded in metadata/processing/regrid.

Any product with geolocation can be regridded: L1B, L1C and L2A. Per-pixel steps still work on a gridded product (a gridded L1B can be turned into L1C with toa_reflectance()). correct_atmosphere() cannot: the AC tools read sensor geometry, so correct first, then regrid.

File layout#

A gridded product has dimensions (y, x), 1D x/y projection coordinates, and a CF grid-mapping variable crs (with crs_wkt) that every band and variable references through grid_mapping. ESA SNAP and GIS tools read it as a map-projected raster. The 2D latitude and longitude stay, as auxiliary coordinates. The grid’s name is a field of the file name, between the AC method and the label.

Resampling to anything else#

Product.resample(target, method="nearest") (or "bilinear", or "average" onto a grid) returns a bare xr.Dataset on any pyresample target, including a SwathDefinition such as another sensor’s swath for matchups. It holds the cube, the derived variables, each flag as a boolean flag_<name>, and the target’s latitude and longitude.