SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.41k stars 359 forks source link

Invalid WIDTH value, NumberFormatException when using WMS #584

Closed ocefpaf closed 9 years ago

ocefpaf commented 9 years ago

I am not sure if this is a cartopy bug or if I am doing something wrong. The code below fails to create an image with the error,

Invalid WIDTH value, NumberFormatException : For input string: "273.379119692"

I notice that, if I force the width and height to be integers, at slippy_image_artist.py line 55, the figure is created (but I am not sure if I mess up the proportions).

Other WebMapService URLs work fine with the width and height as float. Just some, like the one below, fails.

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER

from owslib.wms import WebMapService
url = "http://nowcoast.noaa.gov/wms/com.esri.wms.Esrimap/analyses"
wms = WebMapService(url)

subplot_kw = dict(projection=ccrs.PlateCarree())
fig, ax = plt.subplots(subplot_kw=subplot_kw)
ax.set_extent([-42, 0, -32, 0.5])
ax.add_wms(wms, 'NCEP_RAS_ANAL_RTG_SST')

gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER

Thanks,

-Filipe

rsignell-usgs commented 9 years ago

It seems kind of crazy to request floating point pixels, so it would be nice if cartopy/owslib could round to nearest integer pixel, no?

rsignell-usgs commented 9 years ago

This was also asked (unanswered) here: https://groups.google.com/forum/#!searchin/scitools-iris/Filipe/scitools-iris/rpELfZtdDto/RVo7_kZkEyoJ

ocefpaf commented 9 years ago

Ultimately it boils down to the following URL being passed to OWSLib:

Bad URL (floats):

http://nowcoast.noaa.gov:80/wms/com.esri.wms.Esrimap/analyses?layers=NCEP_RAS_ANAL_RTG_SST&styles=&srs=EPSG%3A4326&format=image%2Fpng&request=GetMap&bgcolor=0xFFFFFF&height=392.0&width=480.0&version=1.1.1&bbox=-42.0%2C-33.790841270378365%2C0.0%2C0.5&exceptions=application%2Fvnd.ogc.se_xml&transparent=TRUE

Good URL (ints): http://nowcoast.noaa.gov:80/wms/com.esri.wms.Esrimap/analyses?layers=NCEP_RAS_ANAL_RTG_SST&styles=&srs=EPSG%3A4326&format=image%2Fpng&request=GetMap&bgcolor=0xFFFFFF&height=392&width=480&version=1.1.1&bbox=-42.0%2C-33.790841270378365%2C0.0%2C0.5&exceptions=application%2Fvnd.ogc.se_xml&transparent=TRUE

pelson commented 9 years ago

Closed by #587. Thanks for reporting @ocefpaf - this will be fixed by v0.12.0.

ocefpaf commented 9 years ago

Sorry, I should have been clearer :flushed:

np.ceil(2.1) results in 2.0, still not an int so the issue persists.

ServiceException: u'Invalid WIDTH value, NumberFormatException : For input string: "481.0"'

PS: Now that I know where to make the changes I can send a PR fixing this.