pysheds icon indicating copy to clipboard operation
pysheds copied to clipboard

Creating flow direction and accumulation rasters using pysheds.grid methods

Open neko1010 opened this issue 7 years ago • 10 comments

We are looking to create our own flow direction and accumulation rasters rather than use the coarse flow direction datasets available from HYDROSHEDS. Attached are examples of the raster I have been trying to use, but have not been successful using the flowdir function in pysheds.grids, and an example in creating these rasters would be great! I am relatively new to python and programming, so please, be gentle. Thanks! Also- are rasters saved in .tif format supported with this tool?

roi_10m.zip

neko1010 avatar Jul 17 '18 19:07 neko1010

Thanks for posting this.

After examining your data, I realized that my flow direction implementation is incomplete! It doesn't appropriately resolve instances where there are multiple possible flow directions (same elevation change in multiple directions).

ArcGIS seems to solve this issue using a lookup table approach, as shown here: https://www.asprs.org/wp-content/uploads/pers/1987journal/oct/1987_oct_1383-1387.pdf

I should hopefully have this patched by the end of the week.

Thanks, MDB

mdbartos avatar Jul 19 '18 19:07 mdbartos

Greetings.

See the following recipe for a step-by-step guide on how to go from unconditioned DEM data -> flow direction -> accumulation -> catchment.

https://github.com/mdbartos/pysheds/blob/master/recipes/messy_dem.ipynb

I had to add a couple different modules to meet your needs. Make sure you grab the latest copy of pysheds from the github (clone the repo and install).

    $ git clone https://github.com/mdbartos/pysheds.git
    $ cd pysheds
    $ pip install .

In general, the DEM conditioning process is:

  1. Fill pits (grid.fill_pits)
  2. Iteratively raise nondraining flats until all flats have a low edge cell (grid.raise_nondraining_flats)
  3. Resolve flats using the method of Garbrecht and Martz (grid.resolve_flats)

After that, you can use grid.flowdir, grid.accumulation and grid.catchment as usual.

Thanks, MDB

mdbartos avatar Jul 24 '18 19:07 mdbartos

After uninstalling the old version and installing the new, the Grid.from_raster method throws either one of two errors dependent upon the input data: "TypeError: affine transformation matrix required" for a TIFF DEM or "RuntimeError: b'no arguments in initialization list' using traditionally stored DEM data provided as roi_10m. I thought I'd ask for some guidance prior to hacking away at ancillary resources...

Thanks,

Nick

neko1010 avatar Aug 15 '18 14:08 neko1010

Are you using rasterio version 1.0 or higher? See this thread: https://github.com/mdbartos/pysheds/issues/13

mdbartos avatar Aug 16 '18 04:08 mdbartos

After uninstalling an older version of rasterio and installing v1.0.3, ImportError: Requires rasterio module is raised. When trying to import rasterio directly into an interpreter, an ImportError reads: DLL load failed: The specified module could not be found in response to an attempted import within rasterio_init_.py from rasterio._base import gdal_version I inserted the gdal111.dll and gdal data folder into the windows PATH variable, but still no success. I assume this is a windows issue only? Any advice is welcomed and appreciated. Thanks!

neko1010 avatar Aug 21 '18 14:08 neko1010

What version of GDAL are you using? I'm using v2.3/4. I don't think I was able to get v1.11 working.

mdbartos avatar Aug 21 '18 18:08 mdbartos

GDAL version 2.2.4

neko1010 avatar Aug 23 '18 12:08 neko1010

Dear Matt, I am trying to extract river network using SRTMGL1_003 DEM. I am quite new to python, and I have followed the instructions and procedures on https://github.com/mdbartos/pysheds/blob/master/recipes/messy_dem.ipynb I would like to know, how to snap pour point from the DEM. As there multiple Pour Point in DEM file. How to input multiple pour points or shapefile of pour points in pyshed.

kulkarnirp avatar Apr 01 '20 12:04 kulkarnirp

Greetings, I think what you are looking for is the grid.snap_to_mask function, as demonstrated here: https://github.com/mdbartos/pysheds/blob/master/examples/snap_to_mask.ipynb

If you have multiple pour points, you can delineate them in a for loop, as shown in the above notebook.

mdbartos avatar Apr 01 '20 17:04 mdbartos

Greetings.

See the following recipe for a step-by-step guide on how to go from unconditioned DEM data -> flow direction -> accumulation -> catchment.

https://github.com/mdbartos/pysheds/blob/master/recipes/messy_dem.ipynb

I had to add a couple different modules to meet your needs. Make sure you grab the latest copy of pysheds from the github (clone the repo and install).

    $ git clone https://github.com/mdbartos/pysheds.git
    $ cd pysheds
    $ pip install .

In general, the DEM conditioning process is:

  1. Fill pits (grid.fill_pits)
  2. Iteratively raise nondraining flats until all flats have a low edge cell (grid.raise_nondraining_flats)
  3. Resolve flats using the method of Garbrecht and Martz (grid.resolve_flats)

After that, you can use grid.flowdir, grid.accumulation and grid.catchment as usual.

Thanks, MDB

Hi @mdbartos, using current version 0.2.7.1, how I can check the low edge cells using grid.detect_depressions() (old grid.raise_nondraining_flats)? Or, it's not a necessary step call recursively the function to detect pits in order to get low edge cells?

bmalbusca avatar Apr 25 '21 14:04 bmalbusca