# Seam along 0 dateline when regridding with xesmf

**URL:** <https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214>\
**Category:** Uncategorized\
**Created:** [May 10, 2024, 4:57pm UTC](https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214 "2024-05-10T16:57:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mberdahl](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mberdahl](https://discourse.pangeo.io/u/mberdahl)\
**Post date:** [May 10, 2024, 4:57pm UTC](https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214/1 "2024-05-10T16:57:04Z")

</div>

Hi, I’m trying to regrid some cmip6 models with xesmf regridder.  
The operation works, but then some (not all) of the regridded models have a seam in the output at the 0 dateline. I use periodic = True, which I assume is supposed to deal with this issue.

I found this post ([Problem with dateline (longitude=0) for higher resolution global grids · Issue #101 · JiaweiZhuang/xESMF · GitHub](https://github.com/JiaweiZhuang/xESMF/issues/101)), but it appears to be old. Here is a snippet of code and the seam when plotted:

```auto
# define the target grid

starty = 1985; endy = 1986
year_range = range(starty, endy+1)

# ds = dset_dict['CMIP.NCC.NorESM2-LM.historical.Amon.gn']
ds = dt["NorESM2-LM"]["historical"].ds.tas

# Read in the output grid from NorESM
ds_target = ds.sel(time = ds.time.dt.year.isin(year_range)).squeeze()
ds_target

# Define the names of the datasets
dataset_names = ["ACCESS_CM2_hist", "ACCESS_CM2_histNat", "ACCESS_ESM1_5_LM_hist", "ACCESS_ESM1_5_LM_histNat", "BCC_CSM2_MR_hist", "BCC_CSM2_MR_histNat", "CanESM5_hist", "CanESM5_histNat", "CESM2_hist", "CESM2_histNat" ,"FGOALS_g3_hist", "FGOALS_g3_histNat", "GISS_E2_1_G_hist", "GISS_E2_1_G_histNat" , "HadGEM3_GC31_L_hist", "HadGEM3_GC31_L_histNat", "MIROC6_hist", "MIROC6_histNat" , "MRI_ESM2_0_hist", "MRI_ESM2_0_histNat" , "NorESM2_LM_hist", "NorESM2_LM_histNat"]

# Create an empty dictionary to store the regridded datasets
regridded_datasets = {}

# Loop through each dataset name
for dataset_name in dataset_names:
    print(dataset_name)

    # Define the original dataset
    original_dataset = globals()[dataset_name]

    # Define the regridder object
    regridder = xe.Regridder(
        original_dataset, ds_target, "bilinear", periodic=True, ignore_degenerate=True,
    ) # this takes some time to calculate a weight matrix for the regridding

    # Apply regridding and store the regridded dataset in the dictionary
    regridded_datasets[dataset_name] = regridder(original_dataset.squeeze()) 

```

Thanks for any help!

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pangeo/original/2X/5/5db7589a076a9e6ab3886e4745b87a106ce38c7d.png)

---

<div class="post-metadata">

**Author:** ![pochedley](https://avatars.discourse-cdn.com/v4/letter/p/f9ae1b/32.png) [@pochedley](https://discourse.pangeo.io/u/pochedley)\
**Post date:** [May 13, 2024, 4:13pm UTC](https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214/2 "2024-05-13T16:13:24Z")

</div>

Hi @mberdahl – I was surprised that you were left with a seam specifying `periodic=True`. I didn’t get a seam trying to regrid ACCESS-CM2 using xcdat (which uses xesmf, see docs [here](https://xcdat.readthedocs.io/en/latest/generated/xcdat.regridder.xesmf.XESMFRegridder.html) and example [here](https://xcdat.readthedocs.io/en/latest/examples/regridding-horizontal.html)).

One note: I think that xesmf is now being maintained [here](https://github.com/pangeo-data/xESMF). That might be a good place to open an issue. If you can link to specific datasets (you can often get direct dataset links to CMIP data [here](https://aims2.llnl.gov/search)) and create a minimally reproducible example, I think that will help others try to reproduce your issue and provide suggestions.

---

<div class="post-metadata">

**Author:** ![mberdahl](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mberdahl](https://discourse.pangeo.io/u/mberdahl)\
**Post date:** [May 16, 2024, 10:22pm UTC](https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214/3 "2024-05-16T22:22:09Z")

</div>

Hi @pochedley , thanks. I posted and got a response on the xESMF git page. Looks like it was a bug and there is a temporary workaround until it is fixed in the code. Perhaps it’ll help someone else.

> <https://github.com/pangeo-data/xESMF/issues/363>
>
> Hi, 
> 
> I'm trying to regrid some cmip6 models with xesmf regridder.
> The operat…ion works, but upon plotting some (not all) of the regridded models have a seam in the output at the 0 dateline. 
> I am using periodic=True.
> Appreciate any help!
> 
> Here is a small bit of code that illustrates the issue with one model:
> \[Data.zip\](https://github.com/pangeo-data/xESMF/files/15325348/Data.zip)
> 
> \`\`\`
> import xarray as x
> import cartopy.crs as ccrs
> import matplotlib.pyplot as plt
> import matplotlib.path as mpath
> import numpy as np
> import xesmf as xe
> 
> original\_dataset = xr.open\_dataset("ds\_input.nc")
> ds\_target = xr.open\_dataset("ds\_target.zarr")
> 
> \# Define the names of the datasets
> dataset\_names = \["tas\_ACCESS\_CM2\_hist"\]
> 
> \# Create an empty dictionary to store the regridded datasets
> regridded\_datasets = {}
> 
> \# Loop through each dataset name
> for dataset\_name in dataset\_names:
>     
> # Define the original dataset
> original\_dataset = globals()\[dataset\_name\]
> 
> # Define the regridder object
> regridder = xe.Regridder(
> original\_dataset, ds\_target, "bilinear", periodic=True, ignore\_degenerate=True,
> ) # this takes some time to calculate a weight matrix for the regridding
> 
> # Apply regridding and store the regridded dataset in the dictionary
> regridded\_datasets\[dataset\_name\] = regridder(original\_dataset.squeeze()) # this is a bit of a lazy operation
> 
> tas\_ACCESS\_CM2\_hist\_regridded = regridded\_datasets\["tas\_ACCESS\_CM2\_hist"\]
> 
> 
> \# for testing, just compare the original with the regridded dataset to see about the seam
> 
> 
> fig, (axs) = plt.subplots(
> # ncols=2, nrows=11, figsize=\[10, 35\], subplot\_kw={"projection": ccrs.Robinson()}
> ncols=2, nrows=1, figsize=\[10, 3\], subplot\_kw={"projection": ccrs.PlateCarree()}
> 
> )
> 
> vupper = 293.15
> vlower = 253.15
> 
> 
> \# plot the model data
> original\_dataset.plot(
> ax=axs\[0\],
> x="x",
> y="y",
> transform=ccrs.PlateCarree(),
> cmap="RdBu\_r",
> vmax = vupper,
> vmin = vlower,
> robust=True,
> )
> 
> tas\_ACCESS\_CM2\_hist\_regridded.plot(
> ax=axs\[1\],
> x="x",
> y="y",
> transform=ccrs.PlateCarree(),
> cmap="RdBu\_r",
> vmax = vupper,
> vmin = vlower,
> robust=True,
> )
> 
> axs\[0\].coastlines()
> axs\[0\].set\_title("Historical ACCESS\_CM2")
> 
> axs\[1\].coastlines()
> axs\[1\].set\_title("Historical ACCESS\_CM2 - regridded")
> \`\`\`
> !\[Screenshot 2024-05-15 at 10 55 46 AM (2)\](https://github.com/pangeo-data/xESMF/assets/67171256/707043a4-b8c3-4f26-8eff-fb468adfa99e)
> 
> !\[image\](https://github.com/pangeo-data/xESMF/assets/67171256/bf633bab-5a53-4dd0-abd8-c53d393f93c6)

---

<div class="post-metadata">

**Author:** ![pochedley](https://avatars.discourse-cdn.com/v4/letter/p/f9ae1b/32.png) [@pochedley](https://discourse.pangeo.io/u/pochedley)\
**Post date:** [May 16, 2024, 11:31pm UTC](https://discourse.pangeo.io/t/seam-along-0-dateline-when-regridding-with-xesmf/4214/4 "2024-05-16T23:31:58Z")

</div>

Hi @mberdahl – thank you for the update and for posting a reproducible example (xCDAT also had trouble interpreting how to regrid this data). I think this will be helpful to others.
