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]:
B3 = './images/concat3.ms.cont.image.fits'
rmsB3 = 4.5E-05

B6 = './images/concat2.ms.cont.image.fits'
rmsB6 = 5.4E-05

B7 = './images/uid___A002_X969646_X1aa8.ms.split.cal-CALIBRATE_BANDPASS-J0501-0159.ms.self3.substracted.cont.image.fits'
rmsB7 = 8.4E-05

c = SkyCoord('05h01m12.8s -01d59m14s', unit=(u.hourangle, u.deg), frame='icrs')

center_x, center_y = [[c.ra.value, c.ra.value, c.ra.value], [c.dec.value, c.dec.value, c.dec.value]]

PB = np.array([58., 23., 18.])/3600.0 # in deg

In [16]:
multp = np.array([3, 4, 5, 7, 10, 25])
lvlB3 = rmsB3*multp
lvlB6 = rmsB6*multp
lvlB7 = rmsB7*multp

In [5]:
fig = aplpy.FITSFigure(B3)
#fig.show_contour(B3, colors='red', levels=lvlB3, alpha=0.5)
fig.add_beam()
fig.beam.set_color('black')
fig.add_scalebar(1 * u.arcsecond)
fig.scalebar.set_label('1 arcsec')
fig.scalebar.set_color("black")
fig.show_colorscale()


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]
INFO: Auto-setting vmin to -1.588e-04 [aplpy.core]
INFO: Auto-setting vmax to  2.762e-04 [aplpy.core]

In [6]:
fig = aplpy.FITSFigure(B6)
#fig.show_contour(B6, colors='red', levels=lvlB6, alpha=0.5)
fig.add_beam()
fig.beam.set_color('black')
fig.add_scalebar(1 * u.arcsecond)
fig.scalebar.set_label('1 arcsec')
fig.scalebar.set_color("black")
fig.show_colorscale()
fig.show_colorbar()


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]
INFO: Auto-setting vmin to -2.093e-04 [aplpy.core]
INFO: Auto-setting vmax to  5.106e-04 [aplpy.core]

In [7]:
fig = aplpy.FITSFigure(B7)
#fig.show_contour(B7, colors='red', levels=lvlB3, alpha=0.5)
fig.add_beam()
fig.beam.set_color('black')
fig.add_scalebar(1 * u.arcsecond)
fig.scalebar.set_label('1 arcsec')
fig.scalebar.set_color("black")
fig.show_colorscale()


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]
INFO: Auto-setting vmin to -2.806e-04 [aplpy.core]
INFO: Auto-setting vmax to  3.122e-04 [aplpy.core]

In [8]:
image = aplpy.FITSFigure(B3)
#fig.add_beam()
#fig.beam.set_color('black')


image.show_contour(B3, colors='red', levels=lvlB3, alpha=0.3)#cmap="viridis")
image.show_contour(B6, colors='green', levels=lvlB6, alpha=0.3)#cmap="autumn")
image.show_contour(B7, colors='blue', levels=lvlB7, alpha=0.3)#cmap="gray")

# primary beam circle
image.show_circles(center_x, center_y, PB/2.0, edgecolor=['red', 'green', 'blue'], alpha=0.5)

image.tick_labels.set_font(size='small')
image.hide_xaxis_label()
image.hide_yaxis_label()
image.hide_tick_labels()

#image.add_beam()
#image.beam.set_color('gray')
image.add_scalebar(1 * u.arcsecond)
image.scalebar.set_label('1 arcsec')
image.scalebar.set_color("black")

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


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]
INFO: Setting slices=[0, 0] [aplpy.core]
INFO: Setting slices=[0, 0] [aplpy.core]
INFO: Setting slices=[0, 0] [aplpy.core]

In [9]:
from astroquery.ned import Ned

result = Ned.query_region(c, radius=0.75*u.arcmin, equinox='J2000.0')

result


Out[9]:
Table masked=True length=14
No.Object NameRA(deg)DEC(deg)TypeVelocityRedshiftRedshift FlagMagnitude and FilterDistance (arcmin)ReferencesNotesPhotometry PointsPositionsRedshift PointsDiameter PointsAssociations
degreesdegreeskm / sarcm
int32bytes30float64float64objectfloat64float64objectobjectfloat64int32int32int32int32int32int32int32
1[WMF2001] N-06-3C75.30228-1.98783G----0.0731000000
2[WMF2001] N-06-1D75.30267-1.98742G----0.0421000000
3[WMF2001] N-06-2D75.30289-1.98764G----0.0371000000
4[HB89] 0458-020 ABS0675.3031-1.98746AbLS599285.01.9990.022000000
5[HB89] 0458-020 ABS0175.3031-1.98746G611127.02.03850.0234010000
6[HB89] 0458-020 ABS0275.3031-1.98746AbLS626267.02.0890.025000000
7[HB89] 0458-020 ABS0375.3031-1.98746AbLS467886.01.56070.022000000
8[HB89] 0458-020 ABS0475.3031-1.98746AbLS266845.00.89010.022000000
9[HB89] 0458-020 ABS0575.3031-1.98746AbLS457813.01.52710.022000000
10[HB89] 0458-02075.30337-1.98729QSO685326.02.28618.1V0.004404598281200
11[WMF2001] N-06-4C75.3034-1.98668G----0.0331000000
12NVSS J050112-01593275.30354-1.99222RadioS----2.150.31020000
13[WMF2001] N-06-5C75.30373-1.98656G----0.0461000000
142MASS J05011390-015951075.30793-1.99749UvS----0.6740092000

In [10]:
ra_ned = result['RA(deg)'].data.data # "mask-type" -_-
dec_ned = result['DEC(deg)'].data.data
label = result['No.'].data.data

In [11]:
raB3, decB3, fluxB3, labelB3 = runsextractor(B3)


Ouch, SExtractor complains :
b''

In [17]:
image = aplpy.FITSFigure(B3)
#fig.add_beam()
#fig.beam.set_color('black')


image.show_contour(B3, colors='red', levels=lvlB3, alpha=0.5)#cmap="viridis")
image.show_contour(B6, colors='green', levels=lvlB6, alpha=0.5)#cmap="autumn")
image.show_contour(B7, colors='blue', levels=lvlB7, alpha=0.5)#cmap="gray")

# primary beam circle
image.show_circles(center_x, center_y, PB/2.0, edgecolor=['red', 'green', 'blue'], alpha=0.5)

image.tick_labels.set_font(size='small')
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("black")

#image.show_markers(center_x, center_y, marker='X', edgecolor="red", facecolor="none", s=100)

#marker_size =  120
#image.show_markers(raB3, decB3, edgecolor='green', facecolor='green', marker='o', s=marker_size, alpha=0.5)

# 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.show_markers(ra_ned, dec_ned, edgecolor='none', facecolor='red', marker='s', s=40, alpha=0.5)
# for i, lbl in enumerate(label):
#     image.add_label(ra_ned[i], dec_ned[i]-0.0002, lbl)

#image.recenter(c.ra.value, c.dec.value, radius=(5.0/3600.))


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]
INFO: Setting slices=[0, 0] [aplpy.core]
INFO: Setting slices=[0, 0] [aplpy.core]
INFO: Setting slices=[0, 0] [aplpy.core]

In [13]:
image.savefig("combine.png", dpi=300)#, transparent=True)

In [14]:
#image.savefig("zoom.png", dpi=300)#, transparent=True)

In [ ]: