pycsamt.format.topography#

Topography helpers — per_station and raster PCSF kinds.

per_station wires TopographyPerStation through the existing pycsamt.map.topo elevation sources instead of adding a third, independent CSV/HDF5/NPZ parser next to the two that already existed and had quietly drifted apart: pycsamt.map.topo.parse_elevation_file() (_ID_KEYS included "station_names") and pycsamt.app.web.callbacks.map3d._parse_topo_upload (a hand-rolled duplicate whose own id-column list did not). This module reuses the former; map3d.py was updated to delegate to it (see its own docstring), so both live-app uploads and PCSF conversion now agree on exactly one set of recognised column/dataset names.

raster (TopographyRaster) is a standalone gridded-DEM surface, independent of any station table. topography_from_grid() builds one from plain x/y/ elevation arrays a caller already has — it never parses a georeferenced raster file format (GeoTIFF, ASCII grid, …) itself, so no GDAL/rasterio dependency is introduced here: reading such a file is the caller’s own responsibility, done by whatever means it likes, outside pyCSAMT’s dependency chain (e.g. with rasterio in a one-off script that then hands PCSF three plain arrays).

Functions

topography_from_elevation_file(content, filename)

Build topography from an uploaded elevation file.

topography_from_grid(x, y, elevation)

Build a gridded-DEM TopographyRaster.

topography_from_map_data(data)

Build topography from a MapData's own station elevations (typically real, EDI-derived values).

topography_raster_to_grid(topo)

Return (x, y, elevation), the inverse of topography_from_grid().

topography_to_elev_map(topo)

Return {station_id: elevation}, the inverse of both builders.

pycsamt.format.topography.topography_from_map_data(data)[source]

Build topography from a MapData’s own station elevations (typically real, EDI-derived values).

Parameters:

data (MapData) – Survey data, e.g. from pycsamt.map.load_lines().

Returns:

None when no station carries a finite elevation, so callers can leave PCSFModel.topography unset rather than persisting an all-nan table.

Return type:

TopographyPerStation or None

Examples

>>> from pycsamt.map import load_lines
>>> from pycsamt.format.topography import topography_from_map_data
>>> data = load_lines("data/AMT/WILLY_DATA", detect="folder")
>>> topo = topography_from_map_data(data)
pycsamt.format.topography.topography_from_elevation_file(content, filename)[source]

Build topography from an uploaded elevation file.

Thin wrapper around pycsamt.map.topo.parse_elevation_file() (CSV / HDF5 / NPZ, flexible station-id and elevation column/array names) — the same parser the “Upload file” elevation source in pycsamt.app.web uses, so a file that works there also works here.

Parameters:
  • content (str or bytes) – A Dash dcc.Upload-style data URI ("data:...;base64,..."), raw base64 text, or raw bytes — anything parse_elevation_file() already accepts.

  • filename (str) – Used only for its extension (.csv/.h5/.hdf5/.npz).

Returns:

None when the file cannot be parsed (unrecognised format, missing id/elevation column) — matches parse_elevation_file()’s own best-effort, non-raising contract.

Return type:

TopographyPerStation or None

pycsamt.format.topography.topography_to_elev_map(topo)[source]

Return {station_id: elevation}, the inverse of both builders.

The same shape pycsamt.map.topo.apply_elevations() and pycsamt.map.topo.parse_elevation_file() already use, so a PCSF file’s topography can be applied straight back onto a MapData with no extra conversion.

Parameters:

topo (TopographyPerStation)

Return type:

dict[str, float]

pycsamt.format.topography.topography_from_grid(x, y, elevation)[source]

Build a gridded-DEM TopographyRaster.

Parameters:
  • x (ndarray (n_x,)) – Grid x-coordinates (or longitude), increasing.

  • y (ndarray (n_y,)) – Grid y-coordinates (or latitude), increasing.

  • elevation (ndarray (n_y, n_x)) – Elevation surface, metres, on the (y, x) meshgrid implied by x/y (numpy.meshgrid(x, y)’s default row-major convention).

Return type:

TopographyRaster

Examples

>>> import numpy as np
>>> from pycsamt.format.topography import topography_from_grid
>>> x = np.linspace(0.0, 500.0, 6)
>>> y = np.linspace(0.0, 300.0, 4)
>>> elevation = 100.0 + 0.01 * np.add.outer(y, x)
>>> topo = topography_from_grid(x, y, elevation)
>>> topo.elevation.shape
(4, 6)
pycsamt.format.topography.topography_raster_to_grid(topo)[source]

Return (x, y, elevation), the inverse of topography_from_grid().

Parameters:

topo (TopographyRaster)

Return type:

tuple[ndarray, ndarray, ndarray]