open_viewmin.filter_tree_plot.utilities.calculations#

General calculation utilities.

Attributes#

Functions#

calculate_from_one_vector_field_and_one_scalar_field(...)

Create a callable that defines a new dataset on a given mesh from a

calculate_from_scalar_field(plotter, ...[, mesh_name])

Create callable that will apply a calculation to a scalar dataset.

calculate_from_tensor_field(plotter, ...[, mesh_name])

Create callable that will apply a calculation to a dataset of

calculate_from_two_vector_fields(plotter, ...[, mesh_name])

Create a callable that defines a new dataset on a given mesh from a

calculate_from_vector_field(plotter, ...[, mesh_name])

Create callable that will apply a calculation to a vector dataset.

centered_first_derivative_finite_difference_second_order(...)

centered_second_derivative_finite_difference_second_order_mixed_partial(...)

centered_second_derivative_finite_difference_second_order_one_dim(...)

di(arr, array_dims[, flatten, component, data_stride])

Gradient

dij(arr, array_dims[, flatten, data_stride])

Hessian

einstein_sum(sum_str, *arrays[, reshape])

Increase flexibility of numpy.einsum, for convenience in calculating

list_to_xyzmat(arr, dims)

Unflatten a list of values so that the first three dimensions of the

matrix_times_transpose(arr)

Compute matrix product $A A^T$ for a matrix $A$.

roll_zyx(arr, shift, axis)

safe_inverse(arr)

take inverse $x rightarrow 1/x$ but with $0 rightarrow 0$

smooth_gaussian_filter(arr[, smooth_length, ...])

smoothen(arr[, smooth_method_name, smooth_length, ...])

smoothen_box_filter(arr[, ...])

Box filter with uniformly weighted 27-point box

transpose_times_matrix(arr)

Compute matrix product $A^T A$ for a matrix $A$.

xyzmat_to_list(arr)

Partially flatten an array from shape (Lx, Ly, Lz, ...) to

Module Contents#

calculate_from_one_vector_field_and_one_scalar_field(plotter, vector_field_name, scalar_field_name, operation_string, mesh_name='fullmesh')#

Create a callable that defines a new dataset on a given mesh from a named operation on one vector field and one scalar field already defined on that mesh.

Parameters:
  • plotter (FilterTreePlot)

  • vector_field_name (str)

  • scalar_field_name (str)

  • operation_string (str) – Must be “scale”

  • mesh_name (str)

Return type:

callable()

calculate_from_scalar_field(plotter, scalar_field_name, operation_string, mesh_name='fullmesh')#

Create callable that will apply a calculation to a scalar dataset.

Parameters:
  • plotter (FilterTreePlot)

  • scalar_field_name (str) – Name of scalar dataset

  • operation_string (str) – String key for calculation; must be one of: “gradient” or “Laplacian”

mesh_namestr, optional

Name of mesh from which to extract dataset

Return type:

callable()

calculate_from_tensor_field(plotter, tensor_field_name, operation_string, mesh_name='fullmesh')#

Create callable that will apply a calculation to a dataset of Hermitian, rank-2 tensors.

Parameters:
  • plotter (FilterTreePlot)

  • tensor_field_name (str) – Name of tensor dataset

  • operation_string (str) – String key for calculation; must be ‘eigvalsh’ or ‘eigh’

  • mesh_name (str, optional) – Name of mesh from which to extract dataset

Return type:

callable()

calculate_from_two_vector_fields(plotter, vector_field1_name, vector_field2_name, operation_string, mesh_name='fullmesh')#

Create a callable that defines a new dataset on a given mesh from a named operation on two vector fields already defined on that mesh.

Parameters:
  • plotter (FilterTreePlot)

  • vector_field1_name (str)

  • vector_field2_name (str)

  • operation_string (str) – Must be “cross” or “dot”

  • mesh_name (str)

Return type:

callable()

calculate_from_vector_field(plotter, vector_field_name, operation_string, mesh_name='fullmesh')#

Create callable that will apply a calculation to a vector dataset.

