You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks a lot for this great tool that comes in super handy for harmonizing CMIP data
The bug
When using data with more than 360 lon coordinates, the replace_x_y_nominal_lat_lon will not work as a 360 periodicity is assumed in _interp_nominal_lon. I noticed this behavior in EC-Earth-Consortium EC-Earth3 ssp585 r1i1p1f1 Amon tas gr v20200310, which has this subdegree gridding (lon being 512 datapoints long).
Don't suffle the data when interpolating with sub-degree longitude gridding. This can be solved by not assuming a 360 periodicity.
Underlying cause:
numpy.interp takes the period argument, but this is in the x-coordinate, however, in _interp_nominal_lon, the period is set to 360, this causes funky behavior in this function when you feed it an array with >360 entries, as they are sorted by their arg index.
MWE:
Maybe a small example might be helpful here:
# Create some dummy dataimportnumpyasnpimportxarrayasxrfromxmip.preprocessingimportpromote_empty_dims, replace_x_y_nominal_lat_lon, rename_cmip6, correct_coordinates, broadcast_lonlatimportmatplotlib.pyplotaspltlon=np.linspace(0,360, 513)[:-1]
lat=np.linspace(-90,90, 181)[:-1]
time=np.arange(1)
# Totally arbitrary datadata=np.arange(len(lat)*len(lon)*len(time)).reshape(len(time), len(lat), len(lon))*lon# Add some NaN values just as an exampledata[:, :, len(lon)//2+30: len(lon)//2+50] =np.nands_dummy=xr.Dataset(
data_vars=dict(var=(('time','lat', 'lon'), data,)),
coords=dict(time=time, lon=lon, lat=lat,),
attrs=dict(source_id='bla'))
ds_dummy['var'].isel(time=0).plot(cbar_kwargs=dict(orientation='horizontal'))
# Now apply the recast using replace_x_y_nominal_lat_londefrecast(data_set):
ds=rename_cmip6(data_set)
ds=promote_empty_dims(ds)
ds=broadcast_lonlat(ds)
ds=replace_x_y_nominal_lat_lon(ds)
returndsds_dum_recast=recast(ds_dummy)
replace_x_y_nominal_lat_lon(ds_dum_recast)['var'].isel(time=0).plot(cbar_kwargs=dict(orientation='horizontal'),)
This second imagine is clearly not what we'd hoped for.
I am also encountering some of the issues described here (and similar once related to coordinates). For some models the longitude fixing seems to screw the data, as also experienced by @Quentin-Bourgeois. Is a fix for this issue in the pipeline @jbusecke?
First of all, thanks a lot for the carefully crafted report here @JoranAngevaare. And even more for putting in a fix for this. Ill reopen the PR and continue discussion over there?
Thanks a lot for this great tool that comes in super handy for harmonizing CMIP data
The bug
When using data with more than 360 lon coordinates, the
replace_x_y_nominal_lat_lon
will not work as a 360 periodicity is assumed in_interp_nominal_lon
. I noticed this behavior inEC-Earth-Consortium EC-Earth3 ssp585 r1i1p1f1 Amon tas gr v20200310
, which has this subdegree gridding (lon
being 512 datapoints long).Expected behavior
Don't suffle the data when interpolating with sub-degree longitude gridding. This can be solved by not assuming a 360 periodicity.
Underlying cause:
numpy.interp
takes the period argument, but this is in thex-coordinate
, however, in_interp_nominal_lon
, the period is set to 360, this causes funky behavior in this function when you feed it an array with >360 entries, as they are sorted by their arg index.MWE:
Maybe a small example might be helpful here:
This second imagine is clearly not what we'd hoped for.
Versions
Related PRs/Issues
I believe #93 is also related to this and #79 might be where the bug was introduced.
One way this might be solved is by replacing the above mentioned line as is done in this PR:
#296
The text was updated successfully, but these errors were encountered: