Repository navigation
Closed
Labels
bugSomething isn't working
Description
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]Metadata
Metadata
Labels
bugSomething isn't working
Type
Fields
Priority
None yet
Projects
- StatusShow more project fields✅ Done
Activity
erogluorhan commentedon Jul 14, 2026
@rajeeja do you think this might be due to the recent work where we touched similar areas?
rajeeja commentedon Jul 14, 2026
No, none of my recent fixes broke this — I checked
_scrip.pyand its history, and we've never read theunitsattribute 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
unitsattribute isn't always present or consistent across our own example grids — e.g. ne30pg2/outCSne8 useunits="degrees", the oasis grids use CF-styledegrees_east/degrees_north, and some files omit units entirely. So the fix should default to degrees when units are missing, and convert when it seesradian/radians(ideally tolerating the CF variants too).Sevans711 commentedon Jul 14, 2026
I believe this was solved by #1433 and should be safe to mark as closed now that it has been merged into main!
erogluorhan commentedon Jul 17, 2026
Thanks both!