pamela recipe

This document describes a typical reduction sequence in fairly brief form. There are some more hints inside the help on the various commands. Commands written as e.g. icsub are Figaro, Kappa or other non-pamela commands. pamela is separate from these other facilities now but does not attempt to cover such standard actions as subtraction, etc. Figaro, Kappa etc should be used to help out.
  1. Dispersion direction. The pamela routines expect the frames to have the dispersion direction in the Y direction. You should rotate the frames with irot90 if they are not in this orientation.

  2. Bias subtraction. CCDs typically come with an added constant or near constant which has to be removed as the first step in reduction. Note that it is not safe to leave it in to be removed during sky subtraction because the flat fielding and uncertainty estimation will be affected. I normally just subtract a constant determined from unexposed or overscan regions with icsub. You could instead subtract a bias frame, but it had better be the average of many to avoid adding extra noise. A pamela routine called picstat can determine the mean over a series of rectangular regions with sigma clipping.

  3. Flat fielding. The pamela routines require a "balance" frame. This is a frame which when multiplied into the data frames corrects for flat field sensitivity variations. I normally first median together all the suitable flats with medsky . Next I obtain a mean spectrum (over the good region of the frame) with ystract. Then I fit a spline ( splfit ) or polynomial ( polfit ) through this and then divide this through with isydiv. If I don't have a twilight frame then that's it, otherwise I divide out the spatial profile (use extract followed by isxdiv) and multiply in the twilight profile (extract again, this time on the twilight frame, follwoed by isxmul). Finally I invert the result (generate a unit frame and use idiv) and normalise to 1 over the good area of the chip (e.g. with istat and icdiv ), and that is the balance frame. The main decision that has to be made is what scale of features should you fit. You should only fit features that you think may affect only the flat-field and not the data. INowadays I almost always take flat-fields with the same grating setting as the data and so generally almost every feature will appear in the data. I thus typically use polfit with just 2 coefficients (a linear fit).

    When working in the blue, it is not uncommon to get flats that have a very large range in count level because tungsten lamps are so red. In this case it is often best to fit the polynomial to the log of the spectral profile and then anti-log the fit. This gives a fit that is uniform in terms of fractional deviation from the profile rather than one which is an absolute number of counts different. If for example your profile ranged from 5000 to 30000, and you did a normal fit, it might typically deviate by 1000 counts which is OK at 30000 but not at 5000. The log/antilog procedure prevents this.

    Finally if there are obvious bad pixels, columns etc in your data, you should mask these regions now by setting them to the bad pixel value. Any pamela routine requirring a flat should ignore these pixels. Take care though: the operative word here is "should" - I have not checked this option much.

  4. Noise characteristics. A series of flats taken with different exposure levels can be used to obtain the noise characteristics of the chip. You need the RMS readout noise in counts (called READOUT) and the number of electrons (=detected photons)/count (called PHOTON). If you have the right series of files, multiply them by the balance frame and then enter the names of the corrected files into an ASCII file. Then run noise which computes the variance as a function of signal and allows you to fit models to the results. If you don't have the data you will have to take known values. The routines will work if you get these values wrong but then the extraction will not be 'optimal' and the uncertainty estimates will be wrong. In this case you may notice skyfit and extopt producing estimated RMS values during fits that disagree with the actual ones found.

  5. Tracing the spectra. Normally the spectra are fairly straight up and down the detector. If they are not, you should use the routine track to fit the position as a function of Y coordinate. You will need the file produced by track in later routines.

  6. Sky region selection. Select sky and object regions (re-run it separately for each object on the slit) with regpic . This produces an NDF with an array of 1 for each selected sky pixel and 0 for non-sky pixels. You can plot this file if you wish to check the regions that you have selected. It also contains a structure (.more.pamela.regpic) containing the selected object limits. Use hdstrace to look at it in detail.

  7. Fitting the sky. Pamela fits polynomials to estimate the sky under the object. This is carried out with skyfit .

  8. Extraction. For straight spectra with no tracing you then extract using extnor for normal extraction or extopt for optimal extraction. The latter implements Keith Horne's optimal extraction and is descended from his original pamela version.

    For tilted spectra extnor still works but extopt does not. Instead for optimal extraction you first fit the profiles with profit and then extract with optext .

    extopt and profit store files of the fractions of flux in each pixels which can be used to extract arcs at the same position as the object. You should extract arc spectra using a zero frame as the sky. You can also extract a spectrum representing the sky from the fitted sky frame generated by skyfit but you must use a unit frame as the balance frame since the fitted sky accounts for flat field variations. As with extracting arcs you should use a zero frame as the "sky" in this case.

    I would normally try extracting a bright spectrum first as you get a better idea of what order of fit to use. One always wants the lowest order that works of course.

  9. Automation. Once you have done a few by hand, you may want to run something more automatic. In this case I have written a program called skymov to move the sky regions appropriately according to where the object is on the slit. You set this up first by running regpic on some representative frame to set up a sky region file that will be applied albeit shifted, to all the frames. You should be careful if seeing was dramatically variable during the night; look at a few frames through the night to get a feel.

    Note that I have not tried to determine sky regions automatically from scratch. I have tried doing so in the past, and basically I would never trust any automatic sky selection. You have to do some things yourself.

    The skymov method works excellently on a set of spectra of the same object. With a number of different objects, other objects may appear on the slit. If you are ultra-careful you would re-run regpic for each object (and PA of the slit), but there is an option in skymov for kicking out such interloper objects by looking for regions too far above the background level. You should check that it works of you have such data.

  10. Input to molly. What you do from this point is up to you. I use a program called molly following pamela which for convenience expects some header items to be in a standard format. Look at the perl script perl/fixhead.pl for an example.

  11. Possible problems. Normally the rejection methods used by pamela are pretty robust. If possible they work on a "reject the worst pixel and then refit" method which is safer than rejecting all pixels worse than 3 sigma straight off. However I have had to compromise with profit because the fits are relatively slow. This means that really bad cosmic rays can sometimes ruin the fits and the only sign is maybe a rather large number of rejected pixels (if you don't look at the fits). Thus profit has an extra parameter which is huge by default but can be set to some more relevant value. Just take care to alter it for different frame types. Alternatively there are routines to specifically mask pixels in kappa which could be used for really pathological cases.

Tom Marsh, Warwick.