Skip to content

Consider adding opt-in support for circular axes when calling bounds_to_vertices (related to #594) #596

@tomvothecoder

Description

@tomvothecoder

Description

The latest bounds_to_vertices() function in cf-xarray v0.10.7+ only handles core dimensions that are in ascending or descending order. Core dims that are in mixed order instead raise a NotImplementedError #595 with a message for the user to normalize coordinates to a monotonic convention (related comment).

Examples

  • Ascending

    [0, 1, 2, ..., 357, 358, 359]
    
  • Descending

    [359, 358, 357, ..., 2, 1, 0]
    
  • Mixed (wraps at seam)

    [0, 1, 2, ..., 179, -180, -179, ..., -1]
    

bounds_to_vertices() works in the first two cases but fails in the third.


Proposed solution

For a long-term solution, it might be worth considering opt-in support for circular axes, e.g.:

bounds_to_vertices(..., circular_period=360.0, start=None)

With circular_period set, cf-xarray could:

  • Detect circular monotonicity
  • Rotate away from the seam
  • Proceed safely as if the dimension were monotonic

While longitude (circular_period=360.0) is the most common use case, the same approach could generalize to other periodic axes (e.g. angles, phases).

Why it is useful

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions