DEM tools

A collection of functions to handle digital elevation models in GAMMA

dem_autocreate

dem_import

convert an existing DEM in GDAL-readable format to GAMMA format including optional geoid-ellipsoid conversion.

dempar

create GAMMA parameter text files for DEM files

fill

interpolate missing values in the SRTM DEM (value -32768)

hgt

concatenate hgt file names overlapping with multiple SAR scenes

hgt_collect

automatic downloading and unpacking of srtm tiles

makeSRTM

Create a DEM in GAMMA format from SRTM tiles

mosaic

mosaicing of multiple DEMs

swap

byte swapping from small to big endian (as required by GAMMA)

pyroSAR.gamma.dem.dem_autocreate(geometry, demType, outfile, buffer=None, t_srs=4326, tr=None, logpath=None, username=None, password=None, geoid_mode='gamma', resampling_method='bilinear')[source]
automatically create a DEM in GAMMA format for a defined spatial geometry.
The following steps will be performed:
  • collect all tiles overlapping with the geometry using pyroSAR.auxdata.dem_autoload()

    • if they don’t yet exist locally they will automatically be downloaded

    • the tiles will be downloaded into the SNAP auxdata directory structure, e.g. $HOME/.snap/auxdata/dem/SRTM 3Sec

  • create a mosaic GeoTIFF of the same spatial extent as the input geometry plus a defined buffer using pyroSAR.auxdata.dem_create()

  • if necessary, subtract the geoid-ellipsoid difference (see pyroSAR.auxdata.dem_autoload() for height references of different supported DEMs)

  • convert the result to GAMMA format

    • If t_srs is 4326 and the DEM’s height reference is either WGS84 ellipsoid or EGM96 geoid, the command srtm2dem can be used. This is kept for backwards compatibility.

    • For all other cases the newer command dem_import can be used if it exists and if the command create_dem_par accepts a parameter EPSG.

Parameters:
  • geometry (spatialist.vector.Vector) – a vector geometry delimiting the output DEM size

  • demType (str) – the type of DEM to be used; see dem_autoload() for options

  • outfile (str) – the name of the final DEM file

  • buffer (float or None) – a buffer in degrees to create around the geometry

  • t_srs (int, str or osgeo.osr.SpatialReference) – A target geographic reference system in WKT, EPSG, PROJ4 or OPENGIS format. See function spatialist.auxil.crsConvert() for details. Default: 4326.

  • tr (tuple or None) – the target resolution as (xres, yres) in units of t_srs; if t_srs is kept at its default value of 4326, tr does not need to be defined and the original resolution is preserved; in all other cases the default of None is rejected

  • logpath (str) – a directory to write GAMMA logfiles to

  • username (str or None) – (optional) the user name for services requiring registration; see dem_autoload()

  • password (str or None) – (optional) the password for the registration account

  • geoid_mode (str) –

    the software to be used for converting geoid to ellipsoid heights (if necessary); options:

    • ’gamma’

    • ’gdal’

  • resampling_method (str) – the gdalwarp resampling method; See here for options.

pyroSAR.gamma.dem.dem_import(src, dst, geoid=None, logpath=None, outdir=None, shellscript=None)[source]

convert an existing DEM in GDAL-readable format to GAMMA format including optional geoid-ellipsoid conversion.

Parameters:
  • src (str) – the input DEM

  • dst (str) – the output DEM

  • geoid (str | None) –

    the geoid height reference of src; supported options:

    • ’EGM96’

    • ’EGM2008’

    • None: assume WGS84 ellipsoid heights and do not convert heights

  • logpath (str | None) – a directory to write logfiles to

  • outdir (str | None) – the directory to execute the command in

  • shellscript (str | None) – a file to write the GAMMA commands to in shell format

Return type:

None

pyroSAR.gamma.dem.dempar(dem, logpath=None)[source]

create GAMMA parameter text files for DEM files

currently only EQA and UTM projections with WGS84 ellipsoid are supported

Parameters:
  • dem (str) – the name of the DEM

  • logpath (str) – a directory to write logfiles to

pyroSAR.gamma.dem.fill(dem, dem_out, logpath=None, replace=False)[source]

interpolate missing values in the SRTM DEM (value -32768)

Parameters:
  • dem (str) – the input DEM to be filled

  • dem_out (str) – the name of the filled DEM

  • logpath (str) – a directory to write logfiles to

  • replace (bool) – delete dem once finished?

pyroSAR.gamma.dem.hgt(parfiles)[source]

concatenate hgt file names overlapping with multiple SAR scenes

  • this list is read for corner coordinates of which the next integer lower left latitude and longitude is computed

  • hgt files are supplied in 1 degree equiangular format named e.g. N16W094.hgt (with pattern [NS][0-9]{2}[EW][0-9]{3}.hgt

  • For north and east hemisphere the respective absolute latitude and longitude values are smaller than the lower left coordinate of the SAR image

  • west and south coordinates are negative and hence the nearest lower left integer absolute value is going to be larger

Parameters:

parfiles (list of str or pyroSAR.ID) – a list of GAMMA parameter files or pyroSAR ID objects

Returns:

the names of hgt files overlapping with the supplied parameter files/objects

Return type:

list

pyroSAR.gamma.dem.hgt_collect(parfiles, outdir, demdir=None, arcsec=3)[source]

automatic downloading and unpacking of srtm tiles

Parameters:
  • parfiles (list of str or pyroSAR.ID) – a list of Gamma parameter files or pyroSAR ID objects

  • outdir (str) – a target directory to download the tiles to

  • demdir (str or None) – an additional directory already containing hgt tiles

  • arcsec ({1, 3}) – the spatial resolution to be used

Returns:

the names of all local hgt tiles overlapping with the parfiles

Return type:

list

pyroSAR.gamma.dem.makeSRTM(scenes, srtmdir, outname)[source]

Create a DEM in GAMMA format from SRTM tiles

  • coordinates are read to determine the required DEM extent and select the necessary hgt tiles

  • mosaics SRTM DEM tiles, converts them to GAMMA format and subtracts offset to WGS84 ellipsoid

intended for SRTM products downloaded from:

Parameters:
  • scenes (list of str or pyroSAR.ID) – a list of Gamma parameter files or pyroSAR ID objects to read the DEM extent from

  • srtmdir (str) – a directory containing the SRTM hgt tiles

  • outname (str) – the name of the final DEM file

pyroSAR.gamma.dem.mosaic(demlist, outname, byteorder=1, gammapar=True)[source]

mosaicing of multiple DEMs

Parameters:
  • demlist (list[str]) – a list of DEM names to be mosaiced

  • outname (str) – the name of the final mosaic file

  • byteorder ({0, 1}) –

    the byte order of the mosaic

    • 0: small endian

    • 1: big endian

  • gammapar (bool) – create a GAMMA parameter file for the mosaic?

pyroSAR.gamma.dem.swap(data, outname)[source]

byte swapping from small to big endian (as required by GAMMA)

Parameters:
  • data (str) – the DEM file to be swapped

  • outname (str) – the name of the file to write