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/concat2.ms.cont.image.fits"

In [4]:
ra, dec, flux, label = runsextractor(imgfile)


Ouch, SExtractor complains :
b''

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


Out[15]:
(<Column name='ALPHA_J2000' dtype='float64' unit='deg' description='Right ascension of barycenter (J2000)' length=3>
 75.3035913
 75.3036114
 75.3030971,
 <Column name='DELTA_J2000' dtype='float64' unit='deg' description='Declination of barycenter (J2000)' length=3>
 -1.9877503
  -1.987177
 -1.9874529,
 <Column name='FLUX_MAX' dtype='float64' unit='ct' description='Peak flux above background' length=3>
 0.0006485541
 0.0008014459
 0.0008301067,
 <Column name='NUMBER' dtype='int64' description='Running object number                                     ' length=3>
 1
 2
 3)

In [6]:
#rms = 1.92070720004e-05
#rms = 1.92046941265e-05
rms = 5.4e-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 = 23./3600.0 



multp = np.array([5, 7, 10])
lvl = rms*multp

In [20]:
hdu_list = fits.open(imgfile)
image_data = hdu_list[0].data
vmax = image_data.max()

In [22]:
image = aplpy.FITSFigure(imgfile)#, figsize=(10, 10), dpi=300)

#image.show_colorscale()#(vmin=0, vmax=0.002)
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 B6", size=18)
#image.add_label(ra[i], dec[i]-0.0004, "J1139-1350 in B3")


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 [8]:
# image.savefig("J0501_B6.png", dpi=300, transparent=True)

In [9]:
#hdu_list = fits.open(imgfile)

In [10]:
# image_data = hdu_list[0].data
# print(type(image_data))
# print(image_data.shape)
# img = image_data[0][0]


<class 'numpy.ndarray'>
(1, 1, 200, 200)

In [11]:
# hdu_list[0].header['BMAJ']*3600


Out[11]:
1.28495097160344

In [12]:
# hdu_list[0].header['BMIN']*3600


Out[12]:
0.7050560712814801

In [13]:
# hdu_list[0].header['BPA']


Out[13]:
87.55899047852

In [ ]: