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

Method ambiguity - indexing with DimSelectors doesn't work on Projected axes #814

Open
asinghvi17 opened this issue Nov 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@asinghvi17
Copy link
Collaborator

MWE:

r1 = Raster(WorldClim{Climate}, :tmin, month = 1)
r2 = r1[1:10, 1:10]
r3 = r1[DimSelectors(r2, selectors = At)]

Error (ignore the task stuff):

    nested task error: MethodError: selectindices(::Projected{…}, ::At{…}) is ambiguous.
    
    Candidates:
      selectindices(l::Projected, sel::At)
        @ Rasters ~/.julia/packages/Rasters/0qvMe/src/lookup.jl:96
      selectindices(l::DimensionalData.Dimensions.Lookups.Lookup, sel::At{<:AbstractVector}; kw...)
        @ DimensionalData.Dimensions.Lookups ~/.julia/packages/DimensionalData/hhCBb/src/Lookups/selector.jl:140
    
    Possible fix, define
      selectindices(::Projected, ::At{<:AbstractVector})
    
    Stacktrace:
      [1] _dims2indices
        @ ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:117 [inlined]
      [2] _dims2indices
        @ ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:109 [inlined]
      [3] macro expansion
        @ ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:55 [inlined]
      [4] _dims2indices(lookups::Tuple{Projected{…}, Projected{…}}, dims::Tuple{X{…}, Y{…}}, I::Tuple{X{…}, Y{…}})
        @ DimensionalData.Dimensions ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:55
      [5] dims2indices
        @ ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:50 [inlined]
      [6] dims2indices
        @ ~/.julia/packages/DimensionalData/hhCBb/src/Dimensions/indexing.jl:32 [inlined]
      [7] _dim_dotview
        @ ~/.julia/packages/DimensionalData/hhCBb/src/array/indexing.jl:110 [inlined]
      [8] dotview(::Raster{…}, ::Y{…}, ::X{…})
        @ DimensionalData ~/.julia/packages/DimensionalData/hhCBb/src/array/indexing.jl:87
      [9] merge_and_index(f::Function, A::Raster{…}, dims::Tuple{…})
        @ DimensionalData ~/.julia/packages/DimensionalData/hhCBb/src/array/indexing.jl:151
     [10] _dim_dotview
        @ ~/.julia/packages/DimensionalData/hhCBb/src/array/indexing.jl:117 [inlined]
     [11] dotview(A::Raster{…}, i::DimSelectors{…})
        @ DimensionalData ~/.julia/packages/DimensionalData/hhCBb/src/array/indexing.jl:97

I can fix the ambiguity, but then I get a stackoverflow of reprojects.

Ambiguity fix:

function LA.selectindices(l::Projected, sel::At{<: AbstractVector})
    selval = reproject(mappedcrs(l), crs(l), dim(l), val(sel))
    LA.at(l, rebuild(sel; val=selval))
end
@asinghvi17 asinghvi17 added the bug Something isn't working label Nov 5, 2024
@rafaqz
Copy link
Owner

rafaqz commented Nov 6, 2024

Haha I hit this too and fixed it last night

@asinghvi17
Copy link
Collaborator Author

Nice...pr? :D

@rafaqz
Copy link
Owner

rafaqz commented Nov 6, 2024

Yeah it's bundled with something else, maybe I'll split it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants