<p>I want to perform sky background estimation and subtraction.
To do that, I am adopting some libraries in python, i.e. photutils which does have *some support for <a href="https://photutils.readthedocs.io/en/stable/background.html" rel="nofollow noreferrer">background estimation</a>.</p>
<p>However, I wonder if there are some guidelines to do that, for instance in masking sources to estimate the background. My final goal is to obtain the best image possible to perform the source extraction.</p>
<p>Thanks in advance.</p>

CC BY-SA 4.0
2022-01-28T14:21:15.877Z
This might be better suited for Photography SE.
WarpPrime
CC BY-SA 4.0
2022-01-28T14:35:15.377Z
My final goal would be to obtain the best image possible to perform source extraction. The image I am working on comes from JWST simulations. I am testing the JWST pipeline and it seems that the background is not well subtracted...
x12red
CC BY-SA 4.0
2022-01-28T15:41:44.093Z
While it might also be on-topic in photography-SE, I think it's perfectly on-topic here as astronomical data reduction has its own quirks beyond "normal" photography and is an essential part of observational work
planetmaker
CC BY-SA 4.0
2022-01-28T15:45:03.387Z
@x12red have you looked at some sources like https://www.astropy.org/ccd-reduction-and-photometry-guide/v/dev/notebooks/00-00-Preface.html or similar?
planetmaker
CC BY-SA 4.0
2022-01-28T16:30:09.743Z
@planetmaker thanks for the suggestion. However, dealing with JWST data will not be the same we used to in the past. As far as I understand, the reduction is completely different compared to what I saw in the past.
x12red
CC BY-SA 4.0
2022-01-28T16:35:53.297Z
"My final goal is to obtain the best image possible to perform the source extraction." It is doubtful that you would do background subtraction first. The best methods will determine the source and background flux together, The best methods will also depend on what kind of data you have - how crowded is the photometry, are you talking about galaxies or point sources, is the PSF uniform, do you hvae cosmic rays, what is the signal-to-noise ratio... etc. The question seems too broad.
ProfRob
CC BY-SA 4.0
2022-01-28T17:21:43.460Z
@x12red if your pipeline will "not be as in the past" - thus the past does not serve as guideline (may make sense, see also comment by @ProfRob). How can one answer the question? I think you will have to provide further constraints to narrow down the question and describe what will have to be different and what particular challanges you expect not encountered "usually". Maybe at least sketch your idea of a pipeline and which step(s) your question deals with in particular
planetmaker
CC BY-SA 4.0
2022-01-28T17:27:58.090Z
@planetmaker I think the OP is commenting on the fact that techniques of background subtraction that they may have used in the past for optical CCD images may/will not be applicable to JWST's IR images as the background is higher and thermal in nature, unlike in optical images. IR detectors can also have different noise properties and more correlated noise across the image due to the different readout techniques used.
astrosnapper
CC BY-SA 4.0
2022-01-28T17:30:15.823Z
@astrosnapper I don't see how that is not dealt with by dark frames, gain and bias frame reductions. But I'm happy to learn about the peculiarities... I'm not an observer nor IR instrumentalist.
planetmaker
CC BY-SA 4.0
2022-01-28T19:37:20.893Z
@planetmaker The [pipeline docs](https://jwst-pipeline.readthedocs.io/en/latest/jwst/pipeline/calwebb_detector1.html#calwebb-detector1) list several steps that their pipelines do which I would not have to do for CCD data (and there may well be others at the per-image Step 2 and multi-image/combined product Step 3; didn't read the whole doc...). There were also several pipeline processing modules listed under the TOC on the LHS that seemed to be IR-specific and wouldn't expect to need for CCD data (at least relatively modern/high-end CCDs anyway)
astrosnapper
CC BY-SA 4.0
2022-01-29T13:55:59.933Z
@astrosnapper I'm sure background-subtraction techniques developed for optical (CCD) and near-/mid-IR ground-based imaging will be relevant. And *JWST* backgrounds will be *lower*, because it's a) a space telescope; and b) aggressively cooled in ways impossible for ground-based telescopes. (I also don't see how the background being "thermal" -- which is only true for the mid-IR anyway -- is relevant.)
Peter Erwin
CC BY-SA 4.0
2022-01-29T14:11:14.220Z
Also, discussions of background estimation for *JWST* observations make it clear that many/most observations will be background-limited, and so the noise characteristics of the detectors will not be very important (as is also the case for most ground-based IR observations). See, e.g., 
https://jwst-docs.stsci.edu/jwst-general-support/jwst-background-model
Peter Erwin
CC BY-SA 4.0
2022-01-29T23:37:49.487Z
@fasterthanlight careful, quantitative background subtraction is a critical procedure in observational astronomy, how could Photography SE possibly be a better site? This is where the astronomers are, no?
uhoh
CC BY-SA 4.0
2022-01-30T00:46:29.490Z
Do you plan to do aperture photometry on point sources? That procedure includes background already, and should be OK. You haven't said what instrument this is for, nor what specific issues remain when "the background is not well subtracted."
giardia
CC BY-SA 4.0
2022-02-01T07:56:15.753Z
I am currently testing the JWST pipeline on NIRCam images.

To do that, I am simulating the Hubble Ultra Deep Field in three different filters in order to have exposure both in short and long wavelength channels.
x12red
CC BY-SA 4.0
2022-02-01T07:56:41.790Z
From what I saw so far, the background looks not so homogeneous as expected. For instance, if we simulate observation with the A5 detector, you can see some strange structures, which I can't remove with the given dithering strategy.
x12red
CC BY-SA 4.0
2022-02-01T07:57:06.413Z
(the A5 detector is the red square in this image https://www.stsci.edu/jwst/instrumentation/instruments)
x12red
CC BY-SA 4.0
2022-02-01T07:58:10.983Z
It seems that the pipeline is not able to remove those strange structures (artefacts??), from step 1 to step 3. So, I wanted to add an extra step to work on the background to model it and subtract it correctly.
x12red
<observational-astronomy><python><image-processing>
How to subtract background correctly?
x12red
# How to subtract background correctly?

(Asked by: username_0 on 2022-01-28)

I want to perform sky background estimation and subtraction.
To do that, I am adopting some libraries in python, i.e. photutils which does have \*some support for [background estimation](https://photutils.readthedocs.io/en/stable/background.html).

However, I wonder if there are some guidelines to do that, for instance in masking sources to estimate the background. My final goal is to obtain the best image possible to perform the source extraction.

Thanks in advance.

**Tags:** observational-astronomy, python, image-processing
> **Comments:**
> **username_1**: This might be better suited for Photography SE.  
> **username_0**: My final goal would be to obtain the best image possible to perform source extraction. The image I am working on comes from JWST simulations. I am testing the JWST pipeline and it seems that the background is not well subtracted...  
> **username_2**: While it might also be on-topic in photography-SE, I think it's perfectly on-topic here as astronomical data reduction has its own quirks beyond "normal" photography and is an essential part of observational work  
> **username_2**: @x12red have you looked at some sources like https://www.astropy.org/ccd-reduction-and-photometry-guide/v/dev/notebooks/00-00-Preface.html or similar?  
> **username_0**: @planetmaker thanks for the suggestion. However, dealing with JWST data will not be the same we used to in the past. As far as I understand, the reduction is completely different compared to what I saw in the past.  
> **username_3**: "My final goal is to obtain the best image possible to perform the source extraction." It is doubtful that you would do background subtraction first. The best methods will determine the source and background flux together, The best methods will also depend on what kind of data you have - how crowded is the photometry, are you talking about galaxies or point sources, is the PSF uniform, do you hvae cosmic rays, what is the signal-to-noise ratio... etc. The question seems too broad.  
> **username_2**: @x12red if your pipeline will "not be as in the past" - thus the past does not serve as guideline (may make sense, see also comment by @ProfRob). How can one answer the question? I think you will have to provide further constraints to narrow down the question and describe what will have to be different and what particular challanges you expect not encountered "usually". Maybe at least sketch your idea of a pipeline and which step(s) your question deals with in particular  
> **username_4**: @planetmaker I think the OP is commenting on the fact that techniques of background subtraction that they may have used in the past for optical CCD images may/will not be applicable to JWST's IR images as the background is higher and thermal in nature, unlike in optical images. IR detectors can also have different noise properties and more correlated noise across the image due to the different readout techniques used.  
> **username_2**: @astrosnapper I don't see how that is not dealt with by dark frames, gain and bias frame reductions. But I'm happy to learn about the peculiarities... I'm not an observer nor IR instrumentalist.  
> **username_4**: @planetmaker The [pipeline docs](https://jwst-pipeline.readthedocs.io/en/latest/jwst/pipeline/calwebb_detector1.html#calwebb-detector1) list several steps that their pipelines do which I would not have to do for CCD data (and there may well be others at the per-image Step 2 and multi-image/combined product Step 3; didn't read the whole doc...). There were also several pipeline processing modules listed under the TOC on the LHS that seemed to be IR-specific and wouldn't expect to need for CCD data (at least relatively modern/high-end CCDs anyway)  
> **username_5**: @astrosnapper I'm sure background-subtraction techniques developed for optical (CCD) and near-/mid-IR ground-based imaging will be relevant. And *JWST* backgrounds will be *lower*, because it's a) a space telescope; and b) aggressively cooled in ways impossible for ground-based telescopes. (I also don't see how the background being "thermal" -- which is only true for the mid-IR anyway -- is relevant.)  
> **username_5**: Also, discussions of background estimation for *JWST* observations make it clear that many/most observations will be background-limited, and so the noise characteristics of the detectors will not be very important (as is also the case for most ground-based IR observations). See, e.g.,  https://jwst-docs.stsci.edu/jwst-general-support/jwst-background-model  
> **username_6**: @fasterthanlight careful, quantitative background subtraction is a critical procedure in observational astronomy, how could Photography SE possibly be a better site? This is where the astronomers are, no?  
> **username_7**: Do you plan to do aperture photometry on point sources? That procedure includes background already, and should be OK. You haven't said what instrument this is for, nor what specific issues remain when "the background is not well subtracted."  
> **username_0**: I am currently testing the JWST pipeline on NIRCam images.  To do that, I am simulating the Hubble Ultra Deep Field in three different filters in order to have exposure both in short and long wavelength channels.  
> **username_0**: From what I saw so far, the background looks not so homogeneous as expected. For instance, if we simulate observation with the A5 detector, you can see some strange structures, which I can't remove with the given dithering strategy.  
> **username_0**: (the A5 detector is the red square in this image https://www.stsci.edu/jwst/instrumentation/instruments)  
> **username_0**: It seems that the pipeline is not able to remove those strange structures (artefacts??), from step 1 to step 3. So, I wanted to add an extra step to work on the background to model it and subtract it correctly.  

---

## 0 answers

