mergespec

sofia_redux.spectroscopy.mergespec.mergespec(spec1, spec2, info=None, sum_flux=False, s2n_threshold=None, s2n_statistic='median', noise_test=False, local_noise=False, local_radius=3)[source]

Combine two spectra into a single spectrum

The two arrays are combined along the independent (x) values (row 0 of both arrays). If the x-range of spec2 overlaps with that of spec1, then the dependent (row 1), error (row 2), and bitmask (row 3) of spec2 is interpolated onto spec1 and combined appropriately:

|------------| array 1
        |--------------| array 2
|-------+++++----------| array 2 merged with array 1

In the combined example above, + indicates a combined point and - indicates a original point from array 1 or 2.

If the x-ranges of spec1 and spec2 do not overlap, then arrays will simply be joined together. Note that the final output array is sorted according to x (lowest -> highest). If the arrays do not overlap then the separation between the arrays are marked by two NaNs in all rows > 0: one at the last element of the lowest x-ranged array and one as the first element of the highest x-ranged array:

|----------o-| array 1
               |-o----------| array 2
|----------oxxo----------| array 2 merged with array 1

In the separated example above, x indicates a NaN and - indicates an original point from array 1 or 2, and ‘o’ marks the penultimate or second element.

Note that all NaNs will be trimmed from the beginning and end of the input arrays

Parameters:
spec1array_like of float
(2-4, N) array matching the shape of spec2 where:

spec1[0] = independent variable spec1[1] = dependent variable spec1[2] = error in dependent variable, optional spec1[3] = bitmask

spec2array_like of float
(2-4, N) array matching the shape of spec1 where:

spec2[0] = independent variable spec2[1] = dependent variable spec2[2] = error in dependent variable, optional spec2[3] = bitmask

infodict, optional
If supplied will be updated with:
overlap_range -> numpy.ndarray (2,)

The (min, max) wavelength range over which arrays overlap.

sum_fluxbool, optional

If True, sum the flux instead of averaging.

s2n_thresholdfloat, optional

If set and the value is greater than 0, and errors are provided, data below this value times the reference signal-to-noise (S/N) value in the spectrum will be clipped before combination.

s2n_statistic{‘median’, ‘mean’, ‘max’}, optional

Statistic to use for computing the reference S/N value. Default is median.

noise_testbool, optional

If set, only the noise is considered for thresholding spectra. The s2n_threshold is interpreted as a fraction of 1/noise.

local_noisebool, optional

If set, noise for the spectrum is computed from the standard deviation in a sliding window with radius local_radius.

local_radiusint, optional

Sets the local window in pixels for computing noise if local_noise is set.

Returns:
numpy.ndarray of numpy.float64
(2-4, M) array where row index gives the following values:

0: combined independent variable 1: combined dependent variable 2: combined error 3: combined bit-mask