8.4.10. pymodaq_utils.math_utils module

class pymodaq_utils.math_utils.LSqEllipse[source]

Bases: object

Attributes:
center
height
phi

angle of counterclockwise rotation of major-axis of ellipse to x-axis

width

Methods

fit(data)

Lest Squares fitting algorithm

parameters

fit(data)[source]

Lest Squares fitting algorithm

Theory taken from (*) Solving equation Sa=lCa. with a = |a b c d f g> and a1 = |a b c>

a2 = |d f g>

Parameters:

(list (data) – ellipse. of the form [[x1, x2, …, xi],[y1, y2, …, yi]]

Returns:

coef (list) – [a,b,c,d,f,g] corresponding to ax**2+2bxy+cy**2+2dx+2fy+g

Return type:

list of the coefficients describing an ellipse

parameters()[source]
property center
property height
property phi

angle of counterclockwise rotation of major-axis of ellipse to x-axis [eqn. 23] from (**)

property width
pymodaq_utils.math_utils.find_common_index(x, y, x0, y0)[source]

find the index in two vectors corresponding to x0 and y0

Return type:

Tuple

pymodaq_utils.math_utils.find_index(x, threshold)[source]

find_index finds the index ix such that x(ix) is the closest from threshold

Parameters:
Returns:

out – out=[(ix0,xval0),(ix1,xval1),…]

Return type:

List[tuple]

pymodaq_utils.math_utils.flatten(xs)[source]

Flatten nested list

pymodaq_utils.math_utils.ft(x, dim=-1)[source]

Process the 1D fast fourier transform and swaps the axis to get coorect results using ftAxis :type x: (ndarray) the array on which the FFT should be done :param x: :type x: (ndarray) the array on which the FFT should be done :type dim: the axis over which is done the FFT (default is the last of the array) :param dim: :type dim: the axis over which is done the FFT (default is the last of the array)

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.ft2(x, dim=(-2, -1))[source]

Process the 2D fast fourier transform and swaps the axis to get correct results using ftAxis :type x: (ndarray) the array on which the FFT should be done :param x: :type x: (ndarray) the array on which the FFT should be done :type dim: the axis over which is done the FFT (default is the last of the array) :param dim: :type dim: the axis over which is done the FFT (default is the last of the array)

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.ftAxis(Npts, omega_max)[source]

Given two numbers Npts,omega_max, return two vectors spanning the temporal and spectral range. They are related by Fourier Transform

Parameters:
  • Npts ((int)) – A number of points defining the length of both grids

  • omega_max ((float)) – The maximum circular frequency in the spectral domain. its unit defines the temporal units. ex: omega_max in rad/fs implies time_grid in fs

Returns:

  • omega_grid ((ndarray)) – The spectral axis of the FFT

  • time_grid ((ndarray))) – The temporal axis of the FFT

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.ftAxis_time(Npts, time_max)[source]

Given two numbers Npts,omega_max, return two vectors spanning the temporal and spectral range. They are related by Fourier Transform

Parameters:
  • Npts (number) – A number of points defining the length of both grids

  • time_max (number) – The maximum tmporal window

Returns:

  • omega_grid (vector) – The spectral axis of the FFT

  • time_grid (vector) – The temporal axis of the FFT

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.gauss1D(x, x0, dx, n=1)[source]

compute the gaussian function along a vector x, centered in x0 and with a FWHM i intensity of dx. n=1 is for the standart gaussian while n>1 defines a hypergaussian

Parameters:
  • x ((ndarray) first axis of the 2D gaussian)

  • x0 ((float) the central position of the gaussian)

  • dx ((float) :the FWHM of the gaussian)

  • n=1 (an integer to define hypergaussian, n=1 by default for regular gaussian)

Returns:

out – the value taken by the gaussian along x axis

Return type:

vector

pymodaq_utils.math_utils.gauss2D(x, x0, dx, y, y0, dy, n=1, angle=0)[source]

