# HOW-TO Subtract sky background¶

## Overview¶

Sky background subtraction is a factor in several places in the reduction process. In most cases SExtractor/SWarp is involved in the algorithm to determine the background image.

Sky background subtraction may be applied first and foremost in RegriddedFrame. This is the last opportunity in the data-reduction process before images are coadded into a CoaddedRegriddedFrame. But here is a complete overview of the places where background subtraction plays a role:

• RegriddedFrame: see text above
• ReducedScienceFrame: when/if an IlluminationCorrectionFrame is applied, a background image is created and the illumination correction is applied to everything but the background. Afterwards the background is added again.
• SourceList: when SExtractor is run, default behaviour of SExtractor is to subtract a background.
• In SWarp. Default behaviour of SWarp is to make and subtract a background image. In Astro-WISE this default is changed to no background subtraction.
• In addition, background images are determined in the algorithms for HotPixelMap, ColdPixelMap, CosmicMap and SatelliteMap.

## Configuring background subtraction¶

At this point it is not possible to configure the background subtraction in great detail, but it is possible to choose from several options in RegriddedFrame.

awe> pars = Pars(RegriddedFrame)
awe> pars.show()
RegriddedFrame
|
+--process_params
|   |
|   +--BACKGROUND_SUBTRACTION_TYPE: 0
|   +--MAXIMUM_PSF_DIFFERENCE: 0.25
|
+--swarpconf
|   |
|   +--BACK_DEFAULT: 0.0
|   +--BACK_FILTERSIZE: 3
|   +--BACK_SIZE: 128
|   +--BACK_TYPE: AUTO
etc.


Note in particular the process parameter BACKGROUND_SUBTRACTION_TYPE. The possible values for this parameter are:

• 0: Leave background subtraction to SWarp
• 1: Create a background image outside SWarp, which gives better results than SWarp
• 2: Subtract a constant as background, which is determined by iteratively clipping around the median pixel value

See HOW-TO Configure process parameters for details about how to configure process parameters.

Note that a check is performed to prevent subtracting background both outside and inside SWarp; in other words, when setting the BACKGROUND_SUBTRACTION_TYPE parameter to something other than 0, the RegriddedFrame.swarpconf.SUBTRACT_BACK option has to be ‘N’, which is the default.

### The background image¶

When option 1 is chosen for the BACKGROUND_SUBTRACTION_TYPE, a background image is created. How is this image created? The process consists of these steps:

• Determine all pixels which are part of sources. This is done by running SExtractor on the image and using the “segmentation” check image.
• Exclude those pixels and calculate the median of the other pixels.
• Replace the pixels attributed to sources with the median calculated in the previous step.
• Run SExtractor to obtain the “background” check image. This is the background image that will be subtracted.