katsu.katsu_math module

class katsu.katsu_math.BackendShim(src)

Bases: object

A shim that allows a backend to be swapped at runtime. Taken from prysm.mathops with permission from Brandon Dube

katsu.katsu_math.RMS_calculator(calibration_matrix)

Calculates the root mean square (RMS) error of a matrix by comparing it to the identity matrix.

Parameters:

calibration_matrix (array) – 4x4 matrix.

Returns:

RMS – RMS error of the matrix.

Return type:

float

katsu.katsu_math.broadcast_kron(a, b)

broadcasted kronecker product of two N,M,…,2,2 arrays. Used for jones -> mueller conversion In the unbroadcasted case, this output looks like

out = [a[0,0]*b,a[0,1]*b]

[a[1,0]*b,a[1,1]*b]

where out is a N,M,…,4,4 array. I wrote this to work for generally shaped kronecker products where the matrix is contained in the last two axes, but it’s only tested for the Nx2x2 case

Parameters:
  • a (numpy.ndarray) – N,M,…,2,2 array used to scale b in kronecker product

  • b (numpy.ndarray) – N,M,…,2,2 array used to form block matrices in kronecker product

Returns:

N,M,…,4,4 array

Return type:

out

katsu.katsu_math.broadcast_outer(a, b)

broadcasted outer product of two A,B,…,N vectors. Used for polarimetric data reduction

where out is a A,B,…,N,N matrix. While in principle this does not require vectors of different length, it is not tested to produce anything other than square matrices.

Parameters:
  • a (numpy.ndarray) – A,B,…,N vector 1

  • b (numpy.ndarray) – A,B,…,N vector 2

Returns:

outer product matrix

Return type:

numpy.ndarray

katsu.katsu_math.condition_number(matrix)

returns the condition number of a matrix. Useful for quantifying the quality of a polarimeter.

Parameters:

matrix (numpy.ndarray) – array containing the matrices to evaluate in the last two dimensions

Returns:

condition number

Return type:

numpy.ndarray

katsu.katsu_math.propagated_error(M_R, RMS)

Propogates error in the Mueller matrix to error in the extracted value of retardance. Assumes the RMS error is the same for all elements of the matrix.

Parameters:
  • M_R (array) – 4x4 Mueller matrix for a linear retarder

  • RMS (float) – root mean square error of the Mueller matrix.

Return type:

float, error in the extracted retardance value in radians.

katsu.katsu_math.set_backend_to_cupy()

Convenience method to automatically configure katsu’s backend to cupy.

katsu.katsu_math.set_backend_to_jax()

Convenience method to automatically configure katsu’s backend to jax.

katsu.katsu_math.set_backend_to_numpy()

Convenience method to automatically configure katsu’s backend to numpy.