Skip to content

Change xarray coordinate identification to enforce dimensionality and allow both lat/lon and x/y identification #1090

@jthielen

Description

@jthielen

As mentioned in #1089, it would be helpful to systematically identify both lat/lon and x/y coordinates on a DataArray/Dataset. This could be useful both as a sanity check (as in #1089) and in kinematics calculations (as in #893). There have also been issues with the current implementation of da.metpy.x and da.metpy.y when latitude_longitude grid mapping is assumed but the data grid is not latitude_longitude (such as #1004).

I would propose that in place of the current behavior of da.metpy.x and da.metpy.y, we have the following:

  • da.metpy.x and da.metpy.y bind only to the orthogonal x and y coordinates of the DataArray's data grid.
    • Should be 1D
    • While most of the time should also be dimension coordinates, I don't think we should restrict them to only dimension coordinates, since there are use cases where having them be auxiliary coordinates would be useful (such as cross sections, where both the projection x and y coordinates are in one-to-one relation with the index dimension)
    • If such coordinates do not exist, raise an AttributeError (which may suggest adding them to the DataArray/Dataset once sufficient helpers are implemented)
  • da.metpy.longitude and da.metpy.latitude bind to geographic longitude and latitude coordinates (according to CF conventions and heuristics as already implemented)
    • Can be any dimensionality (e.g., 1D for plate carrée, 2D for grid with most other projections, 3D for moving nests)
    • Will be identical to da.metpy.x and da.metpy.y, respectively, for plate carrée
    • Question: if not already present, should they be computed and added on-demand from da.metpy.x and da.metpy.y using da.metpy.cartopy_crs when accessed? Or should this be left to a separate helper function?

For "nice" datasets, where the data projection, dimensions, and coordinates correspond as expected, these changes should not affect the behavior of da.metpy.x and da.metpy.y, and would simply add the longitude and latitude attributes. However, for "mystery projection" datasets where the latitude_longitude grid mapping is assumed (ref #1039/#1065) even though the data grid is not latitude_longitude, this would be an API break (in that case, users would have to change instances of da.metpy.x and da.metpy.y to da.metpy.longitude and da.metpy.latitude, respectively).

Before digging into implementing this, what are everyone's thoughts on it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions