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#
Cell averages on a grid: each target cell gets the mean of the |
|
How each kind of variable goes from a product onto target with |
|
Nearest-neighbour and (optionally) bilinear resampling from source |
Functions#
|
AreaDefinition of a gridded product, from its x/y coordinates |
|
A grid covering the given coordinates, snapped to the pixel size. |
|
File-name token for a grid (io/naming.py GRID_TOKEN): utm33n_880m, |
|
A product tree on a map grid, at the same level. |
|
A product's contents on any pyresample target, as a bare Dataset. |
|
Ground resolution (m): a gridded product's pixel size (converted from |
|
What to resample from: a gridded product's AreaDefinition, else its |
|
SwathDefinition of a product's per-pixel geolocation (direct or not). |
|
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:
- mean(data)[source]#
Float (rows, cols[, bands]) -> cell means in the input’s float dtype.
- Parameters:
data (numpy.ndarray)
- Return type:
- 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:
tree (xarray.DataTree)
method (str)
radius_of_influence (float)
- 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.
- coverage(method)[source]#
True where the target has data from the source with method.
- Parameters:
method (str)
- Return type:
- nearest(data, fill_value=np.nan)[source]#
(rows, cols[, bands]); integer data keeps its dtype (fill 0).
- Parameters:
data (numpy.ndarray)
- Return type:
- 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:
- 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:
- Returns:
Extent snapped to whole multiples of
resolution, so grids of two captures in the same CRS and resolution share pixel boundaries.- Return type:
- 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.
- 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:
- 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 booleanflag_<name>, and the target’s latitude and longitude.- Return type:
- 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:
- 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:
tree (xarray.DataTree)
direct (bool)
- Return type: