Viz¶
Display-time helpers: composites, stretches, colormaps, hillshade overlays. Outputs are typically
uint8 RGB(A) for direct rendering.
- Composites:
Composite,TrueColor,FalseColor,SWIRComposite(spectral.SelectBandspresets: the selected bands'band_names/wavelengthstravel with the output), andRGBRecipe— three band expressions with fixedvmin/vmaxstretches and per-channel gamma, the form of the operational satellite RGBs (day cloud phase, fire temperature, …) - Stretches:
StretchToUint8(=radiometry.PercentileClip+ a rounded byte cast; samelower/upper/reduce_axesarguments),GammaCorrect(radiometry's gamma on the display range) - Colormaps:
ApplyColormap,ApplyDiscreteColormap - Terrain:
Hillshade,ShadedRelief - Overlays:
AnnotatePoints,AnnotatePolygons,Overlay - Tier-A primitives:
stretch_to_uint8,gamma_correct_display,rgb_recipe,rgba_from_scalar,rgba_from_categories,ensure_rgba,blend_rgba
geoops.viz
¶
Visualization Operators for RGB composites, display stretching, and overlays.
AnnotatePoints
¶
Bases: Operator
Draw circular point markers into a display GeoArray.
Renders disk-shaped markers at the supplied points into the RGBA
carrier. Accepts either an (N, 2) array of (x, y) map
coordinates or a GeoDataFrame (which is reprojected when it carries
a CRS). Flagged forbid_in_yaml = True because the points are
runtime objects. Geo-dependent: locating the markers needs the
carrier's transform / crs, so a georeferenced GeoArray
input is required. A (T, C, H, W) stack is annotated frame by
frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Any
|
|
required |
radius
|
int
|
Marker radius in pixels. |
3
|
color
|
Color
|
RGBA tuple in |
(1.0, 1.0, 0.0, 1.0)
|
Examples:
>>> import geoops as gz
>>> import numpy as np
>>> annotated = gz.viz.AnnotatePoints(
... points=np.array([[12.5, 41.9]]), radius=4
... )(rgb_gt)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
AnnotatePolygons
¶
Bases: Operator
Rasterize polygon outlines into a display GeoArray.
Burn polygon boundaries (buffered by width pixels) into the
RGBA carrier. The geometries are reprojected into the carrier's
CRS when they ship as a GeoDataFrame with a CRS set. Flagged
forbid_in_yaml = True because the geometries themselves are
runtime objects and don't round-trip through YAML. Geo-dependent:
rasterisation needs the carrier's transform / crs, so a
georeferenced GeoArray input is required. A (T, C, H, W) stack
is annotated frame by frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometries
|
Any
|
Iterable of Shapely geometries or a GeoDataFrame. |
required |
color
|
Color
|
RGBA tuple in |
(1.0, 0.0, 0.0, 1.0)
|
width
|
int
|
Outline width in pixels. |
2
|
Examples:
>>> import geoops as gz
>>> from shapely.geometry import Polygon
>>> field = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])
>>> annotated = gz.viz.AnnotatePolygons(geometries=[field])(rgb_gt)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
ApplyColormap
¶
Bases: Operator
Map a single-band raster to a four-band RGBA GeoArray.
Looks up name in matplotlib's registry (or in cmocean if the
name is prefixed with "cmocean."). The colormap is referenced
by string name, not by the live Colormap object — so
get_config() round-trips through JSON / YAML cleanly.
Geo-metadata (transform / crs) is preserved.
Metadata-independent: plain np.ndarray carriers pass through
as plain arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Colormap registry name (e.g. |
'viridis'
|
vmin
|
float | None
|
Optional explicit lower bound. |
None
|
vmax
|
float | None
|
Optional explicit upper bound. |
None
|
nan_color
|
Color
|
RGBA tuple in |
(0.0, 0.0, 0.0, 0.0)
|
Examples:
>>> import geoops as gz
>>> # Render an NDVI raster as a viridis RGBA overlay.
>>> rgba = gz.viz.ApplyColormap(name="viridis", vmin=-1, vmax=1)(ndvi_gt)
>>> # Use a cmocean ocean colourmap with the prefix.
>>> rgba = gz.viz.ApplyColormap(name="cmocean.thermal")(sst_gt)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
ApplyDiscreteColormap
¶
Bases: Operator
Map integer categories to a four-band RGBA GeoArray.
Classic categorical-label visualisation (land-cover classes, cloud
masks, etc). Unmapped pixels render fully transparent. Pixels not
in the mapping fall back to that default colour. Nodata pixels
(equal to the carrier's fill_value) render fully
transparent (0) even if the fill value appears in mapping.
Metadata-independent: plain np.ndarray carriers pass through
as plain arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
Mapping[int, Color] | Sequence[Sequence[Any]]
|
|
required |
Examples:
>>> import geoops as gz
>>> # Render a 3-class land-cover mask.
>>> cmap = {
... 0: (0.0, 0.0, 0.0, 0.0), # nodata -> transparent
... 1: (0.1, 0.5, 0.1, 1.0), # forest
... 2: (0.7, 0.7, 0.2, 1.0), # cropland
... }
>>> rgba = gz.viz.ApplyDiscreteColormap(mapping=cmap)(lulc_gt)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
Composite
¶
Bases: SelectBands
Build a multi-band composite by arbitrary band reference.
A thin :class:geoops.spectral.SelectBands subclass spelled with
bands — the generic band-selection operator the named composites
(TrueColor, FalseColor, SWIRComposite) wrap. Bands may be
referenced by integer position along axis or by name, resolved
against the carrier's attrs by the package-wide resolver
(band_names, then descriptions, then bands). Output has
len(bands) slices along axis and the same spatial footprint
as the input — transform and crs round-trip unchanged. The
selected bands' per-band attrs (band_names, wavelengths, ...)
travel with the output in output order, in a fresh attrs dict.
Plain np.ndarray carriers are supported with integer band
references (returning a plain array); string names need a carrier
with band names in attrs. Fill values pass through unchanged
(pure band selection).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
Sequence[BandRef]
|
Sequence of band references. Each entry is either an
integer position or a string name resolved against the
carrier's |
required |
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> import geoops as gz
>>> # Sentinel-2 natural-colour composite by name.
>>> rgb = gz.viz.Composite(bands=["B04", "B03", "B02"])(s2_geotensor)
>>> # Or by integer position when the carrier has no band names.
>>> rgb = gz.viz.Composite(bands=[3, 2, 1])(s2_geotensor)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
FalseColor
¶
Bases: Composite
Build a NIR-red-green false-colour composite.
Vegetation visualisation preset: healthy vegetation shows red
because NIR reflectance is high. Equivalent to
Composite(bands=[nir, red, green]) with self-documenting kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nir
|
BandRef
|
Near-infrared band reference (rendered as red). |
required |
red
|
BandRef
|
Red band reference (rendered as green). |
required |
green
|
BandRef
|
Green band reference (rendered as blue). |
required |
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> import geoops as gz
>>> # Sentinel-2 vegetation false colour (8/4/3).
>>> vis = gz.viz.FalseColor(nir="B08", red="B04", green="B03")(s2)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
GammaCorrect
¶
Bases: Operator
Apply display gamma correction.
Power-law correction for display-range arrays — brightens midtones
when gamma > 1. The exponent is
:func:geoops.radiometry.gamma_correct (the math behind
:class:geoops.radiometry.Gamma); this operator adds the display
range handling: float carriers are clipped to [0, 1] before the
exponent, and integer carriers are normalised to [0, 1] by their
dtype maximum and rounded back so the transform is display-correct
rather than a raw 256 ** (1 / gamma) = 16 on uint8.
Metadata-independent: plain np.ndarray carriers pass through as
plain arrays. Elementwise: fill (and non-finite) values are passed
through unchanged rather than gamma-corrected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
float
|
Gamma factor (must be strictly positive). Default |
1.0
|
inplace_norm
|
bool
|
Normalise integer inputs to |
True
|
Examples:
>>> import geoops as gz
>>> # Brighten midtones on a percentile-stretched RGB.
>>> pipe = (
... gz.viz.TrueColor(red="B04", green="B03", blue="B02")
... | gz.viz.StretchToUint8()
... | gz.viz.GammaCorrect(gamma=1.2)
... )
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
Hillshade
¶
Bases: Operator
Compute a single-band uint8 hillshade from a DEM.
GDAL-style hillshade: combines slope and aspect from the DEM with
a sun position (azimuth + altitude). The output is a single-band
(H, W) uint8 raster, ready to compose with a colour relief
(see ShadedRelief). Pixel sizes come from the carrier's
transform as ground step lengths (hypot(a, d) /
hypot(b, e)), so units are correct in physical projections and on
rotated grids (the azimuth is then relative to the grid's "up"
direction); a sheared grid or a geographic CRS (degree pixel sizes
against linear elevations) raises ValueError -- reproject first,
or pass both resolutions explicitly.
Geo-dependent by default: plain np.ndarray DEMs are accepted
only when x_resolution and y_resolution are given
explicitly; otherwise a TypeError is raised. Nodata DEM pixels
(non-finite or equal to fill_value) do not leak into
their neighbours' slope and are written as 0 (the output fill).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
azimuth_deg
|
float
|
Sun azimuth in degrees clockwise from north.
Default |
315.0
|
altitude_deg
|
float
|
Sun elevation in degrees above horizon. Default
|
45.0
|
z_factor
|
float
|
Vertical exaggeration. Default |
1.0
|
x_resolution
|
float | None
|
Explicit pixel width in map units. |
None
|
y_resolution
|
float | None
|
Explicit pixel height in map units. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
Overlay
¶
Bases: Operator
Blend background and foreground GeoArrays on the same grid.
Two-input Operator: Overlay()(background, foreground). When
both carriers are georeferenced they must share transform and
crs (this is a viz primitive, not a reprojector); plain
np.ndarray carriers skip the metadata check and blend on pixel
grids alone, returning the background's carrier kind. Output is
always 4-band uint8 RGBA — even when alpha=0 — so
downstream code sees a consistent shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Foreground opacity in |
0.6
|
mode
|
str
|
Blend mode. One of |
'alpha'
|
Examples:
>>> import geoops as gz
>>> # Overlay a cloud mask at 50 % opacity.
>>> blended = gz.viz.Overlay(alpha=0.5)(rgb_uint8, cloud_rgba)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
RGBRecipe
¶
Bases: Operator
Build a display RGB from three band expressions with fixed stretches.
The operational satellite RGB products (the CIRA / EUMETSAT "quick
guide" composites: day cloud phase, fire temperature, natural colour,
dust, air mass, ...) are all one recipe: each colour channel is a band
or a small band expression, linearly stretched between a fixed
vmin and vmax, clipped to [0, 1] and raised to
1 / gamma. This operator is that recipe; see
:func:geoops.viz.rgb_recipe for the maths.
red / green / blue are each an integer band position, a band
name resolved against the carrier's attrs (band_names, then
descriptions, then bands), or an arithmetic expression over band
names in :class:geoops.spectral.BandMath grammar
("0.45 * C02 + 0.10 * C03 + 0.45 * C01"). Invalid input pixels
(non-finite or equal to the fill) become NaN per band, so a channel
is NaN wherever one of its bands is. Output is (3, H, W)
float32 in [0, 1] with band_names=("red", "green", "blue")
and NaN fill; follow with StretchToUint8 or multiply by 255 for
bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
BandRef
|
Red channel: band position, band name or expression. |
required |
green
|
BandRef
|
Green channel. |
required |
blue
|
BandRef
|
Blue channel. |
required |
vmin
|
float | Sequence[float]
|
Value mapped to 0 — one for all channels or one per channel.
Set above |
0.0
|
vmax
|
float | Sequence[float]
|
Value mapped to 1. Default |
1.0
|
gamma
|
float | Sequence[float]
|
Display gamma ( |
1.0
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
A |
Examples:
>>> import geoops as gz
>>> # CIRA day cloud phase distinction from ABI channels.
>>> dcp = gz.viz.RGBRecipe(
... red="C13", green="C02", blue="C05",
... vmin=(280.65, 0.0, 0.01), vmax=(219.65, 0.78, 0.59),
... )
>>> rgb = dcp(abi_stack) # (3, H, W) float32 in [0, 1]
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
SWIRComposite
¶
Bases: Composite
Build a SWIR2-NIR-red composite.
Burn-scar / urban / geology visualisation preset where SWIR2 is
rendered as red. Equivalent to Composite(bands=[swir2, nir, red]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swir2
|
BandRef
|
SWIR2 band reference (rendered as red). |
required |
nir
|
BandRef
|
NIR band reference (rendered as green). |
required |
red
|
BandRef
|
Red band reference (rendered as blue). |
required |
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> import geoops as gz
>>> # Landsat-8 SWIR2/NIR/red burn-scar composite (7/5/4).
>>> vis = gz.viz.SWIRComposite(swir2="B7", nir="B5", red="B4")(l8)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
ShadedRelief
¶
Bases: Operator
Apply an elevation colormap and modulate RGB with hillshade.
The composite terrain visualisation: run the DEM through
ApplyColormap and modulate the RGB channels by a Hillshade
so the result reads like a cartographer's shaded-relief map.
Alpha channel is preserved from the colormap, so nodata DEM pixels
stay fully transparent (see ApplyColormap / Hillshade). Geo-dependent: the
hillshade pixel size comes from the carrier's transform, so a
georeferenced GeoArray input in a projected CRS is required (a
geographic CRS raises ValueError; see Hillshade).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
azimuth_deg
|
float
|
Sun azimuth (degrees clockwise from north).
Default |
315.0
|
altitude_deg
|
float
|
Sun elevation (degrees). Default |
45.0
|
colormap
|
str
|
Name of the elevation colormap. Default |
'terrain'
|
z_factor
|
float
|
Vertical exaggeration for the hillshade. Default
|
1.0
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
StretchToUint8
¶
Bases: Operator
Percentile-stretch display data to uint8.
Exactly :class:geoops.radiometry.PercentileClip (same lower /
upper / reduce_axes) followed by a rounded byte cast, so the result
is ready for PIL / matplotlib. Use PercentileClip directly if you
instead need the [0, 1] floats for further math.
Metadata-independent: plain np.ndarray carriers pass through as
plain arrays.
Nodata pixels (any band non-finite or equal to the carrier's
fill_value) are excluded from the percentiles, so a
-9999 fill cannot dominate the stretch, and are written as 0
-- the output's fill_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
float
|
Lower percentile. Default |
2.0
|
upper
|
float
|
Upper percentile. Default |
98.0
|
reduce_axes
|
int | tuple[int, ...] | None
|
Axes the percentiles are computed over. Default
|
(-2, -1)
|
Examples:
>>> import geoops as gz
>>> # Classic satellite display pipeline.
>>> pipe = (
... gz.viz.TrueColor(red="B04", green="B03", blue="B02")
... | gz.viz.StretchToUint8(lower=2.0, upper=98.0)
... )
>>> rgb_uint8 = pipe(s2_geotensor)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
TrueColor
¶
Bases: Composite
Build an RGB composite from explicit red, green, and blue band refs.
Convenience wrapper over Composite that keeps the band ordering
self-documenting. Output is shaped (3, H, W) in (R, G, B) order
— the matplotlib / PIL display convention. Geo-metadata is
preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
BandRef
|
Red-band reference (int index or string name). |
required |
green
|
BandRef
|
Green-band reference. |
required |
blue
|
BandRef
|
Blue-band reference. |
required |
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> import geoops as gz
>>> # Named Sentinel-2 natural-colour RGB.
>>> rgb = gz.viz.TrueColor(red="B04", green="B03", blue="B02")(s2)
>>> # Stretched display-ready pipeline.
>>> display = (
... gz.viz.TrueColor(red="B04", green="B03", blue="B02")
... | gz.viz.StretchToUint8(lower=2.0, upper=98.0)
... )
>>> rgb_uint8 = display(s2)
Source code in packages/geotoolz-ops/src/geoops/viz/_src/operators.py
blend_rgba(background, foreground, *, alpha=0.6, mode='alpha')
¶
Blend two display images and return uint8 RGBA.
Both inputs are first promoted through :func:ensure_rgba (2-D
grayscale, 3-band RGB, or 4-band RGBA in). The foreground's alpha
channel is scaled by alpha and composed over the background
using source-over alpha composition, so partially transparent
layers accumulate opacity correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
background
|
Num[ndarray, 'h w'] | Num[ndarray, 'c h w']
|
Bottom layer — |
required |
foreground
|
Num[ndarray, 'h w'] | Num[ndarray, 'c h w']
|
Top layer on the same pixel grid. |
required |
alpha
|
float
|
Global foreground opacity in |
0.6
|
mode
|
str
|
Blend mode for the RGB channels — |
'alpha'
|
Returns:
| Type | Description |
|---|---|
UInt8[ndarray, '4 h w']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
ensure_rgba(arr, *, name='ensure_rgba')
¶
Return arr as a four-band uint8 RGBA image.
Accepts (H, W) grayscale (replicated to RGB), (3, H, W) RGB,
or (4, H, W) RGBA. Float (or boolean) inputs whose finite values
are all <= 1 are treated as [0, 1] fractions and scaled to
byte range; other numeric inputs are treated as already
display-scaled and clipped into [0, 255]. The decision is made on
the input values alone; RGB / grayscale inputs then get an opaque
(255) alpha plane. NaNs map to 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, 'h w'] | Num[ndarray, 'c h w']
|
The display array. |
required |
name
|
str
|
Caller name that prefixes the error message (an operator passes its own). |
'ensure_rgba'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
gamma_correct_display(arr, *, gamma=1.0, inplace_norm=True)
¶
Apply power-law gamma correction to display-range arrays.
Gamma is a unit-interval operation: the math
out = clip(arr, 0, 1) ** (1 / gamma) (via
:func:geoops.radiometry.gamma_correct) is only meaningful when
the input is normalised to [0, 1]. Display arrays, however,
arrive in two flavours — float in [0, 1] or integer in
[0, 255] (uint8) / [0, 65535] (uint16). Without
normalisation, an integer input is raised to 1 / gamma directly,
giving e.g. 256 ** 0.5 = 16 — not a display-correct gamma
transform.
With inplace_norm=True (the default), integer inputs are scaled
by their dtype maximum into [0, 1], the gamma exponent is
applied, and the result is rounded back to the original integer
dtype's full range. Floating-point inputs are clipped to [0, 1]
(the display range) before the exponent; NaN stays NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*dims']
|
Display array. Integer ( |
required |
gamma
|
float
|
Strictly positive gamma factor. |
1.0
|
inplace_norm
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
Num[ndarray, '*dims']
|
Gamma-corrected array of the same shape; same dtype as |
Num[ndarray, '*dims']
|
for float input and for integer input with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
hillshade(dem, *, x_resolution=1.0, y_resolution=1.0, azimuth_deg=315.0, altitude_deg=45.0, z_factor=1.0, valid=None)
¶
Compute GDAL-style hillshade as a single uint8 band.
Slope and aspect are derived from the DEM gradient (in map units,
via x_resolution / y_resolution) and combined with a sun
position to give the classic terrain-shading effect. Illumination
is clipped to [0, 1] and scaled to byte range. The DEM is
assumed north-up (row 0 is the northern edge, as in a standard
geotransform), so for a planar DEM the result matches
matplotlib.colors.LightSource(azimuth_deg, altitude_deg).hillshade
(up to byte quantization; matplotlib additionally contrast-stretches
non-constant outputs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
Num[ndarray, 'h w'] | Num[ndarray, '1 h w']
|
Elevation map, |
required |
x_resolution
|
float
|
Pixel width in map units. Default |
1.0
|
y_resolution
|
float
|
Pixel height in map units. Default |
1.0
|
azimuth_deg
|
float
|
Sun azimuth in degrees clockwise from north.
Default |
315.0
|
altitude_deg
|
float
|
Sun elevation in degrees above the horizon.
Default |
45.0
|
z_factor
|
float
|
Vertical exaggeration applied to the DEM before the
gradient. Default |
1.0
|
valid
|
Bool[ndarray, 'h w'] | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
UInt8[ndarray, 'h w']
|
|
UInt8[ndarray, 'h w']
|
fully lit). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
rgb_recipe(channels, *, vmin=0.0, vmax=1.0, gamma=1.0)
¶
Stretch and gamma-correct three channels into a display RGB.
Each channel c is mapped through a fixed linear stretch and a power
law — the "RGB recipe" form of the operational satellite RGB guides:
.. math::
y_c \;=\; \operatorname{clip}\!\Bigl(
\frac{x_c - v_{\min,c}}{v_{\max,c} - v_{\min,c}}, 0, 1
\Bigr)^{1/\gamma_c}
A vmin above vmax inverts the channel (colder brightness
temperatures brighter, for instance). NaN inputs stay NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
Float[ndarray, '3 h w']
|
The red, green and blue inputs stacked on the first axis. |
required |
vmin
|
float | tuple[float, float, float]
|
Value mapped to 0, per channel or one for all. |
0.0
|
vmax
|
float | tuple[float, float, float]
|
Value mapped to 1, per channel or one for all. |
1.0
|
gamma
|
float | tuple[float, float, float]
|
Gamma per channel or one for all ( |
1.0
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '3 h w']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
rgba_from_categories(arr, mapping, *, default=(0.0, 0.0, 0.0, 0.0))
¶
Map integer classes to a four-band uint8 RGBA image.
Categorical-label rendering: each class ID in mapping paints its
pixels with the associated colour; pixels whose value is not in the
mapping fall back to default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Int[ndarray, 'h w'] | Int[ndarray, '1 h w']
|
Single-band label map, |
required |
mapping
|
Mapping[int, Color]
|
|
required |
default
|
Color
|
RGBA colour for unmapped classes. Default fully transparent. |
(0.0, 0.0, 0.0, 0.0)
|
Returns:
| Type | Description |
|---|---|
UInt8[ndarray, '4 h w']
|
Channel-first |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
rgba_from_scalar(arr, cmap, *, vmin=None, vmax=None, nan_color=(0.0, 0.0, 0.0, 0.0))
¶
Map a single-band array to a four-band uint8 RGBA image.
Values are linearly normalised into [0, 1] between vmin and
vmax (auto-detected from the finite values when omitted), then
looked up through cmap. Non-finite pixels are painted with
nan_color rather than whatever the colormap does at 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, 'h w'] | Num[ndarray, '1 h w']
|
Single-band map, |
required |
cmap
|
Callable[[ndarray], ndarray]
|
Matplotlib-style callable mapping unit-interval floats to
|
required |
vmin
|
float | None
|
Lower normalisation bound. |
None
|
vmax
|
float | None
|
Upper normalisation bound. |
None
|
nan_color
|
Color
|
RGBA tuple in |
(0.0, 0.0, 0.0, 0.0)
|
Returns:
| Type | Description |
|---|---|
UInt8[ndarray, '4 h w']
|
Channel-first |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/viz/_src/array.py
stretch_to_uint8(arr, *, lower=2.0, upper=98.0, reduce_axes=(-2, -1))
¶
Percentile stretch an array into display-ready uint8 values.
Exactly :func:geoops.radiometry.percentile_clip (NaN-safe:
percentiles via np.nanpercentile) followed by a rounded byte
cast; NaN pixels map to 0. Use percentile_clip directly if
you need the intermediate [0, 1] floats for further math.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch y x']
|
Input array, typically |
required |
lower
|
float
|
Lower percentile. Default |
2.0
|
upper
|
float
|
Upper percentile. Default |
98.0
|
reduce_axes
|
int | tuple[int, ...] | None
|
Axes the percentiles are computed over. Default
|
(-2, -1)
|
Returns:
| Type | Description |
|---|---|
UInt8[ndarray, '*batch y x']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |