Search code examples
python-3.xastropyphotutils

Photutils DAOPhot Not Fitting stars well?


I recently ran across the PhotUtils package and am trying to use it to perform PSF Photometry on some images I have. However, when I try to run the code, I get very strange results. When I plot the image generated by get_residual_image(), the stars are not removed well. Some sample images are shown below.

The first image has sigma set to 2.05, as it is in one of the sample programs in the PhotUtils documentation:Image 1. For this image, sigma is set to 2.05 according to one of the samples on the website. On the left is the image with the stars "subtracted." On the right is the original image.

However, the stars only appear to be removed in their center.

The second image has sigma set to 5.0. This one is especially strange. Some stars are way over-removed, some are under removed, some black squares are added to the image, etc.

Image 2. For this image, I set sigma to 5.0. Here is my code:

import photutils
from photutils.psf import DAOPhotPSFPhotometry as DAOP
from photutils.psf import IntegratedGaussianPRF as PRF
from photutils.background import MMMBackground

bkg = MMMBackground()
background = 2.5*bkg(img)
gaussian_prf = PRF(sigma=5.0)
gaussian_prf.sigma.fixed = False
photTester = DAOP(8,background,5,gaussian_prf,31)
photResults = photTester(imgStars)

finalImg = photTester.get_residual_image()

After this, I simply plot the original and final image in MatPlotLib. I use a greyscale colormap. The reason that the left images appear slightly darker is that they use a different color scaling.

Perhaps I have set one of the parameters incorrectly?

Could someone help me out with this? Thank you!


Solution

  • Looking at the residual image instantly told me that the background subtraction might be wrong. I could reproduce the result and wondered, if MMMBackground did not do the job correctly. After taking a closer look at the documentation, Getting startet with Photutils finally gave the essential hint:

    image -= np.median(image)