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 tool

Script 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.

static main(args)[source]

Main Driver

Simple function that calls the primary function.

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 routine dfocus.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 the deveny_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

Parameters:
  • spectrum (ndarray) – The trimmed spectral image

  • traces (ndarray) – The trace(s) along which to extract spectra

  • win (int) – Window over which to average the spectrum

Returns:

ndarray – 2D or 3D array of spectra of individual orders

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 spectrum

  • thresh (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:

  • n_c (int) – Number of lines found and returned

  • centers (ndarray) – Line centers (pixel #)

  • fwhm (ndarray) – The computed FWHM for each peak

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.

Parameters:
  • filename (str) – Filename of the arc frame to find lines in

  • thresh (float, optional) – Line intensity threshold above background for detection [Default: 100]

Returns:

ndarray – List of 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:
  • fwhm (ndarray) – Array of FWHM for all lines as a function of COLLFOC

  • fnom (float, optional) – Nominal FHWM of an in-focus line. (Default: 2.7)

  • norder (int, optional) – Polynomial order of the focus fit (Default: 2 = Quadratic)

  • debug (bool, optional) – Print debug statements (Default: False)

Returns:

  • min_cf_idx_value (ndarray) – Best fit focus values

  • optimal_cf_idx_value (ndarray) – Best fit linewidths

  • min_linewidth (ndarray) – Minimum linewidths

  • foc_fits (ndarray) – Fit parameters (for plotting)

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.

Parameters:
  • path (Path) – The path to the current working directory

  • flog (str) – Identifier for the focus log to be processed

Returns:

dict – Dictionary of the various needed quantities

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.

Parameters:
  • path (Path) – The path to the current working directory

  • flog (str) – Identifier for the focus log to be processed

Returns:

  • n_files (int) – Number of files for this focus run

  • files (list) – List of Path files associated with this focus run

  • focus_id (str) – The focus ID

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 line

  • min_focus_values (ndarray) – List of the minimum focus values found from the polynomial fit

  • optimal_focus_values (ndarray) – List of the optimal focus values found from the polynomial fit

  • min_linewidths (ndarray) – List of the minumum linewidths found from the fitting

  • fit_pars (ndarray) – Array of the polynomial fit parameters for each line

  • df (float) – Spacing between COLLFOC settings

  • focus_0 (float) – Lower end of the COLLFOC range

  • fnom (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 quantities

  • centers (ndarray) – Array of the centers of each line

  • optimal_focus_values (ndarray) – Array of the optimal focus values for each line

  • med_opt_focus (float) – Median optimal focus value

  • debug (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:
  • focus (dict, optional) – Dictionary containing needed variables for plot

  • thresh (float) – Line intensity threshold above background for detection

  • debug (bool, optional) – Print debug statements (Default: False)

Returns:

  • centers, ndarray – Centers

  • trace, ndarray – Trace

  • mid_collfoc, float – Collimator focus of the middle frame

  • mspectra, ndarray – The spectrum from the middle frame (for later plotting)

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])

Parameters:

filename (Path) – Filename of the spectrum to get and trim

Returns:

ndarray – The trimmed CCD image