Skip to content

Instantly share code, notes, and snippets.

@spacelis
Created October 7, 2014 12:58
Show Gist options
  • Save spacelis/d05363ff08248d202a7a to your computer and use it in GitHub Desktop.
Save spacelis/d05363ff08248d202a7a to your computer and use it in GitHub Desktop.
--- __init__.py.old 2014-10-07 01:26:24.682034979 +0200
+++ __init__.py 2014-10-07 14:48:02.542868362 +0200
@@ -4272,7 +4272,7 @@
return self.imshow(imread(urllib2.urlopen(basemap_url)),origin='upper')
def wmsimage(self,server,\
- xpixels=400,ypixels=None,\
+ xpixels=400,ypixels=None,togray=False,\
format='png',verbose=False,**kwargs):
"""
Retrieve an image using from a WMS server using the
@@ -4357,8 +4357,21 @@
srs='EPSG:%s' % self.epsg, **kwargs)
# return AxesImage instance.
# this works for png and jpeg.
- return self.imshow(imread(io.BytesIO(urllib2.urlopen(img.url).read()),
- format=format),origin='upper')
+ im = imread(io.BytesIO(urllib2.urlopen(img.url).read()),
+ format=format)
+ if togray and im.shape[2] >= 3:
+ if togray is True:
+ togray = [0.3, 0.6, 0.1]
+ else:
+ assert len(togray) == 3, \
+ '`togray` must be either False, True or [r, g, b].'
+ gray = (togray[0] * im[:,:,0] +
+ togray[1] * im[:,:,1] +
+ togray[2] * im[:,:,2])
+ im[:,:,0] = gray
+ im[:,:,1] = gray
+ im[:,:,2] = gray
+ return self.imshow(im,origin='upper')
# this works for png, but not jpeg
#return self.imshow(imread(urllib2.urlopen(img.url),format=format),origin='upper')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment