question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error with `Canvas().raster` on xarray 0.17

See original GitHub issue

ALL software version info

The full list is available here, the gist is:

  • Python 3.8
  • xarray 0.17.0
  • datashader 0.12.0

Description of expected behavior and the observed behavior

I expect Canvas().raster to return a DataArray object, instead it returns an error.

Complete, minimal, self-contained example code that reproduces the issue

Adapted from your documentation

from datashader import transfer_functions as tf, reductions as rd
import numpy as np, datashader as ds, xarray as xr

def f(x,y):
    return np.cos((x**2+y**2)**2)

def sample(fn, n=50, range_=(0.0,2.4)):
    xs = ys = np.linspace(range_[0], range_[1], n)
    x,y = np.meshgrid(xs, ys)
    z   = fn(x,y)
    return xr.DataArray(z, coords=[('y',ys), ('x',xs)])

da = sample(f)
ds.Canvas().raster(da, interpolate='linear')

Stack traceback and/or browser JavaScript console output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-7e8b8b432665> in <module>
     12 
     13 da = sample(f)
---> 14 ds.Canvas().raster(da, interpolate='linear')

/opt/conda/lib/python3.8/site-packages/datashader/core.py in raster(self, source, layer, upsample_method, downsample_method, nan_value, agg, interpolate, chunksize, max_mem)
   1131         dims = [ydim, xdim]
   1132         attrs = dict(res=res[0])
-> 1133         if source._file_obj is not None and hasattr(source._file_obj, 'nodata'):
   1134             attrs['nodata'] = source._file_obj.nodata
   1135 

/opt/conda/lib/python3.8/site-packages/xarray/core/common.py in __getattr__(self, name)
    237                 with suppress(KeyError):
    238                     return source[name]
--> 239         raise AttributeError(
    240             "{!r} object has no attribute {!r}".format(type(self).__name__, name)
    241         )

AttributeError: 'DataArray' object has no attribute '_file_obj'

I think this is related to #4809.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
philippjfrcommented, Mar 3, 2021

This was always just a heuristic. I think we should support the major readers and conventions including attrs['NODATA'] and attrs['nodatavals'].

0reactions
ppwadhwacommented, Mar 22, 2021
Screen Shot 2021-03-22 at 10 20 39 AM

This should be fixed in 0.12.1, which is available on the pyviz channel, conda-forge, and pip.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releases — Datashader v0.14.3
Canvas.raster() now accepts xarray Dataset types, not just DataArrays, with the specific DataArray selectable from the Dataset using the column= argument of ...
Read more >
Installation — xarray 0.17.1.dev0+g835a53e6.d20210226 ...
If you are using pip to install xarray, optional dependencies can be ... rasterio: for reading GeoTiffs and other gridded raster datasets.
Read more >
RuntimeWarning when I try to plot a raster - GIS Stack Exchange
I'm be able to plot the source raster without problem: import geopandas as gpd import rioxarray as rxr from xarray.plot import imshow vector ......
Read more >
Pakiety oprogramowania w gałęzi "bionic", Podsekcja python
... bpython3 (0.17.1-1) [universe]: fancy interface to the Python 3 interpreter ... python-bs4 (4.6.0-1): error-tolerant HTML parser for Python ...
Read more >
Activity - QGIS Application - QGIS Issue Tracking
10:01 PM Bug report #17418 (Closed): UnicodeEncodeError when trying to create new layer with spatial index... I tried to upload a layer to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found