Skip to content

from_template: use CF Conventions metadata instead of crs_units/crs_name #3531

Description

@brendancol

What's wrong

from_template tags its output DataArray with two attribute keys that don't follow any recognized metadata standard:

  • crs_units ('m' or 'degree')
  • crs_name (the human-readable projection name, e.g. 'NAD83 / Conus Albers')

crs_units also duplicates information that belongs on the coordinate variables, and the coordinate units it mirrors ('degree') isn't CF-valid for lon/lat axes.

Proposed change

Align the template metadata with the CF (Climate and Forecast) Conventions, the metadata standard xarray and the wider geoscience stack already lean on.

  • Drop crs_units from the DataArray attrs. Units belong on the coordinates, where x/y already carry them.
  • Make the coordinate metadata CF-correct:
    • EPSG:4326: units of degrees_east/degrees_north with standard_name longitude/latitude (today it emits 'degree').
    • Projected: units of m with standard_name projection_x_coordinate/projection_y_coordinate.
  • Replace crs_name with the CF grid-mapping keys grid_mapping_name (the projection token, e.g. albers_conical_equal_area) and crs_wkt (full WKT, which carries the human-readable name). This matches how the rest of the library identifies a CRS: crs/crs_wkt, with everything else derived via pyproj.

Notes

  • The CF keys come from pyproj.CRS.to_cf(). Same as the current crs_name, they stay best-effort: without pyproj the default path is dependency-free and the keys are omitted.
  • Equal Earth (the preserve='area' fallback) has no CF grid mapping, so grid_mapping_name is left off there and only crs_wkt is emitted.
  • This changes the attribute contract of from_template. The library is pre-1.0, so no deprecation shim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions