-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
RGB #130
Comments
Thanks for adding this @philippjfr, it seems hvplot.rgb() doesn't work with DataArray types only DataSet: import xarray as xr
import holoviews as hv
import hvplot
da = xr.open_rasterio('https://s3.amazonaws.com/earth-data/UCMerced_LandUse/Images/airplane/airplane00.tif')
# works:
da.plot.imshow()
hv.RGB(da.transpose('y','x','band').data).options(invert_yaxis=True) #works
# errors with DataArray
#hv.RGB(da.transpose('y','x','band').data, bounds=(0,256,0,256)).options(invert_yaxis=True) #error (ZeroDivisionError: float division by zero)
#da.hvplot.rgb() #error (KeyError: None)
#da.hvplot.rgb(x='x', y='y', bands='bands') #error (KeyError: None)
# rgb() works with Dataset instead of DataArray:
ds = da.to_dataset(name='z')
ds.hvplot.rgb(z='z', bands='bands') |
Thanks @scottyhq, I'll have a look and push a micro release out asap. |
Fixed in #138. |
Great! thanks for such a speedy fix. I also noticed a possible bug trying to browse multiple thumbnails with different sizes. Seems that the 'band' coordinate has to be first in order for the following to work. Might want to add another unit test for this case: # Gives Error: WARNING:root:dynamic_operation: Callable raised "IndexError('index 3 is out of bounds for axis 0 with size 3')".
url1 = 'https://s3-us-west-2.amazonaws.com/landsat-pds/c1/L8/047/027/LC08_L1TP_047027_20130421_20170310_01_T1/LC08_L1TP_047027_20130421_20170310_01_T1_thumb_large.jpg'
da1 = xr.open_rasterio(url1)
url2 = 'https://s3-us-west-2.amazonaws.com/landsat-pds/c1/L8/047/027/LC08_L1TP_047027_20130523_20170310_01_T1/LC08_L1TP_047027_20130523_20170310_01_T1_thumb_large.jpg'
da2 = xr.open_rasterio(url2)
ds = xr.concat([da1,da2], 'time')
ds = ds.assign_coords(time=[0,1]).to_dataset(name='z')
print(ds)
ds.hvplot.rgb('x','y', z='z',bands='band',groupby='time', width=700, height=500) # Works if 'band' is first coordinate
coords = dict(band=(['band'], ds.coords['band'].values),
time=(['time'], ds.coords['time'].values),
y=(['y'], ds.coords['y'].values),
x=(['x'], ds.coords['x'].values),
)
ds = xr.Dataset({'z': (['time','band','y','x'], ds['z'].data.astype('uint8'))}, coords=coords)
print(ds)
ds.hvplot.rgb('x','y', z='z',bands='band',groupby='time', width=700, height=500) |
I think the issues have now been resolved, please reopen if issues persist. |
I was working with an
xarray.DataArray
with shape MxNx3 stored as adask.array
:There are some issues that need to be resolved with holoviews first (holoviz/holoviews#3311), but then it would be nice to implement RGB in hvplot.
This would be particularly nice if the intake-xarray image plugin (intake/intake-xarray#25) gets in since we could then support RGB plotting in the intake plotting API.
For a comparison with matplotlib and full traceback:
https://gist.github.com/jsignell/4eeef0850708625e0b444db34600ea98
The text was updated successfully, but these errors were encountered: