+ Identifier sap_rebin Purpose Perform resampling (=rebinning =interpolation) of an AAR Synopsis struc_out=sap_rebin(struc_in , err_stat,[,ref=ref] [,xstart=xstart][,xend=xend] [,stepwidth=stepwidth][,nstep=nstep] [,resol=resol][,/log][,algo=algo] [,/flxcons] [,band=band][,scnt = scnt] [,sdir = sdir][,det=det][,/mean] [,epsilon=epsilon]) Arguments Name I/O Type Description ----------------------------------------------------- struc_in I AAR input structure (spectrum) containing the x-scale (wavelength) and the y-scale (flux) that are to be rebinned err_stat I int Error status : 1 for fatal, 0 otherwise ref I Fltarr reference scale (wavelength) array to which x-scale is to be resampled xstart I Float start x value (start wavelength) of new x-scale xend I Float end x value (end wavelength) of new x-scale stepwidth I Float distance between two points in new x-scale (in case of equidistant rebinning) nstep I Long number of steps in the new x-scale resol I Float resolution for the new x-scale log I Integer keyword for logarithmic equidistant scale flxcons I Integer keyword for flux conserving linear interpolation algo I string indicate interpolation algorithm default = 'spline' (for cubic spline) band I intarr band #(s) whose detectors will be rebinned. band = 'none' means option is not set scnt I intarr scan #(s) whose detectors will be rebinned. scnt ='none' means option is not set sdir I intarr scan direction(s) whose detectors will be rebinned. sdir = 'none' means option is not set det I intarr individual output for each detector in this list. det = 'all' means all detectors individually rebinned. det = 'none' means option is not set (all detctors) mean I Integer keyword for computing arithmatic mean values instead of weighted mean in CHK_MULTIX epsilon I Float minimum seperation between wavelength points for multiple point processing in CHK_MULTIX struc_out O struct the rebinned structure (spectrum) Returns The rebinned AAR structure Description - This routine takes automatically Wavelength and Flux as x-scale and y-scale and the uncertainties of fluxes (stdev> for error propagation. The error for each interpolated data point (flux) is computed as follows. weighted mean of the standard deviations of the points used in interpolation (For cubic spline, 5 points are used, the closest point, and 2 additional points on each side). Weights are computed as the seperations between the reference point and the points in input xarr array. The user can specify two catagories: the character of the new x-scale (-> scale_define) and the method of interpolation (-> inter_pol). - First Call SCALE_DEFINE: The new x-scale is either 1) identical to a reference scale (i.e. the wavelength scale of another spectrum or any arbitrary scale) or 2) equidistant with - a given start and end wavelength and a given number of steps or with - a given start wavelength, a stepwidth and a number of steps or 3) consistent with a given resolution and a start wavelength and number of steps. This is equivalent to a logarithmic equidistant scale, which can have two advantages: doppler shifts are now given by addition: L = L0*(1+v/c) transforms into log(L) = log(L0) + log(1+v/c) and lineprofiles keep constant when they are shifted on logarithmic equidistant scales. - Then call CHK_MULTIX: check if xscale contains multiple points at the same value. If so, compute weighted mean of yarr and sarr at the mean xarr-points and modify xarr, yarr and sarr accordingly.(For definition of xarr, yarr and sarr see CHK_MULTIX). - Call INTER_POL: Perform the interpolation. The supported methods of interpolation are: 1) cubic spline interpolation Value of algo: 'spline' 2) polynomial interpolation Value of algo: 'polyx' where x stands for the grade of the polynomial. Example: poly3 for third order polynomial. Default value of algo used = 'poly1' (No flux conserving) - Call BIN_STRUCT: Create the output structure with meaningful tags in the data. Comment The Widget User Interface has to provide this subroutine with the necessary parameters and to make plots of the original spectrum and the result possible. It should also ask the user whether (s)he accepts the result or wants to try another interpolation. If the reference array contains multiple points at the 'same' value, the interpolation has to provide each of these points with the same value. This means that the reference array has to be monotonically but need not to be strictly monotonically increasing (or decreasing). "same value" means value1 - value2 < epsilon with epsilon = 1.E-5 as default Rebinning of SPDs is currently not included because of the complex behaviour of the wavelength scale Example 1) struc_out = sap_rebin(aar1, ref=lsanwav2) new grid is given by lsanwav2 (the wavelength scale of a second spectrum). The interpolation is linear (the default). The data tags in output AAR will be WAVE, FLUX, and STDEV. 2) struc_out = sap_rebin(aar1, xstart=3.0, xend=4.0, nstep=100, algo='spline', det='all') new scale is equidistant beginning at 3.0 um ending at at 4.0 um and with a step width of (4.-3.)/100.=0.01 um. The interpolation algorithm is a spline. The output AAR contain individual detector resampled spectrum with data tags WAVE, FLUX, STDEV, DET 3) struc_out = sap_rebin(struc_in, xstart=3.0, resol= 0.0033, nstep=100., scnt=1) new scale contains 101 points and has a constant resolution ( L(i+1) - L(i) ) / L(i) = 0.0033 ) starting at 3.0 um. (As a consequence xend = 4.1706 um). The processing arrays are the input arrays of AAR struc_in subset on scnt = 1 The output AAR contain individual detector resampled spectrum with data tags WAVE, FLUX, STDEV, SCNT 4) struc_out = sap_rebin(struc_in, xstart=3.0, xend=4.0, nstep=100, /log) new scale is logarithmic equidistant, contains 101 wavelenths and reaches from 3.0 um to 4.0 um. (e.g. the second wavelength value is given by L2=10^(log(3.0)+stepwidth) where stepwidth = (log(4.0) - log(3.0)) / 100. ) This is almost equivalent to example 3). Dependencies - CALLS: AVGSIG, BAND_2_DET, BIN_STRUCT, BINSRCH, CHK_MULTIX, FLUX_CONSERV, INTER_POL, KWD_NOTSET, POLYINT, REDO_HDR, SCALE_DEFINE, SAP_ERROR, SHRINK_ARRAY, UPDATE_HISTORY CALLED FROM: IA, GUI, SYN_PHOT Category ISAP Filename sap_rebin.pro Author Iffat Khan (irk@ipac.caltech.edu) Version 1.1 History 27. 7.95 definition of requirements E. Sturm 8. 8.95 revision of requirements E. Sturm 1. 9.95 revision of requirements J. Mazz 0.1 8. 9.95 Design and Code I.Khan 0.1 20.9.95 modified to truncate ref scale outside the data range I. Khan 0.1 21.9.95 Modifications by Sarah Unger S. Unger (replaced the functions MINMAX and UNIQ by MIN and SHRINK_ARRAY) 0.1 21.9.95 Ignore masked out data before I. Khan rebinning 0.1 27.9.95 modify to input band, scan #, I. Khan and scan direction integer arrays 0.2 29.9.95 default setting of options , I. Khan included ( -1 means option is not used) 0.3 02.10.95 default setting of options , I. Khan modified ("none" means option is not used) 0.4 17.10.95 revised code after specs revision irk Allow steps with xstart, xend; resol with xend, "linear" for algo. removed minor bugs 0.5 02-11-95 Revised parameters --> irk@ipac checking/Error messages Add /flxcons for flux conservation with linear interpolation 0.6 09-11-95 changed keyword name --> irk@ipac for BIN_STRUCT (resd ->resdet) 0.7 10-11-95 Updated "Dependencies" in --> irk@ipac the header 0.8 22-11-95 sort struc_in data over --> irk@ipac wave 0.8 28-11-95 remove a minor bug --> irk@ipac 1.0 30-11-95 version 1.0 --> irk@ipac 1.1 29-02-96 include "line" tag in --> irk@ipac rebinned structure with "scnt" option 1.1 22-04-96 removed a bug which appear --> irk@ipac when "DET" tag is missing in input struc 2.0 26-04-96 add keywords /mean and epsilon -> irk@ipac for multi points processing in CHK_MULTIX. 2.0 30-04-96 comment out sorting on "wave" -> irk@ipac -