Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract_geographical_watershed_properties.ipynb: fix run failure in n…
…ew Jupyter env Fixes #392. With the new Jupypter env for latest RavenPy `0.5.2` from PR Ouranosinc/PAVICS-e2e-workflow-tests#75 `Extract_geographical_watershed_properties.ipynb` fails with the following error below. ``` 23:00:58 _ raven-master/docs/source/notebooks/Extract_geographical_watershed_properties.ipynb::Cell 7 _ 23:00:58 Notebook cell execution failed 23:00:58 Cell 7: Cell execution caused an exception 23:00:58 23:00:58 Input: 23:00:58 # Note that geojson, and rasterio/rioxarray need to be installed for this to work. 23:00:58 # In the next birdy release, the tiff grid will be automatically converted to a DataArray. 23:00:58 # Here we need to manually convert it. 23:00:58 features, statistics, grid = stats_resp.get(asobj=True) 23:00:58 23:00:58 with rasterio.io.MemoryFile(grid[0]) as memfile: 23:00:58 with memfile.open() as dataset: 23:00:58 grid = rio.open_rasterio(dataset) 23:00:58 23:00:58 grid.plot() 23:00:58 23:00:58 Traceback: 23:00:58 23:00:58 --------------------------------------------------------------------------- 23:00:58 ValueError Traceback (most recent call last) 23:00:58 <ipython-input-8-8b167a3ecdc9> in <module> 23:00:58 4 features, statistics, grid = stats_resp.get(asobj=True) 23:00:58 5 23:00:58 ----> 6 with rasterio.io.MemoryFile(grid[0]) as memfile: 23:00:58 7 with memfile.open() as dataset: 23:00:58 8 grid = rio.open_rasterio(dataset) 23:00:58 23:00:58 /opt/conda/envs/birdy/lib/python3.7/site-packages/rasterio/io.py in __init__(self, file_or_bytes, dirname, filename, ext) 23:00:58 103 """ 23:00:58 104 super(MemoryFile, self).__init__( 23:00:58 --> 105 file_or_bytes=file_or_bytes, dirname=dirname, filename=filename, ext=ext) 23:00:58 106 23:00:58 107 @ensure_env 23:00:58 23:00:58 rasterio/_io.pyx in rasterio._io.MemoryFileBase.__init__() 23:00:58 23:00:58 /opt/conda/envs/birdy/lib/python3.7/site-packages/xarray/core/common.py in __bool__(self) 23:00:58 127 23:00:58 128 def __bool__(self: Any) -> bool: 23:00:58 --> 129 return bool(self.values) 23:00:58 130 23:00:58 131 def __float__(self: Any) -> float: 23:00:58 23:00:58 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 23:00:58 23:00:58 _ raven-master/docs/source/notebooks/Extract_geographical_watershed_properties.ipynb::Cell 10 _ 23:00:58 Notebook cell execution failed 23:00:58 Cell 10: Cell execution caused an exception 23:00:58 23:00:58 Input: 23:00:58 unique, counts = numpy.unique(grid.sel(band=1), return_counts=True) 23:00:58 display(unique, counts) 23:00:58 23:00:58 # Pixels values at '127' are NaN and can be ignored. 23:00:58 plt.bar(unique[:-1], counts[:-1]) 23:00:58 plt.show() 23:00:58 23:00:58 grid.where(grid != 127).sel(band=1).plot.imshow(cmap="tab20") 23:00:58 plt.show() 23:00:58 23:00:58 Traceback: 23:00:58 23:00:58 --------------------------------------------------------------------------- 23:00:58 AttributeError Traceback (most recent call last) 23:00:58 <ipython-input-11-a26c52126e9c> in <module> 23:00:58 ----> 1 unique, counts = numpy.unique(grid.sel(band=1), return_counts=True) 23:00:58 2 display(unique, counts) 23:00:58 3 23:00:58 4 # Pixels values at '127' are NaN and can be ignored. 23:00:58 5 plt.bar(unique[:-1], counts[:-1]) 23:00:58 23:00:58 AttributeError: 'list' object has no attribute 'sel' 23:00:58 23:00:58 _ raven-master/docs/source/notebooks/Extract_geographical_watershed_properties.ipynb::Cell 11 _ 23:00:58 Notebook cell execution failed 23:00:58 Cell 11: Cell execution caused an exception 23:00:58 23:00:58 Input: 23:00:58 import cartopy.crs as ccrs 23:00:58 23:00:58 # Set a CRS transformation: 23:00:58 crs = ccrs.LambertConformal( 23:00:58 central_latitude=49, central_longitude=-95, standard_parallels=(49, 77) 23:00:58 ) 23:00:58 23:00:58 ax = plt.subplot(projection=crs) 23:00:58 grid.name = "Land Use Categories" 23:00:58 grid.where(grid != 127).sel(band=1).plot.imshow(ax=ax, transform=crs, cmap="tab20") 23:00:58 plt.show() 23:00:58 23:00:58 Traceback: 23:00:58 23:00:58 --------------------------------------------------------------------------- 23:00:58 AttributeError Traceback (most recent call last) 23:00:58 <ipython-input-12-f9fdb6f0e562> in <module> 23:00:58 7 23:00:58 8 ax = plt.subplot(projection=crs) 23:00:58 ----> 9 grid.name = "Land Use Categories" 23:00:58 10 grid.where(grid != 127).sel(band=1).plot.imshow(ax=ax, transform=crs, cmap="tab20") 23:00:58 11 plt.show() 23:00:58 23:00:58 AttributeError: 'list' object has no attribute 'name' ```
- Loading branch information