mod_switchvar module

mod_switchvar.py - Ocean Variable Conversion Module

This module provides functions for converting ocean variables:

ssh_to_currents(ssh, lon, lat)

Compute ocean current components from sea surface height (SSH).

currents_to_potential_vorticity(u, v, lon, lat, h)

Compute oceanic potential vorticity (PV) from ocean current components.

currents_to_relative_vorticity(u, v, lon, lat)

Compute oceanic relative vorticity (zeta) from ocean current components.

lonlat2dxdy(lon, lat)

Compute spatial grid spacings (dx, dy) from longitude and latitude arrays.

mod_switchvar.currents_to_potential_vorticity(u, v, lon, lat, h)

Compute oceanic potential vorticity (PV) from ocean current components.

Parameters:
  • u (numpy.ndarray) – 3D array representing eastward ocean current velocity (time, x, y).

  • v (numpy.ndarray) – 3D array representing northward ocean current velocity (time, x, y).

  • lon (numpy.ndarray) – 1D or 2D array of longitudes corresponding to the x-dimension of u and v.

  • lat (numpy.ndarray) – 1D or 2D array of latitudes corresponding to the y-dimension of u and v.

  • h (numpy.ndarray) – 2D array of water depth.

Returns:

pv – 3D array of oceanic potential vorticity (time, x, y).

Return type:

numpy.ndarray

mod_switchvar.currents_to_relative_vorticity(u, v, lon, lat)

Compute oceanic relative vorticity (zeta) from ocean current components.

Parameters:
  • u (numpy.ndarray) – 3D array representing eastward ocean current velocity (time, x, y).

  • v (numpy.ndarray) – 3D array representing northward ocean current velocity (time, x, y).

  • lon (numpy.ndarray) – 1D or 2D array of longitudes corresponding to the x-dimension of u and v.

  • lat (numpy.ndarray) – 1D or 2D array of latitudes corresponding to the y-dimension of u and v.

Returns:

rv – 3D array of oceanic relative vorticity (time, x, y).

Return type:

numpy.ndarray

mod_switchvar.currents_to_relative_vorticity_old(u, v, lon, lat)

Compute oceanic relative vorticity (zeta) from ocean current components.

Parameters:
  • u (numpy.ndarray) – 3D array representing eastward ocean current velocity (time, x, y).

  • v (numpy.ndarray) – 3D array representing northward ocean current velocity (time, x, y).

  • lon (numpy.ndarray) – 1D or 2D array of longitudes corresponding to the x-dimension of u and v.

  • lat (numpy.ndarray) – 1D or 2D array of latitudes corresponding to the y-dimension of u and v.

Returns:

zeta – 3D array of oceanic relative vorticity (time, x, y).

Return type:

numpy.ndarray

mod_switchvar.lonlat2dxdy(lon, lat)

Compute spatial grid spacings (dx, dy) from longitude and latitude arrays.

Parameters:
  • lon (numpy.ndarray) – 2D array of longitudes.

  • lat (numpy.ndarray) – 2D array of latitudes.

Returns:

  • dx (numpy.ndarray) – 2D array of grid spacings in the longitudinal direction.

  • dy (numpy.ndarray) – 2D array of grid spacings in the latitudinal direction.

mod_switchvar.sla_to_ssh(ds, path_mdt='../data/cnes_obs-sl_glo_phy-mdt_my_0.125deg_P20Y_1695393893725_1mdt.nc', ds_mdt=None, name_lonlat=['longitude', 'latitude'])

Compute sea surface height (SSH) from sea level anomaly (SLA) and mean dynamic topography (MDT).

Parameters:
  • ds (xarray.Dataset) – 3D array representing sea level anomaly (SLA) (time, x, y).

  • path_mdt (str, optional) – Path to the MDT dataset file.

  • ds_mdt (xarray.Dataset, optional) – 2D array representing mean dynamic topography (MDT) (x, y).

  • name_lonlat (list of str, optional) – List containing the names of longitude and latitude variables in the dataset.

Returns:

ds – 3D array of sea surface height (SSH) (time, x, y).

Return type:

xarray.Dataset

mod_switchvar.ssh_to_currents(ssh, lon, lat)

Compute ocean current components from ssh.

Parameters:
  • u (xarray.dataset) – 3D array representing sea surface height (time, x, y).

  • lon (numpy.ndarray) – 1D or 2D array of longitudes corresponding to the x-dimension of u and v.

  • lat (numpy.ndarray) – 1D or 2D array of latitudes corresponding to the y-dimension of u and v.

Returns:

  • u (numpy.ndarray) – 3D array of oceanic zonal current component (time, x, y).

  • v (numpy.ndarray) – 3D array of oceanic meridional current component (time, x, y).