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

skip known http failures #818

Merged
merged 2 commits into from
Dec 15, 2016
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
9 changes: 9 additions & 0 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import shapely.geometry as sgeom
import numpy as np
import six
import warnings

import cartopy.crs as ccrs

Expand Down Expand Up @@ -201,10 +202,18 @@ def get_image(self, tile):

class MapQuestOSM(GoogleTiles):
# http://developer.mapquest.com/web/products/open/map for terms of use
# http://devblog.mapquest.com/2016/06/15/
# modernization-of-mapquest-results-in-changes-to-open-tile-access/
# this now requires a sign up to a plan
def _image_url(self, tile):
x, y, z = tile
url = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/%s/%s/%s.jpg' % (
z, x, y)
mqdevurl = ('http://devblog.mapquest.com/2016/06/15/'
'modernization-of-mapquest-results-in-changes'
'-to-open-tile-access/')
warnings.warn('{} will require a log in and and will likely'
' fail. see {} for more details.'.format(url, mqdevurl))
return url


Expand Down
3 changes: 3 additions & 0 deletions lib/cartopy/io/srtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ def __init__(self,
Downloader.__init__(self, None,
target_path_template,
pre_downloaded_path_template)
warnings.warn('SRTM requires an account set up and log in to access.'
'use of this class is likely to fail with'
' HTTP 401 errors.')

def url(self, format_dict):
# override the url method, looking up the url from the
Expand Down
95 changes: 50 additions & 45 deletions lib/cartopy/tests/io/test_srtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,54 @@
from cartopy.tests.io.test_downloaders import download_to_temp


def _test_srtm_retrieve(Source, read_SRTM, max_, min_, pt):
# test that the download mechanism for SRTM works
with download_to_temp() as tmp_dir:
with warnings.catch_warnings(record=True) as w:
r = Source().srtm_fname(-4, 50)
assert len(w) == 1
assert issubclass(w[0].category, cartopy.io.DownloadWarning)

assert r.startswith(tmp_dir), 'File not downloaded to tmp dir'

img, _, _ = read_SRTM(r)

# check that the data is fairly sensible
msg = 'SRTM data has changed. Arbitrary value testing failed. Got {}.'
assert img.max() == max_, msg.format(img.max())
assert img.min() == min_, msg.format(img.min())
assert img[-10, 12] == pt, msg.format(img[-10, 12])


def test_srtm3_retrieve():
_test_srtm_retrieve(cartopy.io.srtm.SRTM3Source,
cartopy.io.srtm.read_SRTM3,
602, -34, 78)


def test_srtm1_retrieve():
_test_srtm_retrieve(cartopy.io.srtm.SRTM1Source,
cartopy.io.srtm.read_SRTM1,
602, -37, 50)


def _test_srtm_out_of_range(Source, shape):
# Somewhere over the pacific the elevation should be 0.
img, _, _ = Source().combined(120, 2, 2, 2)
assert_array_equal(img, np.zeros(np.array(shape) * 2))


def test_srtm3_out_of_range():
_test_srtm_out_of_range(cartopy.io.srtm.SRTM3Source, (1201, 1201))


def test_srtm1_out_of_range():
_test_srtm_out_of_range(cartopy.io.srtm.SRTM1Source, (3601, 3601))


@unittest.skip('SRTM login not supported')
class TestRetrieve(unittest.TestCase):
def _test_srtm_retrieve(self, Source, read_SRTM, max_, min_, pt):
# test that the download mechanism for SRTM works
with download_to_temp() as tmp_dir:
with warnings.catch_warnings(record=True) as w:
r = Source().srtm_fname(-4, 50)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category,
cartopy.io.DownloadWarning))

self.assertTrue(r.startswith(tmp_dir),
'File not downloaded to tmp dir')

img, _, _ = read_SRTM(r)

# check that the data is fairly sensible
msg = ('SRTM data has changed. Arbitrary value testing failed.'
' Got {}.')
self.assertEqual(img.max(), max_, msg=msg.format(img.max()))
self.assertEqual(img.min(), min_, msg=msg.format(img.min()))
self.assertEqual(img[-10, 12], pt, msg=msg.format(img[-10, 12]))

def test_srtm3_retrieve(self):
self._test_srtm_retrieve(cartopy.io.srtm.SRTM3Source,
cartopy.io.srtm.read_SRTM3,
602, -34, 78)

def test_srtm1_retrieve(self):
self._test_srtm_retrieve(cartopy.io.srtm.SRTM1Source,
cartopy.io.srtm.read_SRTM1,
602, -37, 50)

def _test_srtm_out_of_range(self, Source, shape):
# Somewhere over the pacific the elevation should be 0.
img, _, _ = Source().combined(120, 2, 2, 2)
assert_array_equal(img, np.zeros(np.array(shape) * 2))

def test_srtm3_out_of_range(self):
_test_srtm_out_of_range(self,
cartopy.io.srtm.SRTM3Source, (1201, 1201))

def test_srtm1_out_of_range(self):
_test_srtm_out_of_range(self,
cartopy.io.srtm.SRTM1Source, (3601, 3601))


@unittest.skip('SRTM login not supported')
class TestSRTMSource__single_tile(unittest.TestCase):
def _out_of_range(self, source):
msg = 'No srtm tile found for those coordinates.'
Expand Down Expand Up @@ -110,6 +113,7 @@ def test_zeros1(self):
self._zeros(cartopy.io.srtm.SRTM1Source())


@unittest.skip('SRTM login not supported')
class TestSRTMSource__combined(unittest.TestCase):
def _trivial(self, source):
e_img, e_crs, e_extent = source.single_tile(-3, 50)
Expand Down Expand Up @@ -138,6 +142,7 @@ def test_2by2_1(self):
self._2by2(cartopy.io.srtm.SRTM1Source())


@unittest.skip('SRTM login not supported')
class TestSRTM3Source_fetch_raster(unittest.TestCase):
def _as_combined(self, source):
e_img, e_crs, e_extent = source.combined(-1, 50, 2, 1)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 3 additions & 29 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_web_tiles():
[extent[0], extent[1]]])
map_prj = cimgt.GoogleTiles().crs

ax = plt.subplot(3, 2, 1, projection=map_prj)
ax = plt.subplot(2, 2, 1, projection=map_prj)
gt = cimgt.GoogleTiles()
gt._image_url = types.MethodType(ctest_tiles.GOOGLE_IMAGE_URL_REPLACEMENT,
gt)
Expand All @@ -63,47 +63,21 @@ def test_web_tiles():
interpolation='bilinear', origin=origin)
ax.coastlines(color='white')

ax = plt.subplot(3, 2, 2, projection=map_prj)
ax = plt.subplot(2, 2, 2, projection=map_prj)
qt = cimgt.QuadtreeTiles()
img, extent, origin = qt.image_for_domain(target_domain, 1)
ax.imshow(np.array(img), extent=extent, transform=qt.crs,
interpolation='bilinear', origin=origin)
ax.coastlines(color='white')

ax = plt.subplot(3, 2, 3, projection=map_prj)
mq_osm = cimgt.MapQuestOSM()
img, extent, origin = mq_osm.image_for_domain(target_domain, 1)
ax.imshow(np.array(img), extent=extent, transform=mq_osm.crs,
interpolation='bilinear', origin=origin)
ax.coastlines()

ax = plt.subplot(3, 2, 4, projection=map_prj)
mq_oa = cimgt.MapQuestOpenAerial()
img, extent, origin = mq_oa.image_for_domain(target_domain, 1)
ax.imshow(np.array(img), extent=extent, transform=mq_oa.crs,
interpolation='bilinear', origin=origin)
ax.coastlines()

ax = plt.subplot(3, 2, 5, projection=map_prj)
ax = plt.subplot(2, 2, 3, projection=map_prj)
osm = cimgt.OSM()
img, extent, origin = osm.image_for_domain(target_domain, 1)
ax.imshow(np.array(img), extent=extent, transform=osm.crs,
interpolation='bilinear', origin=origin)
ax.coastlines()


@ImageTesting(['image_nest'], tolerance=1.5)
def test_image_nest():
nest_z0_z1 = ctest_nest.gen_nest()

ax = plt.axes(projection=ccrs.Mercator())
shper_globe = ccrs.Globe(semimajor_axis=np.rad2deg(1))
spher_merc = ccrs.Mercator(globe=shper_globe)
ax.set_extent([-45, 45, -45, 90], spher_merc)
ax.coastlines()
ax.add_image(nest_z0_z1, 'aerial z1 test')


@ImageTesting(['image_merge'])
def test_image_merge():
# tests the basic image merging functionality
Expand Down