Preview:
import xarray as xr
import xesmf as xe
import numpy as np

def regrid(dr_in):
    """Convenience function for one-time regridding"""
    ds_out = xr.Dataset(
                {
                "lat": (["lat"], np.arange(-90, 91, 1.0)),
                "lon": (["lon"], np.arange(-180, 182, 2.0)),
                }
            )
#ds_out
    regridder = xe.Regridder(dr_in, ds_out, 'bilinear', periodic=True)
    dr_out = regridder(dr_in)
    return dr_out

ERAin=xr.open_dataset('ERA5_monthly_SST.nc')

ERAOut=regrid(ERAin)

ERAOut

ERAOut.to_netcdf(path='ERA5_SST.nc',mode='w',format='NETCDF4')
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter