Background

class specreduce.background.Background(image: ~astropy.nddata.nddata.NDData, traces: list = <factory>, width: float = 5, statistic: str = 'average', disp_axis: int = 1, crossdisp_axis: int = 0)[source]

Bases: _ImageParser

Determine the background from an image for subtraction.

Example:

trace = FlatTrace(image, trace_pos)
bg = Background.two_sided(image, trace, bkg_sep, width=bkg_width)
subtracted_image = image - bg
Parameters:
imageNDData-like or array-like

image with 2-D spectral image data

tracestrace, int, float (single or list)

Individual or list of trace object(s) (or integers/floats to define FlatTraces) to extract the background. If None, a FlatTrace at the center of the image (according to disp_axis) will be used.

widthfloat

width of extraction aperture in pixels

statistic: string

statistic to use when computing the background. ‘average’ will account for partial pixel weights, ‘median’ will include all partial pixels.

disp_axisint

dispersion axis

crossdisp_axisint

cross-dispersion axis

Attributes Summary

bkg_array

Deprecated since version 1.3.

crossdisp_axis

disp_axis

statistic

width

Methods Summary

bkg_image([image])

Expose the background tiled to the dimension of image.

bkg_spectrum([image])

Expose the 1D spectrum of the background.

one_sided(image, trace_object, separation, ...)

Determine the background from an image for subtraction above or below an input trace.

sub_image([image])

Subtract the computed background from image.

sub_spectrum([image])

Expose the 1D spectrum of the background-subtracted image.

two_sided(image, trace_object, separation, ...)

Determine the background from an image for subtraction centered around an input trace.

Attributes Documentation

bkg_array

Deprecated since version 1.3: The bkg_array attribute is deprecated and may be removed in a future version.

crossdisp_axis: int = 0
disp_axis: int = 1
statistic: str = 'average'
width: float = 5

Methods Documentation

bkg_image(image=None)[source]

Expose the background tiled to the dimension of image.

Parameters:
imageNDData-like or array-like, optional

Image with 2-D spectral image data. Assumes cross-dispersion (spatial) direction is axis 0 and dispersion (wavelength) direction is axis 1. If None, will extract the background from image used to initialize the class. [default: None]

Returns:
Spectrum1D object with same shape as image.
bkg_spectrum(image=None)[source]

Expose the 1D spectrum of the background.

Parameters:
imageNDData-like or array-like, optional

Image with 2-D spectral image data. Assumes cross-dispersion (spatial) direction is axis 0 and dispersion (wavelength) direction is axis 1. If None, will extract the background from image used to initialize the class. [default: None]

Returns:
specSpectrum1D

The background 1-D spectrum, with flux expressed in the same units as the input image (or u.DN if none were provided) and the spectral axis expressed in pixel units.

classmethod one_sided(image, trace_object, separation, **kwargs)[source]

Determine the background from an image for subtraction above or below an input trace.

Example:

trace = FitTrace(image, guess=trace_pos)
bg = Background.one_sided(image, trace, bkg_sep, width=bkg_width)
Parameters:
imageNDData-like or array-like

Image with 2-D spectral image data. Assumes cross-dispersion (spatial) direction is axis 0 and dispersion (wavelength) direction is axis 1.

trace_object: `~specreduce.tracing.Trace`

estimated trace of the spectrum to center the background traces

separation: float

separation from trace_object for the background, positive will be above the trace, negative below.

widthfloat

width of each background aperture in pixels

statistic: string

statistic to use when computing the background. ‘average’ will account for partial pixel weights, ‘median’ will include all partial pixels.

disp_axisint

dispersion axis

crossdisp_axisint

cross-dispersion axis

sub_image(image=None)[source]

Subtract the computed background from image.

Parameters:
imagenddata-compatible image or None

image with 2-D spectral image data. If None, will extract the background from image used to initialize the class.

Returns:
Spectrum1D object with same shape as image.
sub_spectrum(image=None)[source]

Expose the 1D spectrum of the background-subtracted image.

Parameters:
imagenddata-compatible image or None

image with 2-D spectral image data. If None, will extract the background from image used to initialize the class.

Returns:
specSpectrum1D

The background 1-D spectrum, with flux expressed in the same units as the input image (or u.DN if none were provided) and the spectral axis expressed in pixel units.

classmethod two_sided(image, trace_object, separation, **kwargs)[source]

Determine the background from an image for subtraction centered around an input trace.

Example:

trace = FitTrace(image, guess=trace_pos)
bg = Background.two_sided(image, trace, bkg_sep, width=bkg_width)
Parameters:
imageNDData-like or array-like

Image with 2-D spectral image data. Assumes cross-dispersion (spatial) direction is axis 0 and dispersion (wavelength) direction is axis 1.

trace_object: `~specreduce.tracing.Trace`

estimated trace of the spectrum to center the background traces

separation: float

separation from trace_object for the background regions

widthfloat

width of each background aperture in pixels

statistic: string

statistic to use when computing the background. ‘average’ will account for partial pixel weights, ‘median’ will include all partial pixels.

disp_axisint

dispersion axis

crossdisp_axisint

cross-dispersion axis