hypso.rgb.maps#

RGB images on map grids, and map figures.

  • regrid_camera(): a georeferenced RGB camera image (hypso.rgb.georeference_camera()) on a map grid - the capture’s UTM zone, any CRS, or another product’s grid - by cell averaging (default; the camera’s ~30 m pixels are finer than most grids) or nearest neighbour.

  • decorate_map(): graticule, scale bar, north arrow and coastlines on axes in projected coordinates (shared with hypso.maps).

  • plot_rgb_map(): a gridded RGB image (from regrid_camera(), or a regridded hypso.Product) as a map, with optional map elements: latitude/ longitude graticule, scale bar, north arrow, coastlines and title.

matplotlib is needed for the figures, and cartopy (with its Natural Earth data) for coastlines; neither is a dependency of the package.

Functions#

camera_gsd(geo)

Median distance (m) between neighbouring camera pixel centres.

decorate_map(ax, extent, crs[, graticule, scale_bar, ...])

Map elements on axes in projected coordinates: latitude/longitude

plot_rgb_map(source[, ax, graticule, scale_bar, ...])

Plot a gridded RGB image as a map.

regrid_camera(geo[, target, resolution, method, max_gb])

A georeferenced camera image on a map grid.

Module Contents#

hypso.rgb.maps.camera_gsd(geo)[source]#

Median distance (m) between neighbouring camera pixel centres.

Parameters:

geo (xarray.Dataset)

Return type:

float

hypso.rgb.maps.decorate_map(ax, extent, crs, graticule=True, scale_bar=True, north_arrow=True, coastlines=False, graticule_step=None, ink='white', coast_color='yellow', water=False, water_color='#c6dbef')[source]#

Map elements on axes in projected coordinates: latitude/longitude graticule, scale bar, north arrow and Natural Earth coastlines.

Parameters:
  • ax (matplotlib.axes.Axes)

  • extent (sequence of float) – [xmin, xmax, ymin, ymax] in the CRS’s units; the axes are set to it.

  • crs (pyproj.CRS) – The axes’ projection.

  • graticule (bool) – As in plot_rgb_map().

  • scale_bar (bool) – As in plot_rgb_map().

  • north_arrow (bool) – As in plot_rgb_map().

  • coastlines (bool) – As in plot_rgb_map().

  • graticule_step (float) – As in plot_rgb_map().

  • ink (str, default "white") – Colour of lines and labels (“white” on images, “black” on a light background).

  • coast_color (str, default "yellow")

  • water (bool, default False) – Fill the sea and lakes (Natural Earth 10 m ocean and lakes) in water_color, below anything drawn at zorder >= 0 (images, data).

  • water_color (str, default "#c6dbef" (light blue))

hypso.rgb.maps.plot_rgb_map(source, ax=None, graticule=True, scale_bar=True, north_arrow=True, coastlines=False, title=None, stretch=(2, 98), graticule_step=None, exposure=None)[source]#

Plot a gridded RGB image as a map.

Parameters:
  • source (xarray.Dataset or hypso.Product) – A gridded camera image (regrid_camera()) or a regridded product (its bands nearest 640, 550 and 460 nm).

  • ax (matplotlib.axes.Axes, optional) – Axes to draw on; default a new figure.

  • graticule (bool, default True) – Latitude/longitude lines with labels.

  • scale_bar (bool, default True) – A scale bar (km) in the lower left.

  • north_arrow (bool, default True) – An arrow to true north (in a UTM grid, true north is not straight up).

  • coastlines (bool, default False) – Natural Earth 10 m coastlines (needs cartopy and its data; skipped with a warning otherwise).

  • title (str, optional)

  • stretch (tuple of float, default (2, 98)) – Percentiles mapped to black and white per channel.

  • graticule_step (float, optional) – Degrees between graticule lines; default chosen from the extent.

  • exposure (dict, optional) – Use hypso.rgb.adjust_exposure() (one gain for all channels, colours kept) instead of the per-channel stretch, with these arguments, e.g. {} (automatic), {"ev": 1} or {"gamma": 2.2}.

Return type:

matplotlib.axes.Axes

hypso.rgb.maps.regrid_camera(geo, target='utm', resolution=None, method='auto', max_gb=2.0)[source]#

A georeferenced camera image on a map grid.

Parameters:
  • geo (xarray.Dataset) – From hypso.rgb.georeference_camera() (R, G, B, latitude, longitude).

  • target (str, int, pyproj.CRS or pyresample.geometry.AreaDefinition, default "utm") – "utm" (zone of the image centre), any CRS, or a grid - e.g. the HSI product’s after regridding, l1c.regrid(...).area_definition(), to put both on the same grid.

  • resolution (float, optional) – Pixel size in the CRS’s units; default the camera’s own (~30 m). Not with an AreaDefinition.

  • method ({"auto", "average", "nearest"}, default "auto") – Cell means of the camera pixels in each cell, or the nearest pixel; “auto” averages when cells are at least twice the camera’s pixel size and takes the nearest pixel otherwise (averaging onto cells as small as the pixels leaves empty cells).

  • max_gb (float, default 2) – Refuse grids larger than this.

Returns:

R, G, B on (y, x) with CF projection coordinates and a crs grid mapping (NaN where the camera has no data), and the camera’s attributes plus grid.

Return type:

xarray.Dataset