Package: dted
DTED ParserThis is a package written in pure python (with help fromnumpy) to parse
and investigate Digital Terrain Elevation Data (DTED) files. This package
is tested to work on Shuttle Radar Topography Mission (SRTM) DTED files
(as far as I can tell these are the only publicly available DTED files).
This can be used as a library to parse these files intonumpyarrays
and additionally exposes a CLI that can be used to investigate individual
DTED files.For more information and resources about the DTED file format see the
end of the README.How to installYou can install this as a normal python package usingpippipinstalldtedHow to useThe following example code will parse DTED file checked into this repository
for testing.As a libraryParsing a DTED file into a numpy array is as simple as:importnumpyasnpfrompathlibimportPathfromdtedimportTiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file)assertisinstance(tile.data,np.ndarray)Additionally, you can access the metadata of the DTED file (the User Header
Label, Data Set Identification, and Accuracy Description records) easily.frompathlibimportPathfromdtedimportTiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file)print(tile.dsi.south_west_corner)Parsing entire DTED files has been heavily optimized, but does still take
a little bit of time. On my machine (2014 MacbookPro) parsing the 25MB
example file take about 120 ms. However, if you only need to look up
specific terrain elevations within a DTED file you do not need to parse
the entire file. Doing the following takes <1ms on my machine:frompathlibimportPathfromdtedimportLatLon,Tiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file,in_memory=False)print(tile.get_elevation(LatLon(latitude=41.5,longitude=-70.5)))If for some reason youreallyneed to eke out every bit of performance, and
you thoroughly trust your DTED data, you speed up the data parsing by
skipping the checksum verification. Doing the following takes about 75 ms
on my machine:importnumpyasnpfrompathlibimportPathfromdtedimportTiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file,in_memory=False)tile.load_data(perform_checksum=False)assertisinstance(tile.data,np.ndarray)The final functionality thedted.Tileclass offers is to easily check if
a coordinate location is contained within the DTED file. This also does
not require that the DTED data is fully loaded into memory:frompathlibimportPathfromdtedimportLatLon,Tiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file,in_memory=False)assertLatLon(latitude=41.5,longitude=-70.25)intileAs a CLIInstalling this package into an activated virtual environment also exposes
thedtedterminal command. This provides three pieces of functionality:See report of the metadata of the DTED file.Lookup terrain elevation at a specific point within the DTED file.Display and ASCII representation of the DTED file in your terminal.To get a report of the file metadata:(.venv)user@machine$dtedtest/data/n41_w071_1arc_v3.dt2FilePath:test/data/n41_w071_1arc_v3.dt2(24MB)ProductLevel:DTED2
SecurityCode:U
CompilationDate:02/2000
MaintenanceDate:Datums(V/H):E96/WGS84(42.0N,71.0W)(42.0N,70.0W)NW---------------NE||||||||||||SW---------------SE(41.0N,71.0W)(41.0N,70.0W)Origin:(41.0N,71.0W)Resolution(lat/lon):1.0"/1.0"Accuracy(V/H):6m/13mTo lookup terrain elevation at a specific point:(.venv)user@machine$dtedtest/data/n41_w071_1arc_v3.dt2--location41.7-70.451.0metersTo display the DTED file in your terminal:(.venv)user@machine$dtedtest/data/n41_w071_1arc_v3.dt2--displayThis will attempt to create an ASCII representation of the DTED file within
your terminal at the best resolution possible. Increasing the size of your
terminal window or zooming out your terminal window will increase the
resolution of the chart:Why did I add this feature? Why not?If you want to plot this data like a sane person, you can use the following
example code with thematplotlibpackage (not included)importmatplotlib.pyplotaspltfrompathlibimportPathfromdtedimportTiledted_file=Path("test/data/n41_w071_1arc_v3.dt2")tile=Tile(dted_file)plt.imshow(tile.data.T[::-1],cmap="hot")The DTED file formatThis parser was created using the specification provided here:https://www.dlr.de/eoc/Portaldata/60/Resources/dokumente/7_sat_miss/SRTM-XSAR-DEM-DTED-1.1.pdfSome things to be aware of with the DTED file format:Some DTED files contain "void" values for data points where elevation
data is not known (such as over bodies of water). An example of such a
file can be found attest/data/n00_e006_3arc_v2.dt1. This package
will emit a warning if void data is found, and the definition of the
void value can be found indted.definitions.VOID_DATA_VALUE.The DTED data is structured along longitudinal lines. Therefore, when
accessing the data within thenumpyarray the rows correspond to
longitude and the columns correspond to latitude. This may seem backwards
to your intuition, i.e. you would access the elevation at a coordinate
point withtile.data[longitude_index, latitude_index].Elevation within the DTED file is encoded using "signed magnitude"
notation. This has no effect on a user of this package interacting with
the parsed terrain elevation data, but it does slow down the parsing of
this data as I do not know of an optimized method of parsing signed
magnitude data in python. If someone knows how to do this, this parsing
library could become even faster.Where to find DTED dataPublicly available DTED data is relatively hard to find and access,
but it can be done. The DTED files I used for testing and developing
this package come fromhttps://earthexplorer.usgs.gov/.This EarthExplorer app provided by the USGS provides an interface to
download many types of terrain data, including the SRTM DTED data.
However, you need to make an account with them in order to perform the
download, and I'm unsure of a way to use their machine-to-machine API
to automate downloading data.ContributingContributions are absolutely encouraged! To develop on this project you
need to install thepoetrypackage manager.Clone the repo:user@machine$gitclonehttps://github.com/bbonenfant/dtedCreate and activate the virtual environment:user@machine$poetryinstall&&source.venv/bin/activateTo run the tests:(.venv)user@machine$pytest.If you are gettingBLACKerrors from pytest, run theblackcode formatter:(.venv)user@machine$black.