Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: Dimension not found, even though dimension exists #72

Closed
madHatter106 opened this issue Jun 5, 2017 · 11 comments
Closed

KeyError: Dimension not found, even though dimension exists #72

madHatter106 opened this issue Jun 5, 2017 · 11 comments

Comments

@madHatter106
Copy link

Hi,
the code below used to work but has ceased to do so.
For context, working with the following geoviews dataset:

gvDataset.dimensions()
[Dimension('lon'),
Dimension('lat'),
Dimension('experiment'),
Dimension('rrs_unc')]

where
gvDataset['experiment']
array(['O3', 'Pressure', 'WindSpeed', ..., 'Lt', 'All', 'RH'], dtype=object)

then...
image = gvDataset.to(gv.Image, ['lat', 'lon'] ) * gf.land(style=dict(facecolor='gray'))
yields...

KeyError Traceback (most recent call last)
in ()
3 ancMin, ancMax = 1e-6, 1e-4
4 gvDataset = MakeGvDS(band)
----> 5 image = gvDataset.to(gv.Image, geodims) * gf.land(style=dict(facecolor='gray'))
6 layout = hv.NdLayout(image)
7 layout.cols(2)

~/anaconda3/lib/python3.5/site-packages/geoviews/element/init.py in call(self, *args, **kwargs)
24 if 'crs' not in kwargs and issubclass(group_type, _Element):
25 kwargs['crs'] = self._element.crs
---> 26 return super(GeoConversion, self).call(*args, **kwargs)
27
28 def linecontours(self, kdims=None, vdims=None, mdims=None, **kwargs):

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/init.py in call(self, new_type, kdims, vdims, groupby, sort, **kwargs)
132 return element.sort() if sort else element
133 group = selected.groupby(groupby, container_type=HoloMap,
--> 134 group_type=new_type, **params)
135 if sort:
136 return group.map(lambda x: x.sort(), [new_type])

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/init.py in groupby(self, dimensions, container_type, group_type, dynamic, **kwargs)
549
550 return self.interface.groupby(self, dim_names, container_type,
--> 551 group_type, **kwargs)
552
553 def len(self):

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/xarray.py in groupby(cls, dataset, dimensions, container_type, group_type, **kwargs)
123 if drop_dim:
124 v = v.to_dataframe().reset_index()
--> 125 data.append((k, group_type(v, **group_kwargs)))
126 else:
127 unique_iters = [cls.values(dataset, d, False) for d in group_by]

~/anaconda3/lib/python3.5/site-packages/geoviews/element/geo.py in init(self, data, **kwargs)
81 elif crs:
82 kwargs['crs'] = crs
---> 83 super(_Element, self).init(data, **kwargs)
84
85

~/anaconda3/lib/python3.5/site-packages/holoviews/element/raster.py in init(self, data, bounds, extents, xdensity, ydensity, **params)
257 SheetCoordinateSystem.init(self, bounds, xdensity, ydensity)
258
--> 259 if len(self.shape) == 3:
260 if self.shape[2] != len(self.vdims):
261 raise ValueError("Input array has shape %r but %d value dimensions defined"

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/init.py in shape(self)
565 def shape(self):
566 "Returns the shape of the data."
--> 567 return self.interface.shape(self)
568
569

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/grid.py in shape(cls, dataset, gridded)
101 return dataset.data[dataset.vdims[0].name].shape
102 else:
--> 103 return (cls.length(dataset), len(dataset.dimensions()))
104
105

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/xarray.py in length(cls, dataset)
249 @classmethod
250 def length(cls, dataset):
--> 251 return np.product(dataset[dataset.vdims[0].name].shape)
252
253 @classmethod

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/init.py in getitem(self, slices)
377 value_select = None
378 if len(slices) == 1 and slices[0] in self.dimensions():
--> 379 return self.dimension_values(slices[0])
380 elif len(slices) == self.ndims+1 and slices[self.ndims] in self.dimensions():
381 selection = dict(zip(self.dimensions('key', label=True), slices))

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/init.py in dimension_values(self, dim, expanded, flat)
574 """
575 dim = self.get_dimension(dim, strict=True)
--> 576 return self.interface.values(self, dim, expanded, flat)
577
578

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/xarray.py in values(cls, dataset, dim, expanded, flat)
157 if dim in dataset.vdims:
158 coord_dims = dataset.data[dim.name].dims
--> 159 data = cls.canonicalize(dataset, data, coord_dims=coord_dims)
160 return data.T.flatten() if flat else data
161 elif expanded:

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/grid.py in canonicalize(cls, dataset, data, coord_dims)
143 slices = []
144 for d in coord_dims:
--> 145 coords = cls.coords(dataset, d)
146 if np.all(coords[1:] < coords[:-1]):
147 slices.append(slice(None, None, -1))

~/anaconda3/lib/python3.5/site-packages/holoviews/core/data/xarray.py in coords(cls, dataset, dim, ordered, expanded)
142 @classmethod
143 def coords(cls, dataset, dim, ordered=False, expanded=False):
--> 144 dim = dataset.get_dimension(dim, strict=True).name
145 if expanded:
146 return util.expand_grid_coords(dataset, dim)

~/anaconda3/lib/python3.5/site-packages/holoviews/core/dimension.py in get_dimension(self, dimension, default, strict)
892 name_map.update({dimension_sanitizer(dim.name): dim for dim in all_dims})
893 if strict and dimension not in name_map:
--> 894 raise KeyError("Dimension %s not found" % dimension)
895 else:
896 return name_map.get(dimension, default)

KeyError: 'Dimension experiment not found'

@philippjfr
Copy link
Member

Thanks for reporting this @madHatter106. Could you tell me the versions of holoviews, geoviews and xarray of when it was working and what versions you have now?

@madHatter106
Copy link
Author

madHatter106 commented Jun 5, 2017

Certainly: currently,
gv.version: 1.2.0
hv.version: 1.7.0-x-gf3a9f4f
xr.version: 0.9.5

When it was working:
I believe hv 1.6xx, not sure about the others, I think I did a meta update (all conda packages) about a couple of weeks ago

@philippjfr
Copy link
Member

This may have been fixed in holoviz/holoviews#1467 but I can't be sure. We'll have a dev release later tonight at which point you can get it with conda install -c ioam/label/dev holoviews, would you mind trying that or trying holoviews master right now?

@madHatter106
Copy link
Author

sure, conda reports the master is what I have. I'll wait for the dev then . thanks @philippjfr

@philippjfr
Copy link
Member

Looks like the dev release will happen tomorrow. Any chance you could provide me with a small slice of your dataset containing just a few lats/lons so I can test it?

@madHatter106
Copy link
Author

Sure, thanks. I have a sub-sampled scene, about 1.3 MB. What's the best way to get it to you?

@philippjfr
Copy link
Member

philippjfr commented Jun 6, 2017

Great! At that size email should be okay, could you mail it to philippjfr [at] continuum.io?

@madHatter106
Copy link
Author

Done. Thanks!

@philippjfr
Copy link
Member

I made a fix just before the 1.8dev2 release was out. Unfortunately I now think the fix was incorrect and have submitted a PR for the correct fix here: holoviz/holoviews#1526

@philippjfr
Copy link
Member

Fix has now been merged into holoviews and will be part of the holoviews release early next week.

@returncode13
Copy link

hi @philippjfr ,
I am facing a similar issue when trying to replicate the example code for the iris splom example provided on the holoviews website. http://holoviews.org/gallery/demos/bokeh/iris_splom_example.html
Here is the code

from bokeh.sampledata.iris import flowers
from holoviews.operation import gridmatrix

ds = hv.Dataset(flowers)

grouped_by_species = ds.groupby('species', container_type=hv.NdOverlay)   
grid = gridmatrix(grouped_by_species, diagonal_type=hv.Scatter)

Below is the error

KeyError                                  Traceback (most recent call last)
<ipython-input-57-f2af679219bf> in <module>
      4 ds = hv.Dataset(flowers)
      5 
----> 6 grouped_by_species = ds.groupby('species', container_type=hv.NdOverlay)
      7 grid = gridmatrix(grouped_by_species, diagonal_type=hv.Scatter)

/opt/anaconda3/envs/mlseis368_j/lib/python3.6/site-packages/holoviews/core/data/__init__.py in groupby(self, dimensions, container_type, group_type, dynamic, **kwargs)
    706         if group_type is None: group_type = type(self)
    707 
--> 708         dimensions = [self.get_dimension(d, strict=True) for d in dimensions]
    709         dim_names = [d.name for d in dimensions]
    710 

/opt/anaconda3/envs/mlseis368_j/lib/python3.6/site-packages/holoviews/core/data/__init__.py in <listcomp>(.0)
    706         if group_type is None: group_type = type(self)
    707 
--> 708         dimensions = [self.get_dimension(d, strict=True) for d in dimensions]
    709         dim_names = [d.name for d in dimensions]
    710 

/opt/anaconda3/envs/mlseis368_j/lib/python3.6/site-packages/holoviews/core/dimension.py in get_dimension(self, dimension, default, strict)
   1076         name_map.update({util.dimension_sanitizer(dim.name): dim for dim in all_dims})
   1077         if strict and dimension not in name_map:
-> 1078             raise KeyError("Dimension %r not found." % dimension)
   1079         else:
   1080             return name_map.get(dimension, default)

KeyError: "Dimension 'species' not found."

bokeh version: 1.0.4
hv version: 1.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants