Comments (5)
Hi @cfandel,
Thanks for your question. You can use the weights
parameter to specify the distances from each cell to its downstream neighbor (this should account for differences in height, width, and diagonal distance). To get these distances, you can use grid.cell_distances
. If you use the as_crs
argument you will get the result in projected units (e.g. meters). So, you can do something like:
import pyroj
# Projection for the location I'm interested in (Texas for the example DEM)
new_crs = pyproj.Proj('+init=epsg:3083')
cell_distances = grid.cell_distances('catch', as_crs=new_crs, inplace=False)
flow_distances = grid.flow_distance(x=x, y=y, data='catch', weights=cell_distances.ravel(), inplace=False)
(Note that I haven't tested the above code sample)
I believe you can use either dir
or catch
, as long as it's a flow direction raster. The flow distance function makes you input a pour point, so the result should be the same either way (any points that aren't upstream of the pour point will have a flow distance of infinity).
Btw, I made some scripts to convert DEMs to SWMM input files for a paper a little while back. The source code is here (however, it's really messy because I didn't really intend to distribute it): https://github.com/kLabUM/hydraulic-controller-placement/blob/development/notebooks/swmm.py
Glad that this library has been helpful for you :)
Thanks,
MDB
from pysheds.
For reference, the weights for grid.flow_distance
are used as edge weights in a directed graph of the watershed. Shortest paths to the outlet are then determined using something like Djikstra's algorithm (scipy chooses the algorithm depending on what's best for the particular situation).
from pysheds.
Super helpful thanks! This approach worked great for me using the flow direction raster (though not the catchment raster when it came to calculating cell distances).
Also, I think your SWMM input file code will be helpful as well - I've written something similar (here: https://github.com/cfandel/gottesacker/blob/master/swmmpy.py), but it's in progress, so it's useful to see another approach to it!
from pysheds.
Looks cool!
Btw, what happened when you tried to use cell_distances on the catchment raster? Did it raise an error?
from pysheds.
Actually it's weird because initially when I tried it just gave me an array of zeros, but I just tested it again and now it works fine with either one...not sure what I was doing at first that gave different results.
from pysheds.
Related Issues (20)
- Re-evaluate Numba performance HOT 2
- Allow Numba to perform polymorphic dispatching HOT 5
- Can't 'imshow' DEM for some unkown reason HOT 1
- extract_profiles function returning wrong connections when neighbouring cells drain to outlet
- strang plots HOT 1
- Allow user to disable `parallel=True` with numba HOT 2
- Why stream network `LineStrings` do not pass through the centroid of each grid cell? HOT 1
- accumulation issue HOT 3
- Preprocessing DEM with pysheds seems to produce incorrect accumulations HOT 11
- Using catchment() with discharge point outside of extents crashes program
- sGrid and pGrid have major differences
- Pysheds Cupy / Cuspatial support HOT 1
- Accumulation disconnections HOT 4
- setup fail by github repo of latest release version
- Pixels that should be accumulation watercourses are shown as nodata HOT 2
- Wrong bbox when using `ViewFinder` HOT 3
- issue in pygrid with np.int and np.warnings
- D8 and Dinf flow directions look incorrect HOT 4
- Indexing Error in _d8_distance_from_ridge
- How to exclude NoData values when calculating the flow direction of DEM? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysheds.