Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ellipsoidal SRTM dataset #42

Merged
merged 3 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions elevation/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,37 @@ def srtm3_tiles_names(left, bottom, right, top, tile_template='srtm_{ilon:02d}_{
yield tile_template.format(**locals())


def srtm_ellip_tiles_names(left, bottom, right, top,
tile_name_template='{slat}{slon}_wgs84.tif'):
ileft, itop = srtm1_tile_ilonlat(left, top)
iright, ibottom = srtm1_tile_ilonlat(right, bottom)

for ilon in range(ileft, iright + 1):
slon = '%s%03d' % ('E' if ilon >= 0 else 'W', abs(ilon))
for ilat in range(ibottom, itop + 1):
slat = '%s%02d' % ('N' if ilat >= 0 else 'S', abs(ilat))
subdir = 'North' if ilat >= 0 else 'South'
north_subdir = 'North_30_60' if ilat >= 30 else 'North_0_29'
fname = tile_name_template.format(**locals())

if ilat >= 0:
yield("{subdir}/{north_subdir}/{fname}".format(**locals()))
else:
yield("{subdir}/{fname}".format(**locals()))


DATASOURCE_MAKEFILE = pkgutil.get_data('elevation', 'datasource.mk').decode('utf-8')

SRTM1_ELLIP_SPEC = {
'folders': ('spool', 'cache'),
'file_templates': {'Makefile': DATASOURCE_MAKEFILE},
'datasource_url': 'https://opentopography.s3.sdsc.edu/raster/SRTM_GL1_Ellip/SRTM_GL1_Ellip_srtm',
'tile_ext': '.tif',
'compressed_pre_ext': '',
'compressed_ext': '',
'tile_names': srtm_ellip_tiles_names,
}

SRTM1_SPEC = {
'folders': ('spool', 'cache'),
'file_templates': {'Makefile': DATASOURCE_MAKEFILE},
Expand All @@ -95,6 +124,7 @@ def srtm3_tiles_names(left, bottom, right, top, tile_template='srtm_{ilon:02d}_{
PRODUCTS_SPECS = collections.OrderedDict([
('SRTM1', SRTM1_SPEC),
('SRTM3', SRTM3_SPEC),
('SRTM1_ELLIP', SRTM1_ELLIP_SPEC),
])

PRODUCTS = list(PRODUCTS_SPECS)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def test_srtm3_tiles_names():
assert len(list(datasource.srtm3_tiles_names(9.9, 39.1, 15.1, 45.1))) == 9


def test_srtm_ellip_tiles_names():
# Check the various subdirs in srtm_ellip
ds1 = ['North/North_30_60/N44E010_wgs84.tif']
ds2 = ['North/North_0_29/N07W074_wgs84.tif']
ds3 = ['South/S20E015_wgs84.tif']
assert list(datasource.srtm_ellip_tiles_names(10.1, 44.9, 10.1, 44.9)) == ds1
assert list(datasource.srtm_ellip_tiles_names(-73.99, 7.056, -73.90, 7.660)) == ds2
assert list(datasource.srtm_ellip_tiles_names(15.931, -19.194, 15.329, -19.961)) == ds3


def test_ensure_tiles(mocker):
mocker.patch('subprocess.check_call')
cmd = datasource.ensure_tiles('/tmp', ['a', 'b'])
Expand Down