Hamfoc User's Guide

Hamfoc: The Hamilton Spectrograph Focusing Utility

The principle of focusing the Hamilton is simple. The spectrum of an emission line source is recorded at different focus positions using a narrow slit. Best focus is found where the average line width is at its minimum. In practice, it's somewhat more complicated, but the Hamilton-specific focusing program called "hamfoc" largely automates the process.

Hamfoc operates on Thorium-Argon images, measuring selected lines to determine their full-widths at half-maximum. The program also provides a facility for interactively selecting the lines to be measured on the basis of their strength and symmetry. Hamfoc is easy to use and fast. Its speed permits a large number of lines to be measured, resulting in extremely accurate focusing.

Hamfoc is an IDL program and must be run from within IDL. As of 12/03 it must be run from the IDL installation on catpc.ucolick.org, irrespective of the telescope in use (3-m users host the IDL session from catpc by ssh'ing to that machine).


Starting Hamfoc

If you're operating from the catpc console, simply type "idl" (catpc has two monitors; use the one on the right). If operating from another machine, ssh to catpc's user account and type "idl".

Once in IDL simply type

hamfoc,/[keywords]

Hamfoc will prompt you at each step. When finished, end the IDL session by typing

exit

(N.B. IDL hogs the color map. Vista is less greedy. Consequently, if IDL is run first on a given terminal, Vista or dtake will not have enough colors. On the other hand, starting Vista or dtake first leaves IDL with enough colors to run hamfoc, though it may be somewhat color-starved.)


Hamfoc Modes

Hamfoc has a choice of three operating modes. All use a series of Th-Ar images taken at different focus positions, measure the fwhm's of a preselected group of lines, and return the average fwhm for each image. Best focus is found at the minimum of a parabolic fit to the points. The three modes are automatic, interactive, and batch. They are described below.

In all cases, a list containing coordinates of the Th-Ar lines to be measured must either exist on disk or be interactively created by the user. Hamfoc includes a utility for interactively creating a line list.

The time required to focus the spectrograph will depend largely on the readout time of the images which, in turn, depends on their size. A reasonable initial guess at best focus will speed the process, particularly in automatic mode. See hints for help with selecting image size and starting focus position.

1) Automatic mode operates without intervention by the user (though like other modes, it requires either an existing linelist or that one be interactively created). Automatic mode operates on 'scratch' (i.e., "unrecorded") images, so recording must be turned off in the data-taking program.

Automatic mode turns on the Thorium-Argon lamp, takes an image, measures it, and moves the spectrograph focus, based on the preceding images. The process is automatically repeated until enough points have been found on either side of best focus to produce a good fit.

The program makes two focus passes. The first, or 'coarse' pass moves the spectrograph five focus units between adjacent points. The second, or 'fine' pass takes three points, two units apart, on either side of the minimum found in the coarse pass.

Results are displayed, as they are found, in both graphic and tabular forms. When both coarse and fine passes have been completed, fitted focus plots are displayed. These may be had in hardcopy. Finally, the Th-Ar lamp is automatically turned off and the spectrograph set to the focus position determined from the minimum of a fit to the fine pass.

2) Interactive mode takes and measures Th-Ar images one at at time, at focus positions you choose as you go, building up a focus solution (again, a line list must exist or be interactively created). Interactive mode operates on 'scratch' (i.e., "unrecorded") images, so recording must be turned off in the data-taking program. created).

Like automatic mode, interactive mode automatically moves the spectrograph, takes the images, measures the lines, and provides a running plot of the results, but instead of operating completely autonomously, the user is prompted for input between images.

Unlike automatic mode, interactive mode does not use logic to determine the next focus move. The size and direction of each move is interactively determined by the user. The program will take and measure as many or as few images as the user wishes. The focus moves need be neither monotonic nor evenly spaced, but at least three images must be measured to produce a fit. For accurate results, the points must pass through a minimum.

The results are plotted, cummulatively, as they are found. The user chooses to stop the process when satisfied that enough points have been measured on either side of best focus to produce a good fit. A final plot and fit are displayed and can be had in hardcopy. The Th-Ar lamp is automatically turned off and the spectrograph set to the focus position determined by the minimum of a parabolic fit to the data.

3) Batch mode operates on a series of prerecorded images at different focus settings which have been saved to disk prior to running hamfoc. The images must be in the /data directory, sequentially numbered, and of the form "d#.ccd."

The user is prompted for the total number of images to be measured, and for the number of the first image. Thereafter, the program operates without user intervention. Again, the focus increments needn't be evenly spaced or monotonic, but should be at least three in number and should pass through a minimum. On completion, the results are plotted and the spectrograph set to the best focus.


Creating a Line List

To measure the Th-Ar lines in an image, hamfoc must know their positions. These are read from a user-created list. The list can be interactively generated with hamfoc using a Th-Ar image taken at the same grating and height positions, and with the same CCD window, as the images to be subsequently measured. (If using batch mode, one of the stored Th-Ar images may be used to create the line list.)

Alternatively, an existing line list may be used, in which case the spectrograph must be set so that the Th-Ar lines match the positions in the existing list to within a few pixels. This is convenient for those users who routinely set the spectrograph to exactly the same postition from one run to the next.

Hamfoc assumes, unless otherwise instructed by the inclusion of the "linelist" keyword on the command line, that the user does not have an existing list of Th-Ar line positions, and wishes to make one. The user is prompted for the name of the file containing the image from which the list will be made (the default is the scratch file), and for the name of an output file to which the list will be written (the default name is linelist.ham). The output file may be given any name but will be written to the directory /u/user/hamilton/focus on catpc. (All line lists, irrespective of their names, must be in this directory.)

Hamfoc automatically searches the image for Th-Ar lines. However, it is likely to also find cosmic ray hits and CCD defects, as well as blended lines not suitable for focusing. This is where the interactive part of the list-making process comes in.

When hamfoc has finished its search, the user is prompted for upper and lower limits of line peak intensities; only lines falling between these limits will will be considered. This eliminates very weak lines, saturated lines, and limits the total number of lines. A list of the potential lines found within the range scrolls by and a plot appears showing their positions on the chip. The user can then opt for more or fewer lines by selecting a new range, or accept the current range.

Once the range is established and the potential lines found, two new plots appear. The upper one shows a contour plot of a single line, while the lower shows the positions of all selected lines on the detector, with the currently displayed line highlighted in red. The user is asked whether to include the line in the final list, or to reject it (see hints for help with choosing lines).

As the contour plot of each line is drawn, and as each is accepted or rejected, those selected for inclusion in the final list change to blue in the lower plot, while rejected lines disappear. When the selection process is finished, the linelist is written to disk, the positions of the selected lines are shown in yet another plot, and the program moves on to the actual focusing portion. Note that at least six lines must be selected.


Keywords

IDL keywords are preceded by a "/" and separated by commas. For example, to choose automatic mode, and to specify that the images to be measured will found on the disk of the computer catpc, the user would type:

hamfoc,/auto,/catpc
(Note that in this example, becuase the keyword "linelist" does not appear, hamfoc assumes that a line list is to be created.)

The complete keyword selection is as follows:

hamfoc,[/auto,/inter,/batch],[/shanepc,/shane,/catpc],/linelist,/hdcpy,/silent,/hiz
One, but only one, of the keywords in each of the square brackets must be included. The reaminder are optional. All are described below.

/auto
Specifies automatic mode. If "auto" is set, the keywords
"inter" or "batch" cannot be used.
/inter
Specifies automatic mode. If "inter" is set, the keywords
"auto" or "batch" cannot be used.
/batch
Specifies automatic mode. If "batch" is set, the keywords
"auto" or "inter" cannot be used.
/shane
Specifies that the images to be measured are on the disk
of the host "shane" (in 3-meter readout room).
This will always be the case when the data-taking program
is running on shane. Only one host keyword may be set.
/shanepc
Specifies that the images to be measured are on the disk
of the host "shanepc" (in 3-meter readout room).
This will always be the case when the data-taking program
is running on shanepc. Only one host keyword may be set.
/catpc
Specifies that the images to be measured are on the disk
of the host "catpc" (in CAT control room).
This will always be the case when the data-taking program
is running on catpc. Only one host keyword may be set.
/linelist
Specifies that an exisiting linelist will be used. The user
will be prompted for its name, but it must reside on catpc
in /u/user/hamilton/focus. If this keyword is used, the portion of
hamfoc used to create a linelist is skipped. In the absence
of this keyword, the program's linelist creation routine is
automatically invoked.
/hdcpy
Produces a hardcopy of the final focus plot of average
FWHM vs. focus position. The plot will be directed to
the printer in the readout room if using shanepc, or to the
CAT control room if using catpc.
/silent
Supresses the display of the FWHM of each line as it is
measured, displaying only the average FWHM for each
image. In the absence of this keyword, the row, column,
peak counts, FWHM, FW@10%, and asymetry of each
line is displayed for each image. "Silent" only supresses
alpha-numeric display; plots are unaffected
/hiz
Used when LBL high-resistivity CCD (dewar 8) is being used.
This keyword causes the overscan region to be
ignored when the image is read into hamfoc (note that normally
dewar 6 already has its overscan region removed).


Hints

Windowing: The Hamilton detectors are quite flat and have been carefully adjusted so as to be coplanar with the spectrograph's focal surface, Line profiles are consistent over the whole spectral format. Therefore, a relatively small portion of the chip provides a representative sample of lines for focusing. Considerable time can be saved by limiting the region of the chip used for focusing. By windowing the CCD, readout time is saved when making the images, and "read-in" time is saved when measuring them. For most purposes, a 500 x 500 pixel window is more than adequate.

Choosing lines: Be conservative when choosing lines to include in the linelist. Very weak lines, obvious blends, and lines which appear strongly asymetric in the contour plot should be avoided. As a rule of thumb, also reject any contour plot in which more than one line appears. However, don't be afraid to choose lots of lines. Hamfoc is very fast and the more lines measured the better the focus statistics.

Starting position: Focusing is easier and takes less time if the spectrograph is first set to a focus position not too far from best focus. Taking a test image will quickly reveal if the spectrograph is far out of focus. A few moves and 'eyeball' evaluations of the images to get reasonably close will save time later. Focus is fairly consistent from run to run, but is quite different for different dewars.

Focus resolution: Focus increments of 5 units will give a focus adequate to most purposes; 3-4 units is better. Where very precise focus is a requirement, a carefully selected linelist can reveal changes in focus at the 1-2 unit level. The automatic mode uses 2-unit increments for its final pass.


Acknowledgements
Code for the actual measurement of FWHMs is borrowed from the original foc.pro, written with Geoff Marcy and Paul Butler. The line finding routines are a modified form of "find.pro," an IDL routine adapted from DAOPHOT. Jeff Valenti's rdfits.pro is used for reading FITS files. Chris McCarthy provided helpful input.