mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
698 stars 188 forks source link

Creating flow direction and accumulation rasters using pysheds.grid methods #15

Open neko1010 opened 5 years ago

neko1010 commented 5 years ago

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

mdbartos commented 5 years ago

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 commented 5 years ago

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

neko1010 commented 5 years ago

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

mdbartos commented 5 years ago

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

neko1010 commented 5 years ago

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!

mdbartos commented 5 years ago

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.

neko1010 commented 5 years ago

GDAL version 2.2.4

kulkarnirp commented 4 years ago

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.

mdbartos commented 4 years ago

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.

bmalbusca commented 3 years ago

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?