Closed kcpevey closed 5 years ago
Similar to the GrabCut.ipynb example, I have:
da = xr.open_rasterio(workdir + '/world_imagery_utm15.tif') rgb = gv.RGB((da.x, da.y, da[0], da[1], da[2]), vdims=['R', 'G', 'B'], crs=ccrs.UTM(18)) background = np.array([ [-77.3777271 , 34.66037492], [-77.35987035, 34.62251189], [-77.34130751, 34.64016586], [-77.35563287, 34.65360275], [-77.36083954, 34.66560481], [-77.3777271 , 34.66037492] ]) foreground = np.array([ [-77.46585666, 34.66965009], [-77.46451121, 34.62795592], [-77.43105867, 34.64501054], [-77.41376085, 34.62573423], [-77.37886112,34.63780581], [-77.41283172, 34.6800562 ], [-77.46585666, 34.66965009] ]) dashboard = GrabCutDashboard(rgb, fg_data=[foreground], bg_data=[background], height=600)
The correct projection for the rgb image was UTM 15, but when I specify UTM 18 (like I have above), I get the following error:
WARNING:root:<bound method GrabCutDashboard.extract_foreground of GrabCutDashboard(crs=<cartopy.crs.PlateCarree object at 0x00000250D5B53468>,downsample=1.0,height=600,iterations=5,minimum_size=10,path_type=<class 'geoviews.element.geo.Path'>,update_contour=<function GrabCutDashboard.<lambda> at 0x00000250D3789E18>,width=500)>: Exception raised in callable '<bound method GrabCutDashboard.extract_foreground of GrabCutDashboard(crs=<cartopy.crs.PlateCarree object at 0x00000250D5B53468>,downsample=1.0,height=600,iterations=5,minimum_size=10,path_type=<class 'geoviews.element.geo.Path'>,update_contour=<function GrabCutDashboard.<lambda> at 0x00000250D3789E18>,width=500)>' of type 'method'. Invoked as <bound method GrabCutDashboard.extract_foreground of GrabCutDashboard(crs=<cartopy.crs.PlateCarree object at 0x00000250D5B53468>,downsample=1.0,height=600,iterations=5,minimum_size=10,path_type=<class 'geoviews.element.geo.Path'>,update_contour=<function GrabCutDashboard.<lambda> at 0x00000250D3789E18>,width=500)>(crs=<cartopy.crs.PlateCarree object at 0x00000250D5B53468>, downsample=1.0, height=600, iterations=5, minimum_size=10, path_type=<class 'geoviews.element.geo.Path'>, update_contour=<function GrabCutDashboard.<lambda> at 0x00000250D3789E18>, width=500) WARNING:root:dynamic_operation: Exception raised in callable 'dynamic_operation' of type 'function'. Invoked as dynamic_operation(filter=False) WARNING:root:dynamic_operation: Exception raised in callable 'dynamic_operation' of type 'function'. Invoked as dynamic_operation(filter=False) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) C:\ProgramData\Anaconda3\envs\earthsim\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\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\earthsim\lib\site-packages\holoviews\plotting\renderer.py in components(self, obj, fmt, comm, **kwargs) 327 plot = obj 328 else: --> 329 plot, fmt = self._validate(obj, fmt) 330 331 widget_id = None C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\plotting\renderer.py in _validate(self, obj, fmt, **kwargs) 226 if isinstance(obj, tuple(self.widgets.values())): 227 return obj, 'html' --> 228 plot = self.get_plot(obj, renderer=self, **kwargs) 229 230 fig_formats = self.mode_formats['fig'][self.mode] C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\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\earthsim\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, renderer) 193 194 # Initialize DynamicMaps with first data item --> 195 initialize_dynamic(obj) 196 197 if not isinstance(obj, Plot): C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\plotting\util.py in initialize_dynamic(obj) 242 continue 243 if not len(dmap): --> 244 dmap[dmap._initial_key()] 245 246 C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key) 1132 # Not a cross product and nothing cached so compute element. 1133 if cache is not None: return cache -> 1134 val = self._execute_callback(*tuple_key) 1135 if data_slice: 1136 val = self._dataslice(val, data_slice) C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args) 911 912 with dynamicmap_memoization(self.callback, self.streams): --> 913 retval = self.callback(*args, **kwargs) 914 return self._style(retval) 915 C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs) 572 573 try: --> 574 ret = self.callable(*args, **kwargs) 575 except KeyError: 576 # KeyError is caught separately because it is used to signal C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key, **kwargs) 435 def dynamic_operation(*key, **kwargs): 436 self.p.kwargs.update(kwargs) --> 437 return self._process(map_obj[key], key) 438 if isinstance(self.p.operation, Operation): 439 return OperationCallable(dynamic_operation, inputs=[map_obj], C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key) 1132 # Not a cross product and nothing cached so compute element. 1133 if cache is not None: return cache -> 1134 val = self._execute_callback(*tuple_key) 1135 if data_slice: 1136 val = self._dataslice(val, data_slice) C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args) 911 912 with dynamicmap_memoization(self.callback, self.streams): --> 913 retval = self.callback(*args, **kwargs) 914 return self._style(retval) 915 C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs) 572 573 try: --> 574 ret = self.callable(*args, **kwargs) 575 except KeyError: 576 # KeyError is caught separately because it is used to signal C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key, **kwargs) 435 def dynamic_operation(*key, **kwargs): 436 self.p.kwargs.update(kwargs) --> 437 return self._process(map_obj[key], key) 438 if isinstance(self.p.operation, Operation): 439 return OperationCallable(dynamic_operation, inputs=[map_obj], C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key) 1132 # Not a cross product and nothing cached so compute element. 1133 if cache is not None: return cache -> 1134 val = self._execute_callback(*tuple_key) 1135 if data_slice: 1136 val = self._dataslice(val, data_slice) C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args) 911 912 with dynamicmap_memoization(self.callback, self.streams): --> 913 retval = self.callback(*args, **kwargs) 914 return self._style(retval) 915 C:\ProgramData\Anaconda3\envs\earthsim\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs) 572 573 try: --> 574 ret = self.callable(*args, **kwargs) 575 except KeyError: 576 # KeyError is caught separately because it is used to signal c:\projects\ers\github\earthsim_pyviz\master\earthsim\earthsim\grabcut.py in extract_foreground(self, **kwargs) 173 with warnings.catch_warnings(): 174 warnings.filterwarnings('ignore') --> 175 foreground = gv.Path([contours(foreground, filled=True, levels=1).split()[0].data], 176 kdims=foreground.kdims, crs=foreground.crs) 177 self.result = gv.project(foreground, projection=self.crs) IndexError: list index out of range :Layout .DynamicMap.I :DynamicMap [] :Overlay .RGB.I :RGB [Longitude,Latitude] (R,G,B) .Path.I :Path [Longitude,Latitude] .Path.II :Path [Longitude,Latitude] .DynamicMap.II :DynamicMap []
I change it to UTM 15 and it works beautifully. I tried changing the crs in the GrabCut example notebook, but I couldn't make the same error happen.
Here's the image in question:
world_imagery_utm15.zip
@kcpevey Do you know if this actually improved?
Similar to the GrabCut.ipynb example, I have:
The correct projection for the rgb image was UTM 15, but when I specify UTM 18 (like I have above), I get the following error:
I change it to UTM 15 and it works beautifully. I tried changing the crs in the GrabCut example notebook, but I couldn't make the same error happen.