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
|
Build topography from an uploaded elevation file. |
|
Build a gridded-DEM |
|
Build topography from a |
|
Return |
|
Return |
- 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:
Nonewhen no station carries a finite elevation, so callers can leavePCSFModel.topographyunset rather than persisting an all-nantable.- 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 inpycsamt.app.webuses, so a file that works there also works here.- Parameters:
- Returns:
Nonewhen the file cannot be parsed (unrecognised format, missing id/elevation column) — matchesparse_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()andpycsamt.map.topo.parse_elevation_file()already use, so a PCSF file’s topography can be applied straight back onto aMapDatawith no extra conversion.- Parameters:
topo (TopographyPerStation)
- Return type:
- pycsamt.format.topography.topography_from_grid(x, y, elevation)[source]
Build a gridded-DEM
TopographyRaster.- Parameters:
- Return type:
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)