cross_section2d

mdtools.numpy_helper_functions.cross_section2d(z, ax, x=None, y=None, width=1, mean='arithmetic')[source]

Extract a cross section from a 2-dimensional array along a given axis.

Note

This function is probably not what you want, since the cross section is always averaged either vertically (if y is given) or horizontally (if x is given), but not perpendicular to the given axis as it should be. The problem might get clear, if you uncomment the print(mask) statement in the for loop of this function. For extracting proper cross sections from 2-dimensional arrays use cross_section().

Parameters:
  • z (array_like) – Input array of shape (m, n) from which to extract the cross section. The data representation follows the standard matrix convention, i.e. columns represent the x values and rows the y values.

  • ax (array_like) – The axis along which to extract the cross section from z. Usually ax is a straight line as function of x, but actually it can be any function of x or y. If y is given, ax is interpreted as a function of x and must be of shape (n,). If x is given, it is interpreted as a function of y and must be of shape (m,).

  • x, y (array_like) – The sample points corresponding to the z values. Either x or y must be given, but not both. x must be of shape (n,) if given and y must be of shape (m,) if given.

  • width (scalar, optional) – The width of the cross section. Must be greater than zero and should be chosen sufficiently large to avoid numerical instabilities. If y is given, the cross section is computed from all z values that fall within the range (y >= ax-width/2) & (y <= ax+width/2). If x is given, the cross section is computed from all z values that fall within the range (x >= ax-width/2) & (x <= ax+width/2).

  • mean (str, optional) – How to average over the width of the cross section to obtain the actual value of the cross section at the current x (if y is given) or y (if x is given) position. Must be one of the following choices:

    • 'arithmetic': Use arithmetic mean

    • 'integral': Integrate over the current width slice and divide by the width

Returns:

cross_sec (numpy.ndarray) – Cross section as function of x and shape (n,) if y is given or as function of y and shape (m,) if y is given.