Closed tomvothecoder closed 1 month ago
Have you come across this issue @lee1043?
@tomvothecoder this is interesting. No, I haven't. Maybe because my data mostly have [time, lat, lon] or [lat, lon] dimensions.
@tomvothecoder this is interesting. No, I haven't. Maybe because my data mostly have [time, lat, lon] or [lat, lon] dimensions.
It could be that the logic in _regrid
expects a certain order of dimensions, or it doesn't consider an order of [lat, lev, lon].
As a path forward around this issue, I decided to use xESMF with conservative_normed instead. I got very close results when comparing to CDAT's regrid2 for all of the datasets I tested (PR).
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-OMEGA-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-OMEGA-ANN-global_ref.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 6 / 24480 (0.0245%)
Max absolute difference: 4.56288177e-07
Max relative difference: 5.34042702e-05
x: array([[ 0.784679, 0.796702, 0.792179, ..., 0.804814, 0.773629,
0.774743],
[ 1.379984, 1.417249, 1.4173 , ..., 1.432473, 1.391159,...
y: array([[ 0.784679, 0.796702, 0.792179, ..., 0.804814, 0.773629,
0.774743],
[ 1.379984, 1.417249, 1.4173 , ..., 1.432473, 1.391159,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-OMEGA-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-OMEGA-ANN-global_test.nc
* var_key: OMEGA
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-OMEGA-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-OMEGA-JJA-global_ref.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 3 / 24480 (0.0123%)
Max absolute difference: 5.97006945e-07
Max relative difference: 1.49039703e-05
x: array([[1.08258 , 1.069207, 1.07484 , ..., 1.090696, 1.087342, 1.09467 ],
[1.563664, 1.593989, 1.628474, ..., 1.553196, 1.556833, 1.570584],
[2.220292, 2.307285, 2.364905, ..., 2.215879, 2.220069, 2.228939],...
y: array([[1.08258 , 1.069207, 1.07484 , ..., 1.090696, 1.087342, 1.09467 ],
[1.563664, 1.593989, 1.628474, ..., 1.553196, 1.556833, 1.570584],
[2.220292, 2.307285, 2.364905, ..., 2.215879, 2.220069, 2.228939],...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-OMEGA-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-OMEGA-JJA-global_test.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 2 / 6120 (0.0327%)
Max absolute difference: 3.39774408e-07
Max relative difference: 0.00015039
x: array([[ 1.150119, 1.168407, 1.16202 , ..., 1.153911, 1.138019,
1.152851],
[ 1.567948, 1.599667, 1.601973, ..., 1.42647 , 1.435826,...
y: array([[ 1.150119, 1.168407, 1.16202 , ..., 1.153911, 1.138019,
1.152851],
[ 1.567948, 1.599667, 1.601973, ..., 1.42647 , 1.435826,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-RELHUM-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-RELHUM-ANN-global_ref.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-RELHUM-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-RELHUM-ANN-global_test.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-RELHUM-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-RELHUM-JJA-global_ref.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-RELHUM-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-RELHUM-JJA-global_test.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-T-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-T-ANN-global_ref.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-T-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-T-ANN-global_test.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-T-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-T-JJA-global_ref.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-T-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-T-JJA-global_test.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-U-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-U-ANN-global_ref.nc
* var_key: U
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 1 / 24480 (0.00408%)
Max absolute difference: 8.52794937e-08
Max relative difference: 1.73621834e-05
x: array([[10.269112, 10.260021, 10.25072 , ..., 10.296745, 10.28736 ,
10.278145],
[12.365973, 12.353776, 12.341225, ..., 12.402582, 12.390261,...
y: array([[10.269112, 10.260021, 10.25072 , ..., 10.296745, 10.28736 ,
10.278145],
[12.365973, 12.353776, 12.341225, ..., 12.402582, 12.390261,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-U-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-U-ANN-global_test.nc
* var_key: U
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 1 / 6120 (0.0163%)
Max absolute difference: 1.45889873e-07
Max relative difference: 1.08735566e-05
x: array([[ 9.712424, 9.692257, 9.675111, ..., 9.79681 , 9.779955,
9.765068],
[12.482069, 12.457917, 12.434379, ..., 12.581674, 12.560391,...
y: array([[ 9.712424, 9.692257, 9.675112, ..., 9.79681 , 9.779955,
9.765068],
[12.482069, 12.457917, 12.434379, ..., 12.581674, 12.560391,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-U-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-U-JJA-global_ref.nc
* var_key: U
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 1 / 24480 (0.00408%)
Max absolute difference: 8.38617442e-08
Max relative difference: 1.96239722e-05
x: array([[ 8.311289, 8.302058, 8.292533, ..., 8.338692, 8.329687,
8.320503],
[10.096993, 10.085039, 10.072245, ..., 10.131809, 10.120227,...
y: array([[ 8.311289, 8.302058, 8.292533, ..., 8.338692, 8.329687,
8.320503],
[10.096994, 10.085039, 10.072245, ..., 10.131809, 10.120227,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/ERA5/ERA5-U-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/ERA5/ERA5-U-JJA-global_test.nc
* var_key: U
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-OMEGA-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-OMEGA-ANN-global_ref.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 2 / 9792 (0.0204%)
Max absolute difference: 3.15701861e-07
Max relative difference: 2.42041494e-05
x: array([[0.914233, 0.906507, 0.900358, ..., 0.954717, 0.945675, 0.928962],
[1.617818, 1.601587, 1.580476, ..., 1.631384, 1.64521 , 1.638424],
[2.321404, 2.296666, 2.260593, ..., 2.308052, 2.344744, 2.347885],...
y: array([[0.914233, 0.906507, 0.900358, ..., 0.954717, 0.945675, 0.928962],
[1.617818, 1.601587, 1.580476, ..., 1.631384, 1.64521 , 1.638424],
[2.321404, 2.296666, 2.260593, ..., 2.308052, 2.344744, 2.347885],...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-OMEGA-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-OMEGA-ANN-global_test.nc
* var_key: OMEGA
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-OMEGA-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-OMEGA-JJA-global_ref.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 2 / 9792 (0.0204%)
Max absolute difference: 6.93198768e-07
Max relative difference: 5.40329309e-05
x: array([[ 1.283442, 1.27651 , 1.25776 , ..., 1.292833, 1.29537 ,
1.287421],
[ 1.93963 , 1.950937, 1.957762, ..., 1.901146, 1.91872 ,...
y: array([[ 1.283442, 1.27651 , 1.25776 , ..., 1.292833, 1.29537 ,
1.287421],
[ 1.93963 , 1.950937, 1.957762, ..., 1.901146, 1.91872 ,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-OMEGA-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-OMEGA-JJA-global_test.nc
* var_key: OMEGA
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 2 / 6120 (0.0327%)
Max absolute difference: 3.39774408e-07
Max relative difference: 0.00015039
x: array([[ 1.150119, 1.168407, 1.16202 , ..., 1.153911, 1.138019,
1.152851],
[ 1.567948, 1.599667, 1.601973, ..., 1.42647 , 1.435826,...
y: array([[ 1.150119, 1.168407, 1.16202 , ..., 1.153911, 1.138019,
1.152851],
[ 1.567948, 1.599667, 1.601973, ..., 1.42647 , 1.435826,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-RELHUM-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-RELHUM-ANN-global_ref.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-RELHUM-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-RELHUM-ANN-global_test.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-RELHUM-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-RELHUM-JJA-global_ref.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-RELHUM-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-RELHUM-JJA-global_test.nc
* var_key: RELHUM
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-T-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-T-ANN-global_ref.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-T-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-T-ANN-global_test.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-T-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-T-JJA-global_ref.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-T-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-T-JJA-global_test.nc
* var_key: T
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-U-ANN-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-U-ANN-global_ref.nc
* var_key: U
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 1 / 9792 (0.0102%)
Max absolute difference: 1.06174015e-07
Max relative difference: 1.43005542e-05
x: array([[10.623722, 10.599673, 10.576724, ..., 10.698371, 10.673217,
10.64816 ],
[12.345496, 12.317517, 12.289864, ..., 12.432171, 12.403032,...
y: array([[10.623722, 10.599673, 10.576724, ..., 10.698371, 10.673217,
10.64816 ],
[12.345496, 12.317517, 12.289864, ..., 12.432171, 12.403032,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-U-ANN-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-U-ANN-global_test.nc
* var_key: U
Not equal to tolerance rtol=1e-05, atol=0
Mismatched elements: 1 / 6120 (0.0163%)
Max absolute difference: 1.45889873e-07
Max relative difference: 1.08735566e-05
x: array([[ 9.712424, 9.692257, 9.675111, ..., 9.79681 , 9.779955,
9.765068],
[12.482069, 12.457917, 12.434379, ..., 12.581674, 12.560391,...
y: array([[ 9.712424, 9.692257, 9.675112, ..., 9.79681 , 9.779955,
9.765068],
[12.482069, 12.457917, 12.434379, ..., 12.581674, 12.560391,...
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-U-JJA-global_ref.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-U-JJA-global_ref.nc
* var_key: U
* All close and within relative tolerance (1e-05)
Comparing:
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/657-meridional-mean-2d/meridional_mean_2d/MERRA2/MERRA2-U-JJA-global_test.nc
* /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/meridional_mean_2d/MERRA2/MERRA2-U-JJA-global_test.nc
* var_key: U
* All close and within relative tolerance (1e-05)
I'll take a look this week, the code assumes the dimension ordering is [..., X, Y], I'll adjust this to be more flexible.
@jasonb5 Sounds good, thanks.
@jasonb5 Unless this can be resolved by next Tues, we can push it back to the next release. I don't think it is a high priority because Jiwoo hasn't ran into it and I'm using xESMF in e3sm_diags instead.
@tomvothecoder Go ahead and push this out to the next release.
@jasonb5 Sounds good
What happened?
There is an issue where transposing the shape of data causes misalignment with the original dimension order. When we attempt to preserve bounds, the original dimension order is still being used which does not align with the transposed dimension order.
Example
Let's say we have
ds_a
with an original dimension of shape of(lat: 1, lev: 2, lon: 3)
.After transposing the data,
output_data
becomeshape=(2, 1, 3)
.https://github.com/xCDAT/xcdat/blob/d0e33aaea04ffeca0301cd7773e4f981c7957653/xcdat/regridder/regrid2.py#L164-L172
We recreate the
xr.DataArray
(output_da
) usingoutput_data
anddims
. As mentioned above, the shape ofoutput_data
is now transposed, but it does not align with the originaldims
. This results inoutput_da
having a new dimension shape of(lat: 2, lev: 1, lon: 3)
https://github.com/xCDAT/xcdat/blob/d0e33aaea04ffeca0301cd7773e4f981c7957653/xcdat/regridder/regrid2.py#L184-L197When we attempt to preserve
lat_bnds
in_preserve_bounds()
, the originallat_bnds
still has has a shape of(lat: 1, lev: 2, lon: 3)
, which does not align with(lat: 2, lev: 1, lon: 3)
.https://github.com/xCDAT/xcdat/blob/d0e33aaea04ffeca0301cd7773e4f981c7957653/xcdat/regridder/base.py#L48-L58
This results in
ValueError: cannot reindex or align along dimension 'lat' because of conflicting dimension sizes: {1, 2} (note: an index is found along that dimension with size=1)
.What did you expect to happen? Are there are possible answers you came across?
Maybe
output_data
shape should align with the original dim order or we should also transpose the shape of the bounds?Minimal Complete Verifiable Example (MVCE)
Relevant log output
Anything else we need to know?
No response
Environment
Latest
main
xCDAT