creare-com / pydem

Python library for Global Hydrology Analysis. Used to calculate upstream contributing area, aspect, slope, and topographic wetness index.
Apache License 2.0
114 stars 35 forks source link

Type casting problems with SRTM DEM #5

Closed mbjoseph closed 7 years ago

mbjoseph commented 7 years ago

I was hoping to compute slope and aspect for some digital elevation models from the NASA SRTM mission, and ran into a type error that seems to be related to the _find_flats_edges function.

Here's a reproducible example Jupyter notebook that demonstrates the problem: https://gist.github.com/mbjoseph/9934454330b5715db9529502cf415f72#file-pydem-srtm-example-ipynb

A TypeError is raised:

TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('bool') with casting rule 'same_kind'

It seems like similar issues have arisen elsewhere, e.g., https://github.com/numpy/numpy/issues/7225

mpu-creare commented 7 years ago

@mbjoseph I'll have a look later today. I'd rather not intentionally cast unsafely, I'll see if there's another fix.

Thanks for finding this! I haven't kept up with changes in numpy -- evidently. Are you up and running at least? Are you on a windows machine?

mpu-creare commented 7 years ago

@mbjoseph could you try the proposed fix in 311d2171f07ce1fe0955bff194bde573ec1e3d42 ? It's on the develop branch.

mbjoseph commented 7 years ago

Your fix with 311d217 worked beautifully, thanks! Also I was able to replicate this on OSX and Ubuntu - I haven't tried on a Windows machine.

mpu-creare commented 7 years ago

Excellent, I'll push it into master for the next release.