In [1]:
import numpy as np
import sewpy
import aplpy
import astropy.units as u
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt
import aplpy
from astropy.io import fits
%matplotlib inline
In [2]:
def runsextractor(image_file, detect_thresh=3.5, analysis_thresh=3.0):
params = ['NUMBER', 'FLUX_ISO', 'FLUXERR_ISO', 'FLUX_AUTO', 'FLUXERR_AUTO', 'FLUX_BEST', 'FLUXERR_BEST', 'BACKGROUND',
'THRESHOLD', 'FLUX_MAX', 'XMAX_IMAGE', 'YMAX_IMAGE', 'XPEAK_IMAGE', 'YPEAK_IMAGE', 'ALPHAPEAK_J2000',
'DELTAPEAK_J2000', 'X_IMAGE', 'Y_IMAGE', 'ALPHA_SKY', 'DELTA_SKY', 'ALPHA_J2000', 'DELTA_J2000']
config = {"DETECT_THRESH":detect_thresh, "ANALYSIS_THRESH":analysis_thresh}
sew = sewpy.SEW(params=params, config=config)
out = sew(image_file)
data = out["table"]
ra, dec, flux, label = data['ALPHA_J2000'], data['DELTA_J2000'], data['FLUX_MAX'], data['NUMBER'].astype('int')
return ra, dec, flux, label
In [3]:
imgfile = "./images/concat3.ms.cont.image.fits"
In [4]:
ra, dec, flux, label = runsextractor(imgfile)
In [5]:
ra, dec, flux, label
Out[5]:
In [6]:
#rms = 1.92070720004e-05
#rms = 1.92046941265e-05
rms = 4.5e-05
#c = SkyCoord('11h39m10.702595s -13d50m43.63856s', unit=(u.hourangle, u.deg), frame='icrs')
c = SkyCoord('05h01m12.8s -01d59m14s', unit=(u.hourangle, u.deg), frame='icrs')
center_x, center_y = [c.ra.value, c.dec.value]
PB = 58./3600.0
multp = np.array([5, 7, 10])
lvl = rms*multp
In [7]:
image = aplpy.FITSFigure(imgfile)#, figsize=(10, 10), dpi=300)
image.show_colorscale(vmin=0, vmax=0.0015)
#image.show_colorscale(vmin=0)
#image.show_colorbar()
image.tick_labels.set_font(size='small')
image.show_contour(colors='white', levels=lvl, alpha=0.75)
image.hide_xaxis_label()
image.hide_yaxis_label()
image.hide_tick_labels()
image.add_beam()
image.beam.set_color('gray')
image.add_scalebar(5 * u.arcsecond)
image.scalebar.set_label('5 arcsec')
image.scalebar.set_color("white")
image.show_markers(center_x, center_y, marker='X', edgecolor="red", facecolor="none", s=100)
#marker_size = 100
#image.show_markers(ra, dec, edgecolor='white', facecolor='none', marker='o', s=marker_size, alpha=0.4)
# primary beam circle
image.show_circles(center_x, center_y, PB/2.0, edgecolor='gray', facecolor="none")
#image.set_title("J1139-1350 in B3")
# for i, lbl in enumerate(label):
# image.add_label(ra[i], dec[i]-0.0004, lbl)
#image.add_label(ra[i], dec[i]-0.0004, "J1139-1350 in B3")
In [9]:
hdu_list = fits.open(imgfile)
image_data = hdu_list[0].data
vmax = image_data.max()
In [10]:
image = aplpy.FITSFigure(imgfile)#, figsize=(10, 10), dpi=300)
#image.show_colorscale(vmin=0, vmax=vmax, cmap="gist_heat")
image.show_grayscale(vmin=0, vmax=vmax, invert=True)
#image.show_colorbar()
image.tick_labels.set_font(size='small')
#image.show_contour()#colors='white', levels=lvl, alpha=0.75)
image.hide_xaxis_label()
image.hide_yaxis_label()
image.hide_tick_labels()
# BEAM
image.add_beam()
image.beam.set_color('black')
# SCALE
image.add_scalebar(5 * u.arcsecond)
image.scalebar.set_label('5"')
image.scalebar.set_color("black")
image.scalebar.set_font_size(18)
# CENTER source (calibrator)
image.show_markers(center_x, center_y, marker='X', edgecolor="red", facecolor="none", s=100)
# PB circle
image.show_circles(center_x, center_y, PB/2.0, edgecolor='red', facecolor="none")
# DETECTED SOURCE
image.show_markers(ra, dec, edgecolor='black', facecolor='none', marker='s', s=400)
# for i, lbl in enumerate(label):
# image.add_label(ra[i], dec[i]-0.0004, lbl, color='black', size=18)
image.set_title("J0501-0159 in B3", size=18)
#image.add_label(0.1, 0.1, "J0501-0159 B7")
In [11]:
image.savefig("J0501_B3.png", dpi=300, transparent=True)
In [ ]:
#hdu_list = fits.open(imgfile)
In [ ]:
# image_data = hdu_list[0].data
# print(type(image_data))
# print(image_data.shape)
# img = image_data[0][0]
In [ ]:
# hdu_list[0].header['BMAJ']*3600
In [ ]:
# hdu_list[0].header['BMIN']*3600
In [ ]:
# hdu_list[0].header['BPA']
In [ ]: