Skip to content

SCRIP reader does not respect units (in particular, radians) #1564

Description

@zarzycki

Version

v2026.06.0

How did you install UXarray?

Conda

What happened?

Currently, the SCRIP reader does not respect units attached to relevant lat/lon vars. That is, it assumes degrees. For 90% of grids, this is probably the case. MPAS, by default, writes SCRIP files internally in radians, which are easily convertible using NCO or other external scripts, but it breaks uxarray currently (well, uxarray runs fine since |radians| < |degrees| but then projects fields in a very small location near 0, 0).

What did you expect to happen?

UXarray should read the units attribute and act accordingly. Since the current infrastructure is centered around degrees, it should read "radians" and convert the relevant arrays to "degrees" before progressing in the stack.

Can you provide a MCVE to repoduce the bug?

import uxarray as ux
import numpy as np
import xarray as xr
import os

# Define a tiny 2-cell grid in degrees
center_lon_deg = np.array([10.0, 20.0])
center_lat_deg = np.array([30.0, 40.0])
corner_lon_deg = np.array([[5., 15., 15., 5.], [15., 25., 25., 15.]])
corner_lat_deg = np.array([[25., 25., 35., 35.], [35., 35., 45., 45.]])

# Build a SCRIP dataset with coordinates stored in rad
ds = xr.Dataset()
ds["grid_center_lon"] = xr.DataArray(np.deg2rad(center_lon_deg), dims=["grid_size"], attrs={"units": "radians"})
ds["grid_center_lat"] = xr.DataArray(np.deg2rad(center_lat_deg), dims=["grid_size"], attrs={"units": "radians"})
ds["grid_corner_lon"] = xr.DataArray(np.deg2rad(corner_lon_deg), dims=["grid_size", "grid_corners"], attrs={"units": "radians"})
ds["grid_corner_lat"] = xr.DataArray(np.deg2rad(corner_lat_deg), dims=["grid_size", "grid_corners"], attrs={"units": "radians"})
ds["grid_imask"] = xr.DataArray(np.ones(2, dtype=np.int32), dims=["grid_size"])
ds["grid_area"] = xr.DataArray(np.ones(2), dims=["grid_size"])
ds["grid_dims"] = xr.DataArray(np.array([2], dtype=np.int32), dims=["grid_rank"])

# Write to a small test file to mimic reading a SCRIP nc
out_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "scrip_radians.nc")
ds.to_netcdf(out_path)

grid = ux.open_grid(out_path)

print("face_lon (got):     ", grid.face_lon.values)
print("face_lon (expected):", center_lon_deg)
# Bug: without the fix, face_lon will be ~[0.17, 0.35] (radian values treated as degrees)
# With fix:             face_lon will be ~[10.0, 20.0]

Activity

  1. self-assigned this
    on Jul 13, 2026
  2. self-assigned this
    on Jul 13, 2026
  3. erogluorhan commented on Jul 14, 2026

    @erogluorhan
    Member

    @rajeeja do you think this might be due to the recent work where we touched similar areas?

  4. rajeeja commented on Jul 14, 2026

    @rajeeja
    Contributor

    No, none of my recent fixes broke this — I checked _scrip.py and its history, and we've never read the units attribute at all; the SCRIP reader has always just assumed degrees. So this is a genuine, long-standing bug and it should be fixed.

    One thing to keep in mind for the fix: the units attribute isn't always present or consistent across our own example grids — e.g. ne30pg2/outCSne8 use units="degrees", the oasis grids use CF-style degrees_east/degrees_north, and some files omit units entirely. So the fix should default to degrees when units are missing, and convert when it sees radian/radians (ideally tolerating the CF variants too).

  5. Sevans711 commented on Jul 14, 2026

    @Sevans711
    Collaborator

    I believe this was solved by #1433 and should be safe to mark as closed now that it has been merged into main!

  6. moved this from 📚 Backlog to ✅ Done in UXarray Developmenton Jul 14, 2026
  7. erogluorhan commented on Jul 17, 2026

    @erogluorhan
    Member

    Thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions