SPECTROID: Map the Location of a Spectrum on an Image

   
Form:SPECTROID dest source [SP=s1,s2] [BK=b1,b2] [SPW=ds]
[BKW=db] [MODEL=m] [DLOC=d] [LOC=r] [NOSHIFT] [FIT=p1,p2]
[TRACE] [SELF] [LOAD] [NOMASH] [TAGALONG] [TAG] [MOMENTS]
dest
is the buffer which will hold the map (which is a spectrum)
source
is the image from which the map is being made,
SP=
delimits the rows in the image 'source' which are used to make the spectrum,
SPW=
alternatively, specifies the width of a symmetric spectrum window centered on the centroid,
BK=
delimits rows (or columns) used to determine the background,
BKW=
alternatively, specifies the width of the symmetric background window,
LOC=
specifies the starting row (or column) for calculating the centroid
DLOC=
alternatively, specifies a relative shift in rows (or columns) from the centroid model (see MODEL=),
MODEL=
specifies a buffer containing a model to use as an approximation to the location of the spectrum.
NOMASH
inhibits the mashing feature - the destination buffer will then contain the centroids themselves.
NOSHIFT
specifies that no shift from the model will be calculated,
FIT=
specifies the range in pixels over which a median shift between the model and the calculated centroid will be determined.
TRACE
allows the tracing of the centroiding procedure for debugging purposes.
SELF
tells SPECTROID to do the mashing without a model.
LOAD
loads the VISTA variable SHIFT with the calculated value.
TAGALONG or TAG
implements the "following" algorithm in which a filtered mean of the last 15 centroids is used as the starting guess for the next centroid. (A centroid is rejected from the mean if it differs by more than 0.5 pixels from the previous mean.)
MOMENTS
calculate the first five moments of the spectrum, including both the area and the centroid.
SPECTROID produces a map of the location of a spectrum on an image. This map is stored as a table of row (or column) numbers in a 1-dimensional image (like a spectrum) in one of the image buffers.

In the following description it is assumed that the length of the slit lies along a row (i.e., dispersion runs horizontally across the detector as viewed in the TV display).

SPECTROID calculates the centroid of the spectrum perpendicular to the direction of dispersion, with optional background subtraction. Normally the centroid as a function of column number is then used as the center of a spectrum window and the spectrum is created by summing over the relevant pixels. (Note that unlike in MASH, Lagrangian interpolation is used to account for fractional pixels in SPECTROID.). Look at command FINDPEAK for an alternative way to locate the position of an object along the dispersion.

With the NOMASH keyword the mashing feature is skipped, and the centroid as a function of column number will then be loaded into the destination buffer. This centroid may be smoothed, filtered, fitted, or manipulated in any other manner to produce a MODEL to be used in reducing other spectra. It may also find uses for calibrating telescope flexure, checking grism alignment, etc. Having found the centroid, SPECTROID can then do a 'MASH' using the computed centroids to choose which pixels are summed to form the extracted spectrum.

The centroiding procedure must be given a reasonable starting estimate for the centroid. This is done via the LOC= keyword, or if a model is supplied the value of the first pixel in the model spectrum will be used. (If both a model and the LOC= keyword are specified the latter will be used.) Another option if a model is used is the DLOC= keyword, which will specify a relative row offset from the starting value of the model.

With the TAGALONG (or simply 'TAG') keyword the command will use a "following" algorithm in which a filtered mean of the last 15 centroids is used to guess the next centroid. This allows the routine to follow almost any shape of spectrum with minimal information (just the beginning row). However, if there are regions in which the spectrum disappears the routine may get lost.

Another necessary piece of information is the window over which the centroid will be calculated. This is given via the SP= or the SPW= keywords. The SPW= keyword specifies a window width which will be symmetrically placed around the centroid. Asymmetric windows may be specified via the SP=s1,s2 keyword. In this case the two values must be specified relative to the centroid. Hence SP=-3,5 will specify a window extending three rows above and five rows below the centroid. Note that since the centroid will not in general be an integer the spectrum rows may be floating-point numbers as well. Hence SP=-3.4,4.166158 or SPW=2.3 are legal formats.

If you want to specify a background to be subtracted (which will presumably be the usual procedure) you can use the BKW= and BK= keywords in the same fashion as the SPW= and SP= keywords. Rows common to both spectrum and background will be taken as spectrum as in MASH.

The MODEL= keyword may be used to specify a curvature model for the spectrum. The value specified for this keyword is the buffer in which the model resides. The model may be a smoothed version of a previously determined centroid, for example. If a model is specified and the NOSHIFT keyword is NOT, the command will find the centroid at each column of the spectrum using the specified spectrum and background regions. The median shift between newly computed centroids and the model is found and this shift is added into the original model. This revised model is then used to do the 'MASH' operation.

The NOSHIFT keyword will skip the original centroiding procedure and use the model as it is for the intensity extraction. Note that if the NOSHIFT keyword is specified then the MODEL= keyword must be used as well.

The FIT= keyword limits the region over which the median shift between model and calculated centroid is computed. The two parameters passed via this keyword are the start- and end-column numbers over which the fit is done.

The MOMENTS keyword will load a 5 row image with the first five moments of the light distribution with respect to the model. The area (total counts) will be in row 0, the centroid in row 1, the variance, skewness, and kurtosis in rows 2, 3, and 4 respectively. This keyword proves useful for mapping focus changes along a spectrum, etc.

The TRACE keyword will provide some feedback on the centroiding process, via strategically placed TYPE statements in the subroutine. The output from this takes a while to print out, so use it with restraint.

Examples:

SPECTROID 1 2 SPW=10 BKW=20 LOC=250 NOMASH
SPECTROID in its simplest form, which loads the centroid as a function of column number into buffer 1. The spectrum window is ten pixels wide, and the background window twenty. Row 250 was specified as an estimate of the centroid.

SPECTROID 1 2 SPW=9.4 BK=-6,9 MODEL=5 TRACE
Since the NOMASH keyword was not specified the result of this command will be the production of a total intensity spectrum. Note that the spectrum window is not an integral number of pixels wide, and the BK= background has been used to specify an asymmetric (with respect to the centroid) background window. Also note that the BK= keyword uses relative row numbers, not absolute. Spectrum buffer 5 will be used as a model for the curvature of the spectrum, and a shift between this model and the calculated centroid will be determined and used. The TRACE keyword will cause a (possibly lengthy) tracing of the centroiding process to be printed out.

SPECTROID 6 2 MODEL=5 SPW=3 BK=-25,-20 BK=20,25 NOMASH
This command uses model 5 as the starting estimate for the centroid, but recalculates the centroid using the new spectrum and background window specifications. Again, the NOMASH keyword inhibits the mashing feature.