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


/scratch/home/rwibowo/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: The mpl_toolkits.axes_grid module was deprecated in version 2.1. Use mpl_toolkits.axes_grid1 and mpl_toolkits.axisartist provies the same functionality instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

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)


Ouch, SExtractor complains :
b''

In [5]:
ra, dec, flux, label


Out[5]:
(<Column name='ALPHA_J2000' dtype='float64' unit='deg' description='Right ascension of barycenter (J2000)' length=2>
 75.3040816
 75.3028351,
 <Column name='DELTA_J2000' dtype='float64' unit='deg' description='Declination of barycenter (J2000)' length=2>
  -1.987388
 -1.9875994,
 <Column name='FLUX_MAX' dtype='float64' unit='ct' description='Peak flux above background' length=2>
 0.0004009127
  0.001275289,
 <Column name='NUMBER' dtype='int64' description='Running object number                                     ' length=2>
 1
 2)

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")


WARNING: FITSFixedWarning: PC01_01 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_02 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_03 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_04 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
INFO: Setting slices=[0, 0] [aplpy.core]

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")


INFO: Setting slices=[0, 0] [aplpy.core]
WARNING: FITSFixedWarning: PC01_01 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_01 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_02 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_02 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_03 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_03 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC01_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC02_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC03_04 = 0.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC04_04 = 1.000000000000E+00 
indices in parameterized keywords must not have leading zeroes. [astropy.wcs.wcs]

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 [ ]: