In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from astropy.visualization import ZScaleInterval
import lsst.afw.image
from hugs import primitives as prim
import hugs
In [2]:
exposure = lsst.afw.image.ExposureF('/tigress/jgreco/calexp-HSC-I-9451-2,6.fits')
mi = exposure.getMaskedImage()
mask = exposure.getMask()
In [3]:
psf_sigma = hugs.utils.get_psf_sigma(exposure)
mi_smooth = hugs.imtools.smooth_gauss(mi, psf_sigma)
In [4]:
fpset_low = prim.image_threshold(mi_smooth,
thresh=3.0,
mask=mask,
plane_name='THRESH_LOW',
rgrow=4)
fpset_high = prim.image_threshold(mi_smooth,
thresh=30.0,
mask=mask,
plane_name='THRESH_HIGH',
rgrow=4)
In [5]:
exp_clean = prim.clean(exposure, fpset_low, rgrow=4, max_frac_high_thresh=0.15)
Below I define some functions to visualize the cleaning step:
In [6]:
def show_step(img, ax, vmin, vmax, title, seg=None, alpha=0.6, cmap=plt.cm.gnuplot):
ax.imshow(img, cmap='gray_r', vmin=vmin, vmax=vmax, origin='lower')
if seg is not None:
if type(seg) is not list:
seg = [seg]
if type(alpha) is not list:
alpha = [alpha]*len(seg)
for s, a in zip(seg, alpha):
ax.imshow(s, alpha=a, cmap=cmap, vmin=0, vmax=1, origin='lower')
ax.set_title(title, fontsize=15)
def get_fp_array(fpset):
seg = fpset.insertIntoImage(True).getArray().copy()
seg = seg.astype(float)
seg[seg==0] = np.nan
seg[~np.isnan(seg)] = 1.0
return seg
zscale = ZScaleInterval()
Convert the exposure and low/high threshold footprints to numpy arrays for plotting
In [7]:
img = exposure.getImage().getArray()
img_clean = exp_clean.getImage().getArray()
seg_high = get_fp_array(fpset_high)
seg_low = get_fp_array(fpset_low)
vmin, vmax = zscale.get_limits(img)
Plot the results. The middle panel shows the segmentation maps from the thresholding step.
In [8]:
fig, axes = plt.subplots(3, 1, figsize=(8, 24),
subplot_kw=dict(xticks=[], yticks=[], aspect='equal'))
fig.subplots_adjust(hspace=0.08)
show_step(img, axes[0], vmin, vmax, 'original image')
show_step(img, axes[1], vmin, vmax, 'low (purple) & high (yellow) thresholds',
[seg_low*0.15, seg_high*1], [0.7, 1])
show_step(img_clean, axes[2], vmin, vmax, 'cleaned image')
In [9]:
sex_config = dict(DETECT_THRESH=0.7,
MAG_ZEROPOINT=27.0,
DETECT_MINAREA=100,
FILTER_NAME='../hugs/sextractor/config/gauss_6.0_31x31.conv',
PHOT_APERTURES='3,4,5,6,7,8,16,32,42,54')
sex_io_dir = '/scratch/network/jgreco/sextractor-io'
sources = prim.detect_sources(exp_clean, sex_config, sex_io_dir, label='demo')
The source catalog is an astropy table. $SExtractor$ measures the following parameters:
In [10]:
sources.colnames
Out[10]:
Let's look at the size and mag distribution for sources within this particular patch:
In [11]:
plt.scatter(sources['flux_radius_i'], sources['mag_auto_i'], alpha=0.6)
plt.ylabel(r'$m_i$ [AB mag]', fontsize=18)
plt.xlabel(r'$r_{1/2}$ [arcsec]', fontsize=18);