Skip to content

Commit 27ffdb8

Browse files
committed
Clean Basemap.arcgisimage docstring and comments
1 parent d4eae27 commit 27ffdb8

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

packages/basemap/src/mpl_toolkits/basemap/__init__.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,40 +4260,50 @@ def pil_to_array(*args, **kwargs):
42604260
def arcgisimage(self, server="http://server.arcgisonline.com/ArcGIS",
42614261
service="World_Imagery", xpixels=400, ypixels=None,
42624262
dpi=96, cachedir=None, verbose=False, **kwargs):
4263-
"""
4264-
Retrieve an image using the ArcGIS Server REST API and display it on
4265-
the map. In order to use this method, the Basemap instance must be
4266-
created using the ``epsg`` keyword to define the map projection, unless
4267-
the ``cyl`` projection is used (in which case the epsg code 4326 is
4268-
assumed).
4263+
r"""Display background image using ArcGIS Server REST API.
42694264
4270-
.. tabularcolumns:: |l|L|
4265+
In order to use this method, the :class:`Basemap` instance
4266+
must be created using the ``epsg`` keyword to define the
4267+
map projection, unless the "cyl" projection is used (in
4268+
which case the EPSG code 4326 is assumed).
42714269
4272-
============== ====================================================
4273-
Keywords Description
4274-
============== ====================================================
4275-
server web map server URL (default
4276-
http://server.arcgisonline.com/ArcGIS).
4277-
service service (image type) hosted on server (default
4278-
'World_Imagery', which is NASA 'Blue Marble'
4279-
image).
4280-
xpixels requested number of image pixels in x-direction
4281-
(default 400).
4282-
ypixels requested number of image pixels in y-direction.
4283-
Default (None) is to infer the number from
4284-
from xpixels and the aspect ratio of the
4285-
map projection region.
4286-
dpi The device resolution of the exported image (dots per
4287-
inch, default 96).
4288-
cachedir An optional directory to use as cache folder for the
4289-
retrieved images.
4290-
verbose if True, print URL used to retrieve image (default
4291-
False).
4292-
============== ====================================================
4270+
Parameters
4271+
----------
42934272
4294-
Extra keyword ``ax`` can be used to override the default axis instance.
4273+
server : str, optional
4274+
base URL of the web map server
42954275
4296-
returns a matplotlib.image.AxesImage instance.
4276+
service : str, optional
4277+
service (image type) hosted by the server
4278+
4279+
xpixels : int, optional
4280+
requested number of image pixels in the `x`-direction
4281+
4282+
ypixels : int, optional
4283+
requested number of image pixels in the `y`-direction;
4284+
if not given, it is inferred from ``xpixels`` and the
4285+
aspect ratio of the map projection region
4286+
4287+
dpi : int, optional
4288+
device resolution of the exported image
4289+
4290+
cachedir : str, optional
4291+
if given, directory to use as cache folder for the images
4292+
retrieved from the server
4293+
4294+
verbose : bool, optional
4295+
if True, print debugging information
4296+
4297+
\**kwargs : dict, optional
4298+
keyword-only arguments; currently, only ``ax`` is supported
4299+
to override the default :class:`matplotlib.axes.Axes`
4300+
instance
4301+
4302+
Returns
4303+
-------
4304+
4305+
aximg : matplotlib.image.AxesImage
4306+
image axes instance
42974307
"""
42984308

42994309
# Fix PIL import on some versions of OSX and scipy.
@@ -4313,7 +4323,7 @@ def arcgisimage(self, server="http://server.arcgisonline.com/ArcGIS",
43134323

43144324
ax = kwargs.pop("ax", None) or self._check_ax()
43154325

4316-
# Find the (x, y) values at the corner points.
4326+
# Find the `(x, y)` values at the corner points.
43174327
with warnings.catch_warnings():
43184328
warnings.simplefilter("ignore", category=FutureWarning)
43194329
p = pyproj.Proj(init="epsg:%s" % self.epsg, preserve_units=True)
@@ -4346,34 +4356,30 @@ def arcgisimage(self, server="http://server.arcgisonline.com/ArcGIS",
43464356
if verbose:
43474357
print(basemap_url)
43484358

4359+
# Try to return fast if cache is enabled.
43494360
if cachedir is not None:
4350-
43514361
# Generate a filename for the cached file.
43524362
filename = "%s-bbox-%s-%s-%s-%s-bboxsr%s-imagesr%s-size-%s-%s-dpi%s.png" % \
43534363
(service, xmin, ymin, xmax, ymax, self.epsg, self.epsg, xpixels, ypixels, dpi)
4354-
43554364
# Check if the cache directory exists, if not create it.
43564365
if not os.path.exists(cachedir):
43574366
os.makedirs(cachedir)
4358-
4359-
# Check if the image is already in the cachedir folder.
4367+
# Return fast if the image is already in the cache.
43604368
cache_path = os.path.join(cachedir, filename)
43614369
if os.path.isfile(cache_path):
43624370
if verbose:
43634371
print("Image already in cache")
43644372
img = Image.open(cache_path)
43654373
return self.imshow(img, ax=ax, origin="upper")
43664374

4367-
# Retrieve image from remote server.
4375+
# Retrieve image from the remote server.
43684376
import contextlib
43694377
conn = urlopen(basemap_url)
43704378
with contextlib.closing(conn):
43714379
img = Image.open(conn)
43724380
# Save to cache if requested.
43734381
if cachedir is not None:
43744382
img.save(cache_path)
4375-
4376-
# Return AxesImage instance.
43774383
return self.imshow(img, ax=ax, origin="upper")
43784384

43794385
def wmsimage(self,server,\

0 commit comments

Comments
 (0)