soxspipe.commonutils.create_dispersion_map¶
detect arc-lines on a pinhole frame to generate a dispersion solution
- Author
Marco Landoni & David Young
- Date Created
September 1, 2020
- Module Structure
This module contains the main
create_dispersion_mapclass and helper functions:Main Class:
create_dispersion_map- Generates dispersion solutions from pinhole arc frames
Helper Functions:
measure_line_position()- Detect and measure arc line positions on image stampsstraighten_mph_sets()- Straighten multi-pinhole sets by projecting onto fitted linefind_largest_cluster_center()- Find center of largest cluster using DBSCAN_plot_slit_index_comparisons()- Debug visualization of slit position residuals
Workflow:
Load predicted line positions from static calibrations
Detect arc lines on pinhole frame iteratively
Calculate shifts between predicted and observed positions
Fit polynomial dispersion solution (wavelength, order, slit)
Generate QC plots and write output files
Module Contents¶
Classes¶
detect arc-lines on a pinhole frame to generate a dispersion solution |
Functions¶
Find the center of the largest cluster in (x, y) data using DBSCAN |
|
measure the line position on a given stamp |
|
Straighten multi-pinhole sets by projecting points onto fitted line |
API¶
- class soxspipe.commonutils.create_dispersion_map.create_dispersion_map(log, settings, recipeSettings, pinholeFrame, firstGuessMap=False, orderTable=False, qcTable=False, productsTable=False, sofName=False, create2DMap=True, lineDetectionTable=False, startNightDate='', arcFrame=None, debug=False, turnOffMP=False)[source][source]¶
Bases:
objectdetect arc-lines on a pinhole frame to generate a dispersion solution
Key Arguments:
log– loggersettings– the settings dictionaryrecipeSettings– the recipe specific settingspinholeFrame– the calibrated pinhole frame (single or multi)firstGuessMap– the first guess dispersion map from thesoxs_disp_solutionrecipe (needed insoxs_spat_solutionrecipe). Default False.orderTable– the order geometry tableqcTable– the data frame to collect measured QC metricsproductsTable– the data frame to collect output productssofName– name of the originating SOF filecreate2DMap– create the 2D image map of wavelength, slit-position and order from disp solution.lineDetectionTable– the list of arc-lines detected on the pinhole frame (used only for pipeline tuning)startNightDate– YYYY-MM-DD date of the observation night. Default “”arcFrame– the calibrated arc frame used to determine spectral resolution. Default Nonedebug– debug mode. Default FalseturnOffMP– turn off multiprocessing. Default False.
Usage:
from soxspipe.commonutils import create_dispersion_map mapPath, mapImagePath, res_plots, qcTable, productsTable = create_dispersion_map( log=log, settings=settings, pinholeFrame=frame, firstGuessMap=False, qcTable=self.qc, productsTable=self.products, sofName=sofName, create2DMap=True, recipeSettings=recipeSettings, startNightDate=startNightDate, arcFrame=arcFrame, debug=debug, turnOffMP=turnOffMP ).get()
Initialization
- calculate_residuals(orderPixelTable, xcoeff, ycoeff, orderDeg, wavelengthDeg, slitDeg, writeQCs=False, pixelRange=False)[source][source]¶
calculate residuals of the polynomial fits against the observed line positions
Key Arguments:
orderPixelTable– the predicted line list as a data framexcoeff– the x-coefficientsycoeff– the y-coefficientsorderDeg– degree of the order fittingwavelengthDeg– degree of wavelength fittingslitDeg– degree of the slit fitting (False for single pinhole)writeQCs– write the QCs to dataframe? Default FalsepixelRange– return centre pixel and ± 2nm from the centre pixel (to measure the pixel scale)
Return:
residuals– combined x-y residualsmean– the mean of the combine residualsstd– the stdev of the combine residualsmedian– the median of the combine residuals
- convert_and_fit(order, bigWlArray, bigSlitArray, slitMap, wlMap, iteration, plots=False)[source][source]¶
convert wavelength and slit position grids to pixels
Key Arguments:
order– the order being consideredbigWlArray– 1D array of all wavelengths to be convertedbigSlitArray– 1D array of all split-positions to be converted (same length asbigWlArray)slitMap– place-holder image hosting fitted pixel slit-position valueswlMap– place-holder image hosting fitted pixel wavelength valuesiteration– the iteration index (used for CL reporting)plots– show plot of the slit-map
Return:
orderPixelTable– dataframe containing unfitted pixel inforemainingCount– number of remaining pixels in orderTable
Usage:
orderPixelTable = self.convert_and_fit( order=order, bigWlArray=bigWlArray, bigSlitArray=bigSlitArray, slitMap=slitMap, wlMap=wlMap)
- create_new_static_line_list(dispersionMapPath)[source][source]¶
using a first pass dispersion solution, use a line atlas to generate a more accurate and more complete static line list
Key Arguments:
dispersionMapPath– path to the first pass dispersion solution
Return:
newPredictedLineList– a new predicted line list (to replace the static calibration line-list)
- create_placeholder_images(order=False, plot=False, reverse=False)[source][source]¶
create CCDData objects as placeholders to host the 2D images of the wavelength and spatial solutions from dispersion solution map
Key Arguments:
order– specific order to generate the placeholder pixels for. Inner-order pixels set to nan, else set to 0. Default False (generate all orders)plot– generate plots of placeholder images (for debugging). Default False.reverse– Inner-order pixels set to 0, else set to nan (reverse of default output).
Return:
slitMap– placeholder image to add pixel slit positions towlMap– placeholder image to add pixel wavelength values to
Usage:
slitMap, wlMap, orderMap = self._create_placeholder_images(order=order)
- detect_pinhole_arc_lines(orderPixelTable, iraf=True, sigmaLimit=3, iteration=False, brightest=False, exclude_border=False, returnAll=False)[source][source]¶
detect the observed position of an arc-line given the predicted pixel positions
Key Arguments:
orderPixelTable– the initial line listiraf– use IRAF star finder to generate a FWHMsigmaLimit– the lower sigma limit for arc line to be considered detectediteration– which detect and shift iteration are we on?brightest– find the brightest source?exclude_border– exclude border pixels from detection?
Return:
predictedLine– the line with the observed pixel coordinates appended (if detected, otherwise nan)
- fit_polynomials(orderPixelTable, wavelengthDeg, orderDeg, slitDeg, missingLines=False)[source][source]¶
iteratively fit the dispersion map polynomials to the data, clipping residuals with each iteration
Key Arguments:
orderPixelTable– data frame containing order, wavelengths, slit positions and observed pixel positionswavelengthDeg– degree of wavelength fittingorderDeg– degree of the order fittingslitDeg– degree of the slit fitting (0 for single pinhole)missingLines– lines not detected on the image
Return:
xcoeff– the x-coefficients post clippingycoeff– the y-coefficients post clippinggoodLinesTable– the fitted line-list with metricsclippedLinesTable– the lines that were sigma-clipped during polynomial fitting
- get()[source][source]¶
generate the dispersion map
Return:
mapPath– path to the file containing the coefficients of the x,y polynomials of the global dispersion map fit
Workflow:
LOAD PREDICTED LINE POSITIONS FROM CALIBRATION FILES
PREPARE PINHOLE FRAME (MASKING, STATISTICS)
ITERATIVELY DETECT ARC LINES ON FRAME
FIT POLYNOMIAL DISPERSION SOLUTION
WRITE OUTPUTS (LINE LISTS, MAP FILES, QC PLOTS)
- get_predicted_line_list()[source][source]¶
lift the predicted line list from the static calibrations
Return:
orderPixelTable– a panda’s data-frame containing wavelength,order,slit_index,slit_position,detector_x,detector_y
- map_to_image(dispersionMapPath, orders=False)[source][source]¶
convert the dispersion map to images in the detector format showing pixel wavelength values and slit positions
Key Arguments:
dispersionMapPath– path to the full dispersion map to convert to imagesorders– orders to add to the image map. List. Default False (add all orders)
Return:
dispersion_image_filePath– path to the FITS image with an extension for wavelength values and another for slit positions
Usage:
mapImagePath = self.map_to_image(dispersionMapPath=mapPath)
- order_to_image(orderInfo)[source][source]¶
convert a single order in the dispersion map to wavelength and slit position images
Key Arguments:
orderInfo– tuple containing the order number to generate the images for, the minimum wavelength to consider (from format table) and maximum wavelength to consider (from format table).
Return:
slitMap– the slit map with order values filledwlMap– the wavelengths map with order values filled
Usage:
slitMap, wlMap = self.order_to_image(order=order,minWl=minWl, maxWl=maxWl)
- update_static_line_list_detector_positions(originalOrderPixelTable, dispersionMapPath)[source][source]¶
using a first pass dispersion solution, update the original static line list
Key Arguments:
originalOrderPixelTable– original order pixel tabledispersionMapPath– path to the first pass dispersion solution
Return:
updatedLineList– updated static line list
- write_map_to_file(xcoeff, ycoeff, orderDeg, wavelengthDeg, slitDeg)[source][source]¶
write out the fitted polynomial solution coefficients to file
Key Arguments:
xcoeff– the x-coefficientsycoeff– the y-coefficientsorderDeg– degree of the order fittingwavelengthDeg– degree of wavelength fittingslitDeg– degree of the slit fitting (False for single pinhole)
Return:
disp_map_path– path to the saved file
- soxspipe.commonutils.create_dispersion_map.find_largest_cluster_center(x, y, eps=2.0, min_samples=5)[source][source]¶
Find the center of the largest cluster in (x, y) data using DBSCAN
Key Arguments:
x– x-coordinates of pointsy– y-coordinates of pointseps– maximum distance between points in a clustermin_samples– minimum samples required to form a cluster
Returns:
center_x, center_y– coordinates of largest cluster center, or (None, None) if no cluster found
- soxspipe.commonutils.create_dispersion_map.measure_line_position(stampInfo, log, windowHalf, iraf, sigmaLimit, iteration, brightest=False, exclude_border=False, multipinhole=False, returnAll=True, debug=False)[source][source]¶
measure the line position on a given stamp
Key Arguments:
stampInfo– stamp pixels, xlow, xup, ylow, yuplog– loggerwindowHalf– half of the stamp sideiraf– run IRAF source detection to get FWHM?sigmaLimit– stamp source detection minimum sigmabrightest– find the brightest source?multipinhole– is this a multipinhole frame?
Returns:
list of detected line positions with properties
- soxspipe.commonutils.create_dispersion_map.straighten_mph_sets(group)[source][source]¶
Straighten multi-pinhole sets by projecting points onto fitted line
Key Arguments:
group– dataframe group containing observed_x and observed_y coordinates
Returns:
group– group with added tilt_corrected_x and tilt_corrected_y columns