hypso.maps#

Footprints, shapefiles, RGB images and maps of HYPSO products.

  • footprint(): a product’s ground footprint as a shapely polygon in WGS84 longitude/latitude: the outline of the whole swath, or of the pixels in a mask (e.g. those with data).

  • footprint_attributes(): the capture’s metadata for a footprint (capture, satellite, time, level, georeferencing, calibration, AC method).

  • write_footprints(): one or several footprints as an ESRI Shapefile (.shp/.shx/.dbf/.prj/.cpg, EPSG:4326) or GeoJSON, one feature per product.

  • rgb_image() and save_rgb(): an RGB rendering (bands nearest 640, 550 and 460 nm; percentile stretch, per channel for L1, one gain for L2A; display gamma) in sensor geometry, as an array or a PNG (in the HYPSO servers’ orientation by default); from any product with a cube (L1B, L1C radiance or rhot, L2A Rrs or rhos).

  • plot_map(): a product variable (a band of the cube, a 2D variable such as chlor_a) or an RGB rendering on a map grid (hypso.Product.regrid()), with the footprint outline, coastlines, graticule, scale bar, north arrow and colour bar.

  • plot_overview(): the footprints of several captures on one map.

Optional dependencies: shapely (footprints), pyshp (shapefiles), matplotlib (figures), cartopy and its Natural Earth data (coastlines); pillow writes the PNGs.

Functions#

footprint(product[, mask, step, block])

The product's ground footprint, in WGS84 longitude/latitude.

footprint_attributes(product[, source])

The capture's metadata for a footprint feature (FOOTPRINT_FIELDS).

footprint_record(product[, mask, step, block, source])

(footprint polygon, footprint_attributes with area_km2) of a product.

georeferencing(product)

How the product's latitude/longitude were made: "indirect" (ground

plot_map(source[, variable, wavelength, ax, ...])

Plot a product variable, a band, or an RGB rendering on a map.

plot_overview(sources[, ax, labels, margin, ...])

Plot the footprints of several products on one map.

rgb_image(product[, stretch, wavelengths, ...])

An RGB rendering of a product's cube, in sensor geometry.

save_rgb(product, path[, stretch, wavelengths, ...])

Write rgb_image() as a PNG (transparent where there is no data).

write_footprints(sources, path[, mask, step, block])

Write footprints to an ESRI Shapefile or GeoJSON, one feature per product.

Module Contents#

hypso.maps.footprint(product, mask=None, step=10, block=8)[source]#

The product’s ground footprint, in WGS84 longitude/latitude.

Parameters:
  • product (hypso.Product or path) – Any georeferenced product (L1B after georeferencing, L1C, L2A, L2B), in sensor geometry.

  • mask (array_like of bool or "data", optional) – Outline only these pixels (lines x samples) instead of the whole swath; "data" for pixels with data (any finite band of the cube, else any finite 2D variable). Pixels are taken in blocks of block x block: a block is in when any of its pixels is.

  • step (int, default 10) – Swath outline: a vertex every step pixels along the edges (and at the corners).

  • block (int, default 8) – Block size for mask.

Returns:

Longitudes in -180..180, or 0..360 for a footprint across the antimeridian.

Return type:

shapely.geometry.Polygon or MultiPolygon

hypso.maps.footprint_attributes(product, source=None)[source]#

The capture’s metadata for a footprint feature (FOOTPRINT_FIELDS).

Parameters:
  • product (hypso.Product)

  • source (str or path, optional) – The file the product was read from (its name is recorded).

Return type:

dict

hypso.maps.footprint_record(product, mask=None, step=10, block=8, source=None)[source]#

(footprint polygon, footprint_attributes with area_km2) of a product.

A few kB, for keeping many captures’ footprints (overviews, shapefiles of a batch) without keeping the products: write_footprints() and plot_overview() take these pairs.

Parameters:
Return type:

tuple

hypso.maps.georeferencing(product)[source]#

How the product’s latitude/longitude were made: “indirect” (ground processing’s GCP-corrected coordinates), “direct” (from attitude and position), or “unknown” (no record, e.g. a product from older software).

Return type:

str

hypso.maps.plot_map(source, variable=None, wavelength=None, ax=None, resolution=None, cmap=None, log=None, vmin=None, vmax=None, percentiles=(2, 98), stretch=None, per_channel=None, gamma=None, outline=True, water=True, coastlines=True, graticule=True, scale_bar=True, north_arrow=True, title=None, colorbar=True)[source]#

Plot a product variable, a band, or an RGB rendering on a map.

The product is regridded (hypso.Product.regrid(), nearest neighbour, default the UTM zone of the scene at the product’s own resolution) after reducing it to what is plotted.

Parameters:
  • source (hypso.Product or path) – A product in sensor geometry or already gridded.

  • variable (str, optional) – A 2D variable (e.g. "chlor_a_oci") or the cube’s name ("Rrs", "rhos", "rhot") with wavelength; default an RGB rendering of the cube (bands nearest 640, 550 and 460 nm).

  • wavelength (float, optional) – For a band of the cube (nearest).

  • ax (matplotlib.axes.Axes, optional)

  • resolution (float, optional) – Grid pixel size in m; default the product’s.

  • cmap (str, optional) – Default “viridis” (“turbo” is avoided: not perceptually uniform).

  • log (bool, optional) – Logarithmic colour scale; default on for concentrations and IOPs (chl*, tsm*, a_*, bbp_*, kd*…).

  • vmin (float, optional) – Colour range; default the percentiles of the data.

  • vmax (float, optional) – Colour range; default the percentiles of the data.

  • percentiles (tuple of float, default (2, 98))

  • stretch – RGB rendering, as in rgb_image().

  • per_channel (bool) – RGB rendering, as in rgb_image().

  • gamma (float) – RGB rendering, as in rgb_image().

  • outline (bool, default True) – Draw the swath footprint (needs shapely).

  • water (bool, default True) – Shade the sea and lakes (Natural Earth) light blue under the data; land is light grey.

  • coastlines (bool) – Map elements (hypso.rgb.decorate_map()).

  • graticule (bool) – Map elements (hypso.rgb.decorate_map()).

  • scale_bar (bool) – Map elements (hypso.rgb.decorate_map()).

  • north_arrow (bool) – Map elements (hypso.rgb.decorate_map()).

  • title (str, optional) – Default: target, time, product and variable.

  • colorbar (bool, default True)

Return type:

matplotlib.axes.Axes

hypso.maps.plot_overview(sources, ax=None, labels=None, margin=0.1, coastlines=True, graticule=True, scale_bar=True, north_arrow=True, title=None, crs=None, water=True, fill=False, color_by='auto')[source]#

Plot the footprints of several products on one map.

Parameters:
  • sources (list of hypso.Product, paths, (polygon, attributes) pairs or shapely polygons) – Pairs from footprint_record() keep the satellite and time for the legend and color_by="satellite" without keeping products; bare polygons in WGS84 longitude/latitude are drawn as they are.

  • ax (matplotlib.axes.Axes, optional)

  • labels (list of str, optional) – Legend labels; default each product’s acquisition time (UTC), after its target when the products have several targets.

  • margin (float, default 0.1) – Space around the footprints, as a fraction of their extent.

  • coastlines (bool) – Map elements (hypso.rgb.decorate_map()).

  • graticule (bool) – Map elements (hypso.rgb.decorate_map()).

  • scale_bar (bool) – Map elements (hypso.rgb.decorate_map()).

  • north_arrow (bool) – Map elements (hypso.rgb.decorate_map()).

  • title (str, optional)

  • crs (optional) – Map projection; default the UTM zone of the footprints’ centre.

  • water (bool, default True) – Shade the sea and lakes light blue; land is light grey.

  • fill (bool, default False) – Tint the inside of each footprint in its colour (outlines only by default).

  • color_by ({"auto", "capture", "satellite"}, default "auto") – One colour and legend entry per footprint (“capture”), or per satellite with the number of captures in the legend (“satellite”, thinner lines, for many footprints); “auto” is “capture” up to 8 footprints and “satellite” beyond. labels applies to “capture”.

Return type:

matplotlib.axes.Axes

hypso.maps.rgb_image(product, stretch=None, wavelengths=RGB_WAVELENGTHS, per_channel=None, gamma=None)[source]#

An RGB rendering of a product’s cube, in sensor geometry.

Parameters:
  • product (hypso.Product or path) – A product with a cube (L1B, L1C, L2A); a path is opened with only the three bands.

  • stretch (tuple of float, optional) – Percentiles over the pixels with data that map to 0 and 1 (with one gain for all channels, only the upper one is used: 0 maps to 0). Default (2, 98) for L1, (0, 99.5) for L2A.

  • wavelengths (tuple of float, default (640, 550, 460)) – The bands (nearest) for red, green and blue.

  • per_channel (bool, optional) – Stretch each channel on its own (default for L1 products: one gain for all channels renders TOA land pink) or use one gain for all channels from 0 (default for L2A surface reflectance, whose colours a per-channel stretch distorts).

  • gamma (float, optional) – Display gamma (image ** (1 / gamma)): default 2.2 for L1, 1 (linear) for L2A.

Returns:

(lines, samples, 3) in 0-1, NaN where the product has no data (e.g. masked pixels of an L2A).

Return type:

numpy.ndarray

hypso.maps.save_rgb(product, path, stretch=None, wavelengths=RGB_WAVELENGTHS, per_channel=None, gamma=None, orientation='server', bin_samples=1)[source]#

Write rgb_image() as a PNG (transparent where there is no data).

Parameters:
  • product – As in rgb_image().

  • stretch – As in rgb_image().

  • wavelengths – As in rgb_image().

  • per_channel (bool) – As in rgb_image().

  • gamma (float) – As in rgb_image().

  • path (str or path)

  • orientation ({"server", "product"}, default "server") – “server”: as the HYPSO servers’ quicklooks (lines across, samples up); “product”: the arrays as stored (lines down, samples across).

  • bin_samples (int, default 1) – Average this many neighbouring samples (the servers’ -bin3 images use 3, for pixels closer to square on the ground).

Return type:

pathlib.Path

hypso.maps.write_footprints(sources, path, mask=None, step=10, block=8)[source]#

Write footprints to an ESRI Shapefile or GeoJSON, one feature per product.

Parameters:
  • sources (hypso.Product, path, (polygon, attributes) pair, or a list of them) – Products in sensor geometry; paths are opened (all their bands are read, so prefer the smallest file of a capture, e.g. the L2B.BGC or the L1C opened with a few bands); pairs from footprint_record() are written as they are (for large batches: no product kept open).

  • path (str or path) – *.shp (writes .shp, .shx, .dbf, .prj and .cpg; needs pyshp) or *.geojson/*.json.

  • mask – As in footprint(); mask must be None or "data" here.

  • step (int) – As in footprint(); mask must be None or "data" here.

  • block (int) – As in footprint(); mask must be None or "data" here.

Returns:

The .shp or GeoJSON file.

Return type:

pathlib.Path