From f9defc6153aff2094847dd5296f519ab0874eea8 Mon Sep 17 00:00:00 2001 From: Matthias Dusch <37663627+matthiasdusch@users.noreply.github.com> Date: Mon, 21 Oct 2019 17:34:59 +0200 Subject: [PATCH] fix aster zone bug (#891) * fix aster zone bug * fix aster tests --- oggm/tests/test_utils.py | 15 ++++++++------- oggm/utils/_downloads.py | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/oggm/tests/test_utils.py b/oggm/tests/test_utils.py index 5e1e7657a..c415415a5 100644 --- a/oggm/tests/test_utils.py +++ b/oggm/tests/test_utils.py @@ -1521,16 +1521,16 @@ def test_aster(self): # Make a fake topo file tf = make_fake_zipdir(os.path.join(self.dldir, 'ASTGTMV003_S88W121'), - fakefile='ASTGTMV003_S88W121_dem.tif') + fakefile='ASTGTMV003_S89W121_dem.tif') def down_check(url, *args, **kwargs): expect = ('https://e4ftl01.cr.usgs.gov//ASTER_B/ASTT/ASTGTM.003/' + - '2000.03.01/ASTGTMV003_S88W121.zip') + '2000.03.01/ASTGTMV003_S89W121.zip') self.assertEqual(url, expect) return tf with FakeDownloadManager('_progress_urlretrieve', down_check): - of, source = utils.get_topo_file([-120.2, -120.2], [-88, -88], + of, source = utils.get_topo_file([-120.2, -120.2], [-88.1, -88.9], source='ASTER') assert os.path.exists(of[0]) @@ -1669,11 +1669,12 @@ def test_asterzone(self): self.assertTrue(len(z) == 1) self.assertEqual('ASTGTMV003_N30W096', z[0]) - z = utils.aster_zone(lon_ex=[-96.5, -95.5], + z = utils.aster_zone(lon_ex=[-96.5, -94.5], lat_ex=[30.5, 30.5]) - self.assertTrue(len(z) == 2) - self.assertEqual('ASTGTMV003_N30W096', z[0]) - self.assertEqual('ASTGTMV003_N30W097', z[1]) + self.assertTrue(len(z) == 3) + self.assertEqual('ASTGTMV003_N30W095', z[0]) + self.assertEqual('ASTGTMV003_N30W096', z[1]) + self.assertEqual('ASTGTMV003_N30W097', z[2]) def test_mapzen_zone(self): diff --git a/oggm/utils/_downloads.py b/oggm/utils/_downloads.py index 8016ba0cf..4eb668f87 100644 --- a/oggm/utils/_downloads.py +++ b/oggm/utils/_downloads.py @@ -1249,9 +1249,9 @@ def aster_zone(lon_ex, lat_ex): W20 contains -19.99 to -19.0 """ - # this means flooring should do the job for all points - lons = np.unique(np.floor(lon_ex)) - lats = np.unique(np.floor(lat_ex)) + # adding small buffer for unlikely case where one lon/lat_ex == xx.0 + lons = np.arange(np.floor(lon_ex[0]-1e-9), np.ceil(lon_ex[1]+1e-9)) + lats = np.arange(np.floor(lat_ex[0]-1e-9), np.ceil(lat_ex[1]+1e-9)) zones = [] for lat in lats: