Skip to content

Bug: lat/lon coordinates written as float32 instead of required float64 #269

@siligam

Description

@siligam

Summary

lat and lon coordinate variables are written with float32 (single precision) dtype instead of float64 (double precision), which is required for CMIP-compliant output.

Evidence

Reported by Fabian Wachsmann (DKRZ) after running cmip7repack on pycmor output for tos Omon (based on PR #266):

"The coordinates lat and lon are not of 'dtype double' which is required."

The cmip7repack tool rewrote the file, confirming the output does not meet ESGF publication standards.

Why this is a requirement

  • CMOR3 (the reference implementation) explicitly casts geographic coordinate variables to float64 — this is baked into the library, not optional.
  • CF Conventions §2.2 recommends double precision for coordinate variables to avoid positional errors, especially at high resolution on unstructured grids where float32 (~7 significant digits) introduces measurable inaccuracy.
  • Compliance checkers (PrePARE, cf-checker) and publication tools (cmip7repack) will flag or rewrite float32 coordinates.

Since pycmor writes output via xarray/netCDF4 rather than through the CMOR C library, it must enforce this requirement explicitly.

Expected behavior

lat and lon (and their bounds lat_bnds, lon_bnds) must be written as float64.

Proposed fix

Explicitly cast coordinate variables to float64 before writing — either in the coordinate writing step in std_lib or enforced at the CMOR writer level, so it applies to all pipelines by default.

Related

  • Reported in context of PR Feat/cmip7 awiesm3 veg hr #266 (tos Omon for AWI-ESM-3)
  • Related to the broader goal of producing publication-ready output without requiring post-processing steps like cmip7repack

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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