import xarray as xr
import hvplot.xarray
import holoviews; print(holoviews.__version__)
1.14.0
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'
da = xr.open_rasterio(url).squeeze(dim='band')
print(da)
<xarray.DataArray (y: 7971, x: 7871)> [62739741 values with dtype=uint16] Coordinates: band int64 1 * y (y) float64 5.374e+06 5.374e+06 5.374e+06 ... 5.135e+06 5.135e+06 * x (x) float64 3.525e+05 3.525e+05 3.526e+05 ... 5.886e+05 5.886e+05 Attributes: transform: (30.0, 0.0, 352485.0, 0.0, -30.0, 5374215.0) crs: +init=epsg:32610 res: (30.0, 30.0) is_tiled: 1 nodatavals: (nan,) scales: (1.0,) offsets: (0.0,) AREA_OR_POINT: Point
da.attrs['nodatavals'] = 0
da.attrs['missing_value'] = 0
da.attrs['_FillValue'] = 0
da.attrs['NODATA'] = 0
print(da)
<xarray.DataArray (y: 7971, x: 7871)> [62739741 values with dtype=uint16] Coordinates: band int64 1 * y (y) float64 5.374e+06 5.374e+06 5.374e+06 ... 5.135e+06 5.135e+06 * x (x) float64 3.525e+05 3.525e+05 3.526e+05 ... 5.886e+05 5.886e+05 Attributes: transform: (30.0, 0.0, 352485.0, 0.0, -30.0, 5374215.0) crs: +init=epsg:32610 res: (30.0, 30.0) is_tiled: 1 nodatavals: 0 scales: (1.0,) offsets: (0.0,) AREA_OR_POINT: Point missing_value: 0 _FillValue: 0 NODATA: 0
By default rasterize
renders the missing value 0 in this uint16
data here:
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
da.hvplot.image(x='x', y='y', crs='epsg:32610', tiles='OSM',
rasterize=True, frame_width=300).redim.nodata(value=0)