rfinn / halphagui

development of gui interface for H-alpha narrowband imaging
GNU General Public License v3.0
0 stars 0 forks source link

use photutils segmentation image to set size of cutout #70

Closed rfinn closed 3 years ago

rfinn commented 3 years ago

enough said

rfinn commented 3 years ago

so where best to implement this? We need to run photutils

https://photutils.readthedocs.io/en/stable/segmentation.html

from photutils import detect_threshold
threshold = detect_threshold(data, nsigma=2.)

detect sources. do we want to use a kernel?

from astropy.convolution import Gaussian2DKernel
from astropy.stats import gaussian_fwhm_to_sigma
from photutils import detect_sources
sigma = 3.0 * gaussian_fwhm_to_sigma  # FWHM = 3.
kernel = Gaussian2DKernel(sigma, x_size=3, y_size=3)
kernel.normalize()
segm = detect_sources(data, threshold, npixels=5, filter_kernel=kernel) 

Incorporate deblending?

from photutils import deblend_sources
segm_deblend = deblend_sources(data, segm, npixels=5,
...                                filter_kernel=kernel, nlevels=32,
...                                contrast=0.001)

Then find galaxy within segmentation image

Then fit ellipse to shape, or just use x and y min/max of segmentation image.

from photutils import source_properties
cat = source_properties(data, segm_deblend)

we can get the bounding box from the source_properties

bbox_xmax bbox_xmin bbox_ymax bbox_ymin centroid - returns (y,x) of the data

rfinn commented 3 years ago

We could then expand the bounding box by a factor of e.g. 1.5.

rfinn commented 3 years ago

We could make the segmentation image from the r-band image, and then save the catalog. When the galaxies are selected, we could get the segmentation data values at the position of the galaxy. this should give the object number of the galaxy in the segmentation image. Then grab values from table with corresponding row.

rfinn commented 3 years ago

I tried both photutils and source extractor segmentation images. source extractor is much faster - like 2 seconds compared to 30 for photutils. however, source extractor included some far flung pixels in the segmentation image of one galaxy. This ended up increasing the cutout size, and since I don't know what is causing it, it's hard to know how many images will be affected and by how much. image

so in the end I decided to stick with photutils. it completed more quickly when I changed the min object size from 5 pixels to 15. the time dropped from 50 to ~20 seconds, so that's reasonable.

rfinn commented 3 years ago

I tested on image pointing-13_R.coadd.fits from virgo-coadds-2017. The program is called get_galaxy_size.py.

INPUT

getobjectsize(image,xobj,yobj,scale=1.75,plotflag=False,usese=False)

RETURNS

return objsize

IMPLEMENTATION

need to integrate into halphamain.py

rfinn commented 3 years ago

Integrating into halphamain

Change any calls for cutout_size

rfinn commented 3 years ago

Testing on Virgo INT 2017 data - p013

rfinn commented 3 years ago

Testing on 2019, p0149

Problem with large galaxy. Box is crazy big

image

going to see how source extractor does with this.

image

The answer - not good.

rfinn commented 3 years ago