photutils icon indicating copy to clipboard operation
photutils copied to clipboard

Photutils - SExtractor reconciliation

Open macastronomy opened this issue 4 years ago • 3 comments

HI! I'm having some problems to get the same output as SExtractor using photutils package. I was wondering if I could receive any help with this issue.

I'm trying to detect star-forming regions in galaxies, so the background mesh is done with few pixels in order to detect only this star-forming emission. I'm running SExtractor with the following setup: DETECT_MINAREA = 7 DETECT_THRESH = 3 FILTER_NAME = default.conv (equivalent to gaussian kernel with FWHM=2 and dimension (3, 3)) BACK_SIZE = 2 BACK_FILTERSIZE = 3

This configuration gives the following background, background_rms and segmentation images: image image

If I have understood correctly, I need to build my own Background2D to introduce part of the galaxy emission on it. For so, I built my photutils Background2D map with the following code: from astropy.io import fits from astropy.convolution import Gaussian2DKernel from astropy.stats import gaussian_fwhm_to_sigma, SigmaClip from photutils import SExtractorBackground, detect_sources, Background2D

galaxy = fits.open(galaxy_file)[1].data sigma_clip = SigmaClip(sigma=3) bkg_estimator = SExtractorBackground() back = Background2D(galaxy, box_size=2, filter_size=3, sigma_clip=sigma_clip, bkg_estimator=bkg_estimator)

And now for detecting the regions I use: threshold = back.background + (3*back.background_rms) sigma = 2 * gaussian_fwhm_to_sigma # FWHM = 2. as SExtractor default kernel kernel = Gaussian2DKernel(sigma, x_size=3, y_size=3) kernel.normalize()

seg = detect_sources(galaxy, threshold, npixels=7, filter_kernel=kernel)

In this case, I get the following background, background_rms and segmentation images: image image

The background and background_rms are quite similar, but they don't cover the same range of values. I think that is the main reason why I don't have source detection when using photutils. I also tried to find the sources with the SExtractor background and background_rms maps into the photutils routine. Then some detection is found but it doesn't match with the first SExtractor segmentation, as shown below:

image

Any idea about the problem? Is there something I did wrong? Many thanks!

macastronomy avatar May 26 '20 16:05 macastronomy

@macastronomy I don't see anything wrong with what you did. This is a tricky use case where both the detections and fluxes are very sensitive to the background estimate. It doesn't surprise me that slight differences in background could possibly lead to no detections (photutils and SExtractor background algorithms are very similar but not identical). However, I don't understand the differences where you used the SExtractor background. The photutils and SExtractor basic detection routines should be the same given the same inputs (however, the deblending routines are different). SExtractor does detection/deblending together, so that's one difference, but I don't think that's an issue here. There could be a small difference between the smoothing kernels. To check this, you could load the SExtractor default.conv kernel as an array and pass that to filter_kernel in photutils. I would need your actual data to investigate this in detail.

larrybradley avatar May 27 '20 13:05 larrybradley

Also, I'm not sure that either of these tools are the best for your use case. Modeling the smooth component of the galaxy to separate the star-forming regions may work better.

larrybradley avatar May 27 '20 13:05 larrybradley

@larrybradley thanks for your quick reply! I upload the data I'm using in this link, so you can have a look on it: https://github.com/macastronomy/photutils-SExtractor

Concerning the SExtractor default.conv kernel, I took a look and the array is the same as the normalized Gaussian2DKernel(2, x_size=3, y_size=3) I introduced in my photutils routine. I was also surprised about the results when using the SExtractor background, this makes me think I could be doing something wrong...

The deblending test is also in my check list (although their algorithims are different). I didn't start with this yet because first I want to be sure that the detections are compatible.

macastronomy avatar May 27 '20 19:05 macastronomy