Mixed layer depth#

%load_ext autoreload
%autoreload 2
%%capture 
# comment above line to see details about the run(s) displayed
from misc import *
from mom6_tools.m6plot import myStats, annotateStats, xycompare
import cartopy.crs as ccrs
import cartopy.feature
import intake
%matplotlib inline
# load obs-based mld from oce-catalog
obs = 'mld-deboyer-2023-tx2_3v2'
catalog = intake.open_catalog(diag_config_yml['oce_cat'])
print('\n Reading climatology from: ', obs)
mld_obs = catalog[obs].to_dask().where(grd_xr[0].wet > 0.)
# rename coords and and fix time
#mld_obs = mld_obs.rename({'lon' : 'longitude', 'lat' : 'latitude', 'time' : 'month'})
mld_obs = mld_obs.rename({'time' : 'month'})
mld_obs["month"] = np.arange(1,len(mld_obs.month)+1)
months = [0,1,2]
obs_JFM = np.ma.masked_invalid(mld_obs.mld.isel(month=months).mean('month').values)
months = [6,7,8]
obs_JAS = np.ma.masked_invalid(mld_obs.mld.isel(month=months).mean('month').values)
obs_winter = obs_JAS.copy(); obs_summer = obs_JAS.copy()
j = np.abs( grd[0].geolat[:,0] - 0. ).argmin()
obs_winter[j::,:] = obs_JFM[j::,:]
obs_summer[0:j,:] = obs_JFM[0:j,:]
 Reading climatology from:  mld-deboyer-2023-tx2_3v2

Monthly#

months = ['January', 'February', 'March', 'April', 
          'May', 'June', 'July', 'August', 'September', 
          'October', 'November', 'December']

ds = []
for path, case, i in zip(ocn_path, casename, range(len(label))):
  ds.append(xr.open_dataset(path+case+'_MLD_monthly_clima.nc'))

January#

def plot_mld_month(m=0):
    for i in range(len(label)):
        model = np.ma.masked_invalid(ds[i].mlotst.isel(month=m).values)
        obs   = np.ma.masked_where(grd[i].wet == 0, mld_obs.mld.isel(month=m).values)
        xycompare(model, 
                obs, 
                grd[i].geolon, grd[i].geolat, grd[0].areacello,
                title1 = label[i], 
                title2 = 'obs (deBoyer, 2023)', 
                suptitle=str(months[m]) +' climatology, '+ str(start_date) + ' to ' + str(end_date),
                colormap=plt.cm.nipy_spectral, dcolormap=plt.cm.bwr,
                clim = (0,1000), extend='max',
                dlim=(-200,200))
          
    fig, ax = plt.subplots(figsize=(8,10))
    for i in range(len(label)):
        ds[i].mlotst.isel(month=m).weighted(grd_xr[i].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                            ax=ax, label=label[i], lw=2)
        
    mld_obs.mld.isel(month=m).weighted(grd_xr[0].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                            ax=ax, label='obs (deBoyer, 2023)', lw=4)
    ax.set_title('Zonally averaged MLD, '+str(months[m]))
    ax.grid()
    ax.legend();
    return
plot_mld_month(m=0)
_images/22c82e5fe8225bb4cbddf788f4ecee90fb9a9b861bdefc971662231b7bc9b6e4.png _images/065030a778c75aac19376e12221c951f7e30659638c1abda0b1a2f9581697d71.png

February#

plot_mld_month(m=1)
_images/81bfa2dadc2a5624f30888205cec9110000862f6bd8522afd6c5e415427dcd4e.png _images/7c52530651448fcf99242237107720f6db49315c5c9755b92ddd0544039959b8.png

March#

plot_mld_month(m=2)
_images/b10ab6301db53f5ee67af86bda5715592e27100e9498dcb4822efff62b4b5b0e.png _images/245a9c11eb8c746bc2ac07f55f4c81d7c4050c68369df84821b3141529c5eebb.png

April#

plot_mld_month(m=3)
_images/de2122bfe6b5969f84ad01396571eb8d62e7e77cbfe408f7b7307a5a2b33eb79.png _images/d361c7f21678c86fc5c5a62fd479855bff98b14fb4b2094058d20d7d0e7ae548.png

May#

plot_mld_month(m=4)
_images/b284c766628a0ed250e0dd873b09fbe09107835380a84986c6629db7cc125f17.png _images/bfde2e98b7080acf5f51f090b8e1dd8263c52dae22020002fbc74712b4a982c2.png

June#

plot_mld_month(m=5)
_images/8d585e7fe85fd5ba0d689cd2e08bad2be3b93d86399bc1ad7d78c18fd78e81c6.png _images/e19a4e4b592a7d3ee99d122acf5f141800c360898a24ca17c30078e4d0bd4d36.png

July#

plot_mld_month(m=6)
_images/3071eb3ef3e6cbde5408d4a59ad92d1e6d61d5d2b81636118bbf57e7ab5b430d.png _images/22acbc6114be4c3da74e861d1f5862555f93505d94119a8d39f0934be3c2c9e3.png

August#

plot_mld_month(m=7)
_images/4d922254f14091270c991cf38ea0e9f89030e505f432fb1e348a1f713d6ca84b.png _images/51d0594ff2aeeec819c6cbd18709ee748a3b7090cc71fe7e4e9f5e31875c4249.png

September#

plot_mld_month(m=8)
_images/88af790f4aa113979c38a5de2142f3f23d2e6f817cd8483cc1c45d3b192fc3d8.png _images/86496c26f6a00895a2b9e3b43661803af4713f5dc9e0cae7f51f08088be58fa3.png

October#

plot_mld_month(m=9)
_images/e77caf7145542bf32a47206e99549eca23d009efbdc022918ecf18870e616cc2.png _images/3511cb5dcdac0e49153954cf6b63ecd0556633a6dacac7d4dfe33da2b4068dea.png

November#

plot_mld_month(m=10)
_images/8b43f958da7ceadf231fdc84e23511a472bd0911269899de1299ae3e9301ee1f.png _images/f8976d0d503aacd28ad5acced7bb8cee275739813b77dd1e537188816b48df5e.png

December#

plot_mld_month(m=11)
_images/b0da544bf6ab247bc3dc0c6f32d1a2a258b49f47d5705ba9d0fd2b1f819bfb84.png _images/e396daa1dc6a49357adc7a4db0ed3cffbc2f6e127a4605b694bb1c79fd8825ee.png

All months, obs#

cmap = plt.cm.nipy_spectral.copy()
cmap.set_bad(color='gray') 

g = mld_obs.mld.plot(x="xh", y="yh", col='month', 
            col_wrap=3,
            robust=True,
            figsize=(14,12),
            cmap=cmap,
            vmin=0., vmax=1000.,
            cbar_kwargs={"orientation": "horizontal", "pad": 0.05, "label": 'MLD (m), 0.03 density criteria'},
           )
# Add a suptitle
g.fig.suptitle('deBoyer, 2023', fontsize=16, y=1.02);
_images/13207ae8daf8eb2d69fd2d5d1ae61b6b6d569f9ebfb5b6620ebb6d811e05bf05.png

All months, model#

for path, case, i in zip(ocn_path, casename, range(len(casename))):
  ds =  xr.open_dataset(path+case+'_MLD_monthly_clima.nc')
  g = ds.mlotst.plot(x="longitude", y="latitude", col='month', 
                col_wrap=3,
                robust=True,
                figsize=(14,12),
                cmap=cmap,
                vmin=0., vmax=1000.,
                cbar_kwargs={"orientation": "horizontal", "pad": 0.05, "label": 'MLD (m), 0.03 density criteria'},
               )
  # Add a suptitle
  g.fig.suptitle('Run {}, mean between {} to {}'.format(label[i], start_date, end_date), fontsize=16, y=1.02);
_images/fe948fe7fe2210e9294956f22936a972a73ebaa53871a64564328710a0c58cd8.png

All months, model - obs#

cmap = plt.cm.bwr.copy()
cmap.set_bad(color='gray')  

for path, case, i in zip(ocn_path, casename, range(len(casename))):
  ds =  xr.open_dataset(path+case+'_MLD_monthly_clima.nc')
  diff = ds.mlotst - mld_obs.mld
  g = diff.plot(x="longitude", y="latitude", col='month', 
                col_wrap=3,
                robust=True,
                figsize=(14,12),
                cmap=cmap,
                vmin=-200, vmax=200.,
                cbar_kwargs={"orientation": "horizontal", "pad": 0.05, "label": 'MLD bias (m)'},
               )
  # Add a suptitle
  g.fig.suptitle('Run {} - Deboyer, 2023'.format(label[i]), fontsize=16, y=1.02);
_images/cb76b225c5eb5266a855b3b46842b62540b0254f8264165a8692811f301a3ea4.png

Winter#

%matplotlib inline

title = 'Mean Winter MLD, JFM(NH), JAS(SH)'
try:
  area= grd[0].area_t
except:
  area= grd[0].areacello
