Rebinning functions

qmostetc.rebin.get_borders(bins)

Quick and dirty function to convert bins to borders

In the ETC, we assume that bins are specified by their central value. For flux and transmisson invariant rebinning however we need the borders instead. The borders are now simply assumed to be in the middle of the central bins, which is a good assumption as long as the bin width doesn’t change too much between neighbored bins. The leftmost and rightmost borders are chosen so that the values are really central.

Parameters:
binsnumpy.ndarray

Central bin values

Returns:
numpy.ndarray

Border bin values, with length len(bins)+1

Examples

Get the borders of a small sample array:

>>> import astropy.units as u
>>> bins = np.arange(360., 365., 1.) * u.nm
>>> print(bins)
[360. 361. 362. 363. 364.] nm
>>> print(get_borders(bins))
[359.5 360.5 361.5 362.5 363.5 364.5] nm
qmostetc.rebin.rebin_1d_flux_box(flux, org_bins, new_bins)

Flux-invariant re-binning.

This function takes n flux values and their central bins. It rebins the flux into a sequence of m new flux values, defined by their central bins.

The flux on the part of the bins that are covered by both original and new borders is preserved. If the new borders cover a smaller interval, the uncovered part of the flux will be lost, hence reducing the total flux. Bins in the new borders that are not covered by the original bins are set to 0 flux.

This function should work for both, increasing and decreasing the number or size of bins.

For this function, it is assumed, that the flux within one bin is uniformly distributed over the range of that bin. That means, re- binning to bins of significantly smaller size than in the original sequence will lead to plateaus on the new flux sequence.

Preserved flux means, that if a bin with the borders a and b, a < b has a flux of f, any smaller bin (c, d) within the borders of a and b (a <= c < d <= b) will also the flux that falls into the smaller bin f*(d-c)/(b-a). Also, if the new borders completely cover the old borders, sum(flux) = sum(new_flux), safe for numerical errors.

Parameters:
fluxnumpy.ndarray

Flux values as a 1-dim array with at least two entries.

org_binsnumpy.ndarray

Original bins (central values). The length must be equal to the length of the flux array.

new_binsnumpy.ndarray

New bins (central values). The length must be at least 2.

Returns:
numpy.ndarray

Rebinned flux values. The length is equal to the length of the new_bins parameter.

Examples

Rebin a small sample spectrum:

>>> import astropy.units as u
>>> flux = np.array([1., 5., 1., 1., 1.])
>>> bin0 = np.arange(360., 365., 1.) * u.nm
>>> bin1 = np.arange(360., 365., 2.) * u.nm
>>> print(rebin_1d_flux_box(flux, bin0, bin1))
[3.5 4.  1.5]
qmostetc.rebin.rebin_1d_flux_interp(flux, org_bins, new_bins)

Flux-invariant re-binning with interpolation.

This function takes n flux values and their central bins. It rebins the flux into a sequence of m new flux values, defined by their central bins.

Different from rebin_1d_flux_box, this function assumed, that the flux follows a smooth distribution across the wavelength bins.

Parameters:
fluxnumpy.ndarray

Flux values as a 1-dim array with at least two entries.

org_binsnumpy.ndarray

Original bins (central values). The length must be equal to the length of the flux array.

new_binsnumpy.ndarray

New bins (central values). The length must be at least 2.

Returns:
numpy.ndarray

Rebinned flux values. The length is equal to the length of the new_bins parameter.

Examples

Rebin a small sample spectrum:

>>> import astropy.units as u
>>> flux = np.array([1., 5., 1., 1., 1.])
>>> bin0 = np.arange(360., 365., 1.) * u.nm
>>> bin1 = np.arange(360., 365., 2.) * u.nm
>>> print(rebin_1d_flux_box(flux, bin0, bin1))
[3.5 4.  1.5]
qmostetc.rebin.rebin_1d_trans_box(trans, org_bins, new_bins)

Transmission-invariant re-binning

Parameters:
transnumpy.ndarray

Transmission values as a 1-dim array with at least two entries.

org_binsnumpy.ndarray

Original bins (central values). The length must be equal to the length of the trans array.

new_binsnumpy.ndarray

New bins (central values). The length must be at least 2.

Returns:
numpy.ndarray

Rebinned transmission values. The length is equal to the length of the new_bins parameter.

Examples

Rebin a simple transmission spectrum:

>>> import astropy.units as u
>>> trans = np.array([0.8, 0.1, 0.8, 0.8, 0.8])
>>> bin0 = np.arange(360., 365., 1.) * u.nm
>>> bin1 = np.arange(360., 365., 2.) * u.nm
>>> print(rebin_1d_trans_box(trans, bin0, bin1))
[0.425 0.625 0.6  ]