-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Regrid2 breaks in _preserve_bounds
because _regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds
#625
Comments
Have you come across this issue @lee1043? |
_regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order_regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds
_regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds_regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds
_regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds_preserve_bounds
because _regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds
_preserve_bounds
because _regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds_preserve_bounds
because _regrid
incorrectly transposes output_data
shape, which doesn't align with original dim order used by bounds
@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 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)
.xcdat/xcdat/regridder/regrid2.py
Lines 164 to 172 in d0e33aa
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)
xcdat/xcdat/regridder/regrid2.py
Lines 184 to 197 in d0e33aa
When 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)
.xcdat/xcdat/regridder/base.py
Lines 48 to 58 in d0e33aa
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
xCDATThe text was updated successfully, but these errors were encountered: