jwass / mplleaflet

Easily convert matplotlib plots from Python into interactive Leaflet web maps.
BSD 3-Clause "New" or "Revised" License
521 stars 76 forks source link

Additional documentation for contour.py example #21

Open jhconning opened 9 years ago

jhconning commented 9 years ago

I have been using mplleaflet successfully in other contexts (and it's great!) but just wanted to suggest a small modification (or additional documentation to) the contour.py so that new users like myself can reproduce the results.

I (and independently a friend) have not been able to get the contour.py example to work. We loaded rain data from the listed source into the geodataframe and got matplotlib.contour plot to correctly display in an ipython notebook. However when we make the last mplleaflet.show call the browser window displays only the basemap with no sign of the contour plot.

The contour.py module does mention that the CRS info has been only 'gleaned from reading the NWS and Proj.4 docs' but someone seems to have made it work to produce the example map that you link to in the README.

The data we downloaded is more recent precipitation data than in the example (the last file I downloaded was "nws_precip_year2date_observed_20150101.shp" whereas in the example it is "'nws_precip_year2date_observed_20140406.shp"). I don't think the CRS would change but perhaps it has. I can't see what else we are doing wrong since we are following the contour.py code practically verbatim.

So my suggestion is to either add documentation to give users more guidance on how to 'glean' the CRS themselves (if that is the problem) or perhaps easier and more effective: modify the example to work with another fixed dataset (with a known CRS) to be sure it works everytime. Thanks.

jwass commented 9 years ago

Hi @jhconning. I'm glad you've found mplleaflet useful so far.

Recently a similar bug was discovered with the contour example - see #19 - and was fixed just a few days ago. Do you know if you're still seeing this behavior with the current master or latest update on PyPI (v0.0.2)? If you get a chance, can you try that out and report back?

I think the CRS is unrelated. Either way, I agree about that the doc is lacking there. I'll see if I can find more detailed descriptions for how I came up with the Proj4 parameters.

jhconning commented 9 years ago

Thank your response. I updated to v0.02 as you suggested via pip, but still no luck

Possibly related or another issue: On the final mplleaflet.show call in contour.py I omitted the 'tiles=' option because it was giving an error. I assumed that leaving it blank would revert to a default tile option (appears to be 'maptiles.osm') which would display. This is pointing to something that is not put in place at the time of installation (or actually... that it's not pulling it in from the web as seems to be called for in maptiles.py). When I make the mplleaflet call exactly as it appears in contour.py example I get the following error

In[]: mplleaflet.show(crs=crs, path=mapfile, tiles='mapbox bright')
C:\Users\Jonathan\Anaconda3\lib\site-packages\mplleaflet\_display.py in fig_to_html(fig, template, tiles, crs, epsg)
     58     if tiles is None:
     59         tiles = maptiles.osm
---> 60     elif isinstance(tiles, basestring):
     61         if tiles not in maptiles.tiles:
     62             raise ValueError('Unknown tile source "{}"'.format(tiles))

NameError: name 'basestring' is not defined

FYI: I'm on Windows 7, using Anaconda (updated this AM) in a python 3.4 environment.

jwass commented 9 years ago

@jhconning Finally found some time to take a deeper look at this again.

I just downloaded a fresh file from http://water.weather.gov/precip/download.php for precipitation over the last 30 days. I changed the filename in the script to use the latest file.

It looks like the columns have changed casing. This caused a crash in the code. I just pushed a fix forcing all columns to lowercase and then using those. I'm pretty sure this isn't your problem since you wouldn't have gotten to the point that the map tried to display.

Other than that, the script worked without any modification and the map displayed properly. The CRS for the HRAP system shouldn't depend on the specific file. I also double checked and tested on Python 2.7 and 3.3.

If you run the examples/contour.py script, changing only the filename, do you still have problems? You mentioned that you were trying to display it in the IPython notebook, so there could be problems there. Note that to embed in the notebook you have to call display(), not show().

jwass commented 9 years ago

The file I downloaded is nws_precip_last30days_observed_shape_20150823