pysheds
pysheds copied to clipboard
dtype problem with polygonize
Using polygonize on the output of grid.catchment raises an error:
~/.conda/envs/raven/lib/python3.6/site-packages/rasterio-1.0.1-py3.6-linux-x86_64.egg/rasterio/features.py in shapes(source, mask, connectivity, transform)
106 """
107 transform = guard_transform(transform)
--> 108 for s, v in _shapes(source, mask, connectivity, transform):
109 yield s, v
110
rasterio/_features.pyx in _shapes()
ValueError: image dtype must be one of: int16, int32, uint8, uint16, float32
grid.catchment returns an int64. Converting to int32 apparently solves the issue.
Hi David, thanks for letting me know. A check should probably be added for the datatype.
grid.catchment should probably also return the same datatype as the source flow direction file (unless the nodata and pour_value values don't fit into that datatype).
Note that if you call polygonize with data=None (the default), the input will default to grid.mask. If you previously used grid.clip_to('catch') to clip the mask to the catchment, this should give you an easy way of generating the outline of the catchment:
https://github.com/mdbartos/pysheds/blob/master/examples/shapefiles.ipynb
Looking at the polygonize function, I wonder if the input behavior should be changed to be more consistent with the other functions (e.g. accept a named parameter like 'catch' or 'dem').