@@ -113,6 +113,10 @@ class Grid:
113113 For constructing a grid from non-UGRID datasets or other types of supported data, see our ``ux.open_grid`` method or
114114 specific class methods (``Grid.from_dataset``, ``Grid.from_face_verticies``, etc.)
115115
116+ Note on Sphere Radius:
117+ All internal calculations use a unit sphere (radius=1.0). The physical sphere radius
118+ from the source grid is preserved in the ``sphere_radius`` property for scaling results.
119+
116120
117121 Parameters
118122 ----------
@@ -2030,6 +2034,39 @@ def normalize_cartesian_coordinates(self):
20302034 self ._ds [f"{ prefix } _y" ] = dy / norm
20312035 self ._ds [f"{ prefix } _z" ] = dz / norm
20322036
2037+ @property
2038+ def sphere_radius (self ) -> float :
2039+ """Physical sphere radius from the source grid (e.g., Earth's radius for MPAS ocean grids).
2040+
2041+ Internally, all calculations use a unit sphere. This property stores the original
2042+ radius for scaling results back to physical units.
2043+
2044+ Returns
2045+ -------
2046+ sphere_radius : float
2047+ The physical sphere radius. Defaults to 1.0 if not set.
2048+ """
2049+ return self ._ds .attrs .get ("sphere_radius" , 1.0 )
2050+
2051+ @sphere_radius .setter
2052+ def sphere_radius (self , radius : float ) -> None :
2053+ """Set the sphere radius for the grid.
2054+
2055+ Parameters
2056+ ----------
2057+ radius : float
2058+ The sphere radius to set. Must be positive.
2059+
2060+ Raises
2061+ ------
2062+ ValueError
2063+ If radius is not positive.
2064+ """
2065+ if radius <= 0 :
2066+ raise ValueError (f"Sphere radius must be positive, got { radius } " )
2067+
2068+ self ._ds .attrs ["sphere_radius" ] = radius
2069+
20332070 def to_xarray (self , grid_format : Optional [str ] = "ugrid" ):
20342071 """Returns an ``xarray.Dataset`` with the variables stored under the
20352072 ``Grid`` encoded in a specific grid format.
0 commit comments