Skip to content
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

Use AxisArrays for distance/proximity matrices #7

Open
andreasnoack opened this issue Oct 31, 2021 · 1 comment
Open

Use AxisArrays for distance/proximity matrices #7

andreasnoack opened this issue Oct 31, 2021 · 1 comment

Comments

@andreasnoack
Copy link
Member

That would make it easier to maintain the association between the original grid and the distance values. E.g. it would allow for something like

julia> g = ConScape.Grid(size(r)..., affinities=a, costs=_cost, prune=true)
[ Info: cost graph contains 6 strongly connected subgraphs
[ Info: removing 8 nodes from affinity and cost graphs
ConScape.Grid of size 4x4

julia> lc = ConScape.least_cost_distance(g)
8×8 Matrix{Float64}:
 0.0       0.693147  1.38629   2.07944   0.693147  1.38629   2.07944   2.77259
 0.693147  0.0       0.693147  1.38629   1.38629   0.693147  1.38629   2.07944
 1.38629   0.693147  0.0       0.693147  2.07944   1.38629   0.693147  1.38629
 2.07944   1.38629   0.693147  0.0       2.77259   2.07944   1.38629   0.693147
 1.38629   2.07944   2.77259   3.46574   0.0       1.38629   2.77259   4.15888
 2.07944   1.38629   2.07944   2.77259   1.38629   0.0       1.38629   2.77259
 2.77259   2.07944   1.38629   2.07944   2.77259   1.38629   0.0       1.38629
 3.46574   2.77259   2.07944   1.38629   4.15888   2.77259   1.38629   0.0

julia> lc_aa = AxisArray(lc, source=vec(CartesianIndices((4,4))[:,3:4]), target=vec(CartesianIndices((4,4))[:,3:4]))
2-dimensional AxisArray{Float64,2,...} with axes:
    :source, CartesianIndex{2}[CartesianIndex(1, 3), CartesianIndex(2, 3), CartesianIndex(3, 3), CartesianIndex(4, 3), CartesianIndex(1, 4), CartesianIndex(2, 4), CartesianIndex(3, 4), CartesianIndex(4, 4)]
    :target, CartesianIndex{2}[CartesianIndex(1, 3), CartesianIndex(2, 3), CartesianIndex(3, 3), CartesianIndex(4, 3), CartesianIndex(1, 4), CartesianIndex(2, 4), CartesianIndex(3, 4), CartesianIndex(4, 4)]
And data, a 8×8 Matrix{Float64}:
 0.0       0.693147  1.38629   2.07944   0.693147  1.38629   2.07944   2.77259
 0.693147  0.0       0.693147  1.38629   1.38629   0.693147  1.38629   2.07944
 1.38629   0.693147  0.0       0.693147  2.07944   1.38629   0.693147  1.38629
 2.07944   1.38629   0.693147  0.0       2.77259   2.07944   1.38629   0.693147
 1.38629   2.07944   2.77259   3.46574   0.0       1.38629   2.77259   4.15888

julia> lc_aa[:, atvalue(CartesianIndex(3,4))]
1-dimensional AxisArray{Float64,1,...} with axes:
    :source, CartesianIndex{2}[CartesianIndex(1, 3), CartesianIndex(2, 3), CartesianIndex(3, 3), CartesianIndex(4, 3), CartesianIndex(1, 4), CartesianIndex(2, 4), CartesianIndex(3, 4), CartesianIndex(4, 4)]
And data, a 8-element Vector{Float64}:
 2.0794415416798357
 1.3862943611198906
 0.6931471805599453
 1.3862943611198906
 2.772588722239781
 1.3862943611198906
 0.0
 1.3862943611198906
@rafaqz
Copy link
Collaborator

rafaqz commented Dec 13, 2024

On dev these are now returned as Rasters.jl Raster (A DimensionalData.jl AbstractDimArray) which means they also track crs and other spatial metadata, and can be e.g. written to a .tiff file directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants