holoviz / datashader

Quickly and accurately render even the largest data.
http://datashader.org
BSD 3-Clause "New" or "Revised" License
3.3k stars 366 forks source link

import error in lidar example #315

Closed epifanio closed 7 years ago

epifanio commented 7 years ago

I'm trying to load the lidar example but I got an import error at:

from holoviews.operation import datashade
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'datashade'

I'm using datashader and holoview installed from theirs git:master repository.

Any clue on what I'm missing?

PeterDSteinberg commented 7 years ago

Hi @epifanio . In your notebook, change the import statement to:

from holoviews.operation.datashader import datashade

That was an oversight on my part in testing the lidar example with a slightly out of date holoviews. I'll make a PR now to implement this change.

epifanio commented 7 years ago

Hi @PeterDSteinberg , I tried the following:

>>> from holoviews.operation.datashader import datashade
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'holoviews.operation.datashader'

but the import error persist.

this is what I have in holoviews.operation

In [1]: import holoviews.operation as op

In [2]: dir(op)
Out[2]: 
['Collator',
 'Compositor',
 'Contours',
 'Dataset',
 'Element',
 'ElementOperation',
 'GridMatrix',
 'Histogram',
 'HoloMap',
 'Image',
 'MapOperation',
 'NdOverlay',
 'Overlay',
 'Polygons',
 'QuadMesh',
 'RGB',
 'Raster',
 'Scatter',
 'TreeOperation',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '_current_locals',
 '_k',
 '_public',
 '_v',
 'chain',
 'collapse',
 'contours',
 'convolve',
 'element',
 'factory',
 'find_minmax',
 'gradient',
 'gridmatrix',
 'group_sanitizer',
 'histogram',
 'identity',
 'image_overlay',
 'label_sanitizer',
 'np',
 'operation',
 'param',
 'public',
 'threshold',
 'transform']
PeterDSteinberg commented 7 years ago

@epifanio - I am using holoviews master (commit - 216c00c9e31b81b82ba20396dad99231218452ce). Which Python version are you using? I'll try several Python versions now (I have tried with 3.6 so far)

PeterDSteinberg commented 7 years ago

It may be advisable to do:

conda remove holoviews;pip uninstall -y holoviews;cd holoviews;python setup.py develop

to ensure an older package is not being imported.

jbednar commented 7 years ago

That's pretty strange; holoviews master definitely includes holoviews.operation.datashader. You probably have holoviews 1.6.2 installed; you can either do what Peter just suggested, or conda install -c ioam/c/dev holoviews to get the latest dev release. (The new holoviews 1.7 release is happening today or tomorrow, I swear!)

epifanio commented 7 years ago

yes, that was it! older version 1.6.2 was masking (for some reasons) the new version, maybe because one was installed at the user level and the new version at system level ... i guess the user installed one is the first on the path. Thanks for your help!

d-diaz commented 7 years ago

This problem just popped up for me using this same notebook. Using Holoviews 1.8.2

from holoviews.operation.datashader import datashade

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-455c547f64c8> in <module>()
      1 import holoviews as holo
      2 print(holo.__version__)
----> 3 from holoviews.operation.datashader import datashade

//anaconda/envs/ds/lib/python2.7/site-packages/holoviews/operation/datashader.py in <module>()
      9 import pandas as pd
     10 import xarray as xr
---> 11 import datashader as ds
     12 import datashader.transfer_functions as tf
     13 import dask.dataframe as dd

ImportError: No module named datashader

import holoviews as holo print(holo.__version__)

1.8.2
ivek1312 commented 6 years ago

ImportError Traceback (most recent call last)

in () 12 from colorcet import cm #pip install colorcet 13 from bokeh.models import WMTSTileSource ---> 14 from holoviews.operation.datashader import datashade 15 from holoviews.streams import RangeXY 16 hv.notebook_extension('bokeh') /home/ivik/.local/lib64/python3.5/site-packages/holoviews/operation/datashader.py in () 9 import pandas as pd 10 import xarray as xr ---> 11 import datashader as ds 12 import datashader.transfer_functions as tf 13 import dask.dataframe as dd ImportError: No module named 'datashader' Same here
jbednar commented 6 years ago

Sorry @d-diaz; I didn't see your comment on this closed issue earlier! What you and @ivek1312 are both reporting is an unrelated issue, namely that you don't have datashader installed in your current environment. It's a separate package, not shipped with HoloViews; maybe we should make HoloViews suggest installing it if you try to use datashade? In any case, just do conda install -c bokeh datashader and it should work.

ivek1312 commented 6 years ago

Yes, that was problem for me. Installed datashade from git and it works now. Now i have problem with geoview and datashade, image from datashade is not aligned with coordinates.

philippjfr commented 6 years ago

Could you confirm your versions of holoviews and geoviews?

ivek1312 commented 6 years ago

print(hv.version) 1.8.4 print(gv.version) 1.3.2

This is my example code: %%opts Overlay [width=900 height=500 xaxis=None yaxis=None] geomap = gv.WMTS(tiles["Stamen Toner"]) points = gv.Points(gv.Dataset(df_filt, kdims=['longitude', 'latitude'], vdims=['rtt'])) race = dynspread(datashade(points, element_type=gv.Image, aggregator=ds.mean('rtt'))) geomap * race

Coordinates are in web mercator. Points on map are plotted above null island.

philippjfr commented 6 years ago

That example needs updating then, change it to this for now:

%%opts Overlay [width=900 height=500 xaxis=None yaxis=None]
geomap = gv.WMTS(tiles["Stamen Toner"])
points = gv.Points(gv.Dataset(df_filt, kdims=['longitude', 'latitude'], vdims=['rtt']))
race = dynspread(datashade(points, element_type=hv.Image, aggregator=ds.mean('rtt')))
geomap * race

Note the hv.Image, gv.Image assumes the data specifies lat/lon coordinates.

ivek1312 commented 6 years ago

No change. Here is how it looks: https://ibb.co/hLvjYk

philippjfr commented 6 years ago

Are you sure the data is in Web Mercator coordinates then? Mind printing a few rows of the dataframe?

ivek1312 commented 6 years ago

https://ibb.co/b3ayR5

Without datashader, the coordinates are aligned.

philippjfr commented 6 years ago

That's because gv.Points automatically transforms the coordinates for you. The latitude and longitude columns in that screenshot are not Web Mercator (values like 499000), they are just bare lon,lat values (like 60). Try projecting the points object using gv.operation.project_points before datashading.

philippjfr commented 6 years ago

Note that there's still something to fix at the geoviews level since it should be projecting the datashaded image automatically as well.

ivek1312 commented 6 years ago

I'm totaly confused now with coordinates. I'm using this format: https://en.wikipedia.org/wiki/Web_Mercator and data is correctly plotted without datashade. Link: https://ibb.co/mQ9BDk

This is my example code:

class Options(hv.streams.Stream):
    alpha       = param.Magnitude(default=0.75, doc="Alpha value for the map opacity")
    colormap    = param.ObjectSelector(default=cm["fire"], objects=cm.values())
    plot        = param.ObjectSelector(default="op0",   objects=["op0","op1"])
    passengers  = param.ObjectSelector(default=372,          objects=nodes_counts)

    def make_view(self, x_range=None, y_range=None, **kwargs):
        df_filt = merged[merged.nodeid==self.passengers]
        df_filt = df_filt[df_filt.latitude.notnull()]
        df_filt = df_filt[df_filt.longitude.notnull()]
        df_filt = df_filt[df_filt.rtt.notnull()]
        #df_filt = df_filt['2017-09-18 06:00:00' : '2017-09-18 12:00:00']  

        kdims=[ "latitude", "longitude", ]
        vdims = ['rtt','speed']
        gvdata = gv.Dataset(df_filt,kdims=kdims,vdims=vdims,)

        points = gvdata.to(gv.Points, kdims=['longitude', 'latitude'],vdims=['rtt','speed'])

        #points = datashade(points,  element_type=gv.Image, dynamic=False, width=600, height=600, aggregator=ds.mean('rtt'), cmap=self.colormap)

        %%opts WMTS [apply_ranges=True width=500 height=500 xaxis=None yaxis=None]

        %%opts Overlay [apply_ranges=True width=500 height=500 xaxis=None yaxis=None] 
        %%opts Points [apply_ranges=True] WMTS (alpha=0.5) NdOverlay [tools=['tap']]

        return  gv.WMTS(tiles["Stamen Toner"]) * points`

If I uncoment line with datashed, points are drawn, but not aligned to map.

jbednar commented 6 years ago

The %% lines here will have no effect; those are IPython cell magics and they are used only at the start of an IPython/Jupyter notebook cell. It's hard to debug the code without being able to run it...

ivek1312 commented 6 years ago

Here is example https://github.com/ivek1312/example which is drawing unaligned data.

philippjfr commented 6 years ago

@ivek1312 The data you posted above is definitely not Web Mercator, GeoViews just transforms it for you automatically. Try this:

hv.opts('WMTS [apply_ranges=True width=500 height=500 xaxis=None yaxis=None]')
hv.opts('Overlay [apply_ranges=True width=500 height=500 xaxis=None yaxis=None]')
hv.opts('Points [apply_ranges=True] WMTS (alpha=0.5) NdOverlay [tools=['tap']]')

class Options(hv.streams.Stream):
    alpha       = param.Magnitude(default=0.75, doc="Alpha value for the map opacity")
    colormap    = param.ObjectSelector(default=cm["fire"], objects=cm.values())
    plot        = param.ObjectSelector(default="op0",   objects=["op0","op1"])
    passengers  = param.ObjectSelector(default=372,          objects=nodes_counts)

    def make_view(self, x_range=None, y_range=None, **kwargs):
        df_filt = merged[merged.nodeid==self.passengers]
        df_filt = df_filt[df_filt.latitude.notnull()]
        df_filt = df_filt[df_filt.longitude.notnull()]
        df_filt = df_filt[df_filt.rtt.notnull()]
        #df_filt = df_filt['2017-09-18 06:00:00' : '2017-09-18 12:00:00']  

        kdims=[ "longitude", "latitude"]
        vdims = ['rtt','speed']
        points = gv.Points(df_filt, kdims=kdims, vdims=vdims)
        points = gv.operation.project_points(points)
        points = datashade(points,  element_type=gv.Image, dynamic=False, width=600, height=600, aggregator=ds.mean('rtt'), cmap=self.colormap)

        return  gv.WMTS(tiles["Stamen Toner"]) * points

The gv.operation.project_points bit is what projects your coordinates from latitudes/longitudes to web mercator northings and eastings.

ivek1312 commented 6 years ago

Thanks. It works now.

gaswani commented 5 years ago

Hi @jbednar I have successfully done the installation of the tutorial ( conda create -n pyviz-tutorial python=3.6 ), and I able to get all the notebooks in the tutorial. When I run all the cells of Tutorial 0. Setup I am getting the expected outputs with the exception of cell number 10 which gives the following error : ModuleNotFoundError: No module named 'datashader'. See attached a screenshot of the notebook with the error. How can I resolve this error? I have tried pip installing datashader but the error still persists. Thanks in advance.

Screenshot 2019-06-13 at 14 52 29
jbednar commented 5 years ago

One way or another, your environment isn't set up properly. Maybe you haven't activated the tutorial environment, so that you're getting holoviews from a different environment? In any case you shouldn't need pip; you'd do conda install -c pyviz datashader to get datashader. But really I wouldn't try fetching individual packages like that, or you'll be on a never-ending spiral of trying to track down everything. Rather, I'd go over the instructions again from the top. Note that we're about to release an updated version of the tutorials at pyviz.org (@jsignell can say when that's ready), fixing some issues people had installing things (though not datashader).

gaswani commented 5 years ago

Hi @jbednar Thanks for your reply? What does this step mean? : "Step 3: Install the tutorials in your current working directory and download data". My pyviz-tutorial is installed in a folder called envs (macbookpro/anaconda3/envs). Should my pyviz-examples be installed in the same folder?

jsignell commented 5 years ago

It shouldn't matter where your pyviz-examples folder is. It does matter what environment you launch jupyter notebook from. Did you run conda activate pyviz-tutorial and then jupyter notebook

gaswani commented 5 years ago

Hi @jsignell Thanks for your reply. Installation was ok until the point i was required to : "conda activate pyviz-tutorial". My terminal returned an error that i need to conda init , which i did by running conda init bash. I still got errors.

The installation instructions suggested that I try "source activate pyviz-tutorial" and this worked. I managed to complete the installation and launched my 0-setup notebook directly from jupyter notebook. When i ran all cell theonly error i got was "no module named "datashader"

gaswani commented 5 years ago

Hi @jbednar @jsignell I have one more time followed the installation steps carefully and this time round the installation was successful, and I executed the notebooks without errors. The problem was I hadn't configured the environment correctly. Thanks for your support.

jsignell commented 5 years ago

I'm glad you got up and running :)

gaswani commented 5 years ago

Hi @jsignell @jbednar :-) Yesterday @jbednar commented that Note that we're about to release an updated version of the tutorials at pyviz.org (@jsignell can say when that's ready), fixing some issues people had installing things (though not datashader).". When will you release the updated version, and will you make an announcement? Thanks

jsignell commented 5 years ago

I released the updated version yesterday, but I think we'll hold off on the announcement for a week or so.