GeoTIFF reading objects (sarpy.io.DEM.geotiff1deg)

Classes and methods for parsing and using digital elevation models (DEM) in GeoTIFF format.

This code makes the following assumptions.
  1. The GeoTIFF files tile the earth with one degree offsets in both latitude and longitude.

  2. There is one pixel of overlap between adjacent tiles.

  3. The south-west corner of each tile is at an integer (degrees) latitude and longitude.

  4. The latitude and longitude of south-west corner points is encoded in the GeoTIFF filename.

  5. The anti-meridian is at W180 rather than at E180 so that valid longitude values are (-180 <= lon < 180) degrees.

class sarpy.io.DEM.geotiff1deg.GeoTIFF1DegReader(filename)

Bases: object

Class to read in a GeoTIFF file, if necessary, and cache the data.

class sarpy.io.DEM.geotiff1deg.GeoTIFF1DegInterpolator(dem_filename_pattern, ref_surface='EGM2008', geoid_path=None, *, missing_error=False, interp_method='linear', max_readers=4)

Bases: DEMInterpolator

This class contains methods used to read DEM data from GeoTIFF files and interpolate the height values, as needed.

Parameters:
  • dem_filename_pattern (str) – This is a format string that provides a glob pattern that will uniquely specify a DEM file from the Lat/Lon of the SW corner of the DEM tile. See the GeoTIFF1DegList docstring for more details.

  • ref_surface (str (default: "EGM2008")) – A case-insensitive string specifying the DEM reference surface. (eg., “WGS84” | “EGM2008” | “EGM96” | “EGM84”)

  • geoid_path (str | pathlib.Path | None (default: None)) –

    Optional filename of a specific Geoid file or a directory containing geoid files to choose from. If a directory is specified, then one or more of the following geoid files (in order of preference) will be chosen from this directory.

    ’egm2008-1.pgm’, ‘egm2008-2_5.pgm’, ‘egm2008-5.pgm’, ‘egm96-5.pgm’, ‘egm96-15.pgm’, ‘egm84-15.pgm’, ‘egm84-30.pgm’

  • missing_error (bool (default: False)) – Optional flag indicating whether an exception will be raised when missing DEM data files are encountered. If True then a ValueError will be raised when a needed DEM data file can not be found. If False then a DEM value of zero will be used when a needed DEM data file is not found.

  • interp_method (str (default: 'linear')) – Optional interpolation method. Any scipy.interpolate.RegularGridInterpolator method is valid here.

  • max_readers (init (default: 4)) – Optional maximum number of DEM file readers. A DEM file reader will read a DEM file and cache the results. DEM file readers can use a lot of memory (~8 bytes x number-of-DEM-samples), but will make processing faster.

get_elevation_native(lat, lon, block_size=None)

Get the elevation value relative to the DEM file’s reference surface.

Parameters:
  • lat (numpy.ndarray | list | tuple | int | float) –

  • lon (numpy.ndarray | list | tuple | int | float) –

  • block_size (int | None (default: None)) – Block processing is not supported; this argument is present to maintain a common interface with the DEMInterpolator parent class. A value other than None will result in a warning.

Returns:

The elevation relative to the reference surface of the DEM.

Return type:

numpy.ndarray

get_elevation_hae(lat, lon, block_size=None)

Get the elevation value relative to the WGS84 ellipsoid.

Parameters:
  • lat (numpy.ndarray | list | tuple | int | float) –

  • lon (numpy.ndarray | list | tuple | int | float) –

  • block_size (int | None (default: None)) – Block processing is not supported; this argument is present to maintain a common interface with the DEMInterpolator parent class. A value other than None will result in a warning.

Returns:

The elevation relative to the ellipsoid

Return type:

numpy.ndarray

get_elevation_geoid(lat, lon, block_size=None)

Get the elevation value relative to the geoid.

Parameters:
  • lat (numpy.ndarray | list | tuple | int | float) –

  • lon (numpy.ndarray | list | tuple | int | float) –

  • block_size (int | None (default: None)) – Block processing is not supported; this argument is present to maintain a common interface with the DEMInterpolator parent class. A value other than None will result in a warning.

Returns:

the elevation relative to the geoid

Return type:

numpy.ndarray

get_max_hae(lat_lon_box=None)

Get the maximum dem value with respect to the ellipsoid, which should be assumed approximately correct.

Parameters:

