merge_ucles csj 08 Oct 2003 AAT/UCLES echelle data has been reduced by VMW using IRAF. Results are stored in IRAF FITS files as a (2048 x 39 x 4) matrix. These correspond to ( dispersion x order x array ) where "array" is one of 0: object: flat-fielded, sky-subtracted, wavelength calibrated, cr cleaned 1: object: flat-fielded, sky-subtracted, wavelength calibrated 2: sky: flat-fielded, wavelength calibrated 3: unknown The individual orders have been linearised, but the wavelength coefficients are stored in an internal IRAF format and not as itmes in the FITS header -- this makes it a b****r to read in to other applications. Note also that the linearisation uses a different dispersion (delta-lambda) for each order. 0) The data can be writen out from IRAF as an ASCII file in the format wavelength order_id array_id data eg 5104.1870840393 1. 1. 0.01529857 5104.24513781677 1. 1. 0.01189976 5104.30319159423 1. 1. 0.002035742 5104.3612453717 1. 1. 8.633400E-4 1) This may be read into IDL using the procedure > ucles_read, file, w, f file: string : : in : name of file containing data w : array : (2048, nord) : out : wavelengths for each order f : array : (2048, nord, narr) : out : fluxes in each array 2) The next step is to remove the gross continuum shape using the procedure > ucles_norm, w, f, fn, fs w : array : (2048, nord) : in : wavelengths for each order f : array : (2048, nord, narr) : in : fluxes in each array fs nw x no function used to rectify f fn nw x no = f / fs Our algorithm for this uses an experimental procedure to define the continuum for each order automatically. It is best for high S/N data with few lines! Experimentation with WDW and the thresholds given below may improve the performance for specific cases. i) Remove any remaining CR spikes which stand more than 2* the local data and replace them by the lcoal mean. Uses a 3A Gausian filter. ii) Identify strong lines and bad orders by passing a 2d Gaussian filter (sigma = 2A x 4 orders ) through the data and cutting out values less than 97% of the smooothed data. Replace it with a local mean. iii) Now smooth this data in the dispersion direction with (sig=3A). Then smooth in the order direction with (sig= 2 orders). This passes order shape from one order to the next. iv) Normalise each order using the above continuum. Store the continuum. 3) Define a standard wavelength grid for the entire spectrum. I use the dispersion of the longest wavelength order, and accept some undersampling of the short wavelength orders. This is not generally a problem for the objects we are studying. I resample each order onto this standard wavelength grid, as well as the continuum. > ucles_resample, w,fn,fs, wb,wi ; Input ; w nw x no wavelengths ; fn nw x no normalized fluxes ; fs nw x no rectification function ; Output ; wb nw x no wavelengths remapped to constant dx ; wi no vector containing number of wavelengths in each order ; fn nw x no normalized fluxes remapped to wb ; fs nw x no rectification function remapped to wb 4) Construct the merged spectrum, starting from the blue end. In the overlap between the accumulating merged spectrum and the next order, the data are combined as a weighted average, using the local value of the continuum in each order as weights. A cosine-sqaured weighting wedge is also applied in the overlap interval to ensure a smooth transition. > ucles_merge, wb,wi, fn,fs, wm,fm ; Input ; wb nw x no wavelengths ; wi no number of valid wavelengths in ech order ; fs nw x no resampled rectification function ; fn nw x no resampled normalized spectrum ; Output ; wm merged wavelength grid ; fm merged fluxes 5) It is a good idea to check the resulting spectrum very carefully. Were the parameters for continuum definition suitable. Has the continuum removed the wings of strong lines, or failed to follow sharp bends in the blaze function. These cannot be rectified later. > window,1 > FOR i = 3800,5100,2 DO plot,wm,fm,xrange=[i*1.,i*1.+100.],xstyle=1,yrange=[0,1.2] ;; creates a movie of the merged spectrum, running from one end through to the other. > ucles_exam,w,f,wm,fm,wb,fs,xr,sc ;; shows the merged spectrum, the individual orders, and the continuum used to rectify and merge each order. 6) Save the output in a format suitable to read with SFIT2. sp2wr, 'file', wm, fm, 'header' file : string : : in : filename wm : array : (nw) : in : wavelengths for merged spectrum fm : array : (nw) : in : fluxes for merged spectrum header : string : : in : string continaing line of header In the future, we propose to extend SFIT2 ability to deal with metadata and more complex file structures. At the very least we would like to be able to preserve dta from the original FITS header alongssde the reduced data. Whether this means we will use FITS or an XML or VOTable format remains to be seen. In any case, we will provide new or use an exisiting IDL procedure to give the required data format.