Some tips if you're comparing Xarray/xCDAT objects against cdms2 Masked Arrays #520
Replies: 2 comments 1 reply
-
Hey @gleckler1, if I recall correctly, you mentioned running into issues with large differences when comparing CDAT vs. Xarray/xCDAT results. These tips might be helpful. |
Beta Was this translation helpful? Give feedback.
-
Thanks @tomvothecoder ! For people like me who don't like And, if A is a cdms2 masked variable, you can get the pure np.ma array part (that is, no axes, metadata, etc...) with We have to b careful not to mix masked arrays with np arrays with nans, or it will silently get ugly :-(
|
Beta Was this translation helpful? Give feedback.
-
1. Make sure representation of missing values are the same between cdms2 and Xarray
fill_value
set in the NetCDF file (e.g.,fill_value=1e-20
) or manually set by the user.np.nan
(docs).The problem: If missing values are represented differently, then there can be significant differences in floating point
comparisons.
Solutions:
Replace missing values in cdms2 variable objects with
np.nan
to align with Xarray's behavior with missing values.Replace Xarray and cdms2 variable object missing values with the same fill value (e.g., 1e-20).
2. Compare the underlying numpy arrays found in cdms2 and Xarray data structures
cdms2 and Xarray objects are both interoperable with
np.testing.assert_allclose()
. However, I'm not 100% sure how cdms2 masked arrays behave when passed tonp.testing.assert_allclose()
.Extracting the underlying numpy arrays ensures that cdms2 and/or Xarray does not introduce potential unwanted side-effects when comparing values between packages.
Example:
3. Use
np.testing.assert_allclose()
to compare max absolute difference (floating point) and max relative difference (%).Related resources:
Beta Was this translation helpful? Give feedback.
All reactions