Tidal Dissipation#

Mapping Tidal Wave Dissipation needed for MOM6+CVMix tidal parameterization.

import xarray as xr
import xesmf as xe
import numpy as np
import matplotlib.colors as colors
import datetime
today = datetime.date.today().strftime("%y%m%d")
print(today)
260306
plot_opts = {'size':8, 'norm':colors.LogNorm(vmin=10e-7, vmax=3.0)}

Original Forcing Data#

src_ds = xr.open_dataset("/glade/campaign/cgd/oce/datasets/obs/tidal_dissipation/energy_new.nc")
src_ds.wave_dissipation.plot(**plot_opts)
<matplotlib.collections.QuadMesh at 0x14df689c12b0>
../_images/fd500e0a27bd8ad34fe9dcd5824b3b4fc5ace77f3936e218532de2e30d9bfbb4.png

Fix bad column in src#

# Discard the first column in the src dataset. This bad column
# corresponds to 0.5 deg longitude. Then apply nearest_s2d mapping

regridder = xe.Regridder(
        src_ds.isel(longitude=slice(1,720)),
        src_ds,
        method='nearest_s2d',
        periodic=True,
    )

src_ds_fixed = regridder(src_ds.isel(longitude=slice(1,720))) 
src_ds_fixed.wave_dissipation.plot(**plot_opts)
<matplotlib.collections.QuadMesh at 0x14df5dd75d10>
../_images/9985c2e25a341b1d5339f1204600efff2a56521a649c7e40eb6d00fdc0ff5946.png

Target Grid#

dst_grid_path = "../mesh/tx2_3v3_grid.nc"
dst_grid = xr.open_dataset(dst_grid_path)
dst_grid = dst_grid.rename({'tlon': 'lon', 'tlat': 'lat', 'qlon':'lon_b', 'qlat': 'lat_b'})

Conservative Regridding#

# Conservative regridder from src grid to target grid.
regridder = xe.Regridder(
        src_ds_fixed,
        dst_grid,
        method='conservative',
        periodic=True,
    )

# Field mapped conservatively to the target grid
dst_fld = regridder(src_ds_fixed.wave_dissipation) 
/glade/u/apps/opt/miniforge/envs/npl-2026a/lib/python3.13/site-packages/xesmf/backend.py:57: UserWarning: Latitude is outside of [-90, 90]
  warnings.warn('Latitude is outside of [-90, 90]')
dst_fld.plot(**plot_opts)
<matplotlib.collections.QuadMesh at 0x14df5dcc6e90>
../_images/bb9faf3e42330b95f3a7cf2ff65c56a93d51edd6833c30d0db096a2e050d904e.png

Reapply target mask:#

dst_fld = xr.where(dst_grid.tmask>0, dst_fld, 0.0)
dst_fld.plot(**plot_opts)
<matplotlib.collections.QuadMesh at 0x14df5da7bd90>
../_images/8b763eccb7b80fce7f9cf75b0a0c0885620d19b6ee7b78272db893e7ad5b2ca1.png

Save to file:#

dst_ds = xr.Dataset(
    {"wave_dissipation": dst_fld},
    coords={
        'lon': dst_grid.lon, 
        'lat': dst_grid.lat, 
    },
    attrs = {
        'description': 'Estimated tidal dissipation data by S.R. Jayne. WHOI.',
        'author': 'Gustavo Marques (gmarques@ucar.edu)',
        'created': today
    }
)

fname = 'tidal_energy_tx2_3v3_conserve_{}.nc'.format(today)
dst_ds.to_netcdf(fname, engine="netcdf4", format="NETCDF3_64BIT_DATA",)
/glade/u/apps/opt/miniforge/envs/npl-2026a/lib/python3.13/site-packages/dask/config.py:786: FutureWarning: Dask configuration key 'allowed-failures' has been deprecated; please use 'distributed.scheduler.allowed-failures' instead
  warnings.warn(