barc4ro package

Submodules

barc4ro.barc4ro module

barc4ro.barc4utils module

barc4ro.barc4utils.at_Rx(theta=0, isdgr=False)[source]

Rotation around the x axis.

[x’] [1 0 0 0][x] [y’] = [0 c -s 0][y] [z’] [0 s c 0][z] [1 ] [0 0 0 1][1]

s = sin(theta) c = cos(theta)

Parameters:
  • theta – rotation angle in radians

  • isdgr – boolean for determining if angle is in degree or in radians (default)

Returns:

rotation matrix

barc4ro.barc4utils.at_Ry(theta=0, isdgr=False)[source]

Rotation around the y axis.

[x’] [ c 0 s 0][x] [y’] = [ 0 1 0 0][y] [z’] [-s 0 c 0][z] [1 ] [ 0 0 0 1][1]

s = sin(theta) c = cos(theta)

Parameters:
  • theta – rotation angle in radians

  • isdgr – boolean for determining if angle is in degree or in radians (default)

Returns:

rotation matrix

barc4ro.barc4utils.at_Rz(theta=0, isdgr=False)[source]

Rotation around the z axis.

[x’] [c -s 0 0][x] [y’] = [s c 0 0][y] [z’] [0 0 1 0][z] [1 ] [0 0 0 1][1]

s = sin(theta) c = cos(theta)

Parameters:
  • theta – rotation angle in radians

  • isdgr – boolean for determining if angle is in degree or in radians (default)

Returns:

rotation matrix

barc4ro.barc4utils.at_apply(R, x, y, z)[source]

Apply a transformation matrix R to a set of cardinal points (x,y,z) :param R: transformation matrix :param x: x-coordinates :param y: y-coordinates :param z: z-coordinates :return: transformed coordinates

barc4ro.barc4utils.at_rotate_1D(x, f_x, th=0, isdgr=False, project=False)[source]

Rotates a set of points f_x(x) a angle of th. :param x: abscissa coordinates :param f_x: ordinate values :param th: rotation angle :param isdgr: boolean for determining if angle is in degree or in radians (default) :param project: boolean for recalculating the rotated profile on the original abscissa coordinates :return: rotated coordinates pairs (x,f_x)

barc4ro.barc4utils.at_rotate_2D(x, y, f_x, th_x=0, th_y=0, isdgr=False, project=False)[source]

Rotates a cloud point z(x,y) around theta_x and then, theta_y. 200728RC ATTENTION: function is not working :param x: horizontal axis :param y: vertical axis :param z: cloud point to be rotate: z(x,y) :param th_x: angle around the x-axis for the rotation :param th_y: angle around the y-axis for the rotation :param isdgr: boolean for determining if angle is in degree or in radians (default) :param project: boolean for recalculating the rotated profile on the original grid :return: rotated coordinates pairs

barc4ro.barc4utils.at_rotate_2D_2steps(x, y, z, th_x=0, th_y=0, isdgr=False, project=False)[source]

Rotates a cloud point z(x,y) around theta_x and then, theta_y. 200728RC ATTENTION: function is not working

Parameters:
  • x – horizontal axis

  • y – vertical axis

  • z – cloud point to be rotate: z(x,y)

  • th_x – angle around the x-axis for the rotation

  • th_y – angle around the y-axis for the rotation

  • isdgr – boolean for determining if angle is in degree or in radians (default)

  • project – boolean for recalculating the rotated profile on the original grid

Returns:

rotated coordinates pairs

barc4ro.barc4utils.at_rotate_2D_nested_loop(x, y, z, th_x=0, th_y=0, isdgr=False)[source]

Rotates a cloud point z(x,y) around theta_x and then, theta_y. :param x: horizontal axis :param y: vertical axis :param z: cloud point to be rotate: z(x,y) :param th_x: angle around the x-axis for the rotation :param th_y: angle around the y-axis for the rotation :param isdgr: boolean for determining if angle is in degree or in radians (default) :return: rotated coordinates pairs

barc4ro.barc4utils.at_translate(tx=0, ty=0, tz=0)[source]

Translation matrix.

[x’] [1 0 0 tx][x] [y’] = [0 1 0 ty][y] [z’] [0 0 1 tx][z] [1 ] [0 0 0 1 ][1]

Parameters:
  • tx – translation along the x-axis

  • ty – translation along the y-axis

  • tz – translation along the z-axis

Returns:

translation matrix

barc4ro.barc4utils.calc_surf_rms(_arr)[source]
Parameters:

_arr

Returns:

barc4ro.barc4utils.uti_calc_1d_psd(_profile1D, _axis, _positive_side=False, _pad=False)[source]

This function receives a height profile cut in [m] as a 1D array (_profile1D) and a coordinate array (_axis) also in [m]. A 1D PSD and it’s accompanying axis is returned. If _positive_side is True, negative frequencies are returned. Padding can be done to increase the frequency resolution.

Parameters:
  • _profile1D – height profile as a 1D numpy array in [m]

  • _axis – 1D numpy array in [m]

  • _positive_side – (boolean) crops all negative frequencies

  • _pad – (boolean) zero padding to increase the frequency sampling

Returns:

1D psd and the frequency axis

barc4ro.barc4utils.uti_calc_2d_psd(_profile2D, _axis_x, _axis_y, _pad=False)[source]

This function receives a 2D height profile in [m] as numpy array (_profile2D) and two coordinate arrays (_axis_x and _axis_y) also in [m]. A 2D PSD and its axes (freqx and freqy) are returned.

Parameters:
  • _profile2D – height profile as a 2D numpy array in [m]

  • _axis_x – 1D numpy array in [m]

  • _axis_y – 1D numpy array in [m]

  • _pad – (boolean) zero padding to increase the frequency sampling

Returns:

2D psd and the frequency axis

barc4ro.barc4utils.uti_calc_averaged_psd(_profile2D, _axis_x, _axis_y, _pad=False)[source]

This function receives a 2D height profile in [m] as numpy array (_profile2D) and two coordinate arrays (_axis_x and _axis_y) also in [m]. A 2D PSD is calculated by calling ‘srw_uti_calc_2d_psd’ and an azimuthal average is calculated. A 1D averaged PSD and it’s accompanying axis is returned.

Parameters:
  • _profile2D – height profile as a 2D numpy array in [m]

  • _axis_x – 1D numpy array in [m]

  • _axis_y – 1D numpy array in [m]

  • _pad – (boolean) zero padding to increase the frequency sampling

Returns:

2D psd and its frequency axes

barc4ro.barc4utils.uti_conj_sym_matrix(_mtx)[source]

Apply conjugate symmetry to a 2D array (to be used with PSD calculations) :param _mtx: 2D numpy array :return:

barc4ro.barc4utils.uti_gen_2d_psd_from_param(_sigma, _psd_slope, _pix_size, _m, _n, _qr=0, _noise=False, _dist=0, _seed=None, _isfreq=True)[source]

Generates a 2D PSD can be defined by the rms value of the roughness of a surface (_sigma), _psd_slope and roll-off freq. (_qr); A random phase can be added to the PSD in order to generate some high frequency noise if _noise=True. The random distribution can be uniform (_dist=0), Gaussian (_dist=1) or even zero (_dist=-1). A _seed can be given to the random generator.

parameters (in SI units)

Parameters:
  • _sigma – root-mean-square roughness Rq(m)

  • _psd_slope – PSD _psd_slope = -2(H+1); Hurst _psd_slope 0<= H <= 1, fractal dimension D = 3-H

  • _pix_size – pixel size. If in [m], set _isfreq = False

  • _m – number of pixels in x

  • _n – number of pixels in y

  • _qr – roll-off freq. (1/m); qr > (2*pi/Lx or Ly); qr < (pi/_pix_size) - Nyquist freq.

  • _noise – adds some random noise to the ideal PSD.

  • _dist – -1 for phase = 0, 0 for uniform phase distribution, 1 for Gaussian dist.

  • _seed – seed for random initialisaiton

  • _isfreq – boolean defining in _pix_size is in [m] or in [1/m]

Returns:

surface profile and axes

barc4ro.projected_thickness module

barc4ro.projected_thickness.bumps_and_holes_surf(n_bmp, R, x, y, bmp_type=0, xo=None, yo=None, dist_R=0, dist_xo=0, dist_yo=0, seed=69)[source]
Parameters:
  • n_bmp – number of bumps. Must be >= 1

  • R

    bump or hole main parameters: Gaussian bump: R = [amp, amp_bis, sigma_x, sigma_x_bis, sigma_y, sigma_y_bis]; spherical bump: R = [R, R_bis] sinusoid bump: R = [amp, amp_bis, f_x, f_x_bis, f_y, f_y_bis, phase, phase_bis, offset, offset_bis] hole: R = [R, R_bis, depth, depth_bis] through hole: R = [R, R_bis, depth]

    (value, value_bis) can be (_min, _max) or (_mean, _std) depending on the dist type

  • x – horizontal axis in [m] (1D array)

  • y – vertical axis in [m] (1D array)

  • bmp_type – type of bump or hole bmp_type = 0 # Gaussian bump bmp_type = 1 # spherical_bump bmp_type = 2 # circular holes with different depths bmp_type = 3 # circular through holes bmp_type = 4 # 2D sinusoid

  • xo – bumps or holes positions

  • yo – bumps or holes positions

  • dist_R – type of distribution for R parameters dist = 0 # uniform distribution; requires _min and _max dist = 1 # Gaussian distribution; requires _mean and _std

  • dist_xo – type of distribution for xo parameters

  • dist_yo – type of distribution for yo parameters

  • seed – seed for random generators

Returns:

barc4ro.projected_thickness.circular_holes(depth, R, X, Y, xo=0, yo=0)[source]
Parameters:
  • depth

  • R

  • X

  • Y

  • xo

  • yo

Returns:

barc4ro.projected_thickness.circular_through_holes(depth, R_list, X, Y, xo_list, yo_list)[source]
Parameters:
  • depth

  • R_list

  • X

  • Y

  • xo_list

  • yo_list

Returns:

barc4ro.projected_thickness.fractal_surf(_sigma, _psd_slope, _pix_size, _m, _n, _qr=0, _dist=0, _seed=None, _psd=False, _C=None)[source]

Generates a 2D random (rough) surface in [m] with a pre-determined PSD. The PSD can be defined by either the rms value of the roughness (_sigma), _psd_slope and roll-off freq. (_qr); or by a directly calculated 2D PSD (_C). A random phase is added to the PSD in order to generate the surface. The random distribution can be uniform (_dist=0), Gaussian (_dist=1) or even zero (_dist=-1). A _seed can be given to the random generator. If _psd is True, the 2D PSD and its axes are also returned.

parameters (in SI units)

Parameters:
  • _sigma – root-mean-square roughness Rq(m)

  • _psd_slope – PSD _psd_slope = -2(H+1); Hurst _psd_slope 0<= H <= 1, fractal dimension D = 3-H

  • _pix_size – pixel size in [m] for the resulting surface

  • _m – number of pixels in x

  • _n – number of pixels in y

  • _qr – roll-off freq. (1/m); qr > (2*pi/Lx or Ly); qr < (pi/_pix_size) - Nyquist freq.

  • _dist – -1 for phase = 0, 0 for uniform phase distribution, 1 for Gaussian dist.

  • _seed – seed for random initialisation

  • _psd – (bool) if true, returns Cq and its vectors

  • _C – pre-calculated 2D psd where qx and qy respect the limits imposed by _pix_size, _m and _n

Returns:

surface profile and axes

% Fractal topographies with different fractal dimensions. Adaptation of the MATLAB function ‘artificial_surf’ (version 1.1.0.0) by Mona Mahboob Kanafi. https://www.mathworks.com/matlabcentral/fileexchange/60817-surface-generator-artificial-randomly-rough-surfaces

barc4ro.projected_thickness.fractal_surf_from_2d_psd(_C, _sigma, _pix_size, _dist=0, _seed=None)[source]

Generates a 2D random (rough) surface in [m] with a pre-determined 2D PSD (_C). The surface roughness (rms) is imposed by _sigma. A random phase is added to the PSD in order to generate the surface. The random distribution can be uniform (_dist=0), Gaussian (_dist=1) or even zero (_dist=-1). A _seed can be given to the random generator.

parameters (in SI units)

Parameters:
  • _C – 2D PSD

  • _sigma – root-mean-square roughness Rq(m)

  • _pix_size – pixel size in [m] for the resulting surface

  • _dist – -1 for phase = 0, 0 for uniform phase distribution, 1 for Gaussian dist.

  • _seed – seed for random initialisation

Returns:

surface profile and axes

barc4ro.projected_thickness.fractal_surf_from_psd_param(_sigma, _psd_slope, _pix_size, _m, _n, _qr=0, _dist=0, _seed=None)[source]

Generates a 2D random (rough) surface in [m] with a pre-determined PSD defined by the rms value of the roughness (_sigma), _psd_slope and roll-off freq. (_qr); A random phase is added to the PSD in order to generate the surface. The random distribution can be uniform (_dist=0), Gaussian (_dist=1) or even zero (_dist=-1). A _seed can be given to the random generator. parameters (in SI units)

Parameters:
  • _sigma – root-mean-square roughness Rq(m)

  • _psd_slope – PSD _psd_slope = -2(H+1); Hurst _psd_slope 0<= H <= 1, fractal dimension D = 3-H

  • _pix_size – pixel size in [m] for the resulting surface

  • _m – number of pixels in x

  • _n – number of pixels in y

  • _qr – roll-off freq. (1/m); qr > (2*pi/Lx or Ly); qr < (pi/_pix_size) - Nyquist freq.

  • _dist – -1 for phase = 0, 0 for uniform phase distribution, 1 for Gaussian dist.

  • _seed – seed for random initialisation

Returns:

surface profile and axes

barc4ro.projected_thickness.gaussian_bump(b_amp, sigma_x, sigma_y, X, Y, xo=0, yo=0)[source]
Parameters:
  • b_amp

  • sigma_x

  • sigma_y

  • X

  • Y

  • xo

  • yo

Returns:

barc4ro.projected_thickness.polynomial_surface_2D(_z_coeffs, _pol, _apert_h, _apert_v, _nx=1001, _ny=1001)[source]

If _z_coeffs is a single number, it refers to the piston value. So an array or random numbers representing the coefficients of the polynomials will be generated from -1 to 1 and later normalised to _z_coeffs. If _zcoeffs is a list, the function will return a surface based on it. :param _z_coeffs: either a list of polynomial coefficients or the total RMS value of the surface errors [m] :param _pol: ‘c’ - circular Zernike; ‘r’ - rectangular polynomials; ‘l’ - legendre polynomils :param _apert_h: horizontal aperture size [m] :param _apert_v: vertical aperture size [m] :param _nx: number of points vs horizontal position to represent the transmission element :param _ny: number of points vs vertical position to represent the transmission element :return: thickness profile

barc4ro.projected_thickness.proj_thick_1D_crl(*args, **kwargs)[source]
barc4ro.projected_thickness.proj_thick_2D_crl(*args, **kwargs)[source]
barc4ro.projected_thickness.proj_thick_axicon_2D(_foc_plane, _shape, _apert_h, _apert_v, _h, _wall_thick=0, _xc=0, _yc=0, _nx=1001, _ny=1001, _axis_x=None, _axis_y=None)[source]
Parameters:
  • _foc_plane – plane of focusing: 1- horizontal, 2- vertical, 3- both

  • _shape – ‘p’ - positive or ‘n’ - negative

  • _apert_h – horizontal aperture size [m]

  • _apert_v – vertical aperture size [m]

  • _h – height of the axicon tip/depression (always positive) [m]

  • _wall_thick – support/substrate thickness [m]

  • _xc – horizontal coordinate of center [m]

  • _yc – vertical coordinate of center [m]

  • _nx – number of points vs horizontal position to represent the transmission element

  • _ny – number of points vs vertical position to represent the transmission element

  • _axis_x – forces the lens to be calculated on a given grid - avoids having to interpolate different calculations to the same grid

  • _axis_y – forces the lens to be calculated on a given grid - avoids having to interpolate different calculations to the same grid

Returns:

thickness profile

barc4ro.projected_thickness.proj_thick_crl_1D(_shape, _apert_h, _r_min, _n=2, _wall_thick=0, _xc=0, _nx=1001, _ang_rot_ex=0, _offst_ffs_x=0, _tilt_ffs_x=0, _wt_offst_ffs=0, _offst_bfs_x=0, _tilt_bfs_x=0, _wt_offst_bfs=0, isdgr=False, project=True, _axis=None)[source]

1D X-ray lens (CRL) thickness profile :param _shape: 1- parabolic, 2- circular (future), 3- elliptical (future), 4- Cartesian oval (future) :param _apert_h: aperture size [m] :param _r_min: radius (on tip of parabola for parabolic shape) [m] :param _n: number of refracting surfaces. Either ‘1’ or ‘2’. :param _wall_thick: min. wall thickness between “holes” [m] :param _xc: coordinate of center [m] :param _nx: number of points to represent the transmission element :param _ang_rot_ex: angle [rad] of full CRL rotation about horizontal axis :param _offst_ffs_x: lateral offeset in the horizontal axis of the front focusing surface (ffs) [m] :param _tilt_ffs_x: angle [rad] of the parabolic ffs rotation about horizontal axis :param _wt_offst_ffs: excess penetration [m] of the front parabola to be added to _wall_thick (negative or positive values) :param _offst_bfs_x: lateral offeset in the horizontal axis of the back focusing surface (bfs) [m] :param _tilt_bfs_x: angle [rad] of the parabolic bfs rotation about horizontal axis :param _wt_offst_bfs: excess penetration [m] of the back parabola to be added to _wall_thick (negative or positive values) :param isdgr: boolean for determining if angle is in degree or in radians (default) :param project: boolean. project=True necessary for using the profile as a transmission element :param _axis: forces the lens to be calculated on a given grid - avoids having to interpolate different calculations to the same grid :return: thickness profile

barc4ro.projected_thickness.proj_thick_crl_2D(_foc_plane, _shape, _apert_h, _apert_v, _r_min, _n, _wall_thick=0, _xc=0, _yc=0, _nx=1001, _ny=1001, _ang_rot_ex=0, _ang_rot_ey=0, _ang_rot_ez=0, _offst_ffs_x=0, _offst_ffs_y=0, _tilt_ffs_x=0, _tilt_ffs_y=0, _ang_rot_ez_ffs=0, _wt_offst_ffs=0, _offst_bfs_x=0, _offst_bfs_y=0, _tilt_bfs_x=0, _tilt_bfs_y=0, _ang_rot_ez_bfs=0, _wt_offst_bfs=0, isdgr=False, project=True, _axis_x=None, _axis_y=None, _aperture=None)[source]
Parameters:
  • _foc_plane – plane of focusing: 1- horizontal, 2- vertical, 3- both

  • _shape – 1- parabolic, 2- circular (spherical), 3- elliptical (not implemented), 4- Cartesian oval (not implemented)

  • _apert_h – horizontal aperture size [m]

  • _apert_v – vertical aperture size [m]

  • _r_min – radius (on tip of parabola for parabolic shape) [m]

  • _n – number of lenses (/”holes”)

  • _wall_thick – min. wall thickness between “holes” [m]

  • _xc – horizontal coordinate of center [m]

  • _yc – vertical coordinate of center [m]

  • _nx – number of points vs horizontal position to represent the transmission element

  • _ny – number of points vs vertical position to represent the transmission element

  • _ang_rot_ex – angle [rad] of full CRL rotation about horizontal axis

  • _ang_rot_ey – angle [rad] of full CRL rotation about vertical axis

  • _ang_rot_ez – angle [rad] of full CRL rotation about longitudinal axis

  • _offst_ffs_x – lateral offset in the horizontal axis of the front focusing surface [m]

  • _offst_ffs_y – lateral offset in the vertical axis of the front focusing surface [m]

  • _tilt_ffs_x – angle [rad] of the parabolic front surface rotation about horizontal axis

  • _tilt_ffs_y – angle [rad] of the parabolic front surface rotation about horizontal axis

  • _ang_rot_ez_ffs – angle [rad] of the parabolic front surface rotation about the longitudinal axis

  • _wt_offst_ffs – excess penetration [m] of the front parabola to be added to _wall_thick

  • _offst_bfs_x – lateral offset in the horizontal axis of the back focusing surface [m]

  • _offst_bfs_y – lateral offset in the back axis of the front focusing surface [m]

  • _tilt_bfs_x – angle [rad] of the parabolic front back rotation about horizontal axis

  • _tilt_bfs_y – angle [rad] of the parabolic front back rotation about horizontal axis

  • _ang_rot_ez_bfs – angle [rad] of the parabolic back surface rotation about the longitudinal axis

  • _wt_offst_bfs – excess penetration [m] of the back parabola to be added to _wall_thick (negative or positive values)

  • isdgr – boolean for determining if angles are in degree or in radians (default)

  • project – boolean. project=True necessary for using the profile as a transmission element

  • _axis_x – forces the lens to be calculated on a given grid - avoids having to interpolate different calculations to the same grid

  • _axis_y – forces the lens to be calculated on a given grid - avoids having to interpolate different calculations to the same grid

  • _aperture – specifies the type of aperture: circular or square

Returns:

thickness profile

barc4ro.projected_thickness.sinusoid_bump(amp, f_x, f_y, phase, offset, X, Y, xo=0, yo=0)[source]
Parameters:
  • amp

  • f_x

  • f_y

  • phase

  • offset

  • X

  • Y

  • xo

  • yo

Returns:

barc4ro.projected_thickness.spherical_bump(R, X, Y, xo=0, yo=0)[source]
Parameters:
  • R

  • X

  • Y

  • xo

  • yo

Returns:

barc4ro.wavefront_fitting module

barc4ro.wavefront_fitting.calc_chebyshev(leg_vec, npix, leg_data={}, mask=True)[source]

Constructs wavefront with Chebyshev amplitudes leg_vec. Given vector leg_vec with the amplitude of Chebyshev modes, return the reconstructed wavefront with radius rad. This function uses leg_data as cache. If this is not given, it will be generated. See calc_chebyshev_basis() for details. If mask is True, set everything outside radius rad to zero, this is the default and will use orthogonal Chebyshev. If this is False, the modes will not be cropped.

@param [in] leg_vec 1D vector of 2D Chebyshev amplitudes @param [in] npix array size to calculate the basis @param [in] leg_data 2D Chebyshev basis cache @param [in] mask If True, set everything outside the Chebyshev aperture to zero, otherwise leave as is. @see See calc_chebyshev_basis() for details on leg_data cache and mask

barc4ro.wavefront_fitting.calc_chebyshev_basis(nmodes, npix, modestart=1, calc_covmat=False)[source]

Calculates a basis of nmodes Chebyshev modes with normalised dimensions [-1, 1].

This output of this function can be used as cache for other functions.

@param [in] nmodes Number of modes to generate @param [in] npix array size to calculate the basis @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Chebyshev modes, and its inverse @return Dict with entries ‘modes’ a list of Chebyshev modes, ‘modesmat’ a matrix of (nmodes, npixels), ‘covmat’ a covariance matrix for all these modes with ‘covmat_in’ its inverse, ‘mask’ is a binary mask to crop only the orthogonal part of the modes.

barc4ro.wavefront_fitting.calc_legendre(leg_vec, npix, leg_data={}, mask=True)[source]

Constructs wavefront with Legendre amplitudes leg_vec. Given vector leg_vec with the amplitude of Legendre modes, return the reconstructed wavefront with radius rad. This function uses leg_data as cache. If this is not given, it will be generated. See calc_legendre_basis() for details. If mask is True, set everything outside radius rad to zero, this is the default and will use orthogonal Legendre. If this is False, the modes will not be cropped.

@param [in] leg_vec 1D vector of 2D Legendre amplitudes @param [in] npix array size to calculate the basis @param [in] leg_data 2D legendre basis cache @param [in] mask If True, set everything outside the Legendre aperture to zero, otherwise leave as is. @see See calc_legendre_basis() for details on leg_data cache and mask

barc4ro.wavefront_fitting.calc_legendre_basis(nmodes, npix, modestart=1, calc_covmat=False)[source]

Calculates a basis of nmodes Legendre modes with normalised dimensions [-1, 1].

This output of this function can be used as cache for other functions.

@param [in] nmodes Number of modes to generate @param [in] npix array size to calculate the basis @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Legendre modes, and its inverse @return Dict with entries ‘modes’ a list of Legendre modes, ‘modesmat’ a matrix of (nmodes, npixels), ‘covmat’ a covariance matrix for all these modes with ‘covmat_in’ its inverse, ‘mask’ is a binary mask to crop only the orthogonal part of the modes.

barc4ro.wavefront_fitting.calc_wft_pol()[source]
barc4ro.wavefront_fitting.calc_wft_pol_basis()[source]
barc4ro.wavefront_fitting.calc_zern_circ_basis(nmodes, rad, modestart=1, calc_covmat=False)[source]

Calculate a basis of nmodes Zernike modes with radius rad.

((If mask is true, set everything outside of radius rad to zero (default). If this is not done, the set of Zernikes will be rad by rad square and are not orthogonal anymore.)) –> Nothing is masked, do this manually using the ‘mask’ entry in the returned dict.

This output of this function can be used as cache for other functions.

@param [in] nmodes Number of modes to generate @param [in] rad Radius of Zernike modes @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Zernike modes, and its inverse @return Dict with entries ‘modes’ a list of Zernike modes, ‘modesmat’ a matrix of (nmodes, npixels), ‘covmat’ a covariance matrix for all these modes with ‘covmat_in’ its inverse, ‘mask’ is a binary mask to crop only the orthogonal part of the modes.

barc4ro.wavefront_fitting.calc_zern_rec_basis(nmodes, npix, modestart=1, calc_covmat=False)[source]

Calculates a basis of nmodes Zernike modes with normalised dimensions [2*np.sqrt(1-a**2), 2a].

This output of this function can be used as cache for other functions.

@param [in] nmodes Number of modes to generate @param [in] npix array size to calculate the basis @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Zernike modes, and its inverse @return Dict with entries ‘modes’ a list of Zernike modes, ‘modesmat’ a matrix of (nmodes, npixels), ‘covmat’ a covariance matrix for all these modes with ‘covmat_in’ its inverse, ‘mask’ is a binary mask to crop only the orthogonal part of the modes.

barc4ro.wavefront_fitting.calc_zern_sqr_basis(nmodes, npix, modestart=1, calc_covmat=False)[source]

Calculates a basis of nmodes Zernike modes with normalised dimensions [2*np.sqrt(1-a**2), 2a].

This output of this function can be used as cache for other functions.

@param [in] nmodes Number of modes to generate @param [in] npix array size to calculate the basis @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Zernike modes, and its inverse @return Dict with entries ‘modes’ a list of Zernike modes, ‘modesmat’ a matrix of (nmodes, npixels), ‘covmat’ a covariance matrix for all these modes with ‘covmat_in’ its inverse, ‘mask’ is a binary mask to crop only the orthogonal part of the modes.

barc4ro.wavefront_fitting.calc_zernike_circ(zern_vec, rad, zern_data={}, mask=True)[source]

Constructs wavefront with Zernike amplitudes zern_vec. Given vector zern_vec with the amplitude of Zernike modes, return the reconstructed wavefront with radius rad. This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details. If mask is True, set everything outside radius rad to zero, this is the default and will use orthogonal Zernikes. If this is False, the modes will not be cropped.

@param [in] zern_vec 1D vector of Zernike amplitudes @param [in] rad Radius for Zernike modes to construct @param [in] zern_data Zernike basis cache @param [in] mask If True, set everything outside the Zernike aperture to zero, otherwise leave as is. @see See calc_zern_circ_basis() for details on zern_data cache and mask

barc4ro.wavefront_fitting.calc_zernike_rec(zern_vec, npix, zern_data={}, mask=True)[source]

Constructs wavefront with Zernike amplitudes zern_vec. Given vector zern_vec with the amplitude of Zernike modes, return the reconstructed wavefront with radius rad. This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details. If mask is True, set everything outside radius rad to zero, this is the default and will use orthogonal Zernikes. If this is False, the modes will not be cropped.

@param [in] zern_vec 1D vector of Zernike amplitudes @param [in] npix array size to calculate the basis @param [in] zern_data Zernike basis cache @param [in] mask If True, set everything outside the Zernike aperture to zero, otherwise leave as is. @see See calc_zern_rec_basis() for details on zern_data cache and mask

barc4ro.wavefront_fitting.calc_zernike_sqr(zern_vec, npix, zern_data={}, mask=True)[source]

Constructs wavefront with Zernike amplitudes zern_vec. Given vector zern_vec with the amplitude of Zernike modes, return the reconstructed wavefront with radius rad. This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details. If mask is True, set everything outside radius rad to zero, this is the default and will use orthogonal Zernikes. If this is False, the modes will not be cropped.

@param [in] zern_vec 1D vector of Zernike amplitudes @param [in] npix array size to calculate the basis @param [in] zern_data Zernike basis cache @param [in] mask If True, set everything outside the Zernike aperture to zero, otherwise leave as is. @see See calc_zern_sqr_basis() for details on zern_data cache and mask

barc4ro.wavefront_fitting.chebyshev_1D(Cn, X)[source]

Calculates the 1D Chebyshev polynomials on a X grid ranging from -1 to 1. The polynomials can be obtained using the recurrence relation: C_{0} = 1 C_{1} = x C_{n+1} = 2*x*C_{n}-C_{n-1} @param [in] Cn: polynomial index @param [in] X: grid ranging from [-1,1]. np.linspace(-1,1,npix) or np.meshgrid(-1,1,npix) @return 1D Chebyshev polynomial calculated over a grid.

barc4ro.wavefront_fitting.chebyshev_2D(j, X, Y)[source]

Calculates the orthonormal rectangular Chebyshev mode j on a normalised rectangular grid X and Y given by:

x_axis = np.linspace(-1, 1, npix_x) y_axis = np.linspace(-1, 1, npix_y) X, Y = np.meshgrid(x_axis, y_axis)

@param [in] j indicates the 2D Polynomial order Q_j = C_l(X)*C_m(Y) @param [in] X - horizontal normalised coordinates @param [in] Y - vertical normalised coordinates @return 2D Chebyshev mode j with identical shape as X and Y

barc4ro.wavefront_fitting.fit_chebyshev(wavefront, leg_data={}, nmodes=44, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_leg=True, err=None)[source]

Fit nmodes Chebyshev modes to a wavefront. The wavefront will be fit to Chebyshev modes for a circle with radius rad with origin at center. weigh is a weighting mask used when fitting the modes. If center or rad are between 0 and -1, the values will be interpreted as fractions of the image shape. startmode indicates the Chebyshev mode (Noll index) to start fitting with, i.e. *startmode = 4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if startmode == nmodes, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If err is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared

This function uses leg_data as cache. If this is not given, it will be generated. See calc_chebyshev_basis() for details.

@param [in] wavefront Input wavefront to fit @param [in] leg_data Chebyshev basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Chebyshev modes to fit @param [in] rad Radius of Chebyshev modes to fit @param [in] rec_leg Reconstruct Chebyshev modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Chebyshev mode amplitudes, the second element is a full 2D Chebyshev reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_chebyshev_basis() for details on leg_data cache

barc4ro.wavefront_fitting.fit_legendre(wavefront, leg_data={}, nmodes=44, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_leg=True, err=None)[source]

Fit nmodes Legendre modes to a wavefront. The wavefront will be fit to Legendre modes for a circle with radius rad with origin at center. weigh is a weighting mask used when fitting the modes. If center or rad are between 0 and -1, the values will be interpreted as fractions of the image shape. startmode indicates the Legendre mode (Noll index) to start fitting with, i.e. *startmode = 4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if startmode == nmodes, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If err is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared

This function uses leg_data as cache. If this is not given, it will be generated. See calc_legendre_basis() for details.

@param [in] wavefront Input wavefront to fit @param [in] leg_data Legendre basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Legendre modes to fit @param [in] rad Radius of Legendre modes to fit @param [in] rec_leg Reconstruct Legendre modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Legendre mode amplitudes, the second element is a full 2D Legendre reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_legendre_basis() for details on leg_data cache

barc4ro.wavefront_fitting.fit_wft_pol()[source]
barc4ro.wavefront_fitting.fit_zernike_circ(wavefront, zern_data={}, nmodes=37, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_zern=True, err=None)[source]

Fit nmodes Zernike modes to a wavefront. The wavefront will be fit to Zernike modes for a circle with radius rad with origin at center. weigh is a weighting mask used when fitting the modes. If center or rad are between 0 and -1, the values will be interpreted as fractions of the image shape. startmode indicates the Zernike mode (Noll index) to start fitting with, i.e. *startmode = 4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if startmode == nmodes, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If err is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared

This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details.

@param [in] wavefront Input wavefront to fit @param [in] zern_data Zernike basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Zernike modes to fit @param [in] rad Radius of Zernike modes to fit @param [in] rec_zern Reconstruct Zernike modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Zernike mode amplitudes, the second element is a full 2D Zernike reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_zern_circ_basis() for details on zern_data cache

barc4ro.wavefront_fitting.fit_zernike_rec(wavefront, zern_data={}, nmodes=15, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_zern=True, err=None)[source]

Fit nmodes Zernike modes to a wavefront. The wavefront will be fit to Zernike modes for a circle with radius rad with origin at center. weigh is a weighting mask used when fitting the modes. If center or rad are between 0 and -1, the values will be interpreted as fractions of the image shape. startmode indicates the Zernike mode (Noll index) to start fitting with, i.e. *startmode = 4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if startmode == nmodes, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If err is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared

This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details.

@param [in] wavefront Input wavefront to fit @param [in] zern_data Zernike basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Zernike modes to fit @param [in] rad Radius of Zernike modes to fit @param [in] rec_zern Reconstruct Zernike modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Zernike mode amplitudes, the second element is a full 2D Zernike reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_zern_circ_basis() for details on zern_data cache

barc4ro.wavefront_fitting.fit_zernike_sqr(wavefront, zern_data={}, nmodes=45, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_zern=True, err=None)[source]

Fit nmodes Zernike modes to a wavefront. The wavefront will be fit to Zernike modes for a circle with radius rad with origin at center. weigh is a weighting mask used when fitting the modes. If center or rad are between 0 and -1, the values will be interpreted as fractions of the image shape. startmode indicates the Zernike mode (Noll index) to start fitting with, i.e. *startmode = 4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if startmode == nmodes, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If err is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared

This function uses zern_data as cache. If this is not given, it will be generated. See calc_zern_circ_basis() for details.

@param [in] wavefront Input wavefront to fit @param [in] zern_data Zernike basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Zernike modes to fit @param [in] rad Radius of Zernike modes to fit @param [in] rec_zern Reconstruct Zernike modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Zernike mode amplitudes, the second element is a full 2D Zernike reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_zern_circ_basis() for details on zern_data cache

