#!/usr/bin/env python # coding: utf-8 # ### Demonstrate new capability in Holoviz 1.14.0 to make missing data transparent when rasterizing integer data # In[1]: import xarray as xr import hvplot.xarray import holoviews; print(holoviews.__version__) # In[2]: url = 'https://landsat-pds.s3.amazonaws.com/c1/L8/047/027/LC08_L1TP_047027_20190406_20190422_01_T1/LC08_L1TP_047027_20190406_20190422_01_T1_B2.TIF' # In[3]: da = xr.open_rasterio(url).squeeze(dim='band') # In[4]: print(da) # In[5]: da.attrs['nodatavals'] = 0 da.attrs['missing_value'] = 0 da.attrs['_FillValue'] = 0 da.attrs['NODATA'] = 0 # In[6]: print(da) # In[ ]: # By default `rasterize` renders the missing value 0 in this `uint16` data here: # In[7]: da.hvplot.image(x='x', y='y', crs='epsg:32610', tiles='OSM', rasterize=True, frame_width=300) # We can now specify a `nodata` value to avoid this. See Holoviews [Working with Large Data](https://holoviews.org/user_guide/Large_Data.html) # In[8]: da.hvplot.image(x='x', y='y', crs='epsg:32610', tiles='OSM', rasterize=True, frame_width=300).redim.nodata(value=0)