lat_lon_box (list | numpy.ndarray) – Any area of interest of the form [lat min lat max, lon min, lon max].

Return type:

float

get_min_hae(lat_lon_box=None)

Get the minimum dem value with respect to the ellipsoid, which should be assumed approximately correct.

Parameters:

lat_lon_box (list | numpy.ndarray) – Any area of interest of the form [lat min lat max, lon min, lon max].

Return type:

float

get_max_geoid(lat_lon_box=None)

Get the maximum dem value with respect to the geoid, which should be assumed approximately correct.

Parameters:

lat_lon_box (list | numpy.ndarray) – Any area of interest of the form [lat min lat max, lon min, lon max].

Return type:

float

get_min_geoid(lat_lon_box=None)

Get the minimum dem value with respect to geoid, which should be assumed approximately correct.

Parameters:

lat_lon_box (list | numpy.ndarray) – Any area of interest of the form [lat min lat max, lon min, lon max].

Return type:

float

get_min_max_native(lat_lon_box)

Get the minimum and maximum dem value with respect to the native reference surface of the DEM.

Parameters:

lat_lon_box (List | numpy.ndarray) – The bounding box to search [lat min lat max, lon min, lon max].

Returns:

dict – “min”: {“lat”: lat_deg, “lon”: lon_deg, “height”: height},

”max”: {“lat”: lat_deg, “lon”: lon_deg, “height”: height}

}

Return type:

{“box”: lat_lon_box,

class sarpy.io.DEM.geotiff1deg.GeoTIFF1DegList(dem_filename_pattern, missing_error=False)

Bases: DEMList

GeoTIFF subclass of sarpy.io.DEM.DEMList

This class contains methods used to determine which GeoTIFF files are needed to cover a specified geodetic bounding box.

Parameters:
  • dem_filename_pattern (str) – This is a format string that specifies the glob pattern that will uniquely specify a DEM file from the Lat/Lon of the SW corner of the DEM tile. See the note below for more details.

  • missing_error (bool (default: False)) – Optional flag indicating whether an exception will be raised when missing DEM data files are encountered. If True then a ValueError will be raised when a needed DEM data file can not be found. If False then a DEM value of zero will be used when a needed DEM data file is not found.

Notes

The DEM files must have the SW corner Lat/Lon encoded in their filenames. The dem_filename_pattern argument contains a format string that, when populated, will create a glob pattern that will specify the desired DEM file. The following arguments are provided to the format string.

lat = int(numpy.floor(lat)) lon = int(numpy.floor(lon)) abslat = int(abs(numpy.floor(lat))) abslon = int(abs(numpy.floor(lon))) ns = ‘s’ if lat < 0 else ‘n’ NS = ‘S’ if lat < 0 else ‘N’ ew = ‘w’ if lon < 0 else ‘e’ EW = ‘W’ if lon < 0 else ‘E’

An example (with Linux file separators):

“/dem_root/tdt_{ns}{abslat:02}{ew}{abslon:03}_*/DEM/TDT_{NS}{abslat:02}{EW}{abslon:03}_*_DEM.tif”

will match filenames like:

“/dem_root/tdt_n45e013_02/DEM/TDT_N45E013_02_DEM.tif” “/dem_root/tdt_s09w140_01/DEM/TDT_S09W140_01_DEM.tif”

static filename_from_lat_lon(lat, lon, pattern)

This method will return the filename glob of the GeoTIFF file that contains the specified latitude/longitude.

find_dem_files(lat, lon)

Return a list of filenames of GeoTIFF files that contain DEM data for the specified Lat/Lon point. Since DEM files overlap, there might be more than one file that contains the specified Lat/Lon point.

Parameters:
  • lat (int | float) – The latitude in degrees (-90 <= lat <= 90)

  • lon (int | float) – The longitude in degrees (-180 <= lon < 180)

Returns:

filenames – A list of filenames of DEM data files, if they exists, otherwise []

Return type:

list(str)

get_file_list(lat_lon_box)

This will return the list of files associated with covering the lat_lon_box using a DEM.

If the bounding box spans the anti-meridian (180th meridian), then the maximum longitude will be less than the minimum longitude.

Parameters:

lat_lon_box (numpy.ndarray | list | tuple) – The bounding box of the form [lat min, lat max, lon min, lon max] in degrees.

Returns:

filenames – A list of filenames, without duplication, of the files needed to cover the bounding box.

Return type:

List[str]