barc4ro.wavefront_fitting.legendre_1D(Ln, X, norm=True)[source]

Calculates the 1D Legendre polynomials on a X grid ranging from -1 to 1. The polynomials can be obtained using the Rodrigues formula (https://en.wikipedia.org/wiki/Rodrigues%27_formula): Ln = 1/(2^n n!) * d^n(x^2-1)^n/dx^n, where d^n/dx^n indicates the nth derivative of (x^2-1)^n

@param [in] Ln: polynomial index @param [in] X: grid ranging from [-1,1]. np.linspace(-1,1,npix) or np.meshgrid(-1,1,npix) @param [in] norm: puts the normal in orthonormal, otherwise the base is just orthogonal @return 1D Legendre polynomial calculated over a grid.

barc4ro.wavefront_fitting.legendre_2D(j, X, Y, norm=True)[source]

Calculates the orthonormal rectangular Legendre mode j on a normalised rectangular grid X and Y given by:

x_axis = np.linspace(-1, 1, npix_x) y_axis = np.linspace(-1, 1, npix_y) X, Y = np.meshgrid(x_axis, y_axis)

@param [in] j indicates the 2D Polynomial order Q_j = L_l(X)*L_m(Y) @param [in] X - horizontal normalised coordinates @param [in] Y - vertical normalised coordinates @return 2D Legendre mode j with identical shape as X and Y

barc4ro.wavefront_fitting.mk_circ_mask(r0, r1=None, norm=True, center=None, dtype=<class 'float'>, getxy=False)[source]

Make a rectangular matrix of size (r0, r1) where the value of each element is the Euclidean distance to center. If center is not given, it is the middle of the matrix. If norm is True (default), the distance is normalized to half the radius, i.e. values will range from [-1, 1] for both axes. If only r0 is given, the matrix will be (r0, r0). If r1 is also given, the matrix will be (r0, r1). To make a circular binary mask of (r0, r0), use mk_circ_mask(r0) < 1

@param [in] r0 The width (and height if r1==None) of the mask. @param [in] r1 The height of the mask. @param [in] norm Normalize the distance such that 2/(r0, r1) equals a distance of 1. @param [in] getxy Return x, y-values instead of r @param [in] dtype Datatype to use for radial coordinates @param [in] center Set distance origin to center (defaults to the middle of the rectangle)

barc4ro.wavefront_fitting.noll_to_zern(j)[source]

Convert linear Noll index to tuple of Zernike indices.

j is the linear Noll coordinate, n is the radial Zernike index and m is the azimuthal Zernike index.

@param [in] j Zernike mode Noll index @return (n, m) tuple of Zernike indices @see <https://oeis.org/A176988>.

barc4ro.wavefront_fitting.zern_normalisation(nmodes=37)[source]

Calculates normalisation vector.

This function calculates a nmodes element vector with normalisation constants for Zernike modes that have not already been normalised.

@param [in] nmodes Size of normalisation vector. @see <http://research.opt.indiana.edu/Library/VSIA/VSIA-2000_taskforce/TOPS4_2.html> and <http://research.opt.indiana.edu/Library/HVO/Handbook.html>.

barc4ro.wavefront_fitting.zernike_circ(j, rho, phi, norm=True)[source]

Calculates Zernike mode with Noll-index j on a square grid of <size>^2 elements

barc4ro.wavefront_fitting.zernike_circ_mn(m, n, rho, phi, norm=True)[source]

Calculates Zernike mode (m,n) on grid rho and phi.

rho and phi should be radial and azimuthal coordinate grids of identical shape, respectively.

@param [in] m Radial Zernike index @param [in] n Azimuthal Zernike index @param [in] rho Radial coordinate grid @param [in] phi Azimuthal coordinate grid @param [in] norm Normalize modes to unit variance @return Zernike mode (m,n) with identical shape as rho, phi

barc4ro.wavefront_fitting.zernike_rad(m, n, rho)[source]

Make radial Zernike polynomial on 1D - coordinate grid rho.

@param [in] m Radial Zernike index @param [in] n Azimuthal Zernike index @param [in] rho Radial coordinate grid @return Radial polynomial with identical shape as rho

barc4ro.wavefront_fitting.zernike_rec(j, a, rho, phi)[source]

Calculates the orthonormal rectangular Zernike mode j on grid rho and phi.

rho and phi should be radial and azimuthal coordinate grids of identical shape, respectively.

@param [in] j Radial Zernike index @param [in] a unit rectangle inscribed a unit circle. Its corner points lie at a distance of unity from its centre. @param [in] rho Radial coordinate grid @param [in] phi Azimuthal coordinate grid @return Zernike mode j with identical shape as rho, phi

barc4ro.wavefront_fitting.zernike_sqr(j, rho, phi)[source]

Calculates the orthonormal square Zernike mode j on grid rho and phi.

rho and phi should be radial and azimuthal coordinate grids of identical shape, respectively.

@param [in] j Radial Zernike index @param [in] rho Radial coordinate grid @param [in] phi Azimuthal coordinate grid @return Zernike mode j with identical shape as rho, phi

Module contents