Remap WOA18 to tx1_4#

%matplotlib inline
import xarray as xr
import xesmf
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
fname = '../mesh/tx1_4_grid.nc'
ds_out = xr.open_dataset(fname).rename({'tlon': 'lon','tlat': 'lat', 'qlon': 'lon_b','qlat': 'lat_b',})
ds_out
<xarray.Dataset>
Dimensions:  (ny: 1080, nx: 1440, nxp: 1441, nyp: 1081)
Dimensions without coordinates: ny, nx, nxp, nyp
Data variables: (12/20)
    lon      (ny, nx) float64 ...
    lat      (ny, nx) float64 ...
    ulon     (ny, nxp) float64 ...
    ulat     (ny, nxp) float64 ...
    vlon     (nyp, nx) float64 ...
    vlat     (nyp, nx) float64 ...
    ...       ...
    tarea    (ny, nx) float64 ...
    tmask    (ny, nx) float64 ...
    angle    (ny, nx) float64 ...
    depth    (ny, nx) float64 ...
    ar       (ny, nx) float64 ...
    egs      (ny, nx) float64 ...
Attributes:
    Description:  CESM MOM6 1/4 degree grid
    Author:       Frank, Fred, Gustavo (gmarques@ucar.edu)
    Created:      2022-12-27T10:20:11.076318
    type:         Glogal 1/4 degree grid file
infile = '/glade/campaign/cgd/oce/datasets/obs/woa18/woa18_decav_merged_monthly_deep_04.nc'
ds_in = xr.open_dataset(infile)
def regrid_tracer(fld, ds_in, ds_out, method='bilinear'):

    regrid = xesmf.Regridder(
        ds_in,
        ds_out,
        method=method,
        periodic=True,
    )
    fld_out = regrid(ds_in[fld])#[0,0,:]#.where(ds_in.lat>ds_out.geolat.min())
    return fld_out

Potential temperature#

temp = regrid_tracer('theta0', ds_in, ds_out)

Visual inspection#

Make sure original and remapped plots look similar.

# visual inspection. Make sure original and remapped plots look similar
for t in range(len(temp.time)):
  fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(18,4))
  temp[t,0,:,:].plot.pcolormesh(ax=axes[0], vmin=-2,vmax=30)
  ds_in['theta0'][t,0,:,:].plot.pcolormesh(ax=axes[1], vmin=-2,vmax=30)
  axes[0].set_title('Remapped')
  axes[1].set_title('Original grid')
  plt.suptitle('Month ='+ str(t+1))
../_images/f84d28721b4cc068a95cc6be1a5b1636544b340befe6906ab876d5d935ca05fd.png ../_images/18d800e1f3768f58a750b6c5db8bc0ae50b555d12baee1eae013d3d7b0db943e.png ../_images/d11d16f57773489ef6183d93c38cd606e2f030aaeb6bd3c96d8f6147270118ea.png ../_images/3a8642d02fc6dcf056d75c1f04585c1a5b7c879cb7b8ca83576cf00854e3fce3.png ../_images/98d8bf2757b41c3a74575114a6d527629f7004132ba1328223d3d4b0085edc60.png ../_images/9eb1048ca7207eb01a5fa78650e5f370c5fab8ede34649df52e8f62fc5082b39.png ../_images/0214c171a945faab5919254b5038ab86702920cf926b3ee193a3d685747093a4.png ../_images/0f80197efa3e02b79d77b6bf163fe3b8c8bc8719fdf399f66499ca53f9327a27.png ../_images/2cbbf8a4177abc1825966fdc955c5cdcf382c24e70f04f66447bd9ef1f4746e5.png ../_images/cc09bdbcec3d1acd31b99ce31710a30bfa131a4d76b09bd3589c96b3a1b10c3d.png ../_images/96f23bb037bc7a8451af514d2faaf960047cc9a27b05a0a5e5cc387fae3c7cc4.png ../_images/e880adb4c013eb8fff042cc8e32f8f85d885d5e8366f058c56f3f7d6a2d06311.png

Salinity#

salt = regrid_tracer('s_an', ds_in, ds_out)

Visual inspection#

Make sure original and remapped plots look similar.

# visual inspection. Make sure original and remapped plots look similar
for t in range(len(temp.time)):
  fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(18,4))
  salt[t,0,:,:].plot.pcolormesh(ax=axes[0], vmin=20,vmax=37)
  ds_in['s_an'][t,0,:,:].plot.pcolormesh(ax=axes[1], vmin=20,vmax=37)
  axes[0].set_title('Remapped')
  axes[1].set_title('Original grid')
  plt.suptitle('Month ='+ str(t+1))
../_images/91db436beab71b520d1e99e25ec0509f414a29df5eca31f0b4a8d5c2169fc201.png ../_images/a2975f9149f665c0e70d64f92e6904b89a2da150309aaca53f9983314da1c892.png ../_images/0321d539eb1c89b21fe43c83d7e6f41834a92d77b333163b97a9fd57bb2217e8.png ../_images/d096ab6b2d3cb126c8a79505f251e34a8958a37069718fb353fde5758ceb371a.png ../_images/9a6b86b7117928f2162d82c19d8104be40f9108ca68cc2e4bb096135e47926af.png ../_images/5acebea24c109b8e452577b9c92705dd49f4f08b0af8acda39a0a468b104662a.png ../_images/598ec2b0fa301a666ebc05d8f697bd47add8ec24ed6daf83067e0a7e3d22a4f4.png ../_images/8c68e8ec85c1cdec2c3ef85e2126b4b60a09124195dce1a4dc4fa27e8ca9c413.png ../_images/4aeea7927b612eda17637b070077560efbee11a1612cdf3e8d23d497752276b7.png ../_images/d789f8db70c17017615fa125927e03b45f39be47c876d90400d418ade9f95cb6.png ../_images/afbe178e4e3861815118c751820276e0d7c6a50e937c2c165a2763b6147db47b.png ../_images/26a2a2e2f3a02ff9617fa9a7b28950893bee35df79c13fe9cc36fcf731319120.png

WOA09 layer depths#

To keep consistency with previous datasets and to avoid modifying parameter DIAG_COORD_DEF_Z in CESM/MOM6, we will vertically interpolate temp and salt to the 34 layer depths from WOA09

depths_woa09 = np.array([2.5, 10, 20, 32.5, 51.25, 75, 100, 125, 156.25, 200, 250, 312.5, 400,
500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1537.5, 1750,
2062.5, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000]);

Monthly means#

temp_depths_woa09 = temp.interp(depth=depths_woa09).rename('temp')
# Global attrs
temp_depths_woa09.attrs['title'] = 'Potential temperature (monthly mean) from WOA18 remapped to tx1_4 and vertically interpolated to the WOA09 depths.'
temp_depths_woa09.attrs['author'] = 'Gustavo Marques (gmarques@ucar.edu)'
temp_depths_woa09.attrs['date'] = datetime.now().isoformat()
temp_depths_woa09.attrs['infile'] = infile
temp_depths_woa09.attrs['url'] = 'https://github.com/NCAR/tx1_4/woa18'
# save
fname = 'WOA18_TEMP_tx1_4_35lev_monthly_avg.nc'
temp_depths_woa09.to_netcdf(fname)
salt_depths_woa09 = salt.interp(depth=depths_woa09).rename('salt')
# Global attrs
salt_depths_woa09.attrs['title'] = 'Salinity (monthly mean) from WOA18 remapped to tx1_4 and vertically interpolated to the WOA09 depths.'
salt_depths_woa09.attrs['author'] = 'Gustavo Marques (gmarques@ucar.edu)'
salt_depths_woa09.attrs['date'] = datetime.now().isoformat()
salt_depths_woa09.attrs['infile'] = infile
temp_depths_woa09.attrs['url'] = 'https://github.com/NCAR/tx1_4/woa18'
# save
fname = 'WOA18_SALT_tx1_4_35lev_monthly_avg.nc'
salt_depths_woa09.to_netcdf(fname)

Annual mean#

temp_depths_woa09_ann = temp.mean('time').interp(depth=depths_woa09)#.rename('temp')
# Global attrs
temp_depths_woa09_ann.attrs['title'] = 'Potential temperature from WOA18 (annual mean) remapped to tx1_4 and vertically interpolated to the WOA09 depths.'
temp_depths_woa09_ann.attrs['author'] = 'Gustavo Marques (gmarques@ucar.edu)'
temp_depths_woa09_ann.attrs['date'] = datetime.now().isoformat()
temp_depths_woa09_ann.attrs['infile'] = infile
temp_depths_woa09.attrs['url'] = 'https://github.com/NCAR/tx1_4/woa18'
# save
fname = 'WOA18_TEMP_tx1_4_35lev_ann_avg.nc'
temp_depths_woa09_ann.to_netcdf(fname)
salt_depths_woa09_ann = salt.mean('time').interp(depth=depths_woa09).rename('salt')
# Global attrs
salt_depths_woa09_ann.attrs['title'] = 'Salinity from WOA18 (annual mean) remapped to tx1_4 and vertically interpolated to the WOA09 depths.'
salt_depths_woa09_ann.attrs['author'] = 'Gustavo Marques (gmarques@ucar.edu)'
salt_depths_woa09_ann.attrs['date'] = datetime.now().isoformat()
salt_depths_woa09_ann.attrs['infile'] = infile
temp_depths_woa09.attrs['url'] = 'https://github.com/NCAR/tx1_4/woa18'
# save
fname = 'WOA18_SALT_tx1_4_35lev_ann_avg.nc'
salt_depths_woa09_ann.to_netcdf(fname)