spectral#
Spectral transforms for EO rasters — operations that rotate or combine a sensor's reflectance bands into a derived, physically meaningful space, using the per-sensor knowledge in the registry.
Currently the Kauth-Thomas tasseled cap (tasseled_cap): brightness /
greenness / wetness from a multi-band reflectance Dataset, with the
coefficients selected by sensor and the band order handled by name rather than
assumed — a named stack is reordered to the coefficient order, an unnamed one is
taken in the sensor's documented order, and a stack whose names are ambiguous or
do not match the sensor is rejected — so a mis-ordered stack never silently
produces a plausible-looking but meaningless raster. The per-sensor coefficient
tables themselves live in the registry (get_tasseled_cap,
sensors/registry/data/tasseled_cap.yaml).
pyramids_eo.spectral
#
Spectral transforms for EO rasters.
Operations that rotate or combine a sensor's reflectance bands into a
derived, physically meaningful space, using the per-sensor knowledge in
pyramids_eo.sensors.registry:
tasseled_cap— the Kauth-Thomas brightness / greenness / wetness transform, applied to a multi-band reflectanceDatasetwith the sensor's coefficients.
pyramids_eo.spectral.tasseled_cap
#
Tasseled-cap (Kauth-Thomas) transform for a multi-band reflectance raster.
tasseled_cap(dataset, *, sensor, components=...) rotates a stack of reflectance
bands into the tasseled-cap components -- brightness, greenness, wetness -- using
the per-sensor coefficients from the registry
(pyramids_eo.sensors.registry.get_tasseled_cap). It returns a Dataset with
the requested components as named bands, carrying the input's grid and CRS, so it
stays composable with the rest of the stack.
The coefficients are a fixed linear combination tied to a specific band order,
so a silently wrong band order yields a plausible-looking but meaningless raster
-- the failure this transform is designed against. When the input Dataset's
bands are named (blue/green/... or a sensor spelling such as B4 / SR_B5),
they are matched to the sensor's roles and reordered to the coefficient order;
when they are unnamed (generic), the stack is assumed to already be in the
sensor's documented band order and only its band count is checked.
tasseled_cap(dataset, *, sensor, components=_DEFAULT_COMPONENTS)
#
Rotate a reflectance band stack into its tasseled-cap components.
Applies the sensor's tasseled-cap coefficients (see
pyramids_eo.sensors.registry.get_tasseled_cap) to the bands of dataset and
returns a Dataset whose bands are the requested components, in the order
given, carrying dataset's geotransform and CRS. The input bands must be in
the sensor's documented reflectance domain (TOA / reflectance factor, not raw
DN) and in the sensor's band order -- which is enforced by name when the bands
are named and by count otherwise (see the module docstring).
The whole band stack is read into memory and processed at full resolution (several float64 arrays at once: the input, and one per requested component); there is no windowing, so a full scene is sized accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
sensor
|
str
|
The sensor whose coefficient table to use (e.g. |
required |
components
|
Sequence[str]
|
The components to compute, in output-band order. Defaults to
|
_DEFAULT_COMPONENTS
|
Returns:
| Type | Description |
|---|---|
Any
|
A pyramids |
Any
|
components as its band names, |
Any
|
its nodata value. A pixel that is the input's nodata, or non-finite in any |
Any
|
band, is NaN in every component. |
Raises:
| Type | Description |
|---|---|
TransformError
|
When |
UnknownSensorError
|
When |
Examples:
- Brightness / greenness / wetness from a Landsat 8 OLI reflectance stack:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from pyramids_eo.spectral import tasseled_cap >>> stack = np.ones((6, 1, 1), dtype=float) # blue..swir2, reflectance 1.0 >>> ds = Dataset.from_array( ... stack, geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 1.0, 0.0, -1.0), epsg=4326) ... ) >>> ds.band_names = ["blue", "green", "red", "nir", "swir1", "swir2"] >>> tc = tasseled_cap(ds, sensor="landsat8_oli") >>> tc.band_names ['brightness', 'greenness', 'wetness'] >>> float(tc.read_array()[0, 0, 0].round(4)) # sum of the brightness row 2.3099 - Pick a single component; its coefficients are a sensor-specific constant:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from pyramids_eo.spectral import tasseled_cap >>> stack = np.ones((6, 1, 1), dtype=float) >>> ds = Dataset.from_array( ... stack, geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 1.0, 0.0, -1.0), epsg=4326) ... ) >>> ds.band_names = ["blue", "green", "red", "nir", "swir1", "swir2"] >>> wet = tasseled_cap(ds, sensor="landsat8_oli", components=["wetness"]) >>> wet.band_names ['wetness']
Source code in src/pyramids_eo/spectral/tasseled_cap.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |