skqfit package

Submodules

skqfit.asmjacp module

References:

G W Forbes, “Characterizing the shape of freeform optics”, Opt. Express 20(3), 2483-2499 (2012)

class skqfit.asmjacp.AsymJacobiP(nmax)[source]

Bases: object

Generate asymmetric Jacobi like polynominals needed for the freeform fit as defined in the reference document [A.1]

The Jacobi P polynominals can generate large values that lead to a double overflow for large m and n values. It is tested to (1500, 1500) for (m,n). Exceeding these values may lead to overflow events.

The scipi.special.jacobi function is has a 1.5:1 performance advantage over the current implementation but it doesn’t support the normalization and can lead to an overflow condition for n or m over 500.

build_recursion(m)[source]

Build the recurssion coefficients and saves them as a sequence of tuples. These are the coefficients to build the m type polynominals up to order n.

jmat_u_x(jmat, uv, xv)[source]

Builds the asymmetric Jacobi P polynomial as defined in [2] A.1 for all of the x values with the scaling factor of u**m which extends the range of usable (m,n) values before an overflow condition occurs.

jmat_x(jmat, xv)[source]

Builds the asymmetric Jacobi P polynomial as defined in [2] A.1 for all a vector of x values.

jvec_u_x(jvec, u, x)[source]

Builds the asymmetric Jacobi P polynomial for a single x as defined in [2] A.1 for all of the x values with the scaling factor of u**m which extends the range of usable (m,n) values.

jvec_x(jvec, x)[source]

Builds the sequence of jacobi polynomials for the value x based on [A.2-5]

skqfit.qspectre module

Reference documents

[1] G W Forbes, “Fitting freeform shapes with orthogonal bases”, Opt. Express 21, 19061-19081 (2013) [2] G W Forbes, “Characterizing the shape of freeform optics”, Opt. Express 20(3), 2483-2499 (2012) [3] G W Forbes, “Robust, efficient computational methods for axially symmetric optical aspheres”, Opt. Express 18(19), 19700-19712 (2010)

class skqfit.qspectre.QSpectrum(m_max=None, n_max=None)[source]

Bases: object

Performs precomputation if Q spectrum limits are passed, otherwise it is delayed until the data is loaded. The class supports processing a data map or a pointer to a sag function that can be used for analytic testing.

Parameters: m_max, n_max: int

The azimuthal and radial spectrum order. Setting values above 1500 may lead to overflow events.
bfs_param()[source]

Returns the fitted radius, curvature and centre.

Returns:
radius, curvature, centre: float, float, (x,y) tuple
build_map(x, y, a_nm, b_nm, curv=None, radius=None, centre=None, extend=1.0, interpolated=True, inc_deriv=False)[source]

Creates a 2D topography map and optional x and y derivate maps using the x and y axis vectors and the Q-freeform parameters.

Parameters:
x, y: array
X, and Y axis values for the map to be created. The arrays must be sorted to increasing order.
a_nm, b_nm: 2D array
The cosine and sine terms for the Q freeform polynominal
curv: float
Nominal curvature for the part. If None uses the estimated value from the previous fit.
radius: float
Defines the circular domain from the centre. If None uses the estimated value from the previous fit.
centre: (cx, cy)
The centre of the part in axis coordinates. If None uses the estimated value from previous fit.
extend: float
Generate a map over extend * radius from the centre
interpolated: boolean
If True uses a high resolution regular polar grid to build the underlying data and a spline interpolation to extract the (x, y) grid, otherwise it evaluates each (x, y) point exactly. The non-interpolated solution is significanatly slower and only practical for smaller array sizes.
inc_deriv: boolean
Return the X and Y derivatives as additional maps
Returns:
zmap: 2-D array
Data map with shape (x.size, y.size)
xder: 2-D array
X derivative map with shape (x.size, y.size) if inc_deriv is True, else None
yder: 2-D array
Y derivative map with shape (x.size, y.size) if inc_deriv is True, else None
build_profile(xv, yv, a_nm, b_nm, curv=None, radius=None, centre=None, extend=1.0, inc_deriv=False)[source]

Returns the nominal sag and optional x and y derivatives along a 1D trajectory of (x, y) coordinates.

Parameters:
x, y: arrays
Arrays of values representing the (x, y) coordinates.
a_nm, b_nm: 2D array
The cosine and sine terms for the Q freeform polynominal
curv: float
Nominal curvature for the part. If None uses the estimated value from the previous fit.
radius: float
Defines the circular domain from the centre. If None uses the estimated value from the previous fit.
centre: (cx, cy)
The centre of the part in axis coordinates. If None uses the estimated value from previous fit.
extend: float
Generate a map over extend * radius from the centre
inc_deriv: boolean
Return the X and Y derivatives as additional maps
Returns:
zval: array
Sag values for the (x, y) sequence
xder: array
X derivative map for the (x, y) sequence if inc_deriv is True, else None
yder: array
Y derivative map for the (x, y) sequence if inc_deriv is True, else None
build_q_spectrum(m_max=None, n_max=None)[source]

Fits the departure from a best fit sphere to the Q-polynominals as defined in [1](1.1) and returns the root sum square of the azimuthal terms.

Parameters:
m_max, n_max: int
The azimuthal and radial spectrum order. If None it uses the previous values and if not defined it matches the values to the pixel resolution.
Returns:
2D array
The (m,n) matrix representation of the spectrum (sqrt(cos^2 + sin^2)) terms
data_map(x, y, zmap, centre=None, radius=None, shrink_pixels=7, bfs_curv=None)[source]

Creates the spline interpolator for the map, determines the best fit sphere and minimum valid radius.

Parameters:
x, y: arrays
The arrays are the X and Y axis values for the data map. The arrays must be sorted to increasing order.
zmap: array_like
2-D array of data with shape (x.size,y.size).
centre: (cx, cy)
The centre of the part in axis coordinates. If None the centre is estimated by a centre of mass calculation
radius: float
Defines the circular domain from the centre. If None it determines the maximum radius from the centre that contains no invalids (NAN).
shrink_pixels: int
The estimated radius is reduced by 7 pixels to avoid edge effects with the spline interpolation. Ignored if the radius is specified.
q_fit(m_max=None, n_max=None)[source]

Fits the departure from a best fit sphere to the Q-freeform polynominals as defined in [1](1.1) and returns the individual sine and cosine terms.

Parameters:
m_max, n_max: int
The azimuthal and radial spectrum order. If None it uses the previous values and if not defined it matches the values to the pixel resolution. The maximum resolution supported is (1500, 1500)
Returns:
a_nm, b_nm: 2D array
The (n,m) matrix representation of the cosine and sine terms
set_sag_fn(sag_fn, radius, bfs_curv=None)[source]

A vectorized polar sag function that takes rho and theta as arguments.

This function is used to pass an analytic sag function to test the performance of the algorithm to a higher precision but can also be used to define the input map and bypass data_map().

skqfit.qspectre.qspec(x, y, zmap, m_max=None, n_max=None, centre=None, radius=None, shrink_pixels=7)[source]

A wrapper function that creates the Q-spectrum object, loads and performs the fit of the data to the Q polynomials.

Parameters:
x, y: array_like
The interpolator uses grid points defined by the coordinate arrays x, y. The arrays must be sorted to increasing order.
zmap: array_like
2-D array of data with shape (x.size,y.size)
m_max, n_max: int
The azimuthal and radial spectrum order. If None, it uses the previous values and if not defined it matches the values to the pixel resolution.
centre: (cx, cy)
The centre of the part in axis coordinates. If None the centre is estimated by a centre of mass calculation
radius: float
Defines the circular domain from the centre. If None it determines the maximum radius from the centre that contains no invalids (NAN).
shrink_pixels: int
The estimated radius is reduced by 7 pixels to avoid edge effects with the spline interpolation. Ignored if the radius is specified.
Returns:
2D array
The (m,n) matrix representation of the spectrum (sqrt(cos^2 + sin^2)) terms

Module contents