plot_map(obs_winter, area, grd[0], 'deBoyer, 2023', 
           vmin=0, vmax=1500, suptitle=title)
_images/a9e6cc438bdc09d13fd672e6c24118eca9d706207f60d0730bd800c228df222e.png
title1 = 'Mean Winter MLD, JFM(NH), JAS(SH)'
title2 = 'Mean Winter MLD (model - obs), JFM(NH), JAS(SH)'

for path, case, i in zip(ocn_path, casename, range(len(casename))):
  da = xr.open_dataset(path+case+'_MLD_winter.nc')
  try:
    area= grd[i].area_t
  except:
    area= grd[i].areacello

  # model
  plot_map(da.MLD_winter.values, area, grd[i], label[i], 
           vmin=0, vmax=1500, suptitle=title1) 
  # model - obs
  diff = (da.MLD_winter.values - obs_winter)
  plot_map(diff, area, grd[i], label[i] + ' - deBoyer, 2023', 
           vmin=-500, vmax=500, suptitle=title2, cmap='bwr')
_images/3adc3d49afe279567976391f6e9d73d86671f1cef1472851a7085b5c21449964.png _images/3943d510aafb4fd6eebb031de0f298ef36bbe0c1ab36f4c33afc6a54d5927baf.png
fig, ax = plt.subplots(figsize=(8,10))
for path, case, i in zip(ocn_path, casename, range(len(casename))):
    da = xr.open_dataset(path+case+'_MLD_winter.nc')
    da.MLD_winter.weighted(grd_xr[i].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                        ax=ax, label=label[i], lw=2)

obs_winter_da = xr.DataArray(
    data=obs_winter,  # New data (all zeros)
    coords=da.coords,
    dims=da.dims
)

obs_winter_da.weighted(grd_xr[0].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                        ax=ax, label='obs (deBoyer, 2023)', lw=3)
ax.set_title('Zonally averaged MLD, Winter JFM(NH), JAS(SH)')
ax.grid()
ax.legend();
_images/705102f241a20cffe8ddbe0bc133c45ef1a334b0a61b2b2747bb54d5c5be016c.png

Summer#

title = 'Mean Summer MLD, JFM(SH), JAS(NH)'
try:
  area= grd[0].area_t
except:
  area= grd[0].areacello
plot_map(obs_summer, area, grd[0], 'deBoyer, 2023', vmin=0, vmax=200, 
           suptitle=title, nh='JAS', sh='JFM',)
_images/75c22e41e772000ed620f05c549942faf6db040a68f48330d777ba2a7ba928a6.png
title1 = 'Mean Summer MLD, JFM(SH), JAS(NH)'
title2 = 'Mean Summer MLD (model - obs), JFM(SH), JAS(NH)'

for path, case, i in zip(ocn_path, casename, range(len(casename))):
  da = xr.open_dataset(path+case+'_MLD_summer.nc')
  try:
    area= grd[i].area_t
  except:
    area= grd[i].areacello

  # model
  plot_map(da.MLD_summer.values, area, grd[i], label[i], 
           vmin=0, vmax=200, suptitle=title1, nh='JAS', sh='JFM') 
  # model - obs
  diff = (da.MLD_summer.values - obs_summer)
  plot_map(diff, area, grd[i], label[i] + ' - deBoyer, 2023', 
           vmin=-100, vmax=100, suptitle=title2, nh='JAS', 
           sh='JFM',cmap='bwr')
_images/487e33135e5dd0fe451d075582877ce26ec4200057ff0dcf94e33257befd05f3.png _images/a5e2a2263c036fa9a1c41145fbdab631b1ac151a8565bbd557994ddb941533db.png
fig, ax = plt.subplots(figsize=(8,10))
for path, case, i in zip(ocn_path, casename, range(len(casename))):
    da = xr.open_dataset(path+case+'_MLD_summer.nc')
    da.MLD_summer.weighted(grd_xr[i].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                        ax=ax, label=label[i], lw=2)

obs_summer_da = xr.DataArray(
    data=obs_summer,  # New data (all zeros)
    coords=da.coords,
    dims=da.dims
)

obs_summer_da.weighted(grd_xr[0].areacello.fillna(0)).mean('xh').plot(y="yh", 
                                        ax=ax, label='obs (deBoyer, 2023)', lw=3)
ax.set_title('Zonally averaged MLD, Summer JFM(SH), JAS(NH)')
ax.grid()
ax.legend();
_images/26d583c385b8c048c4e73dc55ad832018ad0958a32b221a9a6ff09d02f6ab4e2.png