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

RGB #130

Closed
jsignell opened this issue Dec 17, 2018 · 5 comments
Closed

RGB #130

jsignell opened this issue Dec 17, 2018 · 5 comments

Comments

@jsignell
Copy link
Member

I was working with an xarray.DataArray with shape MxNx3 stored as a dask.array:

>>> im
<xarray.DataArray 'getitem-5f1ebf179271ce04f7cbd4e90ec207be' (y: 256, x: 256, band: 3)>
dask.array<shape=(256, 256, 3), dtype=uint8, chunksize=(256, 256, 3)>
Coordinates:
  * y        (y) int64 0 1 2 3 4 5 6 7 8 ... 247 248 249 250 251 252 253 254 255
  * x        (x) int64 0 1 2 3 4 5 6 7 8 ... 247 248 249 250 251 252 253 254 255
  * band     (band) int64 0 1 2

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.

screen shot 2018-12-17 at 10 11 21 am

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

@scottyhq
Copy link

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') 

@philippjfr
Copy link
Member

Thanks @scottyhq, I'll have a look and push a micro release out asap.

@philippjfr
Copy link
Member

Fixed in #138.

@scottyhq
Copy link

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)

@philippjfr
Copy link
Member

I think the issues have now been resolved, please reopen if issues persist.

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