hypso.grid#

Map grids for hypso products: swath and grid definitions (pyresample), resampling onto any target as a bare Dataset, and regridding a product onto a map grid as a product of the same level (Product.regrid).

Submodules#

Classes#

Averager

Cell averages on a grid: each target cell gets the mean of the

GridOperators

How each kind of variable goes from a product onto target with

Resampler

Nearest-neighbour and (optionally) bilinear resampling from source

Functions#

area_definition(tree)

AreaDefinition of a gridded product, from its x/y coordinates

grid_area(crs, resolution, latitudes, longitudes[, ...])

A grid covering the given coordinates, snapped to the pixel size.

grid_name(crs, size_x, size_y)

File-name token for a grid (io/naming.py GRID_TOKEN): utm33n_880m,

regrid(tree[, target, resolution, method, ...])

A product tree on a map grid, at the same level.

resample_product(tree, target[, method, ...])

A product's contents on any pyresample target, as a bare Dataset.

resolution(tree)

Ground resolution (m): a gridded product's pixel size (converted from

source_definition(tree)

What to resample from: a gridded product's AreaDefinition, else its

swath_definition(tree[, direct])

SwathDefinition of a product's per-pixel geolocation (direct or not).

utm_crs(latitudes, longitudes)

The WGS84 UTM CRS of the zone containing the scene centre.

Package Contents#

class hypso.grid.Averager(latitudes, longitudes, target)[source]#

Cell averages on a grid: each target cell gets the mean of the source pixels whose centres fall in it (NaN ignored per band) - an unweighted approximation of area-weighted averaging, close when source pixels are much smaller than the cells. Only for targets coarser than the source; finer ones leave empty cells inside the swath.

bitwise_or(data)[source]#

Integer flags (rows, cols) -> per cell, every flag set in any of its pixels (0 for empty cells).

Parameters:

data (numpy.ndarray)

Return type:

numpy.ndarray

mean(data)[source]#

Float (rows, cols[, bands]) -> cell means in the input’s float dtype.

Parameters:

data (numpy.ndarray)

Return type:

numpy.ndarray

class hypso.grid.GridOperators(tree, target, method, radius_of_influence=None)[source]#

How each kind of variable goes from a product onto target with method, so resample_product and regrid treat variables alike:

  • floats(): the cube and float variables - nearest, bilinear, or cell average; azimuths (by name) through their sine and cosine unless nearest, so 0/360 does not average to 180;

  • integers(): nearest neighbour, except bit flags with “average”, which are OR-ed over the cell;

  • covered(): target pixels that received data.

Parameters:
parameters()[source]#

What was done, for provenance.

Return type:

dict

class hypso.grid.Resampler(source, target, radius_of_influence, bilinear)[source]#

Nearest-neighbour and (optionally) bilinear resampling from source to target; radius_of_influence in metres.

Parameters:
  • radius_of_influence (float)

  • bilinear (bool)

coverage(method)[source]#

True where the target has data from the source with method.

Parameters:

method (str)

Return type:

numpy.ndarray

nearest(data, fill_value=np.nan)[source]#

(rows, cols[, bands]); integer data keeps its dtype (fill 0).

Parameters:

data (numpy.ndarray)

Return type:

numpy.ndarray

hypso.grid.area_definition(tree)[source]#

AreaDefinition of a gridded product, from its x/y coordinates (pixel centres) and crs grid-mapping variable.

Parameters:

tree (xarray.DataTree)

Return type:

pyresample.geometry.AreaDefinition

hypso.grid.grid_area(crs, resolution, latitudes, longitudes, area_id='hypso_grid')[source]#

A grid covering the given coordinates, snapped to the pixel size.

Parameters:
  • crs (str, int or pyproj.CRS) – Anything pyproj accepts, e.g. "EPSG:32633".

  • resolution (float) – Square pixel size in the CRS’s units.

  • latitudes (array_like) – Coordinates to cover (NaN ignored).

  • longitudes (array_like) – Coordinates to cover (NaN ignored).

  • area_id (str, default "hypso_grid")

Returns:

Extent snapped to whole multiples of resolution, so grids of two captures in the same CRS and resolution share pixel boundaries.

Return type:

pyresample.geometry.AreaDefinition

hypso.grid.grid_name(crs, size_x, size_y)[source]#

File-name token for a grid (io/naming.py GRID_TOKEN): utm33n_880m, epsg4326_0p01deg, custom_30m; “AxB” for non-square pixels.

Parameters:
Return type:

str

hypso.grid.regrid(tree, target='utm', resolution=None, method='nearest', radius_of_influence=None, max_gb=4.0)[source]#

A product tree on a map grid, at the same level.

Parameters:
  • tree (xarray.DataTree) – Georeferenced L1B, L1C, L2A or L2B product tree.

  • target (str, int, pyproj.CRS or pyresample.geometry.AreaDefinition, default "utm") – "utm" (WGS84 UTM zone of the scene centre), a CRS pyproj accepts (e.g. "EPSG:3035", 4326), or an AreaDefinition (e.g. another product’s grid).

  • resolution (float, optional) – Pixel size in the CRS’s units (m, or degrees for a geographic CRS); default the product’s resolution. Not with an AreaDefinition.

  • method ({"nearest", "bilinear", "average"}, default "nearest") – See the module description.

  • radius_of_influence (float, optional) – In m; default 1.5 times the coarser of source and target pixel size.

  • max_gb (float, default 4.0) – Refuse grids whose cube would exceed this many GB (a fine grid over a long capture gets large quickly).

Return type:

xarray.DataTree

hypso.grid.resample_product(tree, target, method='nearest', radius_of_influence=None)[source]#

A product’s contents on any pyresample target, as a bare Dataset.

Parameters:
  • tree (xarray.DataTree) – A georeferenced product tree.

  • target (pyresample.geometry.AreaDefinition or SwathDefinition)

  • method ({"nearest", "bilinear", "average"}, default "nearest") – Per kind of variable as in GridOperators; "average" only onto grids coarser than the product.

  • radius_of_influence (float, optional) – In m; default default_radius().

Returns:

The cube (y, x, band) with the source band wavelengths, each derived variable (y, x), each flag as boolean flag_<name>, and the target’s latitude and longitude.

Return type:

xarray.Dataset

hypso.grid.resolution(tree)[source]#

Ground resolution (m): a gridded product’s pixel size (converted from degrees for a geographic grid), else the larger of the mean along- and across-track GSD.

Parameters:

tree (xarray.DataTree)

Return type:

float

hypso.grid.source_definition(tree)[source]#

What to resample from: a gridded product’s AreaDefinition, else its swath (as numpy arrays, which pyresample’s kd-tree needs).

Parameters:

tree (xarray.DataTree)

hypso.grid.swath_definition(tree, direct=False)[source]#

SwathDefinition of a product’s per-pixel geolocation (direct or not).

Parameters:
Return type:

pyresample.geometry.SwathDefinition

hypso.grid.utm_crs(latitudes, longitudes)[source]#

The WGS84 UTM CRS of the zone containing the scene centre.

EPSG 326xx (north) or 327xx (south); standard 6-degree zones, without the Norway and Svalbard exceptions.

Parameters:
  • latitudes (array_like)

  • longitudes (array_like)

Return type:

pyproj.CRS