holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 404 forks source link

Even sampling error when using regrid operation #2276

Closed jlstevens closed 6 years ago

jlstevens commented 6 years ago

When using datetimes and regrid on an Image containing an xarray, I get an error regarding the sampling. First the imports:

import time
import datetime
import numpy as np
import xarray as xr
import holoviews as hv
from holoviews.operation.datashader import regrid
hv.extension('bokeh')

Now I generate what should be a perfectly evenly sampled xarray, stick it into an Image and the run regrid:

interval = 70
now = datetime.datetime.now()
timedelta = datetime.timedelta(seconds=interval)
time = [now + (i * timedelta) for i in range(50)]
xvals = np.linspace(1,10, 50)
vals = np.random.rand(50,50)
arr = xr.DataArray(vals, coords={'time': time, 'xvals': xvals},
                   dims=['xvals', 'time'])

image = hv.Image(arr, ['time', 'xvals'])  # This displays fine
regrid(image,  aggregator='mean')

Although the image displays fine, using regrid gives the following exception (end of the traceback):

~/Desktop/development/holoviews/holoviews/element/raster.py in __init__(self, data, kdims, vdims, bounds, extents, xdensity, ydensity, **params)
    269 
    270         # Ensure coordinates are regularly sampled
--> 271         validate_regular_sampling(self, 0)
    272         validate_regular_sampling(self, 1)
    273 

~/Desktop/development/holoviews/holoviews/element/util.py in validate_regular_sampling(img, dimension, rtol)
    300                          "please use the QuadMesh element for "
    301                          "unevenly or irregularly sampled data." %
--> 302                          (type(img).__name__, dim))

ValueError: Image dimension time is not evenly sampled, please use the QuadMesh element for unevenly or irregularly sampled data.
jlstevens commented 6 years ago

Note that if I comment out the code that generates the sampling validation exception, it displays fine.

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.