Skip to content

Commit

Permalink
Fix for xarray 0.17 raster files, supporting various nodata conventio…
Browse files Browse the repository at this point in the history
…ns (#991)
  • Loading branch information
jbednar committed Mar 8, 2021
1 parent 160ea32 commit fcb2950
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions datashader/core.py
Expand Up @@ -1130,8 +1130,19 @@ def raster(self,
coords = {xdim: xs, ydim: ys}
dims = [ydim, xdim]
attrs = dict(res=res[0])
if source._file_obj is not None and hasattr(source._file_obj, 'nodata'):
attrs['nodata'] = source._file_obj.nodata

# Find nodata value if available in any of the common conventional locations
# See https://corteva.github.io/rioxarray/stable/getting_started/nodata_management.html
# and https://github.com/holoviz/datashader/issues/990
for a in ['_FillValue', 'missing_value', 'fill_value', 'nodata', 'NODATA']:
if a in source.attrs:
attrs['nodata'] = source.attrs[a]
break
if 'nodata' not in attrs:
try:
attrs['nodata'] = source.attrs['nodatavals'][0]
except:
pass

# Handle DataArray with layers
if data.ndim == 3:
Expand Down
2 changes: 1 addition & 1 deletion datashader/tests/test_antialias.py
@@ -1,4 +1,4 @@
"""Tests for antialiased line drawing in Datasahder"""
"""Tests for antialiased line drawing in Datashader"""

# The single-pixel width tests consist of 6 test cases, each drawing a
# different set of lines on a square canvas. Tests 1 to 4 are all sets of lines
Expand Down

0 comments on commit fcb2950

Please sign in to comment.