Closed rfinn closed 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
We could then expand the bounding box by a factor of e.g. 1.5.
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.
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.
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.
I tested on image pointing-13_R.coadd.fits from virgo-coadds-2017. The program is called get_galaxy_size.py.
getobjectsize(image,xobj,yobj,scale=1.75,plotflag=False,usese=False)
return objsize
need to integrate into halphamain.py
previous code uses self.cutout_size for the size of one galaxy in arcsec
need to set to value for that galaxy
self.cutout_size = self.cutout_sizes[self.igal]*self.pixelscale
changed get_galaxy_cutout to use self.cutout_size
self.cutout_size is a 2D array with the x,y dimensions. this is what Cutout2D wants. I think the slider reset doesn't do this correctly.
in get_galaxy_cutout
size = self.cutout_sizes[self.igal]
self.cutout_size = u.Quantity((size, size), u.arcsec)
But according to the documentation, Cutout2D can take an integer or a 2D array. And it can take pixels or arcsec. So why do I convert to arcsec?
Problem with large galaxy. Box is crazy big
going to see how source extractor does with this.
The answer - not good.
enough said