Giter Site home page Giter Site logo

Comments (5)

mdbartos avatar mdbartos commented on August 15, 2024

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.

mdbartos avatar mdbartos commented on August 15, 2024

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.

cfandel avatar cfandel commented on August 15, 2024

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.

mdbartos avatar mdbartos commented on August 15, 2024

Looks cool!

Btw, what happened when you tried to use cell_distances on the catchment raster? Did it raise an error?

from pysheds.

cfandel avatar cfandel commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.