pycsamt.map.topo#

Elevation / topography sources for pycsamt.map.

Station elevations carried in the EDI metadata are the default terrain source for 3-D draping. This module lets callers override them from a file (CSV / HDF5 / NPZ) or fetch them online from station coordinates, so MapView and the platform can drape real terrain rather than only the values embedded in the EDIs.

Functions

apply_elevations(data, elev_map)

Return a copy of data with station elevations overridden.

export_elevations(data, path, *[, fmt])

Export station id/elevation/coordinates to CSV or HDF5.

fetch_elevations(data, *[, api_name])

Fetch station elevations online from their coordinates.

parse_elevation_file(content, filename)

Parse an uploaded elevation file into {station_id: elev}.

pycsamt.map.topo.apply_elevations(data, elev_map)[source]#

Return a copy of data with station elevations overridden.

Parameters:
  • data (MapData) – Source survey data.

  • elev_map (dict[str, float]) – Mapping of station_id -> elevation (m). Stations not present keep their existing elevation.

Return type:

MapData

pycsamt.map.topo.export_elevations(data, path, *, fmt=None)[source]#

Export station id/elevation/coordinates to CSV or HDF5.

EDI files carry real, field-surveyed elevation; a ModEM (or Occam2D/MARE2DEM) inversion result does not. Exporting a survey’s EDI-derived topography here produces a small, portable lookup table — station + elevation (plus latitude/ longitude/line for provenance) — that parse_elevation_file() already knows how to read back in. That means it can be applied to an inversion-sourced view later via the “Upload file” elevation source, in a different session that never reloads the original EDIs, matching stations by id (with the same normalized fallback used by apply_elevations()).

Parameters:
  • data (MapData) – Survey to export (typically EDI-sourced, where elevation is already populated).

  • path (path-like) – Destination file. fmt defaults to the file’s own suffix (.csv / .h5 / .hdf5); pass it explicitly to override.

  • fmt ({"csv", "h5", "hdf5"}, optional)

Returns:

The path written to.

Return type:

pathlib.Path

Raises:

ValueError – If no station in data has a known elevation, or fmt is unsupported.

pycsamt.map.topo.fetch_elevations(data, *, api_name='open_meteo')[source]#

Fetch station elevations online from their coordinates.

Uses pycsamt.gis.utils.get_elevation_from_api() (needs an internet connection and requests).

Returns:

station_id -> elevation (m) for stations with valid coordinates and a finite fetched value.

Return type:

dict

Parameters:
pycsamt.map.topo.parse_elevation_file(content, filename)[source]#

Parse an uploaded elevation file into {station_id: elev}.

Supports CSV, HDF5 (.h5/.hdf5) and NPZ. The file must hold a station-id column/array (one of station, id, name, sta) and an elevation column/array (elevation, elev, z, alt, altitude, height). Returns {} on any parse failure rather than raising.

Parameters:
Return type:

dict[str, float]