Rebin to Reference Scale :
This routine is similar to REBIN
AND DEFINE SCALE except that the x-values of the
reference AAR (see MAKE
REFERENCE) is used instead of the user defined x-scale.
Here we explain the various options and then give a detailed description
of the algorithm. We will refer to (wavelength, flux) and (x, y)
If there are any masked data, they will be ignored during the rebinning
but retained in the output AAR. If the user wishes, these can be
unmasked or deleted afterwards from the main GUI window.
Rebinning data separately or together:
Scan, detector, line, and scan-direction buttons will appear under
the label "Rebin Separately to Reference These Parts of Prime AAR..." in
the top left corner of the gui window. Buttons will appear for only
those tags found in the prime AAR which have two or more values.
Thus, no buttons will appear for some AARs. Again, the tags used to build
the buttons on the gui are only from the prime AAR and not from the reference
Depending on the AOT type, some of the scan, detector, line, and scan-direction
buttons will be preselected for the user's convenience. The user
may override these selections.
The feeder will first take unique portions of the prime AAR according
to what buttons have been pushed. It will then make a decision about
which part of the reference scale to feed the routine. If the reference
has a tag present like the one that is selected for the prime data, then
the reference data with those matching the prime tag values are feed.
However, if the reference does not have that tag present, then that tag
is not used as a criteria for rejecting reference data. That is,
no match is required in this case, and any reference data can be feed.
An Example: Suppose the prime AAR has one scan for each
of the 10 detector ranges and has one value for each of the line and scan-direction
tags. First, only the detector button will appear on the gui window.
Now, if the reference AAR also has 10 different detector values as well,
and the detector button is pushed down, then the prime AAR's individual
detector scans will be rebinned using the corresponding reference detector's
x-values. Hence, there will be ten spectra - one for each detector.
On the other hand, if the detector button is not selected, then only one
spectrum results because no consideration is given to the detector tag
values. In another case, if the reference AAR has no tags, then there
are two possibilities again, assuming that both prime and reference spectra
cover a similar wavelength range. One, if the detector button is
selected, then the individual detector arrays of the prime AAR will be
rebinned using the corresponding wavelength ranges from the reference AAR.
If the detector button is not selected, then there will be only one spectrum
because the whole prime AAR data will be rebinned using the corresponding
reference AAR's wavelength range.
Defining the x-scale:
The reference AAR provides the x scale for the output and the routine.
When possible, the rebinned result should have y-values at each of the
reference wavelengths, but not all of these reference wavelengths are necessarily
used. The following check is applied in the beginning to limit the
reference x-scale if it covers wider wavelength range than the prime array
selected to be rebinned. Suppose xarr is the array of prime AAR wavelength
values, and refarr is the array of reference AAR wavelength values.
Then, the x-values used in rebinning include only those reference wavelengths
that lies between the first xarr - delta and the last xarr + delta, where
delta is defined as the difference between the first and the second xarr
epsilon is used to eliminate multiple x-values as discussed
Finally, on the gui_rebin, a user has the advantage of viewing the
data before and after rebin. These two displays also come with all
the flexibilities such as Set Plotstyle, Replot, Unzoom, Hard Copy, Freeze
Ranges and etc. In the end, the user has the choice to quit without
saving rebin or to exit which delivers the result to the main gui.
First, the reference x-array is obtained as described above.
Next, the "chk_multix"
routine is performed. This checks if any array of x values from the
prime AAR contains multiple points at the same wavelength value from the
reference AAR. Here, the "same" value means value +- epsilon.
If so, this routine computes the mean of the corresponding y values and
stdev values at the mean of the duplicated points in the x-array and modifies
the x-array, y-array, and stdev-array accordingly. In addition, this
routine remembers the number of multiple points used for each of the modified
y-array elements. This information will be used later, when rebinning
the data, as the weight of each flux value. This is intended as a
pre-binning operation to simplify interpolation and rebinning of a spectrum.
Finally, the rebin is performed conserving flux via approximate trapezoidal
integration method. This is outlined as follows.
Let xarr and yarr be the wavelength and flux array of the prime AAR,
and refarr the wavelength array of the reference AAR.
Please refer to sap_rebin
for more details.
1. The middle point array is generated from the user-defined
wavelength scale according to
xmid(i) = (refarr(i+1) + refarr(i)) / 2.
2. Using all the xarr values ranging from the xmid(i-1) to
xmid(i) and the corresponding yarr values, this routine computes the new
flux at refarr(i) as the total integral via the simple trapezoidal rule.
Sum of ( (yarr(k) + yarr(k-1)) * (xarr(k) - xarr(k-1)) * w_av(k)
/ 2 )
Sum of ( w_av(k) * (xarr(k) - xarr(k-1)) )
where w_av is (weight(k-1) + weight(k)) / 2
for all k such that xmid(i-1) <= xarr(k) <= xmid(i).
Because of the boundary, the first k in this range will not be applied
to this formula. The weight(k) is the product of the
routine explained above; it is a number equal to or greater than one, and
it shows how many data points were used in calculating this modified yarr(k).
3. For the edges at the xmid(i-1) and xmid(i), there are
two cases. First, if a data point coincidentally exists at either
of these points, then its corresponding flux is used to compute the integration.
If not (which is the usual case), then the fluxes at these points are linearly
interpolated from the two nearest points to each side of them.
4. For the first element, refarr(0), all the points of
xarr within the range, refarr(0) to xmid(0) are used if there are no xarr
points to the left of the refarr(0). Note that "(0)" designates the
first element in the array.
5. If there are no points inside a bin, the value for that
bin is found by linearly interpolating between the nearest two data point
on either side of the bin: call these: (x_lo, y_lo), (x_hi, y_hi):
xarr(i) - x_lo
yarr(i) = y_lo + (y_hi - y_lo) --------------
x_hi - x_lo
6. New "STDEV" values are computed as the errors in
the mean. Specifically:
sum ( (yarr(k) - yc)^2 )
STDEV= SQRT ( ------------------------ )
n * (n-1)
where yc = computed flux for the bin
and n = number of data points found in the bin + 2 (for bin