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:
ScriptBase
Script class for
dfocus
toolScript structure borrowed from
pypeit.scripts.scriptbase.ScriptBase
.- classmethod get_parser(width=None)[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.
- 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
dfocus
function 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 musy be of form:deveny_focus.YYYYMMDD.HHMMSS
thresh (
float
, optional) – Line intensity threshold above background for detection (Default: 100.0)debug (
bool
, optional) – Print debug statements (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, traces, win)[source]
Object spectral extraction routine
Extract spectra by averaging over the specified window
- obstools.dfocus.find_lines(image, thresh=20.0, minsep=11, verbose: bool = True, do_plot: bool = False, focus_dict=None, pdf=None, docfig: bool = False, path: Path = None)[source]
Automatically find and centroid lines in a 1-row image
Uses
scipy.signal.find_peaks()
for this task- Parameters:
image (
ndarray
) – Extracted spectrumthresh (
float
, optional) – Threshold above which to indentify lines [Default: 20 DN above bkgd]minsep (
int
, optional) – Minimum line separation for identification [Default: 11 pixels]verbose (
bool
, optional) – Produce verbose output? [Default: False]do_plot (
bool
, optional) – Create a plot on the provided axes? [Default: False]focus_dict (
dict
, optional) – Dictionary containing needed variables for plot [Default: None]
- Returns:
- obstools.dfocus.find_lines_in_spectrum(filename, thresh=100.0)[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(fwhm, fnom=2.7, norder=2, debug=False)[source]
Fit line / star focus curves
[extended_summary]
- Parameters:
- Returns:
- obstools.dfocus.initialize_focus_values(path: Path, flog: str)[source]
Initialize a dictionary of focus values
Create a dictionary of values (mainly from the header) that can be used by subsequent routines.
- obstools.dfocus.parse_focus_log(path: Path, flog: 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 of the focus images for this run, largely discarding the remaining information in the focus log file.
- obstools.dfocus.plot_focus_curves(centers, line_width_array, min_focus_values, optimal_focus_values, min_linewidths, fit_pars, delta_focus, focus_0, fnom=2.7, pdf=None, docfig: bool = False, path: Path = None)[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 linemin_focus_values (
ndarray
) – List of the minimum focus values found from the polynomial fitoptimal_focus_values (
ndarray
) – List of the optimal focus values found from the polynomial fitmin_linewidths (
ndarray
) – List of the minumum linewidths found from the fittingfit_pars (
ndarray
) – Array of the polynomial fit parameters for each linedf (
float
) – Spacing between COLLFOC settingsfocus_0 (
float
) – Lower end of the COLLFOC rangefnom (
float
, optional) – Nominal (optimal) linewidth (Default: 2.7)
- obstools.dfocus.plot_optimal_focus(focus, centers, optimal_focus_values, med_opt_focus, debug: bool = False, pdf=None, docfig: bool = False, path: Path = None)[source]
Make the Optimal Focus Plot (IDL2 Window)
[extended_summary]
- Parameters:
focus (
dict
) – Dictionary 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)
- obstools.dfocus.process_middle_image(focus, thresh, debug=False)[source]
Process the middle focus image
This finds the lines to be measured – presumably the middle is closest to focus
- Parameters:
- Returns:
- obstools.dfocus.trim_deveny_image(filename)[source]
Trim a DeVeny Image
The IDL code from which this was ported contains a large amount of vistigial code from previous versions of the DeVeny camera, including instances where the CCD was read out using 2 amplifiers and required special treatment in order to balance the two sides of the output image.
The code below consists of the lines of code that were actually running using the keywords passed from current version of
dfocus.pro
, and the pieces of that code that are actually used.Specifically, this routine trims off the 50 prescan and 50 postscan pixels, as well as several rows off the top and bottom. (Extracts rows
[12:512]
)