composites#
Day/night compositing for EO imagery — the pyramids-eo true_color_with_night_ir
chain, over NumPy + pyramids with no third-party compositing dependency.
Covers the solar and viewing geometry (solar_zenith_angle,
cos_solar_zenith_angle, solar_zenith_azimuth, satellite_zenith_azimuth,
relative_azimuth), the solar-zenith correction / reduction
(sunz_correct / sunz_reduce), a local Rayleigh atmospheric correction
(rayleigh_correct), the SZA cross-fade (day_night_blend / day_weight),
the alpha overlay (alpha_overlay), the static background image (static_image),
the true-colour composite (true_color), and the full assembly (night_ir,
true_color_with_night_ir).
The display and resampling helpers at the bottom finish
the chain: stretch maps a physical composite onto a displayable range, and
to_area lands a georeferenced composite on an exact target grid.
pyramids_eo.composites
#
Day/night compositing for EO imagery.
The pyramids-eo day/night composite chain (the true_color_with_night_ir
look), implemented over NumPy + pyramids with no third-party compositing
dependency. So far:
solar_zenith_angle/cos_solar_zenith_angle— per-pixel solar zenith angle (degrees) and its cosine (thecos_szaform the readers expect), the geometry the day/night blend keys off.sunz_correct/sunz_reduce— sun-zenith correction (divide bycos(sza), capped) and reduction (taper the signal toward the terminator), thesunz_corrected/sunz_reducedpair applied to a true-colour composite's solar bands so deep shadow renders dark rather than as a washed-out floor.solar_zenith_azimuth/satellite_zenith_azimuth/relative_azimuth— the solar and geostationary viewing geometry (zenith + azimuth, degrees clockwise from north) that an atmospheric correction needs.rayleigh_correct— a local, closed-form single-scattering Rayleigh correction (no third-party dependency) that removes the blue molecular-scattering veil, usable per band throughtrue_color'srayleigh=hook.day_night_blend/day_weight— the SZA-weighted cross-fade of a day and a night image.alpha_overlay— the "over" composite of an RGBA foreground on an RGB(A) background.static_image— load a georeferenced background image (e.g. Black Marble), caching a remote URL and warping it to a target grid.true_color— true-colour RGB from calibrated reflectance bands with a CIMSS synthetic green (no Rayleigh).night_ir/true_color_with_night_ir— assemble the full day/night image (RGBA IR clouds over city lights, cross-faded against the day image by SZA).
Together these compose the true_color_with_night_ir day/night look.
static_image(source, *, like=None, cache_dir=None, timeout=60.0, max_bytes=_DEFAULT_MAX_BYTES, refresh=False)
#
Load a georeferenced image, caching a remote URL and warping to a grid.
Loads a georeferenced background image. source may be a local path
(relative or absolute) or an http/https URL; a URL is downloaded once and
cached under cache_dir. When like is given, the loaded image is warped
and cropped onto that dataset's grid (CRS + rows/columns + cell size) via
pyramids' align.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
A local filesystem path or an http/https URL to a georeferenced raster (e.g. the Black Marble GeoTIFF). |
required |
like
|
Any
|
A pyramids |
None
|
cache_dir
|
Any
|
Directory used to cache a downloaded URL. Defaults to
|
None
|
timeout
|
float
|
Per-request download timeout in seconds (default 60). |
60.0
|
max_bytes
|
int
|
Cap on a URL download in bytes (default ~1 GB) — guards against an oversized/hostile URL filling the cache. |
_DEFAULT_MAX_BYTES
|
refresh
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A pyramids |
Any
|
otherwise the image at its native grid. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When a local |
EOError
|
When a URL download exceeds |
Source code in src/pyramids_eo/composites/background.py
day_night_blend(day, night, sza, *, lim_low=78.0, lim_high=88.0, mode='day_night', keep_alpha=False)
#
Cross-fade a day and a night image by solar zenith angle.
Computes a per-pixel day weight from sza (see day_weight) and mixes:
day * weight + night * (1 - weight).
day / night may be (H, W) or (band, H, W) arrays, or pyramids
Dataset objects; the weight broadcasts across bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
Any
|
The day image — array-like or a pyramids |
required |
night
|
Any
|
The night image — same shape/type family as |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees ( |
required |
lim_low
|
float
|
SZA at/below which it is fully day (default 78). |
78.0
|
lim_high
|
float
|
SZA at/above which it is fully night (default 88). |
88.0
|
mode
|
str
|
|
'day_night'
|
keep_alpha
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The blended image. A pyramids |
Any
|
geotransform + CRS) when either input is a |
Any
|
ndarray. With |
Any
|
band. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- A day (1s) / night (0s) pair collapses to the day weight per pixel:
keep_alphaappends a coverage band, giving a 4-band RGBA result:
Source code in src/pyramids_eo/composites/blend.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
day_weight(sza, lim_low=78.0, lim_high=88.0)
#
Per-pixel day weight in [0, 1] from the solar zenith angle.
The weight is 1 where the Sun is high (sza <= lim_low, full day), 0 where
it is low (sza >= lim_high, full night), and a smooth cos-space ramp
through the twilight band between them — the DayNightCompositor curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sza
|
Any
|
Solar zenith angle in degrees (scalar or array), e.g. from
|
required |
lim_low
|
float
|
SZA (degrees) at/below which it is fully day. Default 78. |
78.0
|
lim_high
|
float
|
SZA (degrees) at/above which it is fully night. Default 88. |
88.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The day weight, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Overhead Sun is full day, horizon is full night, midway is ~0.5:
Source code in src/pyramids_eo/composites/blend.py
cos_solar_zenith_angle(time, *, lat=None, lon=None, grid=None)
#
Per-pixel cosine of the solar zenith angle.
A thin wrapper over solar_zenith_angle returning cos(SZA) directly — the
form the readers' and radiance_to_reflectance's cos_sza arguments expect
(note solar_zenith_angle itself returns the angle in degrees). Same
arguments as solar_zenith_angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time (a naive datetime is treated as UTC). |
required |
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The cosine of the solar zenith angle, same shape as the coordinates. |
Source code in src/pyramids_eo/composites/geometry.py
relative_azimuth(sun_az, sat_az)
#
Sun-satellite azimuth difference, folded into [0, 180] degrees.
The absolute difference of two azimuths (each in [0, 360), clockwise from
north) folded to [0, 180] — the relative-azimuth input every atmospheric
correction expects. Order-independent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sun_az
|
Any
|
Solar azimuth(s) in degrees (e.g. from |
required |
sat_az
|
Any
|
Satellite azimuth(s) in degrees (e.g. from
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The relative azimuth in |
Examples:
- Opposed azimuths (0deg and 180deg) give the maximum, 180deg:
- Azimuths 350deg and 10deg are only 20deg apart (wrap-around):
Source code in src/pyramids_eo/composites/geometry.py
satellite_zenith_azimuth(*, lat=None, lon=None, grid=None, sat_lon=0.0, sat_radius_km=_R_GEO_KM)
#
Per-pixel (zenith, azimuth) of a geostationary satellite, in degrees.
Closed-form and time-invariant (a geostationary satellite sits at a fixed
sub-satellite longitude). The zenith is 0 at the sub-satellite point and
rises toward 90 at the limb; the azimuth is in degrees clockwise from
north ([0, 360)), the same convention as solar_zenith_azimuth, so the
two feed relative_azimuth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
sat_lon
|
float
|
Sub-satellite longitude in degrees east (default 0.0, Meteosat prime). |
0.0
|
sat_radius_km
|
float
|
Satellite orbital radius from Earth's centre in km (default 42164, geostationary) — this is a radius, not an altitude. |
_R_GEO_KM
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
geometric horizon (points that cannot see the satellite, e.g. the far |
tuple[ndarray, ndarray]
|
side of the Earth on a full global grid). |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- The sub-satellite point sees the satellite at the local zenith (0deg):
- A point due north of the sub-point sees the satellite due south (~180deg):
Source code in src/pyramids_eo/composites/geometry.py
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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
solar_zenith_angle(time, *, lat=None, lon=None, grid=None)
#
Per-pixel solar zenith angle (degrees) for a UTC time and a lon/lat grid.
Computed directly with the NOAA solar-position algorithm. Provide the
geographic coordinates either as lat
and lon arrays/scalars, or as a grid (a pyramids Dataset in EPSG:4326,
whose lat / lon cell-centre axes are meshed to 2-D).
The returned angle is the zenith angle in degrees (0 = Sun overhead,
90 = on the horizon / terminator, 180 = antisolar). day_night_blend takes
this and applies cos(deg2rad(...)) internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time. A naive datetime is treated as UTC; an aware one is converted to UTC. |
required |
lat
|
Any
|
Latitude(s) in degrees north — scalar or array. Mutually exclusive
with |
None
|
lon
|
Any
|
Longitude(s) in degrees east — scalar or array, broadcast against
|
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The solar zenith angle in degrees. Shape follows the broadcast of |
ndarray
|
and |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither |
Examples:
- The Sun is nearly overhead at (0degN, 0degE) at equinox noon:
- The antisolar point is in deep night (SZA near 180deg):
Source code in src/pyramids_eo/composites/geometry.py
solar_zenith_azimuth(time, *, lat=None, lon=None, grid=None)
#
Per-pixel solar (zenith, azimuth) in degrees.
Same coordinate inputs as solar_zenith_angle (a lat/lon pair, or an
EPSG:4326 grid). The returned zenith is identical to solar_zenith_angle;
the azimuth is the NOAA solar azimuth in degrees clockwise from north
([0, 360): 0 = north, 90 = east, 180 = south, 270 = west) — the same
convention as satellite_zenith_azimuth, so the two feed relative_azimuth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time (a naive datetime is treated as UTC). |
required |
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Same coordinate-argument errors as |
Examples:
- At equinox noon on the Greenwich meridian the Sun is due south:
Source code in src/pyramids_eo/composites/geometry.py
sunz_correct(band, sza, *, correction_limit=88.0, max_sza=95.0)
#
Correct a solar band for the sun-zenith angle (divide by cos(sza), capped).
A plain 1 / cos(sza) diverges at the terminator, so the correction is capped:
below correction_limit the factor is 1 / cos(sza); from correction_limit
to max_sza it tapers from 1 / cos(correction_limit) down to 0 by an
inverted-log2 ramp; beyond max_sza (and where sza is NaN) the factor is
0. The band is multiplied by this factor. This mirrors the reference
sunz_corrected modifier (SunZenithCorrector), whose defaults are
correction_limit=88, max_sza=95.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band (reflectance) — array-like or a pyramids |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees (e.g. from
|
required |
correction_limit
|
float
|
SZA (degrees), in |
88.0
|
max_sza
|
float | None
|
SZA (degrees) at which the correction reaches |
95.0
|
Returns:
| Type | Description |
|---|---|
Any
|
The corrected band ( |
Any
|
|
Any
|
|
Any
|
factor is |
Any
|
value stays NaN ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Overhead sun is unchanged; a 60deg zenith doubles the signal (
1/cos60): - The correction stays finite at the terminator (no
1/0blow-up):
Source code in src/pyramids_eo/composites/geometry.py
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 | |
sunz_reduce(band, sza, *, correction_limit=80.0, max_sza=90.0, strength=1.3)
#
Taper a solar band's signal toward the terminator so deep shadow reads dark.
Below correction_limit the signal is unchanged; from correction_limit to
max_sza it is multiplied by a factor that ramps from 1 down to 0 by an
inverted-log2 curve sharpened by a strength sigmoid; at/beyond max_sza
(and where sza is NaN) the factor is 0. This mirrors the reference
sunz_reduced modifier (SunZenithReducer), whose defaults are
correction_limit=80, max_sza=90, strength=1.3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band (reflectance) — array-like or a pyramids |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees (e.g. from
|
required |
correction_limit
|
float
|
SZA (degrees), |
80.0
|
max_sza
|
float | None
|
SZA (degrees) at which the signal is fully reduced to |
90.0
|
strength
|
float
|
Sigmoid power sharpening the reduction ramp; |
1.3
|
Returns:
| Type | Description |
|---|---|
Any
|
The reduced band ( |
Any
|
(carrying |
Any
|
otherwise an ndarray (a 0-d array for scalar inputs). The factor is |
Any
|
at/beyond |
Any
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Unchanged below the limit, fully reduced to
0atmax_sza: - Inside the band the signal is dimmed (a shadow, not a grey floor):
Source code in src/pyramids_eo/composites/geometry.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
alpha_overlay(foreground, background)
#
Composite an RGBA foreground over an RGB(A) background.
Implements the "over" operator. For an opaque (RGB) background the result
is fg_rgb * fg_a + bg_rgb * (1 - fg_a) (a 3-band RGB image). For an RGBA
background the full premultiplied over is used, yielding a 4-band RGBA image
with a_out = fg_a + bg_a * (1 - fg_a).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
foreground
|
Any
|
The RGBA foreground — a |
required |
background
|
Any
|
The background — a |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The composited image: 3-band RGB for an RGB background, 4-band RGBA for an |
Any
|
RGBA background. A pyramids |
Any
|
background's geotransform + CRS) when either input is a |
Any
|
otherwise an ndarray. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- A half-transparent red foreground over a blue background blends 50/50:
Source code in src/pyramids_eo/composites/overlay.py
rayleigh_correct(band, *, wavelength_um, sza, vza, azidiff, pressure_hpa=_P0_HPA)
#
Rayleigh-correct a solar band by subtracting the molecular path reflectance.
Computes the single-scattering Rayleigh reflectance (see
:func:rayleigh_reflectance) for the band's wavelength and geometry and
subtracts it from the band, clipping the result at 0. Because the
correction grows as wavelength^-4, blue is corrected far more than red.
Designed to be used as the true_color rayleigh= hook (per band):
rayleigh=lambda band, *, role: rayleigh_correct(
band, wavelength_um=WL[role], sza=sza, vza=vza, azidiff=azidiff)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band reflectance in |
required |
wavelength_um
|
float
|
The band's centre wavelength in micrometres (e.g. from the
sensor registry |
required |
sza
|
Any
|
Solar zenith angle(s) in degrees. |
required |
vza
|
Any
|
Satellite (view) zenith angle(s) in degrees. |
required |
azidiff
|
Any
|
Sun-satellite relative azimuth in degrees. |
required |
pressure_hpa
|
float
|
Surface pressure in hPa (default sea level). |
_P0_HPA
|
Returns:
| Type | Description |
|---|---|
Any
|
The corrected band. A pyramids |
Any
|
CRS) when |
Examples:
- Correcting reduces a band, and blue drops more than red:
>>> import numpy as np >>> from pyramids_eo.composites.rayleigh import rayleigh_correct >>> geom = dict(sza=40.0, vza=30.0, azidiff=60.0) >>> blue = rayleigh_correct(np.array([0.6]), wavelength_um=0.444, **geom) >>> red = rayleigh_correct(np.array([0.6]), wavelength_um=0.640, **geom) >>> bool(blue[0] < red[0] < 0.6) True
Source code in src/pyramids_eo/composites/rayleigh.py
night_ir(red, green, blue, *, alpha=None)
#
Stack three IR bands into an RGBA night-cloud image.
Stack the three IR bands (e.g. ir_38, ir_105, ir_123) as RGB and
attach an alpha channel. The alpha controls where the
background (city lights) shows through — pass a cloud-derived alpha
(opaque over cold cloud tops, transparent over clear sky) to reproduce the
reference look; the default is fully opaque (alpha = 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
Any
|
The IR band mapped to red (e.g. |
required |
green
|
Any
|
The IR band mapped to green (e.g. |
required |
blue
|
Any
|
The IR band mapped to blue (e.g. |
required |
alpha
|
Any
|
Per-pixel alpha in |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Any
|
|
Source code in src/pyramids_eo/composites/true_color_night.py
true_color_with_night_ir(day, night_ir_rgba, background, sza, *, lim_low=78.0, lim_high=88.0, keep_alpha=False)
#
Compose the full true_color_with_night_ir day/night image.
Overlays the RGBA night-IR clouds on the city-lights background
(alpha_overlay), then cross-fades that night image against the day
true-colour image by solar zenith angle (day_night_blend).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
Any
|
The day image — true-colour RGB |
required |
night_ir_rgba
|
Any
|
The RGBA night-IR clouds from |
required |
background
|
Any
|
The RGB city-lights background (e.g. Black Marble warped to
the grid via |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees, from |
required |
lim_low
|
float
|
SZA at/below which it is fully day (default 78). |
78.0
|
lim_high
|
float
|
SZA at/above which it is fully night (default 88). |
88.0
|
keep_alpha
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The composed day/night image — a pyramids |
Any
|
one, otherwise an ndarray. |
Any
|
|
Examples:
- Compose a day/night frame from the primitives:
>>> import numpy as np >>> from pyramids_eo.composites import night_ir, true_color_with_night_ir >>> day = np.ones((3, 1, 2)) >>> clouds = night_ir(np.ones((1, 2)), np.ones((1, 2)), np.ones((1, 2))) >>> bg = np.zeros((3, 1, 2)) >>> true_color_with_night_ir(day, clouds, bg, np.zeros((1, 2))).shape (3, 1, 2) - Keep a coverage band for edge feathering (4-band RGBA):
>>> import numpy as np >>> from pyramids_eo.composites import night_ir, true_color_with_night_ir >>> day = np.ones((3, 1, 2)) >>> clouds = night_ir(np.ones((1, 2)), np.ones((1, 2)), np.ones((1, 2))) >>> bg = np.zeros((3, 1, 2)) >>> out = true_color_with_night_ir( ... day, clouds, bg, np.zeros((1, 2)), keep_alpha=True ... ) >>> out.shape (4, 1, 2)
Source code in src/pyramids_eo/composites/true_color_night.py
pyramids_eo.composites.geometry
#
Solar geometry for day/night compositing.
solar_zenith_angle gives the per-pixel solar zenith angle (SZA) from a UTC
time and a lon/lat grid, computed directly with the NOAA solar-position
algorithm over NumPy. The SZA drives the day/night cross-fade
(day_night_blend),
which keys off the Sun's geometric position rather than how dark a pixel looks
(the property that renders an eclipse shadow as day, not night).
sunz_correct and sunz_reduce consume that angle: the first divides a solar
band by cos(sza) (capped, so it does not blow up at the terminator), the second
tapers the signal back down toward the terminator so deep shadow renders dark
rather than as a washed-out floor. Together they mirror the sunz_corrected and
sunz_reduced modifiers used on every solar prerequisite of a reference
true-colour composite.
For atmospheric corrections, solar_zenith_azimuth and satellite_zenith_azimuth
add the viewing geometry — the Sun's and a geostationary satellite's zenith and
azimuth per pixel — and relative_azimuth folds the two azimuths into the
Sun-satellite difference every correction model expects. All azimuths use one
convention: degrees clockwise from north ([0, 360)).
solar_zenith_angle(time, *, lat=None, lon=None, grid=None)
#
Per-pixel solar zenith angle (degrees) for a UTC time and a lon/lat grid.
Computed directly with the NOAA solar-position algorithm. Provide the
geographic coordinates either as lat
and lon arrays/scalars, or as a grid (a pyramids Dataset in EPSG:4326,
whose lat / lon cell-centre axes are meshed to 2-D).
The returned angle is the zenith angle in degrees (0 = Sun overhead,
90 = on the horizon / terminator, 180 = antisolar). day_night_blend takes
this and applies cos(deg2rad(...)) internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time. A naive datetime is treated as UTC; an aware one is converted to UTC. |
required |
lat
|
Any
|
Latitude(s) in degrees north — scalar or array. Mutually exclusive
with |
None
|
lon
|
Any
|
Longitude(s) in degrees east — scalar or array, broadcast against
|
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The solar zenith angle in degrees. Shape follows the broadcast of |
ndarray
|
and |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither |
Examples:
- The Sun is nearly overhead at (0degN, 0degE) at equinox noon:
- The antisolar point is in deep night (SZA near 180deg):
Source code in src/pyramids_eo/composites/geometry.py
cos_solar_zenith_angle(time, *, lat=None, lon=None, grid=None)
#
Per-pixel cosine of the solar zenith angle.
A thin wrapper over solar_zenith_angle returning cos(SZA) directly — the
form the readers' and radiance_to_reflectance's cos_sza arguments expect
(note solar_zenith_angle itself returns the angle in degrees). Same
arguments as solar_zenith_angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time (a naive datetime is treated as UTC). |
required |
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The cosine of the solar zenith angle, same shape as the coordinates. |
Source code in src/pyramids_eo/composites/geometry.py
solar_zenith_azimuth(time, *, lat=None, lon=None, grid=None)
#
Per-pixel solar (zenith, azimuth) in degrees.
Same coordinate inputs as solar_zenith_angle (a lat/lon pair, or an
EPSG:4326 grid). The returned zenith is identical to solar_zenith_angle;
the azimuth is the NOAA solar azimuth in degrees clockwise from north
([0, 360): 0 = north, 90 = east, 180 = south, 270 = west) — the same
convention as satellite_zenith_azimuth, so the two feed relative_azimuth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
Observation time (a naive datetime is treated as UTC). |
required |
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Same coordinate-argument errors as |
Examples:
- At equinox noon on the Greenwich meridian the Sun is due south:
Source code in src/pyramids_eo/composites/geometry.py
satellite_zenith_azimuth(*, lat=None, lon=None, grid=None, sat_lon=0.0, sat_radius_km=_R_GEO_KM)
#
Per-pixel (zenith, azimuth) of a geostationary satellite, in degrees.
Closed-form and time-invariant (a geostationary satellite sits at a fixed
sub-satellite longitude). The zenith is 0 at the sub-satellite point and
rises toward 90 at the limb; the azimuth is in degrees clockwise from
north ([0, 360)), the same convention as solar_zenith_azimuth, so the
two feed relative_azimuth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Any
|
Latitude(s) in degrees north, paired with |
None
|
lon
|
Any
|
Longitude(s) in degrees east, paired with |
None
|
grid
|
Any
|
A pyramids |
None
|
sat_lon
|
float
|
Sub-satellite longitude in degrees east (default 0.0, Meteosat prime). |
0.0
|
sat_radius_km
|
float
|
Satellite orbital radius from Earth's centre in km (default 42164, geostationary) — this is a radius, not an altitude. |
_R_GEO_KM
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
geometric horizon (points that cannot see the satellite, e.g. the far |
tuple[ndarray, ndarray]
|
side of the Earth on a full global grid). |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- The sub-satellite point sees the satellite at the local zenith (0deg):
- A point due north of the sub-point sees the satellite due south (~180deg):
Source code in src/pyramids_eo/composites/geometry.py
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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
relative_azimuth(sun_az, sat_az)
#
Sun-satellite azimuth difference, folded into [0, 180] degrees.
The absolute difference of two azimuths (each in [0, 360), clockwise from
north) folded to [0, 180] — the relative-azimuth input every atmospheric
correction expects. Order-independent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sun_az
|
Any
|
Solar azimuth(s) in degrees (e.g. from |
required |
sat_az
|
Any
|
Satellite azimuth(s) in degrees (e.g. from
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The relative azimuth in |
Examples:
- Opposed azimuths (0deg and 180deg) give the maximum, 180deg:
- Azimuths 350deg and 10deg are only 20deg apart (wrap-around):
Source code in src/pyramids_eo/composites/geometry.py
sunz_correct(band, sza, *, correction_limit=88.0, max_sza=95.0)
#
Correct a solar band for the sun-zenith angle (divide by cos(sza), capped).
A plain 1 / cos(sza) diverges at the terminator, so the correction is capped:
below correction_limit the factor is 1 / cos(sza); from correction_limit
to max_sza it tapers from 1 / cos(correction_limit) down to 0 by an
inverted-log2 ramp; beyond max_sza (and where sza is NaN) the factor is
0. The band is multiplied by this factor. This mirrors the reference
sunz_corrected modifier (SunZenithCorrector), whose defaults are
correction_limit=88, max_sza=95.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band (reflectance) — array-like or a pyramids |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees (e.g. from
|
required |
correction_limit
|
float
|
SZA (degrees), in |
88.0
|
max_sza
|
float | None
|
SZA (degrees) at which the correction reaches |
95.0
|
Returns:
| Type | Description |
|---|---|
Any
|
The corrected band ( |
Any
|
|
Any
|
|
Any
|
factor is |
Any
|
value stays NaN ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Overhead sun is unchanged; a 60deg zenith doubles the signal (
1/cos60): - The correction stays finite at the terminator (no
1/0blow-up):
Source code in src/pyramids_eo/composites/geometry.py
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 | |
sunz_reduce(band, sza, *, correction_limit=80.0, max_sza=90.0, strength=1.3)
#
Taper a solar band's signal toward the terminator so deep shadow reads dark.
Below correction_limit the signal is unchanged; from correction_limit to
max_sza it is multiplied by a factor that ramps from 1 down to 0 by an
inverted-log2 curve sharpened by a strength sigmoid; at/beyond max_sza
(and where sza is NaN) the factor is 0. This mirrors the reference
sunz_reduced modifier (SunZenithReducer), whose defaults are
correction_limit=80, max_sza=90, strength=1.3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band (reflectance) — array-like or a pyramids |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees (e.g. from
|
required |
correction_limit
|
float
|
SZA (degrees), |
80.0
|
max_sza
|
float | None
|
SZA (degrees) at which the signal is fully reduced to |
90.0
|
strength
|
float
|
Sigmoid power sharpening the reduction ramp; |
1.3
|
Returns:
| Type | Description |
|---|---|
Any
|
The reduced band ( |
Any
|
(carrying |
Any
|
otherwise an ndarray (a 0-d array for scalar inputs). The factor is |
Any
|
at/beyond |
Any
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Unchanged below the limit, fully reduced to
0atmax_sza: - Inside the band the signal is dimmed (a shadow, not a grey floor):
Source code in src/pyramids_eo/composites/geometry.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
pyramids_eo.composites.blend
#
Solar-zenith-angle day/night blending.
day_night_blend cross-fades a day image and a night image by the
per-pixel solar zenith angle (SZA), producing the smooth twilight transition of
the true_color_with_night_ir look. The blend keys off the Sun's geometric
position (from solar_zenith_angle), not on how dark a pixel looks — which is
why an eclipse shadow is rendered as day, not night.
day_weight(sza, lim_low=78.0, lim_high=88.0)
#
Per-pixel day weight in [0, 1] from the solar zenith angle.
The weight is 1 where the Sun is high (sza <= lim_low, full day), 0 where
it is low (sza >= lim_high, full night), and a smooth cos-space ramp
through the twilight band between them — the DayNightCompositor curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sza
|
Any
|
Solar zenith angle in degrees (scalar or array), e.g. from
|
required |
lim_low
|
float
|
SZA (degrees) at/below which it is fully day. Default 78. |
78.0
|
lim_high
|
float
|
SZA (degrees) at/above which it is fully night. Default 88. |
88.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The day weight, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Overhead Sun is full day, horizon is full night, midway is ~0.5:
Source code in src/pyramids_eo/composites/blend.py
day_night_blend(day, night, sza, *, lim_low=78.0, lim_high=88.0, mode='day_night', keep_alpha=False)
#
Cross-fade a day and a night image by solar zenith angle.
Computes a per-pixel day weight from sza (see day_weight) and mixes:
day * weight + night * (1 - weight).
day / night may be (H, W) or (band, H, W) arrays, or pyramids
Dataset objects; the weight broadcasts across bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
Any
|
The day image — array-like or a pyramids |
required |
night
|
Any
|
The night image — same shape/type family as |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees ( |
required |
lim_low
|
float
|
SZA at/below which it is fully day (default 78). |
78.0
|
lim_high
|
float
|
SZA at/above which it is fully night (default 88). |
88.0
|
mode
|
str
|
|
'day_night'
|
keep_alpha
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The blended image. A pyramids |
Any
|
geotransform + CRS) when either input is a |
Any
|
ndarray. With |
Any
|
band. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- A day (1s) / night (0s) pair collapses to the day weight per pixel:
keep_alphaappends a coverage band, giving a 4-band RGBA result:
Source code in src/pyramids_eo/composites/blend.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
pyramids_eo.composites.overlay
#
Alpha overlay of one image over another.
alpha_overlay composites an RGBA foreground over an RGB or RGBA background
with the standard "over" operator. In the day/night chain the foreground is the
night-IR
cloud RGBA (transparent where there are no clouds) and the background is the
Black Marble city lights, so the lights show through the gaps.
alpha_overlay(foreground, background)
#
Composite an RGBA foreground over an RGB(A) background.
Implements the "over" operator. For an opaque (RGB) background the result
is fg_rgb * fg_a + bg_rgb * (1 - fg_a) (a 3-band RGB image). For an RGBA
background the full premultiplied over is used, yielding a 4-band RGBA image
with a_out = fg_a + bg_a * (1 - fg_a).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
foreground
|
Any
|
The RGBA foreground — a |
required |
background
|
Any
|
The background — a |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The composited image: 3-band RGB for an RGB background, 4-band RGBA for an |
Any
|
RGBA background. A pyramids |
Any
|
background's geotransform + CRS) when either input is a |
Any
|
otherwise an ndarray. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- A half-transparent red foreground over a blue background blends 50/50:
Source code in src/pyramids_eo/composites/overlay.py
pyramids_eo.composites.background
#
Static georeferenced background images for compositing.
static_image loads a georeferenced raster (e.g. the NASA Black Marble city
lights that back the night-IR clouds), caching it locally when the source is a
URL, and optionally warps/crops it to another dataset's grid via pyramids'
align.
It takes a plain local or remote path and caches a remote one. A live
Black Marble mirror is
https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_3km_geo.tif
(the older neo.gsfc.nasa.gov/archive/blackmarble/... URLs are 404).
static_image(source, *, like=None, cache_dir=None, timeout=60.0, max_bytes=_DEFAULT_MAX_BYTES, refresh=False)
#
Load a georeferenced image, caching a remote URL and warping to a grid.
Loads a georeferenced background image. source may be a local path
(relative or absolute) or an http/https URL; a URL is downloaded once and
cached under cache_dir. When like is given, the loaded image is warped
and cropped onto that dataset's grid (CRS + rows/columns + cell size) via
pyramids' align.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
A local filesystem path or an http/https URL to a georeferenced raster (e.g. the Black Marble GeoTIFF). |
required |
like
|
Any
|
A pyramids |
None
|
cache_dir
|
Any
|
Directory used to cache a downloaded URL. Defaults to
|
None
|
timeout
|
float
|
Per-request download timeout in seconds (default 60). |
60.0
|
max_bytes
|
int
|
Cap on a URL download in bytes (default ~1 GB) — guards against an oversized/hostile URL filling the cache. |
_DEFAULT_MAX_BYTES
|
refresh
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A pyramids |
Any
|
otherwise the image at its native grid. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When a local |
EOError
|
When a URL download exceeds |
Source code in src/pyramids_eo/composites/background.py
pyramids_eo.composites.true_color
#
True-colour RGB from calibrated reflectance bands.
SEVIRI carries no native green band, so for it true_color synthesises one from
the red, blue, and near-IR ("veggie") reflectances using the CIMSS weighted
recipe (green_mode="synthetic", the default), then stacks red / green / blue
into an RGB image.
FCI FDHSI does carry a native green band (vis_05, ~0.51 um). For FCI, pass
that band as green= and select green_mode="native" to use it directly, or
green_mode="ndvi_hybrid" to blend it with the NIR by an NDVI fraction (more NIR
over barren surfaces, less over vegetation) — the reference true-colour look.
This is the no-Rayleigh variant (per the pyramids-eo compositing decision):
by default it does the band combination only, so the result is slightly flatter
over ocean / haze than a Rayleigh-corrected image. Atmospheric / Rayleigh
correction stays opt-in rather than automatic — pass a rayleigh= callable and
it is applied to each solar band before green synthesis. The package ships a
local, dependency-free correction (rayleigh_correct) for that hook, so opting in
adds no third-party dependency.
true_color(red, blue, nir, *, green=None, green_mode='synthetic', green_weights=_DEFAULT_GREEN_WEIGHTS, ndvi_strength=3.0, ndvi_limits=(0.15, 0.05), rayleigh=None, gamma=None, clip=False)
#
Build a true-colour RGB from red, blue, and near-IR reflectances.
The green channel is built per green_mode:
"synthetic"(default) —green = wr*red + wn*nir + wb*blue(the CIMSS recipe), for sensors with no native green band (SEVIRI). Byte-identical to the historical behaviour."native"— use thegreen=band directly (FCIvis_05)."ndvi_hybrid"— blend thegreen=band with the NIR by an NDVI fraction (see :func:_ndvi_hybrid_green).
When rayleigh is given it is applied to each solar band (red, blue, nir, and
a native green) before green synthesis; None (default) leaves the bands
untouched and adds no dependency. The callable may take just (band), or
(band, *, role) where role is the band's part in the composite — one of
"red", "green", "blue", "nir" — so it can pick a per-band correction
(e.g. a wavelength-dependent Rayleigh) or decline a band by returning it
unchanged. The (band, role=...) form is used when the callable accepts a
role keyword (probed once); otherwise the (band) form is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
Any
|
Red-band reflectance — array-like or a pyramids |
required |
blue
|
Any
|
Blue-band reflectance, same grid as |
required |
nir
|
Any
|
Near-IR ("veggie") reflectance — the synthetic-green source, the
NDVI NIR term, and the |
required |
green
|
Any
|
Native green reflectance (FCI |
None
|
green_mode
|
str
|
How to build the green channel — |
'synthetic'
|
green_weights
|
tuple[float, float, float]
|
The |
_DEFAULT_GREEN_WEIGHTS
|
ndvi_strength
|
float
|
Non-linear NDVI sharpening for |
3.0
|
ndvi_limits
|
tuple[float, float]
|
The |
(0.15, 0.05)
|
rayleigh
|
Callable[..., Any] | None
|
Optional atmospheric correction applied to each solar band
before green synthesis — a callable taking |
None
|
gamma
|
float | None
|
Optional gamma to apply ( |
None
|
clip
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Any
|
|
Any
|
an ndarray. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Synthetic CIMSS green (SEVIRI-style) from red / blue / NIR reflectance:
- Use FCI's native green band directly (
green_mode="native"):
Source code in src/pyramids_eo/composites/true_color.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 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 | |
pyramids_eo.composites.rayleigh
#
Local Rayleigh (molecular-scattering) correction for solar bands.
A self-contained, closed-form single-scattering Rayleigh correction over
NumPy — no third-party radiative-transfer dependency. It removes the blue
molecular-scattering veil a no-Rayleigh true colour leaves over the disc, using
the viewing geometry from geometry.py (solar_zenith_azimuth,
satellite_zenith_azimuth, relative_azimuth).
The model is:
- Rayleigh optical thickness
tau_r(lambda)from the Hansen & Travis (1974) closed form, scaled linearly by surface pressure. - The Rayleigh phase function
P(Theta) = 3/4 (1 + cos^2 Theta)at the Sun-satellite scattering angle. - The single-scattering path reflectance
rho_r = P(Theta) / (4 (mu_s + mu_v)) * (1 - exp(-tau_r (1/mu_s + 1/mu_v))), which stays bounded toward the terminator / limb.
rho_r is subtracted from the (already reflectance-scaled [0, 1]) band. Because
tau_r goes as lambda^-4, blue is corrected several times more than red — the
per-band selectivity the composite needs. This is a single-scattering
approximation (no multiple scattering, aerosol, or surface coupling), so it is
lighter and slightly less accurate than a full radiative-transfer table, but it
carries no dependency and reproduces the bulk of the blue-veil removal.
rayleigh_optical_depth(wavelength_um, pressure_hpa=_P0_HPA)
#
Rayleigh optical thickness at a wavelength, scaled by surface pressure.
Uses the Hansen & Travis (1974) closed form
tau0 = 0.008569 l^-4 (1 + 0.0113 l^-2 + 0.00013 l^-4) (l in micrometres,
sea level), scaled linearly by pressure_hpa / 1013.25.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength_um
|
float
|
Band centre wavelength in micrometres. |
required |
pressure_hpa
|
float
|
Surface pressure in hPa (default sea level, 1013.25). |
_P0_HPA
|
Returns:
| Type | Description |
|---|---|
float
|
The (dimensionless) Rayleigh optical thickness. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Blue scatters far more than red (the
lambda^-4law):
Source code in src/pyramids_eo/composites/rayleigh.py
rayleigh_reflectance(wavelength_um, sza, vza, azidiff, *, pressure_hpa=_P0_HPA)
#
Single-scattering Rayleigh path reflectance for the viewing geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength_um
|
float
|
Band centre wavelength in micrometres. |
required |
sza
|
Any
|
Solar zenith angle(s) in degrees (e.g. from |
required |
vza
|
Any
|
Satellite (view) zenith angle(s) in degrees (from
|
required |
azidiff
|
Any
|
Sun-satellite relative azimuth in degrees (from
|
required |
pressure_hpa
|
float
|
Surface pressure in hPa (default sea level). |
_P0_HPA
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The per-pixel Rayleigh path reflectance in |
ndarray
|
scattering form is unbounded toward the limb), |
ndarray
|
( |
ndarray
|
geometry input is NaN. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- The path reflectance is a small positive fraction, larger for blue:
- There is no single-scatter path on the night side (
sza >= 90):
Source code in src/pyramids_eo/composites/rayleigh.py
rayleigh_correct(band, *, wavelength_um, sza, vza, azidiff, pressure_hpa=_P0_HPA)
#
Rayleigh-correct a solar band by subtracting the molecular path reflectance.
Computes the single-scattering Rayleigh reflectance (see
:func:rayleigh_reflectance) for the band's wavelength and geometry and
subtracts it from the band, clipping the result at 0. Because the
correction grows as wavelength^-4, blue is corrected far more than red.
Designed to be used as the true_color rayleigh= hook (per band):
rayleigh=lambda band, *, role: rayleigh_correct(
band, wavelength_um=WL[role], sza=sza, vza=vza, azidiff=azidiff)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
Any
|
The solar band reflectance in |
required |
wavelength_um
|
float
|
The band's centre wavelength in micrometres (e.g. from the
sensor registry |
required |
sza
|
Any
|
Solar zenith angle(s) in degrees. |
required |
vza
|
Any
|
Satellite (view) zenith angle(s) in degrees. |
required |
azidiff
|
Any
|
Sun-satellite relative azimuth in degrees. |
required |
pressure_hpa
|
float
|
Surface pressure in hPa (default sea level). |
_P0_HPA
|
Returns:
| Type | Description |
|---|---|
Any
|
The corrected band. A pyramids |
Any
|
CRS) when |
Examples:
- Correcting reduces a band, and blue drops more than red:
>>> import numpy as np >>> from pyramids_eo.composites.rayleigh import rayleigh_correct >>> geom = dict(sza=40.0, vza=30.0, azidiff=60.0) >>> blue = rayleigh_correct(np.array([0.6]), wavelength_um=0.444, **geom) >>> red = rayleigh_correct(np.array([0.6]), wavelength_um=0.640, **geom) >>> bool(blue[0] < red[0] < 0.6) True
Source code in src/pyramids_eo/composites/rayleigh.py
pyramids_eo.composites.true_color_night
#
Assemble the true_color_with_night_ir day/night image.
This wires the compositing primitives into the true_color_with_night_ir
chain, entirely in pyramids-eo:
true_color_with_night_ir = day_night_blend(
day = true_color,
night = alpha_overlay(night_ir, static_image(BlackMarble)),
sza = solar_zenith_angle(...),
)
night_ir = stack(ir_38, ir_105, ir_123) -> RGB + alpha
night_ir builds the RGBA night-cloud image (the IR-stack step);
true_color_with_night_ir overlays it on the city-lights background and
cross-fades against the day image by solar zenith angle.
night_ir(red, green, blue, *, alpha=None)
#
Stack three IR bands into an RGBA night-cloud image.
Stack the three IR bands (e.g. ir_38, ir_105, ir_123) as RGB and
attach an alpha channel. The alpha controls where the
background (city lights) shows through — pass a cloud-derived alpha
(opaque over cold cloud tops, transparent over clear sky) to reproduce the
reference look; the default is fully opaque (alpha = 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
Any
|
The IR band mapped to red (e.g. |
required |
green
|
Any
|
The IR band mapped to green (e.g. |
required |
blue
|
Any
|
The IR band mapped to blue (e.g. |
required |
alpha
|
Any
|
Per-pixel alpha in |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Any
|
|
Source code in src/pyramids_eo/composites/true_color_night.py
true_color_with_night_ir(day, night_ir_rgba, background, sza, *, lim_low=78.0, lim_high=88.0, keep_alpha=False)
#
Compose the full true_color_with_night_ir day/night image.
Overlays the RGBA night-IR clouds on the city-lights background
(alpha_overlay), then cross-fades that night image against the day
true-colour image by solar zenith angle (day_night_blend).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
Any
|
The day image — true-colour RGB |
required |
night_ir_rgba
|
Any
|
The RGBA night-IR clouds from |
required |
background
|
Any
|
The RGB city-lights background (e.g. Black Marble warped to
the grid via |
required |
sza
|
Any
|
Per-pixel solar zenith angle in degrees, from |
required |
lim_low
|
float
|
SZA at/below which it is fully day (default 78). |
78.0
|
lim_high
|
float
|
SZA at/above which it is fully night (default 88). |
88.0
|
keep_alpha
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The composed day/night image — a pyramids |
Any
|
one, otherwise an ndarray. |
Any
|
|
Examples:
- Compose a day/night frame from the primitives:
>>> import numpy as np >>> from pyramids_eo.composites import night_ir, true_color_with_night_ir >>> day = np.ones((3, 1, 2)) >>> clouds = night_ir(np.ones((1, 2)), np.ones((1, 2)), np.ones((1, 2))) >>> bg = np.zeros((3, 1, 2)) >>> true_color_with_night_ir(day, clouds, bg, np.zeros((1, 2))).shape (3, 1, 2) - Keep a coverage band for edge feathering (4-band RGBA):
>>> import numpy as np >>> from pyramids_eo.composites import night_ir, true_color_with_night_ir >>> day = np.ones((3, 1, 2)) >>> clouds = night_ir(np.ones((1, 2)), np.ones((1, 2)), np.ones((1, 2))) >>> bg = np.zeros((3, 1, 2)) >>> out = true_color_with_night_ir( ... day, clouds, bg, np.zeros((1, 2)), keep_alpha=True ... ) >>> out.shape (4, 1, 2)
Source code in src/pyramids_eo/composites/true_color_night.py
Display and resampling#
stretch (pyramids_eo.enhance) maps a composite's physical values — reflectance
in roughly [0, 1], brightness temperature in kelvin — onto a display range and
dtype (uint8 by default), via a "linear", "crude", "cira", or "histogram"
curve. to_area (pyramids_eo.resample) warps a georeferenced composite onto an
exact target grid (a CRS, an extent, and a pixel width/height) in a single GDAL
pass — the one step of the chain with no direct pyramids equivalent.
pyramids_eo.enhance
#
Map composite physical values to a display range.
pyramids-eo composites return physical values — reflectance in roughly [0, 1],
brightness temperature in kelvin. stretch maps those to a display range and
dtype (uint8 by default), the step between a raw composite and a displayable
frame.
Four curves are provided:
"linear"— percentile-clip (thecutoffs) then rescale to[0, 1]."crude"— fixed min/max linear rescale,(x - lo) / (hi - lo)."cira"— a logarithmic, human-vision-tuned stretch; recommended for a true-colour composite (no gamma needed). Note it is not the signature default; passkind="cira"explicitly."histogram"— histogram equalisation.
The stretch is computed over the whole array (shared across bands), preserving
inter-band ratios — important for a true-colour image. NaN / nodata pixels are
excluded from the statistics and preserved (float output) or filled with 0
(integer output). For an RGBA input carrying a coverage / alpha band (e.g. from
keep_alpha), pass preserve_alpha=True so the trailing band is passed through
untouched instead of being curved like image data. Reflectance is expected in
[0, 1]; scale first if it is in percent.
For an integer frame, 0 is used for both a masked pixel and a valid-black pixel, so the coverage / alpha band — not the nodata value — is the reliable mask.
stretch(image, *, kind='linear', min_stretch=None, max_stretch=None, gamma=None, cutoffs=(0.005, 0.005), preserve_alpha=False, dtype='uint8')
#
Map a composite's physical values to a display range and dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The composite — an array ( |
required |
kind
|
str
|
The stretch curve — |
'linear'
|
min_stretch
|
float | None
|
Fixed lower bound for |
None
|
max_stretch
|
float | None
|
Fixed upper bound for |
None
|
gamma
|
float | None
|
Optional power curve |
None
|
cutoffs
|
tuple[float, float]
|
|
(0.005, 0.005)
|
preserve_alpha
|
bool
|
When |
False
|
dtype
|
Any
|
Output dtype. Integer dtypes scale |
'uint8'
|
Returns:
| Type | Description |
|---|---|
Any
|
The stretched image in |
Any
|
input's geotransform + CRS, nodata 0 for integer / NaN for float) when |
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- Crude-stretch reflectance onto the 8-bit display range:
- The CIRA log stretch keeps NaN and lifts low reflectance (float out):
Source code in src/pyramids_eo/enhance.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
pyramids_eo.resample
#
Resample a composite onto an explicit target grid.
to_area places a georeferenced composite onto an exact target grid — a CRS, an
extent, and a pixel width/height — with a chosen interpolation method, in a
single GDAL warp. This is the one step of the day/night chain with no pyramids
equivalent: Dataset.to_crs lets GDAL pick the grid, and Dataset.align needs a
pre-built template Dataset already on the grid. A direct warp pins
-t_srs / -te / -ts / -r together and lands the exact grid in one pass —
the same primitive the Earth Engine reader keeps for the same reason.
to_area(dataset, crs, extent, width, height, *, method='bilinear')
#
Warp a composite onto an exact target grid (CRS + extent + size).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
The source composite — a pyramids |
required |
crs
|
Any
|
Target CRS — any string GDAL accepts, including an EPSG code or a
PROJ4 string with no EPSG (e.g. a |
required |
extent
|
tuple[float, float, float, float]
|
Output bounds |
required |
width
|
int
|
Output width in pixels. |
required |
height
|
int
|
Output height in pixels. |
required |
method
|
str
|
Resampling method — one of |
'bilinear'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A pyramids |
Dataset
|
shape |
Dataset
|
preserved from |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
RuntimeError
|
When the GDAL warp fails. |
Examples:
- Warp a small WGS84 raster onto an exact 4x4 grid:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from pyramids_eo.resample import to_area >>> src = Dataset.from_array( ... np.ones((2, 2)), ... geo_ref=GeoReference(top_left_corner=(0.0, 2.0), cell_size=1.0, epsg=4326), ... ) >>> out = to_area(src, 4326, (0.0, 0.0, 2.0, 2.0), 4, 4) >>> out.read_array().shape (4, 4)
Source code in src/pyramids_eo/resample.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |