API Reference#
The pyramids-eo public API. The top-level package (pyramids_eo) re-exports the Earth Engine and Sentinel-2
entry points; the sensor readers, registry, composites, and STAC signers live under their subpackages.
- Earth Engine — read EE
Image/ImageCollectionassets into aDataset/DatasetCollection(from_earthengine,collection_from_earthengine, cost estimation, credentials). - Sentinel — ESA Sentinel product readers (
open_product,from_sentinel2, SCL masking). - Sensors — the L1 data-access layer:
- Composites — day/night compositing (solar / viewing geometry, Rayleigh correction, blend),
plus the
stretch/to_areadisplay and resampling helpers. - STAC signers — EO provider asset signers (PC / Earthdata / CDSE / BDC).
- Errors — the
EOErrorexception family.
pyramids_eo
#
pyramids-eo — the Earth-observation layer of the pyramids stack.
pyramids-eo is built on top of :mod:pyramids (pyramids-core, the generic
raster/vector engine) and adds the logic that is specific to
Earth-observation data. Where pyramids knows how to move rasters around,
pyramids-eo knows what a pixel means for a given instrument or provider: which
subdataset is which channel, how to calibrate it, how to composite it, how to
resample a swath — and how to reach signed EO cloud assets. It is scoped by
domain (EO data), not by a restriction on what it may do.
EarthEngineCredentials
#
Application Default Credentials for the Earth Engine GDAL drivers.
Three modes:
- service-account file — an explicit Google service-account JSON key
file, surfaced to GDAL as
GOOGLE_APPLICATION_CREDENTIALS(:meth:from_service_account). - service-account info (inline JSON) — the key material as a JSON string
or mapping; it is written to a private temp file (owner-only, cleaned up
when the credentials are garbage-collected) and used as the key path
(:meth:
from_service_account_info). Useful when the key comes from a secret store rather than a file on disk. - application default — no explicit key; GDAL resolves ambient ADC
(an already-exported
GOOGLE_APPLICATION_CREDENTIALSorgcloudlogin). :meth:gdal_envis empty in this mode.
Prefer the named constructors :meth:from_service_account /
:meth:from_service_account_info / :meth:application_default over the raw
initializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account_json
|
str | Path | None
|
Path to a service-account JSON key, or |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
The given |
Examples:
Application-default credentials carry no explicit GDAL config — GDAL resolves ambient ADC on its own:
>>> from pyramids_eo.earthengine import EarthEngineCredentials
>>> EarthEngineCredentials.application_default().gdal_env()
{}
A missing service-account file is rejected early:
>>> EarthEngineCredentials.from_service_account( # doctest: +ELLIPSIS
... "/no/such/key.json"
... )
Traceback (most recent call last):
...
pyramids_eo.errors.AuthenticationError: ...not found...
Source code in src/pyramids_eo/earthengine/credentials.py
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 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 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 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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
service_account_path
property
#
The service-account key path, or None in application-default mode.
from_service_account_info(info)
classmethod
#
Build credentials from inline service-account JSON (string or mapping).
The key material is written to a private, owner-only temp file that is removed when the returned credentials are garbage-collected. The contents are never logged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
str | dict
|
The service-account key as a JSON string or a mapping. |
required |
Returns:
| Type | Description |
|---|---|
EarthEngineCredentials
|
Credentials backed by a temp key file; :meth: |
EarthEngineCredentials
|
it. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
|
Examples:
- Build from a mapping and confirm a key file is materialised:
>>> from pyramids_eo.earthengine import EarthEngineCredentials >>> creds = EarthEngineCredentials.from_service_account_info( ... {"type": "service_account"} ... ) >>> creds.service_account_path.is_file() True >>> creds.gdal_env()["GOOGLE_APPLICATION_CREDENTIALS"] == str( ... creds.service_account_path ... ) True - Invalid JSON is rejected:
Source code in src/pyramids_eo/earthengine/credentials.py
from_service_account(path)
classmethod
#
Build credentials from a service-account JSON key path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the Google service-account JSON key. |
required |
Returns:
| Type | Description |
|---|---|
EarthEngineCredentials
|
The credentials, whose :meth: |
Examples:
- Build from an existing key file and read the stored path back:
- A missing key path is rejected early:
Source code in src/pyramids_eo/earthengine/credentials.py
application_default()
classmethod
#
Build credentials that defer to ambient ADC (no explicit key).
Returns:
| Type | Description |
|---|---|
EarthEngineCredentials
|
Credentials with an empty :meth: |
EarthEngineCredentials
|
already-exported |
EarthEngineCredentials
|
login at read time. |
Examples:
- Application-default credentials hold no explicit key:
- They report their mode in
repr:
Source code in src/pyramids_eo/earthengine/credentials.py
coerce(credentials)
classmethod
#
Normalise a caller-supplied credentials value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CredentialsLike
|
An :class: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
An |
EarthEngineCredentials
|
class: |
Examples:
Nonebecomes application-default:- An existing instance passes through unchanged:
Source code in src/pyramids_eo/earthengine/credentials.py
gdal_env()
#
Return the GDAL-config mapping for this credential.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
|
dict[str, str]
|
or an empty mapping for application-default (ambient) resolution. |
Examples:
- Application-default carries no explicit config:
- A service account surfaces its key path for GDAL:
>>> import tempfile >>> from pathlib import Path >>> from pyramids_eo.earthengine import EarthEngineCredentials >>> key = Path(tempfile.mkdtemp()) / "sa.json" >>> _ = key.write_text("{}") >>> EarthEngineCredentials.from_service_account(key).gdal_env() == { ... "GOOGLE_APPLICATION_CREDENTIALS": str(key) ... } True
Source code in src/pyramids_eo/earthengine/credentials.py
activate()
#
Apply this credential's GDAL config for the duration of a with block.
Sets each :meth:gdal_env key as a GDAL config option and restores the
previous value (or clears it) on exit, so the process-wide GDAL config is
left untouched afterwards.
Note
GDAL config options are process-global, so this save/restore is not
thread-safe: two threads activating different service-account
credentials concurrently would clobber each other's
GOOGLE_APPLICATION_CREDENTIALS. The reader is intended for
single-threaded, single-credential use per process.
Yields:
| Name | Type | Description |
|---|---|---|
This |
class: |
Examples:
- Application-default activation is a no-op that yields the credentials:
Source code in src/pyramids_eo/earthengine/credentials.py
ReadCost
#
Bases: NamedTuple
A pre-read cost estimate for an ImageCollection window, from EEDA metadata.
Every figure is read from the EEDA catalog's own per-scene fields — no pixels are fetched — so a caller can size a read (and its EE egress) before paying for it.
Attributes:
| Name | Type | Description |
|---|---|---|
scene_count |
int
|
Number of scenes the date range + AOI (and any |
total_size_bytes |
int
|
Sum of the scenes' reported storage sizes ( |
max_width |
int
|
Widest scene band width across the selection, in pixels. |
max_height |
int
|
Tallest scene band height across the selection, in pixels. |
max_band_count |
int
|
Largest per-scene band count across the selection. |
min_pixel_size |
float
|
Finest ground pixel size across the selection ( |
scenes |
list[_Scene]
|
The per-scene records (connection, acquisition time, and cost fields), in acquisition order. |
Examples:
- Read the aggregate figures and derive the transfer size in megabytes:
>>> from pyramids_eo import ReadCost >>> cost = ReadCost( ... scene_count=2, ... total_size_bytes=300_000_000, ... max_width=10980, ... max_height=10980, ... max_band_count=24, ... min_pixel_size=10.0, ... scenes=[], ... ) >>> cost.scene_count 2 >>> round(cost.total_size_bytes / 1e6) 300 >>> cost.max_width, cost.min_pixel_size (10980, 10.0) - A pixel budget for the widest scene, all bands:
Source code in src/pyramids_eo/earthengine/reader.py
Window
#
Bases: NamedTuple
The output window of an Earth Engine read: which ground, in which CRS, on which grid.
Groups the five values that describe where and at what resolution to read — the
AOI, its CRS, the output pixel size or shape, and the resampler — into one object
that :func:from_earthengine and :func:collection_from_earthengine take as their
window argument.
Attributes:
| Name | Type | Description |
|---|---|---|
bbox |
BBox | None
|
AOI |
crs |
str
|
The CRS |
scale |
float | None
|
Output pixel size in |
shape |
tuple[int, int] | None
|
Output |
resample |
str
|
Resampling algorithm for the warp; defaults to |
Examples:
- A windowed read at an explicit pixel size:
- A projected read at an exact output shape:
Source code in src/pyramids_eo/earthengine/reader.py
SclClass
#
Bases: IntEnum
Sentinel-2 L2A Scene-Classification codes (GDAL category names).
Each member's value is the integer pixel code the SCL band stores, so a member can be used directly as a class selector or compared with a raw code.
Examples:
- A member carries the SCL pixel code and its name:
- Build a cloud/shadow mask selection and read back the codes:
Source code in src/pyramids_eo/sentinel/s2/masks.py
collection_from_earthengine(asset_id, *, start, end, window=Window(), geometry=None, bands=None, credentials=None, block_size=None, property_filter=None, nodata=None)
#
Read an Earth Engine ImageCollection into a DatasetCollection.
Discovers the collection's scenes over the AOI + date range via the GDAL EEDA
catalog driver, then reads each one (EEDAI) windowed to a common grid — one
aligned :class:~pyramids.dataset.Dataset per scene, in acquisition order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
EE |
required |
start
|
str
|
Inclusive ISO start of the acquisition window. |
required |
end
|
str
|
Inclusive ISO end of the acquisition window. |
required |
window
|
Window
|
The output window — a :class: |
Window()
|
geometry
|
object | None
|
Optional polygon AOI (a geopandas |
None
|
bands
|
list[str] | None
|
Band names to request; |
None
|
credentials
|
CredentialsLike
|
An
:class: |
None
|
block_size
|
int | None
|
EEDAI transfer block size (pixels per side); |
None
|
property_filter
|
str | None
|
OGR attribute-filter fragment on the collection's own
property fields (e.g. |
None
|
nodata
|
float | int | None
|
Fill value to tag on every scene's bands (EEDAI exposes none). See
:func: |
None
|
Returns:
| Type | Description |
|---|---|
DatasetCollection
|
A pyramids :class: |
DatasetCollection
|
scene, with the acquisition times as its time axis. The scenes are held in |
DatasetCollection
|
memory ( |
DatasetCollection
|
|
DatasetCollection
|
disk. Two caveats: |
DatasetCollection
|
|
DatasetCollection
|
|
DatasetCollection
|
The reductions read |
DatasetCollection
|
gated behind this package's |
DatasetCollection
|
|
DatasetCollection
|
|
DatasetCollection
|
|
DatasetCollection
|
(e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ReaderError
|
The catalog could not be opened, or the date range + AOI matched no scenes. |
Examples:
- Read a Sentinel-2 collection over a date range (skipped offline):
Source code in src/pyramids_eo/earthengine/reader.py
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 | |
estimate_earthengine_cost(asset_id, *, start, end, bbox=None, geometry=None, crs=_DEFAULT_CRS, credentials=None, property_filter=None)
#
Estimate what an ImageCollection read would cost, without fetching pixels.
Runs only the EEDA scene discovery (the catalog query) and aggregates the cost
fields the catalog reports per scene — band count, pixel dimensions, pixel size and
storage size — into a :class:ReadCost. This answers "how big is this read" as a
fact about the actual scenes rather than a guess from asset-level metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
EE |
required |
start
|
str
|
Inclusive ISO start of the acquisition window. |
required |
end
|
str
|
Inclusive ISO end of the acquisition window. |
required |
bbox
|
BBox | None
|
AOI |
None
|
geometry
|
object | None
|
Optional polygon AOI whose envelope bounds scene discovery (its CRS
is honoured as in :func: |
None
|
crs
|
str
|
The CRS |
_DEFAULT_CRS
|
credentials
|
CredentialsLike
|
Credentials authorising the catalog query (see
:func: |
None
|
property_filter
|
str | None
|
Optional scene property filter (e.g. cloud cover), applied client-side over the discovered page — the same selection a matching read would see. Interpolated verbatim into the OGR filter and not escaped/validated, so build it in code, never from untrusted input. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
ReadCost
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
Neither |
ReaderError
|
The catalog could not be opened, or the date range + AOI matched no scenes. |
Examples:
- Size a Sentinel-2 window before fetching any pixels (needs live credentials):
>>> from pyramids_eo import estimate_earthengine_cost >>> cost = estimate_earthengine_cost( # doctest: +SKIP ... "COPERNICUS/S2_SR_HARMONIZED", ... start="2024-06-01", ... end="2024-06-30", ... bbox=(86.90, 27.90, 86.94, 27.94), ... ) >>> cost.scene_count, cost.max_band_count # doctest: +SKIP (6, 24) - Narrow the estimate to low-cloud scenes with a property filter:
>>> from pyramids_eo import estimate_earthengine_cost >>> clear = estimate_earthengine_cost( # doctest: +SKIP ... "COPERNICUS/S2_SR_HARMONIZED", ... start="2024-06-01", ... end="2024-06-30", ... bbox=(86.90, 27.90, 86.94, 27.94), ... property_filter="CLOUDY_PIXEL_PERCENTAGE < 20", ... ) >>> clear.scene_count <= 6 # doctest: +SKIP True
See Also
collection_from_earthengine: Actually read the selected scenes into a
DatasetCollection.
Source code in src/pyramids_eo/earthengine/reader.py
2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 | |
from_earthengine(asset_id, *, window=Window(), bands=None, geometry=None, start=None, end=None, reducer=None, credentials=None, tile_size=None, path=None, block_size=None, property_filter=None, nodata=None)
#
Read an Earth Engine Image (or reduced ImageCollection) into a Dataset.
Two modes:
- Single
Image(default): opensasset_idthrough the GDAL EEDAI driver and, when abboxis given, warps it tocrsat the requested resolution. ImageCollectioncomposite: whenstart/end+reducerare given, discovers the collection's scenes over the AOI + date range (EEDA), reads them aligned, and reduces them client-side into one compositeDataset. Server-side EE reducers are out of scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
EE image asset id (single mode) or |
required |
bands
|
list[str] | None
|
Band names to request; |
None
|
window
|
Window
|
The output window — a :class: |
Window()
|
geometry
|
object | None
|
Optional polygon AOI (a geopandas |
None
|
start
|
str | None
|
Inclusive ISO start of the acquisition window (composite mode). |
None
|
end
|
str | None
|
Inclusive ISO end of the acquisition window (composite mode). |
None
|
reducer
|
str | None
|
Client-side reducer for the composite mode — one of |
None
|
credentials
|
CredentialsLike
|
An
:class: |
None
|
tile_size
|
int | None
|
Maximum tile size (pixels per side) for an oversize read. When
set, the output grid is split into grid-aligned tiles of at most this
size, each read and written to disk in turn, then mosaicked into
|
None
|
path
|
str | Path | None
|
Output raster path. When given, the result is written there and a
file-backed |
None
|
block_size
|
int | None
|
EEDAI transfer block size (pixels per side); |
None
|
property_filter
|
str | None
|
OGR attribute-filter fragment on the collection's own
property fields (e.g. |
None
|
nodata
|
float | int | None
|
Fill value to tag on the returned dataset's bands. EEDAI exposes no
no-data value, so a real sentinel (e.g. GSW |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A pyramids :class: |
Dataset
|
reduced composite (file-backed when |
Note
A service-account credential is bound per read, never left in the
process-global GDAL config. The windowed and composite paths scope it to the
eager read and restore it afterward; the no-bbox lazy wrap carries it as the
returned Dataset's own gdal_env, which pyramids re-applies and restores
around every deferred pixel read. So two different service accounts can be read
in one process — each Dataset keeps its own credential — and nothing leaks
into unrelated GDAL work. (GDAL's EEDAI VSI_PATH_FOR_AUTH open option is not
used: in the bundled GDAL it does not resolve a path-specific service-account
key, falling back to metadata-server auth; the per-Dataset gdal_env is
the mechanism that actually binds credentials per-open here.) See also the
thread-safety note on :meth:EarthEngineCredentials.activate.
Note
Performance. The EEDAI driver's overviews are unreliable, so the reader
always fetches the AOI at the asset's native resolution (block by
block) and downsamples locally with resample (nearest by default). A
small shape/scale output from a fine-resolution asset over a wide
AOI therefore still transfers the full native window — e.g. a 32x32 read of
10 m Sentinel-2 over a 0.1° box pulls ~1100x1100 native pixels. It is
correct but can be slow/data-heavy; keep the AOI tight for fine-resolution
assets.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ReaderError
|
The asset could not be opened or windowed, or the composite date range + AOI matched no scenes. |
Examples:
- Read a small SRTM window (requires Earth Engine credentials, so skipped offline):
- A median composite over an
ImageCollectiondate range (skipped offline): - Clip to a polygon AOI instead of a bbox (skipped offline):
- Stream an oversize window to disk in 1024-px tiles (skipped offline):
tile_sizewithout apathis rejected before any read:>>> from pyramids_eo import from_earthengine, Window >>> from_earthengine( ... "USGS/SRTMGL1_003", ... window=Window(bbox=(86.9, 27.9, 87.0, 28.0), shape=(4096, 4096)), ... tile_size=1024, ... ) Traceback (most recent call last): ... ValueError: 'tile_size' needs 'path' to stream the mosaic to disk.- Passing both
scaleandshapeis rejected before any read:
Source code in src/pyramids_eo/earthengine/reader.py
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 | |
collection_from_sentinel2(paths, *, root_dir, **kwargs)
#
Read a time series of Sentinel-2 products into a DatasetCollection.
Each product in paths is read with :func:from_sentinel2 (passing
**kwargs through) and written as a GeoTIFF under root_dir; the
written files are then assembled into a DatasetCollection.
The collection is file-backed on purpose, for the two things that still
need it on pyramids-core >= 0.73.0: DatasetCollection.to_zarr and
to_kerchunk require a file-backed collection outright, and out-of-core scale
depends on it — the in-memory cube reads each scene's array eagerly (only the
time stack is lazy), whereas a file-backed collection reads tile-by-tile, so a
series larger than RAM stays readable. Time-axis reductions no longer need
it: since pyramids-core 0.73.0 they also run on a resident datasets=
collection, which is what :func:collection_from_earthengine returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Sequence[str | Path]
|
The Sentinel-2 products (any form :func: |
required |
root_dir
|
str | Path
|
Directory the per-scene GeoTIFFs are written to (created if absent). |
required |
**kwargs
|
Any
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Raises:
| Type | Description |
|---|---|
ProductError
|
|
Source code in src/pyramids_eo/sentinel/s2/reader.py
from_sentinel2(path, *, bands=None, resolution=None, epsg=None, bbox=None, crs=None, reflectance=True, mask_scl=None, resample='nearest', path_out=None)
#
Read a Sentinel-2 product into a pyramids Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | S2Product
|
A product path ( |
required |
bands
|
list[str] | None
|
Band names to read (e.g. |
None
|
resolution
|
int | None
|
Native resolution in metres (10 / 20 / 60). |
None
|
epsg
|
int | None
|
UTM EPSG code, required only for a multi-zone product. |
None
|
bbox
|
BBox | None
|
Optional crop window |
None
|
crs
|
str | int | None
|
Optional target CRS (an EPSG integer or a WKT string) to reproject to. |
None
|
reflectance
|
bool
|
When |
True
|
mask_scl
|
list[Any] | None
|
L2A only — classes to mask out (see
:class: |
None
|
path_out
|
str | Path | None
|
When given, also write the result there (COG by extension). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A pyramids |
Note
No-data is declared in the DN domain (the GDAL convention). Because
reflectance is applied as lazy scale / offset tags, the default
read_array() returns DN * scale + offset for every pixel — so a
DN no-data (and any SCL-masked pixel) reads back as the scaled
sentinel, not the declared no_data_value. On a baseline-≥04.00
product (offset ≈ −1000) a DN-0 no-data reads as ≈ −0.1, not 0. Test for
no-data against a read_array(unpack=False) read, not against a
reflectance one.
Raises:
| Type | Description |
|---|---|
ProductError
|
The product is missing a requested band / resolution, or
a multi-zone product is read without |
Examples:
- Read the red and NIR bands as reflectance:
Source code in src/pyramids_eo/sentinel/s2/reader.py
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 133 134 135 136 | |
open_product(path)
#
Open a Sentinel product and return its typed model.
Sniffs the GDAL driver behind path and dispatches to the concrete
product class. Accepts a .SAFE directory, a product metadata XML, a
manifest.safe, a .zip holding a .SAFE (opened in place), or a
driver connection string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The product to open. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
SentinelProduct
|
class: |
SentinelProduct
|
class: |
Raises:
| Type | Description |
|---|---|
UnsupportedProductError
|
The path opens, but its driver is not a Sentinel product family this package models. |
ProductError
|
The path cannot be opened as a product. |
Examples:
- Open a Level-2A product and inspect its subdatasets:
Source code in src/pyramids_eo/sentinel/product.py
scl_mask(dataset, classes, *, scl=None)
#
Mask dataset pixels whose SCL class is in classes.
Masked pixels are set to the dataset's no-data value across every band. The
SCL source is either an explicit scl (a single-band pyramids Dataset
or a 2-D NumPy array on the same grid), or — when scl is None — an
SCL band found within dataset itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
The pyramids |
required |
classes
|
Sequence[SclClass | str | int]
|
Classes to mask out (see :func: |
required |
scl
|
Any
|
Optional explicit SCL source aligned to |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A new pyramids |
Any
|
names, no-data value, and scale/offset tags are preserved. |
Raises:
| Type | Description |
|---|---|
ProductError
|
No SCL source is available, or its shape does not match
|