cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Missing default natural earth shapefiles

Open yaswant opened this issue 3 years ago • 0 comments

Description

The cartopy geoaxes coastlines() method attempts to download (and store them in local cartopy cache dir) 110m natural earth shapefiles. This is not ideal, particularly when a stack is deployed on a machine which is not internet facing and the user has not manually updated the cache folder.

For example the following code will hang if there is no internet connection and the only way out is via keyboard interruption (eg Ctrl+C)

Code to reproduce

For example, on a Linux OS, remove ~/.local/share/cartopy and disconnect from the internet and run:

#!/usr/bin/env python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

proj = ccrs.PlateCarree()
fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111, projection=proj)
ax.set_global()
ax.coastlines()
plt.show()

Traceback

.../lib/python3.6/site-packages/cartopy/io/__init__.py:260: DownloadWarning: Downloading: https://naciscdn.org/naturalearth/110m/physical/ne_110m_coastline.zip
  warnings.warn('Downloading: {}'.format(url), DownloadWarning)

^CException in Tkinter callback
Traceback (most recent call last):
  File ".../lib/python3.6/tkinter/__init__.py", line 1702, in __call__
    return self.func(*args)
  File ".../lib/python3.6/tkinter/__init__.py", line 746, in callit
    func(*args)
  File ".../lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 253, in idle_draw
    self.draw()
  File ".../lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File ".../lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 407, in draw
    self.figure.draw(self.renderer)
  File ".../lib/python3.6/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File ".../lib/python3.6/site-packages/matplotlib/figure.py", line 1864, in draw
    renderer, self, artists, self.suppressComposite)
  File ".../lib/python3.6/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File ".../lib/python3.6/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File ".../lib/python3.6/site-packages/cartopy/mpl/geoaxes.py", line 479, in draw
    return matplotlib.axes.Axes.draw(self, renderer=renderer, **kwargs)
  File ".../lib/python3.6/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File ".../lib/python3.6/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
    return func(*inner_args, **inner_kwargs)
  File ".../lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2747, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File ".../lib/python3.6/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File ".../lib/python3.6/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File ".../lib/python3.6/site-packages/cartopy/mpl/feature_artist.py", line 155, in draw
    geoms = self._feature.intersecting_geometries(extent)
  File ".../lib/python3.6/site-packages/cartopy/feature/__init__.py", line 302, in intersecting_geometries
    return super(NaturalEarthFeature, self).intersecting_geometries(extent)
  File ".../lib/python3.6/site-packages/cartopy/feature/__init__.py", line 110, in intersecting_geometries
    return (geom for geom in self.geometries() if
  File ".../lib/python3.6/site-packages/cartopy/feature/__init__.py", line 286, in geometries
    name=self.name)
  File ".../lib/python3.6/site-packages/cartopy/io/shapereader.py", line 295, in natural_earth
    return ne_downloader.path(format_dict)
  File ".../lib/python3.6/site-packages/cartopy/io/__init__.py", line 222, in path
    result_path = self.acquire_resource(target_path, format_dict)
  File ".../lib/python3.6/site-packages/cartopy/io/shapereader.py", line 350, in acquire_resource
    shapefile_online = self._urlopen(url)
  File ".../lib/python3.6/site-packages/cartopy/io/__init__.py", line 261, in _urlopen
    return urlopen(url)
  File ".../lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File ".../lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File ".../lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File ".../lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File ".../lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File ".../lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File ".../lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File ".../lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File ".../lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File ".../lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File ".../lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File ".../lib/python3.6/http/client.py", line 1392, in connect
    super().connect()
  File ".../lib/python3.6/http/client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File ".../lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
KeyboardInterrupt

Operating system

Linux

Cartopy version

0.18.0 onwards

yaswant avatar Mar 22 '22 18:03 yaswant