Parameters:
  • plotter (FilterTreePlot)

  • vector_field_name (str) – Name of vector dataset

  • operation_string (str) – String key for calculation; must be one of: ‘x’, ‘y’, ‘z’, ‘|x|’, ‘|y|’, ‘|z|’, ‘div’, or ‘curl’

  • mesh_name (str, optional) – Name of mesh from which to extract dataset

Return type:

callable()

centered_first_derivative_finite_difference_second_order(arr: numpy.ndarray, axis: int)#
Parameters:
  • arr (numpy.ndarray)

  • axis (int)

centered_second_derivative_finite_difference_second_order_mixed_partial(arr: numpy.ndarray, axes: tuple[int])#
Parameters:
  • arr (numpy.ndarray)

  • axes (tuple[int])

centered_second_derivative_finite_difference_second_order_one_dim(arr: numpy.ndarray, axis: int)#
Parameters:
  • arr (numpy.ndarray)

  • axis (int)

di(arr, array_dims, flatten=False, component=None, data_stride=1)#

Gradient

Parameters:
  • arr (np.ndarray)

  • array_dims (tuple(int))

  • flatten (bool)

  • component (int or None)

  • data_stride (int)

Return type:

np.ndarray

dij(arr, array_dims, flatten=False, data_stride=1)#

Hessian

Parameters:
  • arr (np.ndarray)

  • array_dims (tuple(int))

  • flatten (bool)

  • data_stride (int)

Return type:

np.ndarray

einstein_sum(sum_str, *arrays, reshape=True)#

Increase flexibility of numpy.einsum, for convenience in calculating datasets

Parameters:
  • sum_str (str)

  • arrays (tuple(np.ndarray))

  • reshape (bool)

Return type:

np.ndarray

list_to_xyzmat(arr, dims)#

Unflatten a list of values so that the first three dimensions of the returned array correspond to the spatial grid.

Parameters:
  • arr (np.ndarray)

  • dims (tuple(int))

Return type:

np.ndarray

matrix_times_transpose(arr)#

Compute matrix product \(A A^T\) for a matrix \(A\).

Parameters:

arr (np.ndarray)

Return type:

np.ndarray

roll_zyx(arr: numpy.ndarray, shift: int | tuple[int], axis: int | tuple[int])#
Parameters:
  • arr (numpy.ndarray)

  • shift (int | tuple[int])

  • axis (int | tuple[int])

safe_inverse(arr)#

take inverse \(x \rightarrow 1/x\) but with \(0 \rightarrow 0\)

Parameters:

arr (np.ndarray)

Return type:

np.ndarray

smooth_gaussian_filter(arr: numpy.ndarray, smooth_length: float = 1.0, periodic_boundary_conditions: bool = False, out: numpy.ndarray | None = None)#
Parameters:
  • arr (numpy.ndarray)

  • smooth_length (float)

  • periodic_boundary_conditions (bool)

  • out (Optional[numpy.ndarray])

smoothen(arr: numpy.ndarray, smooth_method_name: str | None = None, smooth_length: float = 1.0, periodic_boundary_conditions: bool = False, out: numpy.ndarray | None = None)#
Parameters:
  • arr (numpy.ndarray)

  • smooth_method_name (Optional[str])

  • smooth_length (float)

  • periodic_boundary_conditions (bool)

  • out (Optional[numpy.ndarray])

smoothen_box_filter(arr: numpy.ndarray, periodic_boundary_conditions: bool = False, out: numpy.ndarray | None = None)#

Box filter with uniformly weighted 27-point box

If periodic_boundary_conditions is False then the output array’s boundary elements will have the same values as those of the input array.

Parameters:
  • arr (numpy.ndarray)

  • periodic_boundary_conditions (bool)

  • out (Optional[numpy.ndarray])

transpose_times_matrix(arr)#

Compute matrix product \(A^T A\) for a matrix \(A\).

Parameters:

arr (np.ndarray)

Return type:

np.ndarray

xyzmat_to_list(arr)#

Partially flatten an array from shape (Lx, Ly, Lz, …) to (Lx * Ly * Lz, …).

Parameters:

arr (np.ndarray)

Return type:

np.ndarray

levi_civita#