Plotting interpolated data causes artefacts #6010
Replies: 8 comments 3 replies
-
I decided to also look at what happens when you plot with contourf. In this case both the plot of the original data and the interpolated data have a white line at the central longitude, but the interpolated data also has white lines at the poles: Original MPI-ESM Interpolated MPI-ESM Here's the code that produced the plots: import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
cesm2_waccm = xr.open_dataset('pr_day_CESM2-WACCM_ssp245_r2i1p1f1_gn_20750101-20841231.nc')
mpi = xr.open_dataset('pr_day_MPI-ESM1-2-LR_ssp245_r1i1p1f1_gn_20750101-20941231.nc')
cesm2_waccm_subset = cesm2_waccm.sel(time=slice('2075-01-01', '2075-12-31')).mean(dim='time')
mpi_subset = mpi.sel(time=slice('2075-01-01', '2075-12-31')).mean(dim='time')
map_proj = ccrs.PlateCarree()
# Now this also produces a white line.
plot = mpi_subset.pr.plot.contourf(subplot_kws={'projection': map_proj})
plot.axes.coastlines()
plt.show()
mpi_interp = mpi_subset.interp(lat=cesm2_waccm_subset['lat'], lon=cesm2_waccm_subset['lon'])
# Has a white line at the central longitude.
plot = mpi_interp.pr.plot.contourf(subplot_kws={'projection': map_proj})
plot.axes.coastlines()
plt.show() |
Beta Was this translation helpful? Give feedback.
-
Xarray's built-in interpolation method does not know how to handle periodic coordinates, which is why you see the blank center line. I would recommend using xESMF, which is an xarray wrapper of some code specifically written to interpolate from one geospatial grid to another, and knows how to handle periodic coordinates (see the |
Beta Was this translation helpful? Give feedback.
-
@spencerkclark Thanks for the suggestion! I haven't made any serious tests yet, but my initial tests worked fine =) |
Beta Was this translation helpful? Give feedback.
-
If this solves your issue all is fine. However, I am a bit surprised that the |
Beta Was this translation helpful? Give feedback.
-
@mathause I think the issue is that non-periodic interpolation introduces NaNs into the dataset, which get plotted as a white line. |
Beta Was this translation helpful? Give feedback.
-
As an aside, this is something that we might want to try and fix via a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What happened:
I'm trying to do some analysis of CMIP6 model data, and I want to plot multi-model ensembles. In order to do that I need to regrid all of the models to a common grid. Whenever I try to plot data from a regridded model there's a white line along the central longitude and the poles. I use the PlateCarree projection and it doesn't matter what I choose as the central longitude; there's always a white line there.
The code I've included below produces 4 plots. The first one is of data that hasn't been interpolated and there's no white line:
The next three are with interpolated data and with different central longitudes. They all have a white line at the central longitude.
central_longitude=0
central_longitude=33
central_longitude=164
What you expected to happen:
No plot artefacts.
Minimal Complete Verifiable Example:
Anything else we need to know?:
Here's the data I used for plotting:
https://climate.uiogeo-apps.sigma2.no/ESGF/CMIP6/ScenarioMIP/NCAR/CESM2-WACCM/ssp245/r2i1p1f1/day/pr/gn/v20200224/pr_day_CESM2-WACCM_ssp245_r2i1p1f1_gn_20750101-20841231.nc
https://climate.uiogeo-apps.sigma2.no/ESGF/CMIP6/ScenarioMIP/MPI-M/MPI-ESM1-2-LR/ssp245/r1i1p1f1/day/pr/gn/v20190710/pr_day_MPI-ESM1-2-LR_ssp245_r1i1p1f1_gn_20750101-20941231.nc
Environment:
Output of xr.show_versions()
Beta Was this translation helpful? Give feedback.
All reactions