Skip to content

_coordinate not defined for LatLong points #1936

Open
@Sbozzolo

Description

@Sbozzolo

This leads to problems with Remapper.

  MethodError: no method matching _coordinate(::ClimaCore.Geometry.LatLongPoint{Float64}, ::Val{1})
  
  Closest candidates are:
    _coordinate(::ClimaCore.Geometry.XZPoint, ::Val{1})
     @ ClimaCore ~/.julia/packages/ClimaCore/ANgUC/src/Geometry/coordinates.jl:171
    _coordinate(::ClimaCore.Geometry.YZPoint, ::Val{1})
     @ ClimaCore ~/.julia/packages/ClimaCore/ANgUC/src/Geometry/coordinates.jl:176
    _coordinate(::ClimaCore.Geometry.Abstract1DPoint, ::Val{1})
     @ ClimaCore ~/.julia/packages/ClimaCore/ANgUC/src/Geometry/coordinates.jl:162
    ...
  
  Stacktrace:
    [1] coordinate(pt::ClimaCore.Geometry.LatLongPoint{Float64}, ax::Int64)
      @ ClimaCore.Geometry ~/.julia/packages/ClimaCore/ANgUC/src/Geometry/coordinates.jl:191
    [2] containing_element(mesh::ClimaCore.Meshes.RectilinearMesh{ClimaCore.Meshes.IntervalMesh{ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.LongPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.LongPoint{Float64}, Int64}}, ClimaCore.Meshes.IntervalMesh{ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.LatPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.LatPoint{Float64}, Int64}}}, coord::ClimaCore.Geometry.LatLongPoint{Float64})

I found that I had to define them like this:

    ClimaCore.Geometry._coordinate(
        pt::ClimaCore.Geometry.LatLongPoint,
        ::Val{1},
    ) = ClimaCore.Geometry.LongPoint(pt.long)
    ClimaCore.Geometry._coordinate(
        pt::ClimaCore.Geometry.LatLongPoint,
        ::Val{2},
    ) = ClimaCore.Geometry.LatPoint(pt.lat)

That is, flipping the value with respect to the order implied by the name. If I have them with the same order, the error is:

  promotion of types ClimaCore.Geometry.LatPoint{Float64} and ClimaCore.Geometry.LongPoint{Float64} failed to change any arguments
  Stacktrace:
    [1] error(::String, ::String, ::String)
      @ Base ./error.jl:44
    [2] sametype_error(input::Tuple{ClimaCore.Geometry.LatPoint{Float64}, ClimaCore.Geometry.LongPoint{Float64}})
      @ Base ./promotion.jl:417
    [3] not_sametype(x::Tuple{ClimaCore.Geometry.LatPoint{Float64}, ClimaCore.Geometry.LongPoint{Float64}}, y::Tuple{ClimaCore.Geometry.LatPoint{Float64}, ClimaCore.Geometry.LongPoint{Float64}})
      @ Base ./promotion.jl:411
    [4] promote
      @ ./promotion.jl:394 [inlined]
    [5] isless(x::ClimaCore.Geometry.LatPoint{Float64}, y::ClimaCore.Geometry.LongPoint{Float64})
      @ ClimaCore.Geometry ~/.julia/packages/ClimaCore/ANgUC/src/Geometry/coordinates.jl:225
    [6] lt(o::Base.Order.ForwardOrdering, a::ClimaCore.Geometry.LatPoint{Float64}, b::ClimaCore.Geometry.LongPoint{Float64})
      @ Base.Order ./ordering.jl:117
    [7] searchsortedlast
      @ ./sort.jl:196 [inlined]
    [8] searchsortedlast
      @ ./sort.jl:290 [inlined]
    [9] searchsortedlast
      @ ./sort.jl:292 [inlined]
   [10] containing_element
      @ ~/.julia/packages/ClimaCore/ANgUC/src/Meshes/interval.jl:66 [inlined]
   [11] containing_element(mesh::ClimaCore.Meshes.RectilinearMesh{ClimaCore.Meshes.IntervalMesh{ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.LongPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.LongPoint{Float64}, Int64}}, ClimaCore.Meshes.IntervalMesh{ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.LatPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.LatPoint{Float64}, Int64}}}, coord::ClimaCore.Geometry.LatLongPoint{Float64})
      @ ClimaCore.Meshes ~/.julia/packages/ClimaCore/ANgUC/src/Meshes/rectangle.jl:131
   [12] containing_pid
      @ ~/.julia/packages/ClimaCore/ANgUC/src/Remapping/distributed_remapping.jl:100 [inlined]
   [13] #20
      @ ~/.julia/packages/ClimaCore/ANgUC/src/Remapping/distributed_remapping.jl:115 [inlined]

This is due to the fact that we typically put longitude as first dimension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions