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(description: str = None, width: int = None, formatter: ~argparse.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.

static main(args)[source]

Main Driver

Simple function that calls the primary function.

class obstools.dfocus.FocusCurves(min_focus_values: ndarray, optimal_focus_values: ndarray, min_linewidths: ndarray, fit_pars: ndarray)[source]

Bases: object

Focus Curves DataClass

min_cf_idx_value

Best fit focus values

Type:

ndarray

optimal_cf_idx_value

Best fit linewidths

Type:

ndarray

min_linewidth

Minimum linewidths

Type:

ndarray

foc_fits

Fit parameters (for plotting)

Type:

ndarray

fit_pars: ndarray = <dataclasses._MISSING_TYPE object>
min_focus_values: ndarray = <dataclasses._MISSING_TYPE object>
min_linewidths: ndarray = <dataclasses._MISSING_TYPE object>
optimal_focus_values: ndarray = <dataclasses._MISSING_TYPE object>
class obstools.dfocus.FocusParams(mid_file: Path, start: float, end: float, delta: float, plot_title: str, opt_title: str, mnttemp: float, nominal: float = 2.7, binning: str = '1x1')[source]

Bases: object

Focus Parameters DataClass

mid_file

The filename of the middle file in the focus sequence

Type:

Path

nominal

Nominal linewidth in pixels based on slit width and grating demagnification

Type:

float

start

Starting focus value in the focus sweep

Type:

float

end

Ending focus value in the focus sweep

Type:

float

delta

Step size between focus values in the sweep

Type:

float

mnttemp

Mount temperature from the middle image of the sweep

Type:

float

binning

Binning scheme of the CCD

Type:

str

plot_title

The plot title for …

Type:

str

opt_title

The plot title for …

Type:

str

binning: str = '1x1'
delta: float = <dataclasses._MISSING_TYPE object>
end: float = <dataclasses._MISSING_TYPE object>
mid_file: Path = <dataclasses._MISSING_TYPE object>
mnttemp: float = <dataclasses._MISSING_TYPE object>
nominal: float = 2.7
opt_title: str = <dataclasses._MISSING_TYPE object>
plot_title: str = <dataclasses._MISSING_TYPE object>
start: float = <dataclasses._MISSING_TYPE object>
class obstools.dfocus.LineInfo(spec_1d: ndarray, trace: ndarray, centers: ndarray, fwhm: ndarray)[source]

Bases: object

Extracted Line Information DataClass

spec_1d

Extracted 1D spectrum along the trace

Type:

ndarray

trace

Pixel locations of the extracted spec_1d

Type:

ndarray

centers

Centroid location (along the trace) of each identified line

Type:

ndarray

fwhm

FWHM (in pixles) of each identified line

Type:

ndarray

centers: ndarray = <dataclasses._MISSING_TYPE object>
fwhm: ndarray = <dataclasses._MISSING_TYPE object>
spec_1d: ndarray = <dataclasses._MISSING_TYPE object>
trace: ndarray = <dataclasses._MISSING_TYPE object>
class obstools.dfocus.PlotParams(pdf: PdfPages, path: Path, docfig: bool)[source]

Bases: object

Plotting Parameters DataClass

pdf

The PDF object into which to place plots

Type:

PdfPages

path

The path in which to find the deveny_focus.* files

Type:

Path

docfig

Make example figures for online documentation?

Type:

bool

docfig: bool = <dataclasses._MISSING_TYPE object>
path: Path = <dataclasses._MISSING_TYPE object>
pdf: PdfPages = <dataclasses._MISSING_TYPE object>
obstools.dfocus.centered_trace(spec2d: ndarray) ndarray[source]

Construct a simple trace down the middle of the image

_extended_summary_

Parameters:

spec2d (ndarray) – The 2D image for which to create the trace

Returns:

ndarray – The desired trace

obstools.dfocus.dfocus(path: Path, flog: str = 'last', thresh: float = 100.0, 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 must be of form: deveny_focus.YYYYMMDD.HHMMSS

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

  • 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 image

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

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

  • thresh (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:
  • image (ndarray) – Extracted 1D 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]

Returns:

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

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

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.

Parameters:
  • filename (str or Path) – 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(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 COLLFOC

  • focus_pars (FocusParams) – Focus parameters DataClass from parse_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:
  • ccd (CCDData) – The CCD object returned from ccds()

  • thresh (float, optional) – Threshold above which to identify lines (Default: 20 DN above bkgd)

  • window (int, optional) – Window over which to average the spectrum (Default: 11 pixels)

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 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:

  • ImageFileCollection – The Image File Collection containing the information about focus images requested

  • str – 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 line

  • focus_curves (FocusCurves) – The set of outputs from the focus curve fitting

  • focus_pars (FocusParams, optional) – DataClass containing needed variables for plot

  • plot_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 spectrum

  • centers (ndarray) – The line centers, as reported by find_lines()

  • focus_pars (FocusParams, optional) – DataClass containing needed variables for plot

  • plot_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 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)

  • plot_pars (PlotParams) – DataClass containing needed parameters for plotting