Skip to content

Commit

Permalink
fix aster zone bug (#891)
Browse files Browse the repository at this point in the history
* fix aster zone bug

* fix aster tests
  • Loading branch information
matthiasdusch committed Oct 21, 2019
1 parent 76b118d commit f9defc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions oggm/tests/test_utils.py
Expand Up @@ -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])
Expand Down Expand Up @@ -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):

Expand Down
6 changes: 3 additions & 3 deletions oggm/utils/_downloads.py
Expand Up @@ -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:
Expand Down

0 comments on commit f9defc6

Please sign in to comment.