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

Specifying element as df in Annotator #242

Closed kcpevey closed 5 years ago

kcpevey commented 5 years ago

When you specify an element, e.g. polys, with a dataframe in the initialization of an Annotator, it expects it to have 'x' and 'y' columns. However, when I specified my columns names as 'Latitude' and 'Longitude', it gave me an error that is produced is very confusing and misleading:
DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['Longitude', 'Latitude']

To me, this reads that the supplied data is supposed to have the dimensions 'Latitude' and 'Longitude' but it does not. Which of course, my df did specify those so I was confused. It took looking at a working code to discover that the issue was actually that it wanted 'x' and 'y' columns.

dam_df = pd.DataFrame([[272837.5832584698, 4406624.559198088], 
                         [272751.5990310904, 4405736.01443598], 
                         [273032.87337941024, 4405163.269611161]], columns=['Longitude','Latitude'])  
---------------------------------------------------------------------------
DataError                                 Traceback (most recent call last)
<ipython-input-17-ef289de07285> in <module>()
      5                             poly_columns=[],
      6                             polys=[dam_df],
----> 7                             points=reservoir_df)
      8 ###### the above line is broken - if you switch dm_line to boundary_df it will work,
      9 ###### but then you'll need to delete the polygon and draw a reasonable dam line on the map ####

c:\projects\ers\github\es-workflows\updates\es-workflows\es_workflows\adh\model.py in __init__(self, poly_data, **params)
    608 
    609     def __init__(self, poly_data={}, **params):
--> 610         super(adh_annotator, self).__init__(**params)
    611         style = dict(editable=True)
    612         plot = dict(width=self.width, height=self.table_height)

c:\projects\ers\github\earthsim\master\earthsim\earthsim\annotators.py in __init__(self, polys, points, crs, **params)
    101             self.points = points
    102         else:
--> 103             self.points = Points(points, self.polys.kdims, crs=crs).options(**opts)
    104         self.point_stream = PointDraw(source=self.points, data={})
    105 

c:\projects\ers\github\geoviews\master\geoviews\geoviews\element\geo.py in __init__(self, data, kdims, vdims, **kwargs)
     93         elif crs:
     94             kwargs['crs'] = crs
---> 95         super(_Element, self).__init__(data, kdims=kdims, vdims=vdims, **kwargs)
     96 
     97 

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\data\__init__.py in __init__(self, data, kdims, vdims, **kwargs)
    232         (data, self.interface, dims, extra_kws) = initialized
    233         super(Dataset, self).__init__(data, **dict(kwargs, **dict(dims, **extra_kws)))
--> 234         self.interface.validate(self, validate_vdims)
    235 
    236         self.redim = redim(self, mode='dataset')

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\data\pandas.py in validate(cls, dataset, vdims)
    148             raise DataError("Supplied data does not contain specified "
    149                             "dimensions, the following dimensions were "
--> 150                             "not found: %s" % repr(not_found), cls)
    151 
    152 

DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['Longitude', 'Latitude']

PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
philippjfr commented 5 years ago

The problem here is that the code expects the names of the polygon/path dimensions to match those of the points. Since I can't see the columns in the reservoir_df I can't tell if this error is wrong or not. That said we should definitely try to validate it to produce a more informative error.

kcpevey commented 5 years ago

You are correct, reservoir_df had column names of x and y but dam_df had Longitude and Latitude.