mod_traj module

mod_traj.adv_eul(time0, lon0, lat0, fu, fv, dt=3600)

Perform Eulerian advection for drifter data.

Parameters:
  • time0 (int) – Initial time.

  • lon0 (float) – Initial longitude.

  • lat0 (float) – Initial latitude.

  • fu (function) – Function for calculating u-component of velocity.

  • fv (function) – Function for calculating v-component of velocity.

  • dt (int, optional) – Time step in seconds. Default is 3600 seconds.

Returns:

  • lon1 (float) – New longitude after advection.

  • lat1 (float) – New latitude after advection.

Examples

# Usage Example: lon1, lat1 = adv_eul(time0, lon0, lat0, u_velocity_func, v_velocity_func)

mod_traj.adv_rk4(time0, lon0, lat0, fu, fv, dt=3600)

Perform Runge-Kutta 4th order advection for drifter data.

Parameters:
  • time0 (int) – Initial time.

  • lon0 (float) – Initial longitude.

  • lat0 (float) – Initial latitude.

  • fu (function) – Function for calculating u-component of velocity.

  • fv (function) – Function for calculating v-component of velocity.

  • dt (int, optional) – Time step in seconds. Default is 3600 seconds.

Returns:

  • lon1 (float) – New longitude after advection.

  • lat1 (float) – New latitude after advection.

Examples

# Usage Example: lon1, lat1 = adv_rk4(time0, lon0, lat0, u_velocity_func, v_velocity_func)

mod_traj.check_drifters_distribution(ds_drifters, lon_bin=numpy.arange, lat_bin=numpy.arange, region_name='Global')
mod_traj.compute_deviation(dict1, Nt, dt_hr, horizon_days, lon_out=numpy.arange, lat_out=numpy.arange, dir_out='../results/', method_name='DUACS', results_out='deviat_uv_DUACS.nc', overwrite=False)

Compute deviation between real and artificial drifters.

Parameters:
  • dict1 (dict) – Dictionary containing drifter data.

  • Nt (int) – Total number of time steps.

  • dt_hr (int) – Time step size in hours.

  • horizon_days (list) – List of time horizons for deviation computation.

  • lon_out (numpy.ndarray, optional) – Longitudes for output grids. Default is a range from 0 to 360 with a step of 1 degree.

  • lat_out (numpy.ndarray, optional) – Latitudes for output grids. Default is a range from -90 to 90 with a step of 1 degree.

  • dir_out (str, optional) – Output directory. Default is ‘../results/’.

  • method_name (str, optional) – Name of the deviation method. Default is ‘DUACS’.

  • results_out (str, optional) – Output file name for deviation results. Default is ‘deviat_uv_DUACS.nc’.

  • overwrite (bool, optional) – Option to overwrite (if True) or read (if False) output file when file already exists. Default is False.

Returns:

  • rmse_norm (numpy.ndarray) – Normalized root mean square error (RMSE) of deviation.

  • var_norm (numpy.ndarray) – Normalized variance of deviation.

  • d_mean_1 (numpy.ndarray) – Mean deviation.

Examples

# Usage Example: rmse_norm, var_norm, d_mean_1 = compute_deviation(drifter_data, N_time, time_step, horizon_list, lon_grid, lat_grid, dir_out=’../output’, method_name=’DUACS’, results_out=’deviation_results.nc’)

mod_traj.compute_traj(dict_drifter_adv_maps, horizons, fu, fv, Np, Nt, dt_h, method_name='DUACS', dir_out='../Data', prefix_out='dict_drifter_adv', mode='euler', overwrite=False)

Compute trajectories of drifters based on given advection methods.

Parameters:
  • dict_drifter_adv_maps (dict) – Dictionary containing drifter advection maps.

  • horizons (list) – List of time horizons for trajectory computation.

  • fu (function) – Function for calculating u-component of velocity.

  • fv (function) – Function for calculating v-component of velocity.

  • Np (int) – Number of particles (drifters).

  • Nt (int) – Total number of time steps.

  • dt_h (int) – Time step size in hours.

  • method_name (str, optional) – Name of the advection method. Default is ‘DUACS’.

  • dir_out (str, optional) – Output directory. Default is ‘../Data’.

  • prefix_out (str, optional) – Output file prefix. Default is ‘dict_drifter_adv’.

  • mode (str, optional) – Advection mode (‘euler’ or ‘rk4’). Default is ‘euler’.

  • overwrite (bool, optional) – Whether to overwrite advection maps to files when files already exist. Default is False.

Returns:

dict_drifter_adv_maps – Dictionary containing drifter trajectories.

Return type:

dict

Examples

# Usage Example: trajectories = compute_traj(drifter_adv_maps, horizons, u_velocity_func, v_velocity_func, N_particles, N_time, time_step, method_name=’Euler’, dir_out=’../Output’, overwrite=True)

mod_traj.dist_drifters(lat1, lon1, lat2, lon2)

Calculate the great-circle distance between two sets of coordinates.

Parameters:
  • lat1 (float) – Latitude of the first point.

  • lon1 (float) – Longitude of the first point.

  • lat2 (float) – Latitude of the second point.

  • lon2 (float) – Longitude of the second point.

Returns:

distance – Great-circle distance between the two points in kilometers.

Return type:

float

Examples

# Usage Example: distance = dist_drifters(lat1, lon1, lat2, lon2)

mod_traj.plot_meantraj_deviation(dir_out='../results/', just_basin=None, prefix_='deviat_uv_')

Plot mean drifter trajectory deviation and save plot.

Parameters:
  • dir_out (str, optional) – Directory containing deviation data files. Default is ‘../results/’.

  • just_basin (str, optional) – Filter results for a specific basin (e.g., ‘Pacific’). Default is None.

  • prefix (str, optional) – Prefix of deviation data files. Default is ‘deviat*uv’.

Examples

# Usage Example: plot_meantraj_deviation(dir_out=’../results/’, just_basin=’Pacific’, prefix_=’deviat*uv’)

mod_traj.plot_traj_deviation_maps(lon_g, lat_g, rmse_norm, dt_hr=24, horizon_days=[1, 2, 3], vmax_h=[40, 80, 120], method_name='DUACS')

Plot deviation maps of drifter trajectories and save the maps.

Parameters:
  • lon_g (numpy.ndarray) – Longitudes of the grid.

  • lat_g (numpy.ndarray) – Latitudes of the grid.

  • rmse_norm (numpy.ndarray) – Normalized root mean square error (RMSE) of deviation.

  • dt_hr (int, optional) – Time step size in hours. Default is 24 hours.

  • horizon_days (list, optional) – List of time horizons for deviation maps. Default is [1, 2, 3].

  • vmax_h (list, optional) – List of maximum values for color scaling. Default is [40, 80, 120].

  • method_name (str, optional) – Name of the advection method. Default is ‘DUACS’.

Examples

# Usage Example: plot_traj_deviation_maps(lon_grid, lat_grid, rmse_norm, dt_hr=24, horizon_days=[1, 2, 3], vmax_h=[40, 80, 120], method_name=’Euler’)

mod_traj.prepare_drifter_data(ds_drifters, maps, time_min_str='2019-01-01', time_max_str='2019-12-31')

Prepare drifter data for analysis.

Parameters:
  • ds_drifters (xarray.Dataset) – Drifter dataset containing longitude, latitude, time, and other variables.

  • maps (xarray.Dataset) – Maps dataset.

Returns:

  • ind (numpy.ndarray) – Array of indices.

  • time_drifter (numpy.ndarray) – Array of time values for drifter data.

  • lon_drifter (numpy.ndarray) – Array of longitude values for drifter data.

  • lat_drifter (numpy.ndarray) – Array of latitude values for drifter data.

  • id_drifter (numpy.ndarray) – Array of drifter IDs.

Examples

# Usage Example: ind, time_drifter, lon_drifter, lat_drifter, id_drifter = prepare_drifter_data(drifter_data, maps_data)