Module: sarpyx.utils.dem_utils

File: sarpyx/utils/dem_utils.py

Copernicus DEM COG tile utilities. Download and manage Copernicus GLO-30 (30m) and GLO-90 (90m) DEM tiles from the public AWS S3 bucket, selecting only the tiles that intersect a given WKT geometry. Tile naming convention (GLO-30 example):: Copernicus_DSM_COG_10_N54_00_W004_00_DEM ─────────────────── ── ────── ─────── ─── prefix res lat lon suffix Resolution codes: 10 → GLO-30 (30 m), 30 → GLO-90 (90 m). Each tile covers a 1×1 degree cell. Public HTTPS base URLs (no authentication required):: GLO-30: https://copernicus-dem-30m.s3.eu-central-1.amazonaws.com/ GLO-90: https://copernicus-dem-90m.s3.eu-central-1.amazonaws.com/

Exported Symbols (__all__)

No explicit __all__ list. Public symbols inferred from implementation.

Public Functions (6)

tile_name function

Build the canonical Copernicus DEM COG tile name.

File location: sarpyx/utils/dem_utils.py:69

Signature

tile_name(lat: int, lon: int, resolution_m: int=30) -> str

Parameters

ParameterTypeRequiredDefaultDescription
latintyes-int Latitude of the **south edge** of the 1×1° cell.
lonintyes-int Longitude of the **west edge** of the 1×1° cell.
resolution_mintno30int DEM resolution in metres (30 or 90).

Return Type

str

str e.g. ``'Copernicus_DSM_COG_10_N54_00_W004_00_DEM'``

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.dem_utils import tile_name

result = tile_name(lat=<lat>, lon=<lon>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

tile_url function

Full HTTPS URL for a Copernicus DEM COG GeoTIFF tile.

File location: sarpyx/utils/dem_utils.py:90

Signature

tile_url(lat: int, lon: int, resolution_m: int=30) -> str

Parameters

ParameterTypeRequiredDefaultDescription
latintyes-inferred from implementation.
lonintyes-inferred from implementation.
resolution_mintno30inferred from implementation.

Return Type

str

str e.g. ``'https://copernicus-dem-30m.s3.eu-central-1.amazonaws.com/ Copernicus_DSM_COG_10_N54_00_W004_00_DEM/ Copernicus_DSM_COG_10_N54_00_W004_00_DEM.tif'``

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.dem_utils import tile_url

result = tile_url(lat=<lat>, lon=<lon>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

tiles_from_wkt function

Compute the DEM tile grid cells that intersect a WKT geometry.

File location: sarpyx/utils/dem_utils.py:138

Signature

tiles_from_wkt(wkt_string: str, resolution_m: int=30) -> List[Tuple[int, int, str, str]]

Parameters

ParameterTypeRequiredDefaultDescription
wkt_stringstryes-str Any valid WKT geometry (POLYGON, MULTIPOLYGON, POINT, …).
resolution_mintno30int DEM resolution (30 or 90).

Return Type

List[Tuple[int, int, str, str]]

list of (lat, lon, tile_name, tile_url) One entry per intersecting 1×1° tile.

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.dem_utils import tiles_from_wkt

result = tiles_from_wkt(wkt_string=<wkt_string>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

download_tiles_for_wkt function

Download all Copernicus DEM tiles intersecting a WKT geometry.

File location: sarpyx/utils/dem_utils.py:212

Signature

download_tiles_for_wkt(wkt_string: str, output_dir: str | Path, resolution_m: int=30, overwrite: bool=False, max_workers: int=4) -> List[Path]

Parameters

ParameterTypeRequiredDefaultDescription
wkt_stringstryes-str Any valid WKT geometry string.
output_dirstr | Pathyes-str or Path Directory to save the downloaded ``.tif`` files into. A flat layout is used: ``<output_dir>/<tile_name>.tif``.
resolution_mintno30int DEM resolution in metres — 30 (GLO-30) or 90 (GLO-90).
overwriteboolnoFalsebool Re-download tiles that already exist locally.
max_workersintno4int Number of parallel download threads.

Return Type

List[Path]

list of Path Paths to the downloaded (or already existing) GeoTIFF files.

Exceptions

  • ValueError

Side Effects

  • inferred from implementation

Example Usage

>>> from sarpyx.utils.dem_utils import download_tiles_for_wkt
>>> wkt = "POLYGON ((-3.18 54.28, -3.78 55.89, 0.31 56.30, 0.75 54.69, -3.18 54.28))"
>>> tiles = download_tiles_for_wkt(wkt, "/tmp/dem_tiles")
>>> print([t.name for t in tiles])
['Copernicus_DSM_COG_10_N54_00_W004_00_DEM.tif', ...]

Edge Cases

May raise: ValueError. Includes optional parameters with implementation-defined fallback behavior.

build_vrt function

Merge multiple DEM GeoTIFFs into a single raster mosaic.

File location: sarpyx/utils/dem_utils.py:307

Signature

build_vrt(tile_paths: Sequence[Path | str], output_vrt: str | Path) -> Path

Parameters

ParameterTypeRequiredDefaultDescription
tile_pathsSequence[Path | str]yes-sequence of Path Paths to ``.tif`` DEM tiles.
output_vrtstr | Pathyes-str or Path Path for the output ``.vrt`` file.

Return Type

Path

Path The output mosaic path.

Exceptions

  • ImportError
  • ValueError

Side Effects

  • filesystem

Example Usage

from sarpyx.utils.dem_utils import build_vrt

result = build_vrt(tile_paths=<tile_paths>, output_vrt=<output_vrt>)

Edge Cases

May raise: ImportError, ValueError.

main function

Command-line entry point for downloading Copernicus DEM tiles.

File location: sarpyx/utils/dem_utils.py:375

Signature

main() -> None

Parameters

ParameterTypeRequiredDefaultDescription
--no-No explicit public parameters; behavior inferred from implementation.

Return Type

None

inferred from implementation.

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • io

Example Usage

from sarpyx.utils.dem_utils import main

result = main()

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

Public Classes (0)

No public classes detected.