compute the 2D gaussian function along a vector x, centered in x0 and with a FWHM in intensity of dx and smae along y axis. n=1 is for the standard gaussian while n>1 defines a hypergaussian. optionally rotate it by an angle in degree

Parameters:
  • x ((ndarray) first axis of the 2D gaussian)

  • x0 ((float) the central position of the gaussian)

  • dx ((float) :the FWHM of the gaussian)

  • y ((ndarray) second axis of the 2D gaussian)

  • y0 ((float) the central position of the gaussian)

  • dy ((float) :the FWHM of the gaussian)

  • n=1 (an integer to define hypergaussian, n=1 by default for regular gaussian)

  • angle ((float) a float to rotate main axes, in degree)

Returns:

out

Return type:

ndarray 2 dimensions

pymodaq_utils.math_utils.greater2n(x)[source]

return the first power of 2 greater than x :type x: (int or float) a number :param x: :type x: (int or float) a number

Returns:

int

Return type:

the power of 2 greater than x

pymodaq_utils.math_utils.ift(x, dim=0)[source]

Process the inverse 1D fast fourier transform and swaps the axis to get correct results using ftAxis :type x: (ndarray) the array on which the FFT should be done :param x: :type x: (ndarray) the array on which the FFT should be done :type dim: the axis over which is done the FFT (default is the last of the array) :param dim: :type dim: the axis over which is done the FFT (default is the last of the array)

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.ift2(x, dim=(-2, -1))[source]

Process the inverse 2D fast fourier transform and swaps the axis to get correct results using ftAxis :type x: (ndarray) the array on which the FFT should be done :param x: :type x: (ndarray) the array on which the FFT should be done :type dim: the axis (or a tuple of axes) over which is done the FFT (default is the last of the array) :param dim: :type dim: the axis (or a tuple of axes) over which is done the FFT (default is the last of the array)

See also

ftAxis, ftAxis_time, ift, ft2, ift2

pymodaq_utils.math_utils.linspace_step(start, stop, step)[source]

Compute a regular linspace_step distribution from start to stop values.

Parameters

Type

Description

start

scalar

the starting value of distribution

stop

scalar

the stopping value of distribution

step

scalar

the length of a distribution step

Returns:

  • scalar array – The computed distribution axis as an array.

pymodaq_utils.math_utils.linspace_step_N(start, step, Npts)[source]
pymodaq_utils.math_utils.make_test_ellipse(center=[1, 1], width=1, height=0.6, phi=0.628)[source]

Generate Elliptical data with noise

Parameters:
  • (list (center)

  • (float) (height)

  • (float)

  • (float (phi) – makes with the x-axis

Returns:

data (list – ellipse. of the form [[x1, x2, …, xi],[y1, y2, …, yi]]

Return type:

list:float): list of two lists containing the x and y data of the

pymodaq_utils.math_utils.my_moment(x, y)[source]

Returns the moments of a distribution y over an axe x

Parameters:
  • x (list or ndarray) – vector of floats

  • y (list or ndarray) – vector of floats corresponding to the x axis

Returns:

m – Contains moment of order 0 (mean) and of order 1 (std) of the distribution y

Return type:

list

pymodaq_utils.math_utils.normalize(x)[source]
pymodaq_utils.math_utils.normalize_to(array, value)[source]
pymodaq_utils.math_utils.odd_even(x)[source]

odd_even tells if a number (or an array) is odd (return True) or even (return False)

Parameters:

x (Union[int, ndarray])

Returns:

bool

Return type:

boolean or array of boolean

pymodaq_utils.math_utils.rotate2D(origin=(0, 0), point=(0, 0), angle=0)[source]

Rotate a point counterclockwise by a given angle around a given origin.

The angle should be given in radians. :param origin: :type origin: tuple :param point: :type point: tuple :param angle: :type angle: float

Returns:

out

Return type:

(tuple) x,y coordinate of rotated point

pymodaq_utils.math_utils.wrap(input, phase_range=(0, 6.283185307179586))[source]