From a5d7cc9e75f776aa511c05f39e5ac1114aabee38 Mon Sep 17 00:00:00 2001 From: Jordi Castells Date: Tue, 17 Nov 2020 09:23:46 +0100 Subject: [PATCH 1/3] Added SRTM Ellipsoid altitude from the opentopograpy portal. https://portal.opentopography.org/raster?opentopoID=OTSRTM.082016.4326.1 --- elevation/datasource.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/elevation/datasource.py b/elevation/datasource.py index d4a14a0..2ce2862 100644 --- a/elevation/datasource.py +++ b/elevation/datasource.py @@ -70,8 +70,38 @@ 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): + abs_ilat = abs(ilat) + slat = '%s%02d' % ('N' if abs_ilat >= 0 else 'S', abs_ilat) + subdir = 'North' if abs_ilat >= 0 else 'South' + north_subdir = 'North_30_60' if ilat >= 30 else 'North_0_29' + fname = tile_name_template.format(**locals()) + + if abs_ilat >= 0: + yield(f"{subdir}/{north_subdir}/{fname}") + else: + yield(f"{subdir}/{fname}") + + 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}, @@ -95,6 +125,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) From 29d55eb2408341ce472c82d6e781a568c30199b2 Mon Sep 17 00:00:00 2001 From: Jordi Castells Date: Tue, 17 Nov 2020 11:41:44 +0100 Subject: [PATCH 2/3] Changed f"" string formatting to format(locals) to run tox. --- elevation/datasource.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elevation/datasource.py b/elevation/datasource.py index 2ce2862..208fa15 100644 --- a/elevation/datasource.py +++ b/elevation/datasource.py @@ -85,9 +85,9 @@ def srtm_ellip_tiles_names(left, bottom, right, top, fname = tile_name_template.format(**locals()) if abs_ilat >= 0: - yield(f"{subdir}/{north_subdir}/{fname}") + yield("{subdir}/{north_subdir}/{fname}".format(**locals())) else: - yield(f"{subdir}/{fname}") + yield("{subdir}/{fname}".format(**locals())) DATASOURCE_MAKEFILE = pkgutil.get_data('elevation', 'datasource.mk').decode('utf-8') From 4e4d26b9f8a93ff0ecb2db3361e5bf51098aef74 Mon Sep 17 00:00:00 2001 From: Jordi Castells Date: Tue, 17 Nov 2020 12:33:48 +0100 Subject: [PATCH 3/3] Fixed abs_ilat error in SRTM_ELLIP, added srtm_ellip test --- elevation/datasource.py | 7 +++---- tests/test_datasource.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/elevation/datasource.py b/elevation/datasource.py index 208fa15..be9c61a 100644 --- a/elevation/datasource.py +++ b/elevation/datasource.py @@ -78,13 +78,12 @@ def srtm_ellip_tiles_names(left, bottom, right, top, 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): - abs_ilat = abs(ilat) - slat = '%s%02d' % ('N' if abs_ilat >= 0 else 'S', abs_ilat) - subdir = 'North' if abs_ilat >= 0 else 'South' + 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 abs_ilat >= 0: + if ilat >= 0: yield("{subdir}/{north_subdir}/{fname}".format(**locals())) else: yield("{subdir}/{fname}".format(**locals())) diff --git a/tests/test_datasource.py b/tests/test_datasource.py index fb2866f..49cc81f 100644 --- a/tests/test_datasource.py +++ b/tests/test_datasource.py @@ -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'])