pypeit.core.slitdesign_matching module

Module with slit - mask design matching routines.

Routines are primarily used for matching the traced slit edges to the predicted trace from the mask design/optical model.

TODO: These routines are specific for DEIMOS. Can they be generalized?

These routines are taken from the DEEP2 IDL-based pipeline.

pypeit.core.slitdesign_matching.best_offset(x_det, x_model, step=1, xlag_range=None)[source]

Script to determine the best offset between the slit edge predicted by the optical model and the one found in the image. This is used iteratively.

Taken from DEEP2/spec2d/pro/ discrete_correlate.pro x_det==x1, x_model==x2

Parameters:
  • x_det (numpy.ndarray) – 1D array of slit edge spatial positions found from image

  • x_model (numpy.ndarray) – 1D array of slit edge spatial positions predicted by the optical model

  • step (int) – step size in pixels used to generate a list of possible offsets within the offsets_range

  • xlag_range (list, optional) – range of offsets in pixels allowed between the slit positions predicted by the mask design and the traced slit positions.

Returns:

best offset between the slit edge predicted by the optical model and the one found in the image

Return type:

float

pypeit.core.slitdesign_matching.discrete_correlate_match(x_det, x_model, step=1, xlag_range=[-50, 50])[source]

Script to find the the x_model values that match the traced edges.

This method uses best_offset() to determine the best offset between slit edge predicted by the optical model and the one found in the image, given a range of offsets. This is used iteratively.

Taken from in DEEP2/spec2d/pro/discrete_correlate_match.pro x_det==x1, x_model==x2_in

Parameters:
  • x_det (numpy.ndarray) – 1D array of slit edge spatial positions found from image

  • x_model (numpy.ndarray) – 1D array of slit edge spatial positions predicted by the optical model

  • step (int) – step size in pixels used to generate a list of possible offsets within the offsets_range

  • xlag_range (list, optional) – range of offsets in pixels allowed between the slit positions predicted by the mask design and the traced slit positions.

Returns:

array of indices for x_model, which defines the matches to x_det, i.e., x_det matches x_model[ind]

Return type:

numpy.ndarray

pypeit.core.slitdesign_matching.match_positions_1D(measured, nominal, tol=None)[source]

Match a set of measured 1D positions against a nominal expectation with uniqueness (i.e., more than one measured position cannot be matched to the same nominal position).

The function primarily uses scipy.optimize.linear_sum_assignment to perform the matching, where the matrix of separations of each measured position to every nominal position is used as the cost matrix.

Parameters:
  • measured (numpy.ndarray) – Measured positions. Shape is (n,).

  • nominal (numpy.ndarray) – Expected positions. Shape is (m,).

  • tol (float, optional) – Maximum separation between measured and nominal positions to be considered a match. If None, no limit is applied.

Returns:

Indices of the elements in measured that are matched to the elements of nominal. Shape is (m,). If the tolerance is set or the number of measurements is less than the nominal set (i.e., n < m), any element of nominal that does not have an appropriate match in measured is given an index of -1.

Return type:

numpy.ndarray

pypeit.core.slitdesign_matching.plot_matches(edgetrace, ind, x_model, yref, slit_index, nspat=2048, duplicates=None, missing=None, edge=None)[source]

Plot the slit mask matching results.

Parameters:
  • edgetrace (numpy.ndarray) – 2D array with the location of the slit edges for each spectral pixel as measured from the trace image. Shape is \((N_{\rm spec},N_{\rm trace})\).

  • ind (numpy.ndarray) – 1D array of indices for x_model, which defines the matches to x_det.

  • x_model (numpy.ndarray) – 1D array of slit edge spatial positions predicted by the optical model.

  • yref (float) – Reference pixel in the spec direction.

  • slit_index (numpy.ndarray) – 1D array of slit-mask design indices.

  • nspat (int, optional) – Spatial dimension of the detector, for plotting purpose.

  • duplicates (numpy.ndarray, optional) – 1D array of bool that flags which ind are duplicates.

  • missing (numpy.ndarray, optional) – 1D array of indices for x_model, which defines the missing traces, if any.

  • edge (str, optional) – String that indicates which edges are being plotted, i.e., left of right.

pypeit.core.slitdesign_matching.slit_match(x_det, x_model, step=1, xlag_range=[-50, 50], sigrej=3, print_matches=False, edge=None)[source]

Script that perform the slit edges matching.

This method uses discrete_correlate_match() to find the indices of x_model that match x_det.

Taken from DEEP2/spec2d/pro/deimos_slit_match.pro

Parameters:
  • x_det (numpy.ndarray) – 1D array of slit edge spatial positions found from image.

  • x_model (numpy.ndarray) – 1D array of slit edge spatial positions predicted by the optical model.

  • step (int, optional) – Step size in pixels used to generate a list of possible offsets within the offsets_range.

  • xlag_range (list, optional) – Range of offsets in pixels allowed between the slit positions predicted by the mask design and the traced slit positions.

  • sigrej (float, optional) – Reject slit matches larger than this number of sigma in the match residuals.

  • print_matches (bool, optional) – Print the result of the matching.

  • edge (str, optional) – String that indicates which edges are being plotted, i.e., left of right. Ignored if print_matches is False.

Returns:

  • ind (numpy.ndarray) – 1D array of indices for x_model, which defines the matches to x_det, i.e., x_det matches x_model[ind]

  • dupl (numpy.ndarray) – 1D array of bool that flags which ind are duplicates.

  • coeff (numpy.ndarray) – pypeitFit coefficients of the fitted relation between x_det and x_model[ind]

  • sigres (float) – RMS residual for the fitted relation between x_det and x_model[ind]