holoviz-topics / EarthSim

Tools for working with and visualizing environmental simulations.
https://earthsim.holoviz.org
BSD 3-Clause "New" or "Revised" License
65 stars 21 forks source link

Error on poly_table when initalizing with grabcut.result (gv.Path) #220

Closed kcpevey closed 5 years ago

kcpevey commented 6 years ago

I'm trying to use the grabcut.result to feed into a new annotator for additional editing and attributing. Instantiating the annotator doesn't throw an error, but if I try to visualize poly_table I'm getting an error.

ann = PolyAndPointAnnotator(path_type=gv.Path,  
                            tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
                            crs=proj_param.get_crs(), points=[],
                            polys=grabcuts.result, poly_columns=['type'])
(ann.tiles * ann.polys * ann.points + ann.poly_table).cols(1)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\IPython\core\formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\core\dimension.py in _repr_mimebundle_(self, include, exclude)
   1263         combined and returned.
   1264         """
-> 1265         return Store.render(self)
   1266 
   1267 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\core\options.py in render(cls, obj)
   1287         data, metadata = {}, {}
   1288         for hook in hooks:
-> 1289             ret = hook(obj)
   1290             if ret is None:
   1291                 continue

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\ipython\display_hooks.py in pprint_display(obj)
    270     if not ip.display_formatter.formatters['text/plain'].pprint:
    271         return None
--> 272     return display(obj, raw_output=True)
    273 
    274 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\ipython\display_hooks.py in display(obj, raw_output, **kwargs)
    243     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    244         with option_state(obj):
--> 245             output = layout_display(obj)
    246     elif isinstance(obj, (HoloMap, DynamicMap)):
    247         with option_state(obj):

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\ipython\display_hooks.py in wrapped(element)
    140         try:
    141             max_frames = OutputSettings.options['max_frames']
--> 142             mimebundle = fn(element, max_frames=max_frames)
    143             if mimebundle is None:
    144                 return {}, {}

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\ipython\display_hooks.py in layout_display(layout, max_frames)
    213         return None
    214 
--> 215     return render(layout)
    216 
    217 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\ipython\display_hooks.py in render(obj, **kwargs)
     63         renderer = renderer.instance(fig='png')
     64 
---> 65     return renderer.components(obj, **kwargs)
     66 
     67 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\renderer.py in components(self, obj, fmt, comm, **kwargs)
    268         # Bokeh has to handle comms directly in <0.12.15
    269         comm = False if bokeh_version < '0.12.15' else comm
--> 270         return super(BokehRenderer, self).components(obj,fmt, comm, **kwargs)
    271 
    272 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\renderer.py in components(self, obj, fmt, comm, **kwargs)
    314             plot = obj
    315         else:
--> 316             plot, fmt = self._validate(obj, fmt)
    317 
    318         widget_id = None

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\renderer.py in _validate(self, obj, fmt, **kwargs)
    213         if isinstance(obj, tuple(self.widgets.values())):
    214             return obj, 'html'
--> 215         plot = self.get_plot(obj, renderer=self, **kwargs)
    216 
    217         fig_formats = self.mode_formats['fig'][self.mode]

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls, obj, doc, renderer)
    153             curdoc().theme = self_or_cls.theme
    154         doc.theme = self_or_cls.theme
--> 155         plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
    156         plot.document = doc
    157         return plot

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, renderer)
    200             init_key = tuple(v if d is None else d for v, d in
    201                              zip(plot.keys[0], defaults))
--> 202             plot.update(init_key)
    203         else:
    204             plot = obj

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\plot.py in update(self, key)
    513     def update(self, key):
    514         if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 515             return self.initialize_plot()
    516         item = self.__getitem__(key)
    517         self.traverse(lambda x: setattr(x, '_updated', True))

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\plot.py in initialize_plot(self, plots, ranges)
    837 
    838                 shared_plots = list(passed_plots) if self.shared_axes else None
--> 839                 subplots = subplot.initialize_plot(ranges=ranges, plots=shared_plots)
    840                 nsubplots = len(subplots)
    841 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\plot.py in initialize_plot(self, ranges, plots)
    957             else:
    958                 passed_plots = plots + adjoined_plots
--> 959                 adjoined_plots.append(subplot.initialize_plot(ranges=ranges, plots=passed_plots))
    960         self.drawn = True
    961         if not adjoined_plots: adjoined_plots = [None]

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\tabular.py in initialize_plot(self, ranges, plot, plots, source)
     61         data, _, style = self.get_data(element, ranges, style)
     62         if source is None:
---> 63             source = self._init_datasource(data)
     64         self.handles['source'] = self.handles['cds'] = source
     65 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\plot.py in _init_datasource(self, data)
    185         Initializes a data source to be passed into the bokeh glyph.
    186         """
--> 187         data = {k: decode_bytes(vs) for k, vs in data.items()}
    188         return ColumnDataSource(data=data)
    189 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\plot.py in <dictcomp>(.0)
    185         Initializes a data source to be passed into the bokeh glyph.
    186         """
--> 187         data = {k: decode_bytes(vs) for k, vs in data.items()}
    188         return ColumnDataSource(data=data)
    189 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\holoviews-1.11.0a4.post13+ga08389fc-py3.6.egg\holoviews\plotting\bokeh\util.py in decode_bytes(array)
     79     decoded = [v.decode('utf-8') if isinstance(v, bytes) else v for v in array]
     80     if isinstance(array, np.ndarray):
---> 81         return np.asarray(decoded)
     82     elif isinstance(array, tuple):
     83         return tuple(decoded)

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
    490 
    491     """
--> 492     return array(a, dtype, copy=False, order=order)
    493 
    494 

ValueError: cannot copy sequence with size 5845 to array axis with dimension 3

:Layout
   .Overlay.I :Overlay
      .WMTS.I   :WMTS   [Longitude,Latitude]
      .Path.I   :Path   [Longitude,Latitude]
      .Points.I :Points   [Longitude,Latitude]   (Size)
   .Table.I   :Table   [type]

This is using https://github.com/pyviz/EarthSim/pull/186

@jlstevens @philippjfr - Any ideas on what's going on here?

kcpevey commented 6 years ago

This is happening even when I explicitly reinstantiate the dframe as a gv.Path.

gvpath = gv.Path([grabcuts.result.dframe()], kdims=['Longitude', 'Latitude'], crs=ccrs.PlateCarree())
ann = PolyAndPointAnnotator(path_type=gv.Path, extent=(np.NaN,)*4, 
                        tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
                            crs=proj_param.get_crs(), points=[],
                            polys=gvpath, poly_columns=['type'])

I'm thinking this might be a bug.

kcpevey commented 6 years ago

@philippjfr Can you weigh in on this?

philippjfr commented 6 years ago

Looking at this tonight.

philippjfr commented 6 years ago

Once again I can't reproduce this, although I can't fully reproduce your example since I do not know what proj_param.get_crs() is, so what I tried was:

ann = PolyAndPointAnnotator(path_type=gv.Path,  
                            tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
                            crs=dashboard.result.crs, points=[],
                            polys=dashboard.result, poly_columns=['type'])
(ann.tiles * ann.polys * ann.points + ann.poly_table).cols(1)
philippjfr commented 6 years ago

For reference here are my versions:

GeoViews: '1.5.4a8.post2+g400b850' HoloViews: ''1.11.0a5.post12'

kcpevey commented 5 years ago

Looks great. I had the same hv but my gv was very slightly behind yours. Everything works now!