mdbartos / pysheds

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

Error: Pour point out of bounds. #103

Open ashish-kubade opened 4 years ago

ashish-kubade commented 4 years ago

First of all, thanks for creating this library. I am using it for creating riverlines via grid.catchment(data='dir', x=x, y=y, dirmap=dirmap, out_name='catch', recursionlimit=15000, xytype='label', nodata_out=0) with x and y, say as 100,100 which are inside the bounding box (0.0, 1291.0, 1921.0, 0.0). Could you please have a look?

TIA.

image

mdbartos commented 4 years ago

Greetings,

The bbox format should be (xmin, ymin, xmax, ymax), so I believe your bbox needs to be (0, 0, 1291, 1291).

Let me know if that fixes the issue.

Also, because you are using an integer index, I believe you could also try setting xytype='index'.

Thanks, MDB

YUHAN-G commented 4 years ago

Have you solved this problem? I think I am in the same situation as well. @ashj9

I plot my delineated catchment. It looks weird. How can I fix this problem? @mdbartos

Please have a look.

image

image

image

mdbartos commented 4 years ago

Greetings,

For the first image it looks like you are trying to delineate at the x-coordinate 145.29, which is less than than the minimum x-coordinate of your dataset view (145.290066...). Thus, the pour point is out of bounds.

I'm guessing the error is the result of trying to use grid.catchment again after using grid.clip_to on the tiny catchment shown in the last image. grid.clip_to sets the view to the bounds of the given dataset. If you want to reset the view to the original view (as shown in the middle picture), use grid.clip_to again on the original dem or flow direction data (e.g. grid.clip_to('dem'), grid.clip_to('dir'), etc.).

The reason that the catchment looks strange in the last image is most likely because it's not aligned with a high-accumulation cell. You can use grid.snap_to_mask to fix this problem. See example here: https://github.com/mdbartos/pysheds/blob/master/examples/snap_to_mask.ipynb

I'd probably need to see your code or data to help you more.

Thx, MDB

YUHAN-G commented 4 years ago

@mdbartos Thanks a lot, I tried grid.snap_to_mask and It solved my problem. One more thing to ask. How do I define the general gridded accumulation exceed number when I use a different resolution of DEM? Do you have any suggestions or I have to try to find the best one? 捕获

mdbartos commented 4 years ago

Basically, if you know what the river network is supposed to look like, you'll just want to find an approximate threshold accumulation value that captures that structure. Using a percentile of the total accumulation seems like a reasonable approach (e.g. np.percentile(grid.acc.ravel(), 97)

There's not really a single established method for finding the accumulation threshold--it will be different for different regions/climates/etc. (some studies say that accumulation thresholding is inadequate for channel identification in general). There are also some more sophisticated methods for identifying channels, e.g.: https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2009WR008812

YUHAN-G commented 4 years ago

Further, I was trying this code to delineate some small catchments, two of them in 90m DEM got the error message described below. Have no idea what does it mean. image

MatthieuCMira commented 1 year ago

I have the same issue. Using the basic example from: https://mattbartos.com/pysheds/ I just changed the initialization of the raster using a numpy array.

raster = Raster(my_numpy, viewfinder=ViewFinder(shape=my_numpy.shape)) grid = Grid.from_raster(raster)

My grid bbox is then: grid.bbox = (0.0, 3658.0, 3713.0, 0.0) 

Thus, using grid.catchement() sgrid l724 will raise an error: if (x < xmin) or (x > xmax) or (y < ymin) or (y > ymax): will always raise an error as ymin>ymax.

My question is then the following: Is my raster initialization correct? Or is this a bug?