-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accumulation Cost or Cost distance feature #410
Comments
I have a fast algorithm for this already, but it relies in my not yet registered Neighborhoods.jl package. Another package Neighborhood.jl was registered so I cant get the close name. I havent thought of another one yet! When thats finaliaed I can add cost distance, slope, aspect, focal etc methods here. |
Thanks for that fast answer! |
It may be quire a few months until I get around to adding those functions here ether way. |
Anyway, thanks for your work! |
Neighborhoods.jl is registered now as Stencils.jl: It should be fairly easy to add these things now, I just need a good test suite for it. |
Thanks for your work ! |
That new PR has Can I ping you for feedback on The PR at some point? It would be good to make sure the functionality is broad enough |
Thanks for the proposition. I am neither a specialist on the cost_distance questions nor Julia's good programmer. But I surely can try to give feedback as I am also interested in the slope and focal function (I still have not check yet if your implementation allows using several input rasters and arbitrary focal shapes) |
Im no specialist either, just a random ecologist. But those kind of questions are exactly what Im looking for!
|
One question I have is what kind of cost functuons should be available out of the box? Ive got a walking time model there at the moment but there could be more and they could be more flexible. |
Our use case might be walking distance / least path cost but with custom weighted cost to model some preferences based on path surroundings (vectorial and raster approaches are still on the table in this particular situation at this stage ). So I have not yet an opinion on how to design and the degree of flexibility of such an option. |
Ok. Currently Im allowimg users to pass in a function: f(elev1, elev2, distance, [resistance]) Where resistance is optional if you dont use a resistance matrix. So you can use any function of those arguments and the result will be minimised over the grid. Would that be flexible enough? |
Sorry for the delay. I am not sure to understand the proposed function (or the args) properly. |
Sorry maybe that was confusing. This is the format for a custom cost function you can pass in, with Rasters.jl/ext/RastersStencilsExt/cost_distance.jl Lines 120 to 131 in 43a34df
The idea is you can write whatever formula you like to define cost. You could have driving time here instead, using the same function arguments. Or energy expended by a laden camel ;) Just something to return a cost based on elevations, distance, and optionally landscape resisance. The main cost distanct fuction is here: Rasters.jl/ext/RastersStencilsExt/cost_distance.jl Lines 34 to 39 in 43a34df
It has pretty much what you describe - you provide origin points (currently an array but but could be geometries) and an elevation raster, and optionally a resistance surface, and it returns the cumulative cost over the whole area. The function You didn't mention elevation or resistance layers - do you not use those? |
Ok, I'll get a better picture now. |
Ah ok sounds like an interesting social study. I hadn't thought about cases where elevation doesn't matter. I'll think about how to make that possible. It would be annoying for you to have to pass in an array of zeros for elevation and have two dummy elevation variables you ignore. Maybe elevation and resistance should be generalised to behave in the same way, and each should get an argument that is a tuple of the source and destination cell values. So if you pass in walking_time(distance, (elev1, elev2), (res1, res2)) Or it could be just resistance walking_time(distance, (res1, res2)) Or whatever you like: walking_time(distance, (res1, res2), (somethingelse1, somethingelse1)) It could also be done with walking_time(distance, (elevation=(elev1, elev2), resistance=(res1, res2))) And then you could pass in |
Also to clarify - you may notice that I don't like how cost_distance works in terra, and this is quite different! For most of my uses resistance surface isn't the right way to work with elevation, I would like to be able to do path distance with it, more like: https://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/path-distance.htm. So this formulation may be a little more complicated but much more flexible. We can add various prebaked cost functions over time to fill out the functionality - but people should be able to write their own cost equations easily. That's also possible here because user defined functions will be as fast as C (unless you really mess it up) so you can do whatever you like, its not really doable in R. |
Thanks for your explanation. |
Great! Thanks for riffing on that I think we have something better than my current design. Yes there are a lot of ways to define the cost of slope. Some functions just use the slope in a pixel as a generic cost like you say, but this ignores that paths going on contour are flat, with no vertical cost at all even if tge slope is steep. And a lot of roads and tracks are like that. |
Thanks for the fast development. I had a quick look at the last version (
And apply the window function to each cell with 1) the array (e.g. population raster), 2) the radius = the plume size and 3) the angle given by the wind direction.
The function would be applied as the following:
where the population is a raster with estimated population size, emission distance gives the distance of a plume emission in each cell (depending on the local climate) and the local wind direction.
Thanks in advance, and maybe I should move those questions to the |
As for returning I've thought about localized window shape a bit with DynamicGrids.jl but never actually implemented it, specifically for this wind direction problem too. To do it, you can use specific stencils outside of So in each of your branches above you would just specify a different window shape. You will need to be careful to make all of this type stable and compile away - actually a big if else block like you use above is the way to do that. But it could be much faster than your approach above by ensuring that Building kernels with a runtime radius will be very slow unless you specify the radius in a branch. Maybe we can build a grouped stencil (like For slopes, there is a big set of slope algorithms in the PR with cost_distance. See: (I'm going to refactor it all to use The cost distance model doesn't actually calculate slope directly, it just passes the cost function the start and end elevations that it can use to calculate cost however it needs to. |
Thanks for all this information. I think I get your points regarding the localized focal approach. I'll check when I can (I would like to recode a previous work with your new tools to see what I can get). But I realize that my coding skills are still lacking... As for the slope, I indeed saw a paper on the slopes algorithm. But in a broader perspective, would it be relevant to also add all the "standard" DEM calculations (aspect, ruggedness, etc.) here or in another package ? |
No worries. |
As for the coding skills here I don't think you are far off from the examples above - the key thing is realizing why StaticArrays.jl is the fast way to do this. Having a fixed length and offsets known at compile time means the compiler knows everything about the stencil and is forced to compile specific code for all variants. In your code above the compiler does not know the value of Otherwise Stencils.jl isn't doing anything fancy - there are no optimizations at all except generating a StaticArray for everything and running functions of them in a generic KernelAbstractions.jl kernel (thats just so it runs paralel on GPU/CPU without me writing any custom code for it). |
This functionality should all go into Geomorphometry.jl |
Thanks for this very valuable package. It is not a bug report but more of a feature question. Would it be feasible, or is there any interest in a cost distance analysis solution such as:
Thanks a lot
The text was updated successfully, but these errors were encountered: