FUNCTION unbin_spec, file=file, resp=resp, silent=silent, texp=texp, $ qual=qual, backscal=backscal, w_u=w_u, w_l=w_l ; ---------------------------------------------------------- ;+ ; NAME: ; UNBIN_SPEC ; ; PURPOSE: ; Load and RGS spectrum from a FITS file and 'unbin' ; ; AUTHOR: ; Simon Vaughan (U.Leicester) ; ; CALLING SEQUENCE: ; spec = UNBIN_SPEC(src, resp) ; ; INPUTS: ; file - names of FITS file of spectra (full path) ; resp - name of FITS file of response matrix (full path) ; ; OPTIONAL INPUTS: ; silent - (logical) switch off on-screen output? ; ; OUTPUTS: ; spec - wavelengths of each photon in the spectrum (Angstrom) ; ; OPTIONAL OUTPUTS: ; qual - quality flag (0=good, 1=bad) for each channel ; backscal - BACKSCAL value for each channel from the spectral file ; w_l - wavelength (Angstrom) for lower boundary of each channel ; w_u - wavelength (Angstrom) for upper boundary of each ; channel ; texp - Expsure time of the spectrum ; ; DETAILS: ; Called by RGS_PLOT. ; Performs an 'unbinning' of finely binned spectral data in a ; FITS file ('src') given a response matrix ('resp'). Currently ; the columns of the FITS file that are used are those suitable ; for processing RGS data, but could be adjusted if needed. The ; 'unbinning' works by redistributing each count in the spectrum ; within the wavelength range of the channel it was collected ; in. The redistribution is random and uniform between w[i] and ; w[i]+dw[i] where w[i] and dw[i] are the lower boundary and ; width of the wavelength bin of the ith count in Angstroms. This ; of course assumes the counts are distributed unformly within ; each spectral channel, an assumption that should be true if the ; input data are given with small bin widths. In the case of the ; RGS we recommend using 3400 channels. ; ; Here's exactly what happens: ; - load the data from the FITS file as channel, counts, quality ; - load the corresponding response file FITS ; - use channel-energy table to convert spectral channel to energy ; - convert data wavelength: wavelength, bin width, counts, quality ; - create 'unbinned' spectrum by assigning each count to a ; wavelength uniformly distributed in [w, w+dw] ; - keep track of 'quality' flag ; ; ; EXAMPLE USAGE: ; src = 'spec.FIT' ; resp = 'resp.FIT' ; spec = UNBIN_SPEC(file=src, resp=resp) ; plot, HISTOGRAM(spec, BINSIZE=0.05), PSYM=10 ; ; PROCEDURES CALLED: ; SPEC_READFITS [READFITS, TBGET, SXPAR] ; ; ; HISTORY: ; 26/11/2009 - v1.0 - first working version ; 15/12/2009 - v1.1 - added TEXP output ; ; NOTES: ;- ; ---------------------------------------------------------- ; options for compilation (recommended by RSI) COMPILE_OPT idl2 ; watch out for errors on_error,0 ; ---------------------------------------------------------- ; Check arguments ; check number of spectra to process if (N_ELEMENTS(file) ne 1) then begin print,'** UNBIN_SPEC requies one file for FILE input.' return,0 endif ; check number of response files to process if (N_ELEMENTS(resp) ne 1) then begin print,'** UNBIN_SPEC requies one file for RESP input.' return, 0 endif ; ---------------------------------------------------------- ; Main routine ; load the spectrum from FITS file ; Columns are 1 = channel ; 2 = counts/bin ; 3 = quality (0=good, 1=bad) ; 4 = AREASCAL (0.0 - 1.0) ; 5 = BACKSCAL (arb. units) ; ; In this case we want the counts, quality and BACKSCAL only. data = SPEC_READFITS(file, cols=[2,3,5], texp=texp) ; extract the vectors of counts/bin, quality and BACKSCAL counts = REFORM(data[*,0]) qual = REFORM(data[*,1]) backscal = REFORM(data[*,2]) ; Load the channel-energy table from the response matrix data = SPEC_READFITS(resp, extension=2, cols=[2,3], /DOUBLE) ; lower/upper energies of channel boundaries e_l = REFORM(data[*,0]) e_u = REFORM(data[*,1]) ; convert channel boundary energies to wavelengths (Angstrom) apkev = 12.3984428D w_l = apkev/e_u w_u = apkev/e_l ; channel widths dw = w_u - w_l ; total number of counts and channels in the spectrum n = TOTAL(counts) n_chan = N_ELEMENTS(counts) n_chan2 = N_ELEMENTS(e_l) ; cumulative number of counts in channels > velocity.qdp' ; ---------------------------------------------------------- ; open a file for the output ; ; ---------------------------------------------------------- END