Ray Tracing Canonical Examples ============================== .. code:: ipython3 # data handling import numpy as np import xarray as xr # plotting import matplotlib.pyplot as plt from IPython.display import HTML import cmocean # ray tracing import mantaray # helper functions import utils Introduction ------------ This notebook covers how to run Mantaray with the custom depth and current fields that were constructed in ``idealized_fields.ipynb``. It is recommended that users run through this notebook first. Initial Wave and Model Parameters --------------------------------- The initial wave parameters that we need to define for Mantaray are :math:`k_{x0}`/:math:`k_{y_0}`, the initial x/y wavenumber. We will calculate these from the following parameters: - :math:`T_0`: The initial way period, - :math:`\theta_0`: The initial wave direction (convention: what direction the waves are *going to*), - :math:`n_{rays}`: The number of rays. All waves will have the same x/y wavenumbers. We will use these initial parameters for the 4 canonical examples. .. code:: ipython3 T0 = 10 # Period [s] theta0 = 0 # Direction [rad] .. code:: ipython3 # Convert period to wavenumber magnitude k_0 = utils.period2wavenumber(T0) # Calculate wavenumber components k_x0 = k_0 * np.cos(theta0) k_y0 = k_0 * np.sin(theta0) .. code:: ipython3 # Number of rays n_rays = 100 # Initialize wavenumber for all rays K_x0 = k_x0 * np.ones(n_rays) K_y0 = k_y0 * np.ones(n_rays) Additionally, we need to define the initial positions for all of our rays. To do this, we will extract the grid from one of our canonical examples. All examples have the same grid, and the initial positions for all rays will be the same for each canonical example. .. code:: ipython3 ds_jet = xr.open_dataset("./forcing/zonal_jet.nc") .. code:: ipython3 # Read x and y from file to get domain size x = ds_jet.x.values y = ds_jet.y.values .. code:: ipython3 x0 = 0 * np.ones(n_rays) y0 = np.linspace(0, y.max(), n_rays) Additionally, using the grid, we can compute the optimal timestep and duration for each model. .. code:: ipython3 timestep = utils.compute_cfl(x, y, k_0) duration = utils.compute_duration(x, k_0) Ray Tracing with Mantaray ------------------------- The core ray tracing function expects: - Initial x and y position(s), - Initial :math:`k_{x0}` and :math:`k_{y0}`\ (s), - Model duration, - Model timestep, - Bathymetry/Current ``xarray`` ``datasets`` *paths* as *strings* Zonal Jet ~~~~~~~~~ If ``idealized_fields.ipynb`` was run properly, the paths below should be where the data for the zonal jet and constant bathymetry should be located. .. code:: ipython3 jet_path = "./forcing/zonal_jet.nc" const_bathy_path = "./forcing/4000m_bathymetry.nc" .. code:: ipython3 bundle_jet = mantaray.ray_tracing( x0, y0, K_x0, K_y0, duration, timestep, const_bathy_path, jet_path ) .. code:: ipython3 bundle_jet .. raw:: html
<xarray.Dataset> Size: 802kB Dimensions: (time_step: 200, ray: 100) Coordinates: time (time_step, ray) float64 160kB 0.0 0.0 0.0 ... 2.549e+04 nan x (time_step, ray) float64 160kB 0.0 0.0 0.0 ... 1.989e+05 nan y (time_step, ray) float64 160kB 0.0 1e+03 2e+03 ... 9.81e+04 nan * time_step (time_step) int64 2kB 0 1 2 3 4 5 6 ... 194 195 196 197 198 199 * ray (ray) int64 800B 0 1 2 3 4 5 6 7 8 ... 91 92 93 94 95 96 97 98 99 Data variables: kx (time_step, ray) float64 160kB 0.04024 0.04024 ... 0.04024 nan ky (time_step, ray) float64 160kB 0.0 0.0 0.0 ... 3.893e-05 nan Attributes: date_created: 2025-04-29 15:06:01.681124