Open nuvolet opened 1 year ago
Is it only showing the half between 0 and 180 of longitude ? Could you maybe show us the plotting code with an image as example ?
I'm making the hypothesis that ESMF works in the -180-180 longitude system, not the 0-360 as you are using. Suggestion: replace your first line with:
ds_out = xe.util.grid_global(1, 1)
It does the same thing, is simpler and uses the -180-180 system.
@nuvolet Is this resolved ?
Hi @aulemahal and @huard
I still cannot have a complete plot with data re-griided using xesmf. For instance the code I am using to plot the data I re-gridded looks like this:
ax1 = plt.subplot(221, projection=ccrs.Robinson()) ax1.set_global(); ax1.coastlines(); #ax1.gridlines(); ax1 = nudge_Aqua.plot(transform=ccrs.PlateCarree(), cmap='coolwarm', center=False, vmin=-0.5, vmax=0.5, levels=10, cbar_kwargs={'label': 'AOD[ ]', 'shrink': 0.85, 'format': "%2.1f"}) plt.title('CAM6 Nudge - MATCH Aqua', fontsize=8, loc='left')
Where nudge_Aqua is the difference from 2 datasets I previously re-gridded using xe.Regridder.
The plot I get looks like this:
The only thing I can think of is that your input data has nans.
Also, it might be easier to debug with a simple plt.imshow
to rule out projection issues.
Did someone manage to solve this problem? I have a similar issue. Here is the code. I would greatly appreciate some assistance. Thanks in advance
import xarray as xr
import xesmf as xe
import glob
import cartopy.crs as ccrs
import cartopy.feature as cfeature
# Lat lon formatter
from cartopy.mpl.gridliner import LongitudeFormatter, LatitudeFormatter
# Add cyclic point
from cartopy.util import add_cyclic_point
# Get files to open
path = 'Data_CMIP/tx90p*ssp245*'
files = glob.glob(path)
# # Open files
datasets = []
for f in files:
ds = xr.open_dataset(f).drop('height')
try:
ds['time'] = ds.indexes['time'].to_datetimeindex()
except AttributeError:
pass
datasets.append(ds)
# Create grid to interpolation
ds_out = xe.util.grid_2d(-180.0, 180.0, 1.0, -90.0, 90.0, 1.0)
for i in range(len(datasets)):
regridder = xe.Regridder(datasets[i], ds_out, 'bilinear', periodic=True)
datasets[i] = regridder(datasets[i], keep_attrs=True)
# Concatenate all datasets into one
ds = xr.concat(datasets, dim='model', join='override')
# Calculate the multi-model mean
ensemble_mean = ds.tx90pETCCDI.mean(dim='model')
# Plot the multi-model mean
fig, ax = plt.subplots(figsize=(10, 5), subplot_kw={'projection': ccrs.Robinson(central_longitude=-180)})
ax.coastlines()
ax.set_global()
# ax.add_feature(cfeature.BORDERS)
# Add cyclic point
data_cyclic, lon_cyclic = add_cyclic_point(ensemble_mean, coord=ensemble_mean.x.values)
# Contourf
cs = ax.contourf(lon_cyclic, ensemble_mean.y.values, data_cyclic[-1],
transform=ccrs.PlateCarree(),
levels=40,
cmap=cmap_temp_ncl, extend='both', robust=True)
# Colorbar
cbar = plt.colorbar(cs, orientation='horizontal', shrink=0.7, pad=0.05, extend='both', aspect=35)
Hi Luiz,
Could you post a link to a sample of the data so I can try to reproduce the problem on my end ?
Greetings,
I am trying to figure out why I cannot have a complete plot of from a data array I regrided to another resolution.
The original data array looks like that:
While after using the libraries xESMF:
I got that:
Then, when I plot the new data (Orig_new_reg ) using Matplotlib and Cartopy only shows my half of the data. Is this due to the new data says it is "Dimensions without coordinates: y, x"?. How I can solve that?
Thanks in advance