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

Using datetime objects as vdims in gv.Path #214

Closed
kcpevey opened this issue Sep 5, 2018 · 7 comments
Closed

Using datetime objects as vdims in gv.Path #214

kcpevey opened this issue Sep 5, 2018 · 7 comments

Comments

@kcpevey
Copy link
Collaborator

kcpevey commented Sep 5, 2018

Is that possible? Or do all vdims need to be floats?

@philippjfr
Copy link
Contributor

Is that possible? Or do all vdims need to be floats?

Should be possible but I'm not sure what the implications and use cases are. Do you want to color by the value or do something else with it?

@kcpevey
Copy link
Collaborator Author

kcpevey commented Sep 5, 2018

Really I just want to carry it along so that its available via hover tool, table, and then accessing after visualization. As far as the tools are concerned, they can assume that its a formated string or something, they have to "use" it. Does that make sense?

hurricane_path.txt

wind_df = pd.read_csv('../../data/hurricane_path.txt', delimiter=',', header=0, parse_dates=['Datetime'])
gvpath2 = gv.Path([wind_df], kdims=['Longitude', 'Latitude'], vdims=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], crs=proj)
gvpoint2 = gv.Points(wind_df, kdims=['Longitude', 'Latitude'], vdims=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], crs=proj)  
annot = PolyAndPointAnnotator(path_type=Path, polys=[gvpath2], points=gvpoint2,
                              poly_columns=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], 
                              point_columns=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], 
                              tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
                              crs=proj) 

Throws this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-bf81823a86d9> in <module>()
     20                               point_columns=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'],
     21                               tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
---> 22                               crs=proj) 
     23 # annot = PolyAndPointAnnotator(path_type=Path, polys=[gvpath], points=gvpoint,
     24 #                               poly_columns=['Pressure','Max_Wind_Speed'],

c:\projects\ers\github\earthsim\master\earthsim\earthsim\annotators.py in __init__(self, poly_data, **params)
    200         self.poly_stream.source = self.polys
    201         if len(self.polys):
--> 202             poly_data = gv.project(self.polys).split()
    203             self.poly_stream.event(data={kd.name: [p.dimension_values(kd) for p in poly_data]
    204                                          for kd in self.polys.kdims})

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\param\parameterized.py in __new__(class_, *args, **params)
   2231         inst = class_.instance()
   2232         inst.param._set_name(class_.__name__)
-> 2233         return inst.__call__(*args,**params)
   2234 
   2235     def __call__(self,*args,**kw):

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\operation.py in __call__(self, element, **params)
    161                                 operation=self, kwargs=params)
    162         elif isinstance(element, ViewableElement):
--> 163             processed = self._apply(element)
    164         elif isinstance(element, DynamicMap):
    165             if any((not d.values) for d in element.kdims):

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\operation.py in _apply(self, element, key)
    119         for hook in self._preprocess_hooks:
    120             kwargs.update(hook(self, element))
--> 121         ret = self._process(element, key)
    122         for hook in self._postprocess_hooks:
    123             ret = hook(self, ret, **kwargs)

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\geoviews-1.5.4a6-py3.6.egg\geoviews\operation\projection.py in _process(self, element, key)
    415         for op in self._operations:
    416             element = element.map(op.instance(projection=self.p.projection),
--> 417                                   op.supported_types)
    418         return element

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\dimension.py in map(self, map_fn, specs, clone)
    727             return deep_mapped
    728         else:
--> 729             return map_fn(self) if applies else self
    730 
    731 

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\operation.py in __call__(self, element, **params)
    161                                 operation=self, kwargs=params)
    162         elif isinstance(element, ViewableElement):
--> 163             processed = self._apply(element)
    164         elif isinstance(element, DynamicMap):
    165             if any((not d.values) for d in element.kdims):

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\operation.py in _apply(self, element, key)
    119         for hook in self._preprocess_hooks:
    120             kwargs.update(hook(self, element))
--> 121         ret = self._process(element, key)
    122         for hook in self._postprocess_hooks:
    123             ret = hook(self, ret, **kwargs)

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\geoviews-1.5.4a6-py3.6.egg\geoviews\operation\projection.py in _process(self, element, key)
     32 
     33     def _process(self, element, key=None):
---> 34         return element.map(self._process_element, self.supported_types)
     35 
     36 

c:\projects\ers\github\holoviews\master\holoviews\holoviews\core\dimension.py in map(self, map_fn, specs, clone)
    727             return deep_mapped
    728         else:
--> 729             return map_fn(self) if applies else self
    730 
    731 

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\geoviews-1.5.4a6-py3.6.egg\geoviews\operation\projection.py in _process_element(self, element)
    148                 data[vd.name] = values[0] if scalar else values
    149             if any(vals is not None and not np.isscalar(vals) and len(vals) > 1 for vals in data.values()):
--> 150                 projected += self._project_path(element, path, data, boundary, geom_type, multi_type)
    151             else:
    152                 projected += self._project_contour(element, path, data, boundary, geom_type, multi_type)

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\geoviews-1.5.4a6-py3.6.egg\geoviews\operation\projection.py in _project_path(self, element, path, data, boundary, geom_type, multi_type)
     53 
     54         proj_arr = self.p.projection.quick_vertices_transform(
---> 55             np.column_stack([xs, ys]), element.crs)
     56 
     57         if proj_arr is None:

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\site-packages\numpy\lib\shape_base.py in column_stack(tup)
    367             arr = array(arr, copy=False, subok=True, ndmin=2).T
    368         arrays.append(arr)
--> 369     return _nx.concatenate(arrays, 1)
    370 
    371 def dstack(tup):

TypeError: invalid type promotion

I ask the vague initial question because I'm getting the same error when I drop the Datetime column from the df and from the vdims and annotator columns.

@kcpevey
Copy link
Collaborator Author

kcpevey commented Sep 5, 2018

proj=ccrs.PlateCarree()

@kcpevey
Copy link
Collaborator Author

kcpevey commented Sep 7, 2018

This may have been effected by the fix in holoviz/holoviews#2990 . I'm not seeing this error anymore so I'm attaching a new snippet and screen grab. Now, I can add the 'Datetime' column to my point_columns. However, it doesn't display correctly in the point_column. Interestingly enough, it DOES display correctly if I pull the data back out the stream and display as a dframe.

datetime_column

data_df = pd.read_csv('../../data/hurricane_path_color.txt', delimiter=',', header=0, parse_dates=['Datetime'])
gvpath = gv.Path([data_df], kdims=['Longitude', 'Latitude'], vdims=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], crs=proj)
gvpoint = gv.Points(data_df, kdims=['Longitude', 'Latitude'], vdims=['Datetime','Pressure','Max_Wind_Speed','Radius','Direction_Degrees','Direction_Speed'], crs=proj)
annot = PolyAndPointAnnotator(path_type=Path, polys=gvpath, points=gvpoint,
                              point_columns=['Pressure','Max_Wind_Speed'],
                              tile_url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}',
                              crs=proj)

(annot.tiles * annot.polys * annot.points + annot.point_table).cols(1) 

@kcpevey
Copy link
Collaborator Author

kcpevey commented Sep 7, 2018

And one more bit of weirdness... If I modify the Max_Wind_Speed in point_table, then the Datetime type in the stream switches from a datetime object to int64.

point_columns2

@philippjfr
Copy link
Contributor

Will be fixed in holoviz/holoviews#3005

@philippjfr
Copy link
Contributor

There are now new holoviews and geoviews alpha releases with the fix.

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

No branches or pull requests

2 participants