Septima / malstroem

Tools for screening of bluespots and water flow between bluespots. Fork of original SDFE repository
Other
7 stars 4 forks source link

Buffer dtype mismatch #5

Open itcarroll opened 5 years ago

itcarroll commented 5 years ago

I have installed malstroem from your fork on a linux platform, but cannot run the given example successfully. I don't know how C extensions for Python work, so I'm at a loss to debug this. Is there additional information I could provide to help?

$ malstroem complete -r 10 -r 30 -filter "maxdepth > 0.05" -dem dem.tif -outdir out
Processing
   dem: dem.tif
   outdir: out
   rain: 10.0mm, 30.0mm
   accum: False
   filter: maxdepth > 0.05
Calculating filled DEM
Calculating bluespot depths
Calculating flow directions
Done
Calculating unfiltered bluespots
Number of bluespots found before filtering: 1788
Calculating filtered bluespots
Number of bluespots left after filtering: 1788
Calculating watersheds
Calculating pour points at min filled
Traceback (most recent call last):
  File "/research-home/icarroll/.local/bin/malstroem", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/research-home/icarroll/.local/lib/python3.5/site-packages/malstroem/scripts/complete.py", line 100, in process_all
    bluespot_tool.process()
  File "/research-home/icarroll/.local/lib/python3.5/site-packages/malstroem/bluespots.py", line 204, in process
    filled_no_flats = fill.fill_terrain_no_flats(dem, short, diag)
  File "/research-home/icarroll/.local/lib/python3.5/site-packages/malstroem/algorithms/fill.py", line 209, in fill_terrain_no_flats
    if keep_going and _fill_terrain_no_flats(dtm, filled, 1, maxrow, 1, maxcol, short, diag):
  File "malstroem/algorithms/speedups/_fill.pyx", line 74, in malstroem.algorithms.speedups._fill._fill_terrain_no_flats
ValueError: Buffer dtype mismatch, expected 'DTYPE_t_DTM' but got 'unsigned short'

Versions Ubuntu==16.04 Python==3.5.2 numpy==1.16.2 Cython==0.29.6 click-log=0.1.8 GDAL==2.1.3 scipy==1.2.1

AsgerPetersen commented 5 years ago

I think this is a bug.

It looks like one of your input rasters has integer cells (possibly your dtm) where malstroem expected float32 cells.

You can cast that raster to float32 and it will hopefully work.

itcarroll commented 5 years ago

Yep, I can bypass the error with gdal_translate -ot Float32 .... This solves my problem, I'll leave the issue open in case you plan to look into the bug.

AsgerPetersen commented 5 years ago

I think we should consider if we can safely do the cast in malstroem.

Otherwise we should show a better error message to the user.