obstools.dfocus module
DeVeny Collimator Focus Calculator Module
LDTObserverTools contains python ports of various LDT Observer Tools
Lowell Discovery Telescope (Lowell Observatory: Flagstaff, AZ) https://lowell.edu
This file contains the dfocus routine for computing the required collimator focus for the DeVeny Spectrograph based on a focus sequence completed by the DeVeny LOUI.
- class obstools.dfocus.DFocus[source]
Bases:
ScriptBaseScript class for
dfocustoolScript structure borrowed from
pypeit.scripts.scriptbase.ScriptBase.- classmethod get_parser(description: str = None, width: int = None, formatter: HelpFormatter = <class 'argparse.ArgumentDefaultsHelpFormatter'>)[source]
Construct the command-line argument parser.
- Parameters:
description (
str, optional) – A short description of the purpose of the script.width (
int, optional) – Restrict the width of the formatted help output to be no longer than this number of characters, if possible given the help formatter. If None, the width is the same as the terminal width.formatter (
HelpFormatter) – Class used to format the help output.
- Returns:
ArgumentParser– Command-line interpreter.
- class obstools.dfocus.FocusCurves(min_focus_values: ndarray, optimal_focus_values: ndarray, min_linewidths: ndarray, fit_pars: ndarray)[source]
Bases:
objectFocus Curves DataClass
- class obstools.dfocus.FocusParams(mid_file: Path, start: float, end: float, delta: float, focus_values: ndarray, mid_index: int, plot_title: str, opt_title: str, mnttemp: float, nominal: float = 2.7, binning: str = '1x1')[source]
Bases:
objectFocus Parameters DataClass
- class obstools.dfocus.LineInfo(spec_1d: ndarray, trace: ndarray, centers: ndarray, fwhm: ndarray)[source]
Bases:
objectExtracted Line Information DataClass
- class obstools.dfocus.PlotParams(pdf: PdfPages, path: Path, docfig: bool)[source]
Bases:
objectPlotting Parameters DataClass
- obstools.dfocus.centered_trace(spec2d: ndarray) ndarray[source]
Construct a simple trace down the middle of the image
_extended_summary_
- obstools.dfocus.dfocus(path: Path, flog: str = 'last', thresh: float = 100.0, debug: bool = False, launch_preview: bool = True, docfig: bool = False)[source]
Find the optimal DeVeny collimator focus value
This is the user-facing
dfocusfunction that calls all of the various following subroutines. This function operates identically to the original IDL routinedfocus.pro, but with the additional options of debugging and whether to launch Preview.app to show the PDF plots generated.- Parameters:
path (
Path) – The path in which to find thedeveny_focus.*files.flog (
str, optional) – Focus log to process. If unspecified, process the last sequence in the directory. (Default: ‘last’) flog must be of form:deveny_focus.YYYYMMDD.HHMMSSthresh (
float, optional) – Line intensity threshold above background for detection (Default: 100.0)debug (
bool, optional) – Print additional diagnostics (Default: False)launch_preview (
bool, optional) – Display the plots by launching Preview (Default: True)docfig (
bool, optional) – Make example figures for online documentation? (Default: False)
- obstools.dfocus.extract_spectrum(spectrum: ndarray, traces: ndarray, window: int, thresh: float = 20.0, verbose: bool = False) ndarray[source]
Object spectral extraction routine
Extract spectra by averaging over the specified window and background subtract
- Parameters:
spectrum (
ndarray) – The trimmed spectral imagetraces (
ndarray) – The trace(s) along which to extract spectrawindow (
int) – Window over which to average the spectrumthresh (
float, optional) – Threshold above which to identify lines [Default: 20 DN above bkgd]verbose (
bool, optional) – Produce verbose output? [Default: False]
- Returns:
ndarray– Background-subtracted extracted spectrum
- obstools.dfocus.find_lines(spectrum: ndarray, thresh: float = 20.0, minsep: int = 11, verbose: bool = True) tuple[ndarray, ndarray][source]
Automatically find and centroid lines in a 1-row image
Uses
scipy.signal.find_peaks()for this task- Parameters:
- Returns:
- obstools.dfocus.find_lines_in_spectrum(filename: str | Path, thresh: float = 100.0) ndarray[source]
Find the line centers in a spectrum
This function is not directly utilized in
dfocus, but rather is included as a wrapper for several functions that can be used by other programs.Given the filename of an arc-lamp spectrum, this function returns a list of the line centers found in the image.
- obstools.dfocus.fit_focus_curves(width_array: ndarray, focus_pars: FocusParams, fit_order: int = 2, debug: bool = False) FocusCurves[source]
Fit line focus curves
[extended_summary]
- Parameters:
width_array (
ndarray) – Array of FWHM for all lines as a function of COLLFOCfocus_pars (
FocusParams) – Focus parameters DataClass fromparse_focus_headers()fit_order (
int, optional) – Polynomial order of the focus fit (Default: 2 = Quadratic)debug (
bool, optional) – Print debug statements (Default: False)
- Returns:
FocusCurves– The focus curve object.
- obstools.dfocus.get_lines_from_ccd(ccd: CCDData, thresh: float = 20.0, window: int = 11, trace: ndarray = None, verbose: bool = True) LineInfo[source]
Extract the lines from the CCD image
Since these steps are repeated often enough, pull them out into a separate function.
- Parameters:
- Returns:
LineInfo– Contains the relevant information about the lines found in the frame
- obstools.dfocus.parse_focus_headers(focus_icl: ImageFileCollection) FocusParams[source]
Parse focus headers values into a dictionary
Create a dictionary of values (mainly from the header) that can be used by subsequent routines.
- Parameters:
focus_icl (
ImageFileCollection) – The Image File Collection containing the focus files for this run- Returns:
FocusParams– DataClass containing the focus sweep parameters
- obstools.dfocus.parse_focus_log(path: Path, flog: str) tuple[ImageFileCollection, str][source]
Parse the focus log file produced by the DeVeny LOUI
The DeVeny focus log file consists of filename, collimator focus, and other relevant information:
: Image File Name ColFoc Grating GrTilt SltWth Filter LampCal MntTmp 20230613.0026.fits 7.50 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0027.fits 8.00 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0028.fits 8.50 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0029.fits 9.00 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0030.fits 9.50 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0031.fits 10.00 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10 20230613.0032.fits 10.50 600/4900 27.04 1.20 Clear (C) Cd,Ar,Hg 9.10
This function parses out the filenames and collimator focus values of the focus images for this run, largely discarding the remaining information in the focus log file.
- Parameters:
- Returns:
ImageFileCollection– The Image File Collection containing the information about focus images requestedstr– The Focus ID to be used for creating the PDF chart outputs
- obstools.dfocus.plot_focus_curves(centers: ndarray, line_width_array: ndarray, focus_curves: FocusCurves, focus_pars: FocusParams, plot_pars: PlotParams)[source]
Make the big plot of all the focus curves (IDL1 Window)
[extended_summary]
- Parameters:
centers (
ndarray) – List of line centers from find_lines()line_width_array (
ndarray) – Array of line widths from each COLLFOC setting for each linefocus_curves (
FocusCurves) – The set of outputs from the focus curve fittingfocus_pars (
FocusParams, optional) – DataClass containing needed variables for plotplot_pars (
PlotParams) – DataClass containing needed parameters for plotting
- obstools.dfocus.plot_lines(spectrum: ndarray, centers: ndarray, focus_pars: FocusParams = None, plot_pars: PlotParams = None)[source]
Plot centroid lines in a 1-row image
- Parameters:
spectrum (
ndarray) – Extracted spectrumcenters (
ndarray) – The line centers, as reported byfind_lines()focus_pars (
FocusParams, optional) – DataClass containing needed variables for plotplot_pars (
PlotParams, optional) – DataClass containing needed parameters for plotting
- obstools.dfocus.plot_optimal_focus(focus: FocusParams, centers: ndarray, optimal_focus_values: ndarray, med_opt_focus: float, plot_pars: PlotParams, debug: bool = False)[source]
Make the Optimal Focus Plot (IDL2 Window)
[extended_summary]
- Parameters:
focus (
FocusParams) – Dataclass of the various focus-related quantitiescenters (
ndarray) – Array of the centers of each lineoptimal_focus_values (
ndarray) – Array of the optimal focus values for each linemed_opt_focus (
float) – Median optimal focus valuedebug (
bool, optional) – Print debug statements (Default: False)plot_pars (
PlotParams) – DataClass containing needed parameters for plotting