pylag.mock module

Module containing mock objects that are used to help test different parts of the model. Several of these subclass DataReader, and feedback the results of analytical expressions (as opposed to reading in and giving access to data stored on disk) that can be used to drive the particle tracking model.

Note

mock is implemented in Cython. Only a small portion of the API is exposed in Python with accompanying documentation. However, more details can be found in pylag.data_reader, where a set of python wrappers for data_reader objects have been implemented.

class pylag.mock.MockAtmosphereDataReader(u10, v10)

Bases: DataReader

Mock atmosphere data reader

Mock Data Reader to assist with testing PyLag components that use atmospheric data.

class pylag.mock.MockHorizontalEddyDiffusivityDataReader

Bases: DataReader

Test data reader for reading in the horizontal eddy diffusivity

The data reader returns horizontal eddy viscosities using the analytic formula:

Ah = x^2 + y^2 + C (1)

where x is the x cartesian coordinate, y is the y cartesian coordinate and C is some constant, set equal to 1.0 m2/s. Ah has units m^2/s; the time unit is implicit within equation (1). This class is designed to help test 2D random displacement models; for example, using the well mixed condition.

Variables
  • _C (float) – Constant used in equation (1)

  • _xmax (_xmin,) – Min and max x values between which Ah is defined.

  • _ymax (_ymin,) – Min and max y values between which Ah is defined.

Todo

Will not work as is! It needs find_host() and get_boundary_intersection() implementing properly in order to allow horizontal boundary conditions to be applied.

class pylag.mock.MockOPTModelDataReader

Bases: DataReader

Data reader for testing OPTModel objects

The test data reader defines a grid made up of a unit cube with one corner positioned at the origin, and three sides that run along the positive coordinate axes.

Points within the cube lie within the domain, while anything outside of the cube is outside of the domain.

get_xmin(self) DTYPE_FLOAT_t
get_ymin(self) DTYPE_FLOAT_t
class pylag.mock.MockOceanDataReader(u, v, w)

Bases: DataReader

Mock ocean data reader

Mock Data Reader to assist with testing PyLag components that use ocean data.

class pylag.mock.MockOneDNumMethod(config)

Bases: object

Helper class for performing integrations in 1D

Parameters

config (ConfigParser) – Configuration object.

step(self, DataReader data_reader, DTYPE_FLOAT_t time, x3_arr)
class pylag.mock.MockThreeDNumMethod(config)

Bases: object

Helper class for performing integrations in 2D

Parameters

config (ConfigParser) – Configuration object.

step(self, DataReader data_reader, time, x1_arr, x2_arr, x3_arr)
class pylag.mock.MockTwoDNumMethod(config)

Bases: object

Helper class for performing integrations in 2D

Parameters

config (ConfigParser) – Configuration object.

step(self, DataReader data_reader, time, x1_arr, x2_arr)
class pylag.mock.MockVelocityDataReader

Bases: DataReader

Test data reader for reading in velocity data

The example is taken from Kreyszig, E. (2006) Advanced Engineering Mathematics, Ch. 18. P762. In the example, the complex potential with F(z) = z^2 = x^2 - y^2 + 2ixy models a flow with:

Equipotential lines Phi = x^2 - y^2 = const,

Streamlines Psi = 2xy = const,

The velocity vector is then:

V = 2(x - iy) (1),

with components:

V1 = u = 2x (2), V2 = v = -2y (3),

The speed is:

|V| = sqrt(x^2 + y^2).

An analytical expression for the postion vector (X, Y) can be found by integrating (2) and (3):

X(t, x_0) = x_0 * exp^(2t) Y(t, y_0) = y_0 * exp^(-2t)

get_position_analytic(self, x0, y0, t)

Return particle positions according to the analytic soln.

get_velocity_analytic(self, x1, x2, x3=0.0)

Python friendly version of get_velocity(…).

class pylag.mock.MockVelocityEddyDiffusivityDataReader

Bases: DataReader

Test data reader for reading in horizontal velocity and eddy viscosities

The data reader represents a very simple 2D advection-diffusion test case based upon the point release of a tracer into an environment with a time independent, spatially homogeneous horizontal velocity field described by the variables u and v; and a time independent, spatially homogeneous, isotropic horizontal eddy diffusivity field described by the variable Ah.

Under these conditions, the evolution of the tracer c (units g m-2) is described by the equation:

c(t, x, y) = M/(4 * Pi * Ah * t) * exp (-((x - u * t)**2 + (y - v * t)**2)/(4 * Ah * t))

where M (units g) is the amount of tracer released at time t = 0 (s) and position (x,y) = (0,0) (m).

For testing purposes, u = 1.0 m s-1, v = 1.0 m s-1, Ah = 10 m2 s-1 and M = 1 x 10^4 g. Furthermore, w = 0.0 m s-1 and Kz = 0.0 m2 s-1.

Variables
  • _u (float) – x velocity component in Cartesian space.

  • _v (float) – y velocity component in Cartesian space.

  • _Ah (float) – Horizontal eddy diffusivity.

  • M (float) – Mass of tracer released at t = t0

M
get_concentration_analytic(self, DTYPE_FLOAT_t time, DTYPE_FLOAT_t x1, DTYPE_FLOAT_t x2)

Return the mass concentration C(t, x, y) using the analytic formula

class pylag.mock.MockVerticalDiffusivityDataReader

Bases: DataReader

Test data reader for reading in the vertical eddy diffusivity

The data reader returns vertical eddy diffusivities drawn from the analytic profile:

k = 0.001 + 0.0136245*x3 - 0.00263245*x3**2 + 2.11875e-4 * x3**3 - 8.65898e-6 * x3**4 + 1.7623e-7 * x3**5 - 1.40918e-9 * x3**6

where k (m^2/s) is the vertical eddy diffusivity and x3 (m) is the height above the sea bed (positivite up). See Visser (1997) and Ross and Sharples (2004).

Variables
  • _zmin (float) – The minimum depth in m.

  • _zmax (float) – The maximum depth in m.

References

Visser, A. Using random walk models to simulate the vertical distribution of particles in a turbulent water column Marine Ecology Progress Series, 1997, 158, 275-281

Ross, O. & Sharples, J. Recipe for 1-D Lagrangian particle tracking models in space-varying diffusivity Limnology and Oceanography Methods, 2004, 2, 289-302

get_vertical_eddy_diffusivity_analytic(self, DTYPE_FLOAT_t x3)
get_vertical_eddy_diffusivity_derivative_analytic(self, DTYPE_FLOAT_t x3)
class pylag.mock.MockWavesDataReader(stokes_drift_u_component, stokes_drift_v_component)

Bases: DataReader

Mock waves data reader

Mock Data Reader to assist with testing PyLag components that use wave data.