API reference¶
All of pySDP's public surface. Import everything from the top-level package:
Catalog discovery¶
get_catalog
¶
get_catalog(
domains: Sequence[str] | None = None,
types: Sequence[str] | None = None,
releases: Sequence[str] | None = None,
timeseries_types: Sequence[str] | None = None,
deprecated: bool | None = False,
*,
source: Literal[
"packaged", "live", "stac"
] = "packaged",
) -> DataFrame | Catalog
Discover SDP datasets by filtering the product catalog.
pySDP ships with a snapshot of the SDP product catalog baked in; filtering
is instantaneous and works offline. source="live" refetches the
canonical CSV from S3 (useful when the packaged snapshot lags a recent
catalog update). source="stac" returns the SDP's static STAC v1
catalog as a pystac.Catalog, which composes with the broader STAC
ecosystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domains
|
sequence of str
|
Spatial domains to include ( |
None
|
types
|
sequence of str
|
Dataset type categories (e.g., |
None
|
releases
|
sequence of str
|
Dataset release cohorts ( |
None
|
timeseries_types
|
sequence of str
|
One or more of |
None
|
deprecated
|
bool or None
|
|
False
|
source
|
('packaged', 'live', 'stac')
|
Where to pull the catalog from. See Notes. |
"packaged"
|
Returns:
| Type | Description |
|---|---|
DataFrame or Catalog
|
For CSV-backed sources, a DataFrame with one row per dataset and
columns matching the SDP product-table schema ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any filter argument contains a value outside its canonical
vocabulary, or if |
Warns:
| Type | Description |
|---|---|
UserWarning
|
When |
Notes
The packaged CSV is refreshed on each pysdp release. source="live"
hits the S3-hosted canonical CSV directly, so it's always as fresh as
upstream. source="stac" ignores filter arguments — use pystac
traversal to filter the returned catalog. The catalog is browsable at
radiantearth's STAC Browser
<https://radiantearth.github.io/stac-browser/#/external/rmbl-sdp.s3.us-east-2.amazonaws.com/stac/v1/catalog.json>_.
Examples:
Get every current dataset:
Filter to Upper Gunnison vegetation products:
Find all yearly time-series products across every domain:
Return both current and deprecated entries:
See Also
get_metadata : Fetch detailed XML metadata for one dataset.
open_raster : Open a catalog entry as a lazy xarray.Dataset.
Source code in src/pysdp/catalog.py
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 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 | |
get_metadata
¶
Fetch the QGIS-style XML metadata for one SDP dataset.
Each SDP product has a companion metadata XML document on S3 that describes provenance, sensor details, processing history, and other long-form context. This function fetches that XML over HTTP and parses it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_id
|
str
|
Six-character SDP catalog ID (e.g., |
required |
as_dict
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
dict or _Element
|
Parsed metadata. For dict output, the top-level key is typically
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If |
HTTPError
|
If the XML URL returns a non-2xx status (rare; implies an upstream data-hosting issue). |
Examples:
Get the metadata for the UG 3 m bare-earth DEM as a dict:
>>> import pysdp
>>> meta = pysdp.get_metadata("R3D009")
>>> meta["qgis"]["abstract"]
'This 3 m resolution digital elevation model...'
See Also
get_catalog : Discover catalog IDs by filtering. open_raster : Open a catalog entry as a raster.
Source code in src/pysdp/catalog.py
Raster access¶
open_raster
¶
open_raster(
catalog_id: str | None = None,
url: str | None = None,
*,
years: Sequence[int] | None = None,
months: Sequence[int] | None = None,
date_start: str | date | None = None,
date_end: str | date | None = None,
chunks: dict[str, int]
| Literal["auto"]
| None = "auto",
download: bool = False,
download_path: str | PathLike[str] | None = None,
overwrite: bool = False,
verbose: bool = True,
) -> Dataset
Open an SDP raster as a lazy xarray.Dataset.
Reads cloud-optimized GeoTIFFs from S3 via GDAL's VSICURL, without
downloading. Returns a Dataset with one data variable named after the
product's canonical short name (e.g. "UG_dem_3m_v1"). CRS is always
set to EPSG:32613 (UTM 13N). For time-series products, the Dataset
gains a uniform pandas.DatetimeIndex on the time coordinate —
Daily → actual date, Monthly → first-of-month, Yearly → Jan 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_id
|
str
|
Six-character SDP catalog ID (e.g., |
None
|
url
|
str
|
Direct HTTPS URL to an SDP COG. Mutually exclusive with
|
None
|
years
|
sequence of int
|
For Yearly products, which years to load. Alternative to
|
None
|
months
|
sequence of int
|
For Monthly products, which months (1–12) to load. Must be combined
with |
None
|
date_start
|
str or date
|
Date range to load (inclusive). For Daily, defines the time slice;
for Monthly/Yearly, uses rSDP's anchor-day stepping semantics. When
neither is given on a Daily product, the first 30 days from
|
None
|
date_end
|
str or date
|
Date range to load (inclusive). For Daily, defines the time slice;
for Monthly/Yearly, uses rSDP's anchor-day stepping semantics. When
neither is given on a Daily product, the first 30 days from
|
None
|
chunks
|
dict, "auto", or None
|
Dask chunking. |
"auto"
|
download
|
bool
|
Not yet implemented (Phase 5). For now, raises
|
False
|
download_path
|
str or PathLike
|
Directory for downloaded files (only used when |
None
|
overwrite
|
bool
|
Reserved for the download path (not yet implemented). |
False
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with one data variable. Dimensions depend on the product:
CRS is |
Raises:
| Type | Description |
|---|---|
ValueError
|
On invalid |
KeyError
|
If |
NotImplementedError
|
If |
Examples:
Open the UG 3 m bare-earth DEM (Single product):
Open three days of daily Tmax:
>>> tmax = pysdp.open_raster(
... "R4D004",
... date_start="2021-11-02",
... date_end="2021-11-04",
... )
>>> tmax.sizes["time"]
3
Open a single year of annual snow persistence:
See Also
open_stack : Load multiple products as variables in one Dataset. extract_points : Sample an opened raster at point locations. extract_polygons : Summarize an opened raster over polygons.
Source code in src/pysdp/raster.py
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 | |
open_stack
¶
open_stack(
catalog_ids: Sequence[str],
*,
years: Sequence[int] | None = None,
months: Sequence[int] | None = None,
date_start: str | date | None = None,
date_end: str | date | None = None,
chunks: dict[str, int]
| Literal["auto"]
| None = "auto",
align: Literal["exact", "reproject"] = "exact",
verbose: bool = True,
) -> Dataset
Load multiple SDP products into a single xarray.Dataset.
Each product becomes one data variable. x/y (and time where
applicable) coordinates are shared across variables, so downstream
analysis can treat the stack as a single object (ds["dem"] -
ds["snow_persistence"].mean("time") etc.). Use this when you want to
compose products that are already on the same grid — for example an
elevation model and a slope raster both derived from the same LiDAR
campaign.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_ids
|
sequence of str
|
Non-empty sequence of SDP catalog IDs. |
required |
years
|
optional
|
Shared time-slicing args. Applied to every time-series product in
the stack; ignored for |
None
|
months
|
optional
|
Shared time-slicing args. Applied to every time-series product in
the stack; ignored for |
None
|
date_start
|
optional
|
Shared time-slicing args. Applied to every time-series product in
the stack; ignored for |
None
|
date_end
|
optional
|
Shared time-slicing args. Applied to every time-series product in
the stack; ignored for |
None
|
chunks
|
dict, "auto", or None
|
Dask chunking, passed through to each |
"auto"
|
align
|
('exact', 'reproject')
|
|
"exact"
|
verbose
|
bool
|
Forwarded to |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
One data variable per catalog_id. See
:func: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotImplementedError
|
If |
Examples:
Stack the UG 3 m DEM with the matching slope and aspect rasters:
>>> import pysdp
>>> topo = pysdp.open_stack(["R3D009", "R3D012", "R3D010"])
>>> sorted(topo.data_vars)
['UG_dem_3m_v1', 'UG_dem_slope_1m_v1', 'UG_topographic_aspect_southness_1m_v1']
See Also
open_raster : Single-product load.
Source code in src/pysdp/raster.py
367 368 369 370 371 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 | |
Extraction¶
extract_points
¶
extract_points(
raster: Dataset | DataArray,
locations: GeoDataFrame | DataFrame,
*,
x: str = "x",
y: str = "y",
crs: str | None = None,
method: Literal["nearest", "linear"] = "linear",
years: Sequence[int] | None = None,
date_start: str | date | None = None,
date_end: str | date | None = None,
bind: bool = True,
verbose: bool = True,
) -> GeoDataFrame
Extract raster values at point locations.
Accepts an xarray.Dataset or DataArray (typically from
:func:open_raster / :func:open_stack) and a GeoDataFrame or
plain DataFrame with x/y columns. Reprojects the input
locations to the raster CRS if they differ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Dataset or DataArray
|
The raster to sample from. Must have |
required |
locations
|
GeoDataFrame or DataFrame
|
Points to sample. If a plain |
required |
x
|
str
|
Column names holding longitude/x and latitude/y for
|
"x", "y"
|
y
|
str
|
Column names holding longitude/x and latitude/y for
|
"x", "y"
|
crs
|
str
|
CRS of the input locations (e.g., |
None
|
method
|
('nearest', 'linear')
|
Interpolation method. |
"nearest"
|
years
|
sequence of int
|
Time filter applied before extraction. Only valid for time-series rasters. |
None
|
date_start
|
str or date
|
Date-range filter applied before extraction. |
None
|
date_end
|
str or date
|
Date-range filter applied before extraction. |
None
|
bind
|
bool
|
If |
True
|
verbose
|
bool
|
Print per-extraction progress messages to stderr. |
True
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Output GeoDataFrame with the raster's data variables as columns.
For time-series rasters, output is long-form (one row per
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the raster has no CRS, if location CRS/columns are missing, if
|
Examples:
Extract elevation at three RMBL-area field sites:
>>> import pysdp, geopandas as gpd
>>> from shapely.geometry import Point
>>> dem = pysdp.open_raster("R3D009")
>>> sites = gpd.GeoDataFrame(
... {"site": ["Roaring Judy", "Gothic", "Galena Lake"]},
... geometry=[
... Point(-106.853186, 38.716995),
... Point(-106.988934, 38.958446),
... Point(-107.072569, 39.021644),
... ],
... crs="EPSG:4326",
... )
>>> samples = pysdp.extract_points(dem, sites)
Sample daily Tmax at the same sites and pivot to wide format:
>>> tmax = pysdp.open_raster("R4D004", date_start="2021-11-02", date_end="2021-11-04")
>>> long = pysdp.extract_points(tmax, sites)
>>> wide = long.pivot_table(index="site", columns="time", values="bayes_tmax_est")
Extract from a plain DataFrame (no GeoPandas needed upfront):
>>> import pandas as pd
>>> df = pd.DataFrame({"site": ["A"], "lon": [-106.85], "lat": [38.95]})
>>> out = pysdp.extract_points(dem, df, x="lon", y="lat", crs="EPSG:4326")
See Also
extract_polygons : Summarize values over polygon geometries. open_raster : Load a raster to extract from.
Source code in src/pysdp/extract.py
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 391 392 393 | |
extract_polygons
¶
extract_polygons(
raster: Dataset | DataArray,
locations: GeoDataFrame,
*,
stats: Sequence[str] | str = "mean",
exact: bool = False,
all_cells: bool = False,
years: Sequence[int] | None = None,
date_start: str | date | None = None,
date_end: str | date | None = None,
bind: bool = True,
verbose: bool = True,
) -> GeoDataFrame | DataFrame
Summarize raster values over polygon locations.
Computes per-polygon summary statistics (mean by default). For
time-series rasters, produces one summary per (polygon × time)
pair in long-form output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Dataset or DataArray
|
Raster to summarize. Must have a CRS set. |
required |
locations
|
GeoDataFrame
|
Polygon geometries. Must be a |
required |
stats
|
str or sequence of str
|
Summary statistic(s) to compute. Accepts any |
"mean"
|
exact
|
bool
|
|
False
|
all_cells
|
bool
|
If |
False
|
years
|
optional
|
Time-series filters applied before summarization. Same semantics as
in :func: |
None
|
date_start
|
optional
|
Time-series filters applied before summarization. Same semantics as
in :func: |
None
|
date_end
|
optional
|
Time-series filters applied before summarization. Same semantics as
in :func: |
None
|
bind
|
bool
|
Merge input attribute columns onto output rows when |
True
|
verbose
|
bool
|
Print progress messages. |
True
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame or DataFrame
|
GeoDataFrame when |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
On missing CRS or other location validation failures. |
NotImplementedError
|
For |
Examples:
Compute mean snow duration over watersheds for 2019:
>>> import pysdp, geopandas as gpd
>>> snow = pysdp.open_raster("R4D001", years=[2019])
>>> watersheds = gpd.read_file("watersheds.gpkg")
>>> out = pysdp.extract_polygons(snow, watersheds, stats="mean")
Compute multiple statistics in one call:
See Also
extract_points : Extract at point geometries. open_raster : Load a raster.
Source code in src/pysdp/extract.py
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 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 | |
Download¶
download
¶
Bulk download of SDP datasets to local disk.
Ports rSDP's download_data(). See SPEC.md §4.4.
Primary backend: requests + concurrent.futures.ThreadPoolExecutor,
using only core pysdp dependencies. Higher-throughput backends
(obstore, fsspec + s3fs) are planned for Phase 7 when at-scale
download performance becomes a hot path (ROADMAP §Phase 7); for the
v0.1 use case — researchers pulling a handful of SDP products to local
disk — the threaded-requests path is plenty fast.
download
¶
download(
urls: str | Sequence[str] | None = None,
output_dir: str | PathLike[str] | None = None,
*,
catalog_ids: str | Sequence[str] | None = None,
overwrite: bool = False,
resume: bool = True,
max_workers: int = 8,
return_status: bool = True,
verbose: bool = True,
) -> DataFrame | None
Download SDP COGs to a local directory.
Use this when you need the raster on disk (for tools that don't support
cloud reads, for offline workflows, or for bulk mirroring). For
interactive analysis, :func:open_raster lazy-reads from cloud without
a download step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
str or sequence of str
|
Direct HTTPS URL(s) to the COGs to download. Mutually exclusive with
|
None
|
output_dir
|
str or PathLike
|
Destination directory. Created if it doesn't exist. Files are named from the URL basename. |
None
|
catalog_ids
|
str or sequence of str
|
Alternative to
|
None
|
overwrite
|
bool
|
If |
False
|
resume
|
bool
|
When a small partial file exists (< 1 kB), attempt an HTTP Range resume instead of re-downloading from scratch. |
True
|
max_workers
|
int
|
Number of concurrent HTTP fetches (via a |
8
|
return_status
|
bool
|
If |
True
|
verbose
|
bool
|
Print skip/download progress messages to stderr. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame or None
|
Status report with columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
KeyError
|
If a catalog_id isn't in the packaged catalog. |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If any downloads failed; details are in the returned DataFrame's
|
Examples:
Download two real SDP products by catalog ID:
>>> import pysdp
>>> status = pysdp.download(
... catalog_ids=["R1D001", "R3D009"],
... output_dir="~/sdp-data",
... )
>>> status[["dest", "success", "size"]]
Hand-pick a subset of daily temperature slices:
>>> urls = [
... "https://rmbl-sdp.s3.us-east-2.amazonaws.com/data_products/released/release4/bayes_tmax_year_2021_day_0305_est.tif",
... "https://rmbl-sdp.s3.us-east-2.amazonaws.com/data_products/released/release4/bayes_tmax_year_2021_day_0306_est.tif",
... ]
>>> pysdp.download(urls=urls, output_dir="~/tmax-samples")
See Also
open_raster : Open an SDP raster lazily, without downloading.
Source code in src/pysdp/download.py
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 | |
Constants¶
constants
¶
Package constants for pysdp.
Values mirror the internal constants in rSDP's R/constants.R.
SDP_CRS
module-attribute
¶
Coordinate reference system for all SDP raster products (UTM zone 13N).
DOMAINS
module-attribute
¶
Spatial domains available in the SDP.
TYPES
module-attribute
¶
TYPES: Final[tuple[str, ...]] = (
"Mask",
"Topo",
"Vegetation",
"Hydro",
"Planning",
"Radiation",
"Snow",
"Climate",
"Imagery",
"Supplemental",
)
Dataset type categories.
RELEASES
module-attribute
¶
RELEASES: Final[tuple[str, ...]] = (
"Basemaps",
"Release1",
"Release2",
"Release3",
"Release4",
"Release5",
)
Dataset release cohorts.
TIMESERIES_TYPES
module-attribute
¶
Time-series structure types for SDP datasets.