In [1]:
import numpy as np
import pandas as pd

from astropy import coordinates
from astropy.coordinates import match_coordinates_sky
import astropy.units as u
import astroquery
from astroquery.irsa import Irsa
from astroquery.vizier import Vizier
from astropy.table import Table, join

Irsa.ROW_LIMIT = -1
Vizier.ROW_LIMIT = -1

import matplotlib.pyplot as plt

%matplotlib inline

Get the data


In [2]:
obj = ["3C 454.3", 343.49062, 16.14821, 4./60.]
# name, ra, dec, radius of cone
obj_name = obj[0]
obj_ra   = obj[1]
obj_dec  = obj[2]
cone_radius  = obj[3]

In [3]:
obj_coord = coordinates.SkyCoord(ra=obj_ra, dec=obj_dec, unit=(u.deg, u.deg), frame="icrs")

In [4]:
data_2mass = Irsa.query_region(obj_coord, catalog="fp_psc", radius=cone_radius * u.deg)
data_wise  = Irsa.query_region(obj_coord, catalog="allwise_p3as_psd", radius=cone_radius * u.deg)
__data_galex = Vizier.query_region(obj_coord, catalog='II/335', radius=cone_radius * u.deg)
data_galex = __data_galex[0]

In [5]:
num_2mass = len(data_2mass)
num_wise  = len(data_wise)
num_galex = len(data_galex)

print("Number of object in (2MASS, WISE, GALEX): ", num_2mass, num_wise, num_galex)


Number of object in (2MASS, WISE, GALEX):  44 218 41

Matching coordinates (3 Catalogs)


In [6]:
ra_2mass = data_2mass['ra']
dec_2mass = data_2mass['dec']
c_2mass = coordinates.SkyCoord(ra=ra_2mass, dec=dec_2mass, unit=(u.deg, u.deg), frame="icrs")

ra_wise  = data_wise['ra']
dec_wise = data_wise['dec']
c_wise = coordinates.SkyCoord(ra=ra_wise, dec=dec_wise, unit=(u.deg, u.deg), frame="icrs")

ra_galex  = data_galex['RAJ2000']
dec_galex = data_galex['DEJ2000']
c_galex = coordinates.SkyCoord(ra=ra_galex, dec=dec_galex, unit=(u.deg, u.deg), frame="icrs")

In [7]:
sep_min = 2.5 * u.arcsec # minimum separation in arcsec

In [8]:
idx_2mass, idx_wise, d2d, d3d = c_wise.search_around_sky(c_2mass, sep_min)
c_2mass_wise = c_2mass[idx_2mass]
print("Only 2MASS and WISE: ", len(idx_2mass))


Only 2MASS and WISE:  41

Plot W1-J vs W1


In [9]:
# from matching of 2 cats (2MASS and WISE) coordinate
w1 = data_wise[idx_wise]['w1mpro']
j = data_2mass[idx_2mass]['j_m']
w1j = w1-j

# match between WISE and 2MASS
data_wise_2mass = data_wise[idx_wise] # WISE dataset

galaxy = data_wise_2mass[w1j<-1.7] # https://academic.oup.com/mnras/article/448/2/1305/1055284

In [10]:
galaxy


Out[10]:
Table masked=True length=2
designationradecclonclatsigrasigdecsigradecw1mprow1sigmprow1snrw1rchi2w2mprow2sigmprow2snrw2rchi2w3mprow3sigmprow3snrw3rchi2w4mprow4sigmprow4snrw4rchi2nbnaw1satw2satw3satw4satpmrasigpmrapmdecsigpmdeccc_flagsext_flgvar_flgph_qualmoon_levw1nmw1mw2nmw2mw3nmw3mw4nmw4mdistangleid
degdegarcsarcsarcsmagmagmagmagmagmagmagmagmaspyrmaspyrmaspyrmaspyrarcsdeg
objectfloat64float64objectobjectfloat64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64int32int32float64float64float64float64int32int32int32int32objectint32objectobjectobjectint32int32int32int32int32int32int32int32float64float64object
J225357.74+160853.7343.49116.14822h53m57.75s16d08m53.70s0.02870.027-0.00239.2630.02150.923.178.1470.01957.631.035.8010.01382.72.7893.3870.0254.31.135100.00.00.00.0-247592236000019964AAAA110024242424131313130.147404349.0462510
J225350.60+160943.7343.46116.16222h53m50.60s16d09m43.74s0.06430.0649-0.007914.2540.02937.23.14814.0530.04524.01.04610.680.09811.01.0878.8130.4642.30.9725100.00.00.00.068196-437208000d1000nAAAC110025252424813013114.54805295.98473356

In [11]:
plt.scatter(w1j, w1, color='blue')
for i, name in enumerate(data_wise_2mass['designation']):
    for galaxyname in galaxy['designation']:
        if name == galaxyname:
            plt.scatter(w1j[i], w1[i], color="red")  
            
plt.axvline(x=-1.7) # https://academic.oup.com/mnras/article/448/2/1305/1055284


Out[11]:
<matplotlib.lines.Line2D at 0x7ff31606a438>
  • W1-J < -1.7 => galaxy
  • W1-J > -1.7 => stars

only 2 object are galaxy?


In [12]:
# + GALEX
___idx_2mass_wise_galex, idx_galex, d2d, d3d = c_galex.search_around_sky(c_2mass_wise, sep_min)

match_all_coord = c_galex[idx_galex]
print("Match all 3 cats: ", len(match_all_coord))


Match all 3 cats:  14

Filter


In [13]:
### GALEX data which match with 2MASS and WISE!
match_galex = data_galex[idx_galex]
match_galex


Out[13]:
Table masked=True length=14
RAJ2000DEJ2000r.fovbFUVmage_FUVmagNUVmage_NUVmagFaflNaflFexfNexfFrNr
degdegdegmagmagmagmagdegdeg
float64float64float64uint8float64float32float64float32int16int16int16int16float64float64
343.49051216.1484150.358822317.92530.053416.93600.016700000.0015270.001446
343.49973816.1650880.3430001----22.81850.43430000--0.002056
343.47953416.1190630.3875211----20.38660.10140000--0.002548
343.46068616.1621620.344095321.46040.346020.47610.145000000.0022260.007870
343.52069016.1295480.3807781----22.18910.48420000--0.004134
343.43612316.1524720.3547041----22.44520.40190000--0.002512
343.43428816.1355230.3717371----22.10460.39530000--0.004224
343.46272916.0987880.4074631----20.24400.09280100--0.001539
343.45124616.1042990.4021051----21.85590.27230000--0.004275
343.43525016.1746490.3326541----22.05680.42260000--0.002250
343.55186216.1637450.3530081----22.87390.42270000--0.002446
343.53340016.1028000.4091021----21.35200.30040000--0.004801
343.54623216.1155820.3987901----21.78550.25750000--0.002586
343.47336716.0874320.4189411----22.85550.47070100--0.002129

In [14]:
idx_2mass, idx, d2d, d3d = match_all_coord.search_around_sky(c_2mass, sep_min)
match_2mass = data_2mass[idx_2mass]
match_2mass


Out[14]:
Table masked=True length=14
radecclonclaterr_majerr_minerr_angdesignationj_mj_cmsigj_msigcomj_snrh_mh_cmsigh_msigcomh_snrk_mk_cmsigk_msigcomk_snrph_qualrd_flgbl_flgcc_flgndetgal_contammp_flghemisxdatescanglonglatadist_optphi_optb_m_optvr_m_optnopt_mchsext_keydistanglej_hh_kj_kid
degdegarcsarcsdegmagmagmagmagmagmagmagmagmagdegdegarcsdegmagmagarcsdeg
float64float64objectobjectfloat64float64int32objectfloat64float64float64float64float64float64float64float64float64float64float64float64objectobjectobjectobjectobjectint32int32objectobjectint32float64float64objectfloat64int32float64float64int32int32float64float64float64float64float64object
343.49116.14822h53m57.75s16d08m53.63s0.070.069022535774+160853614.4940.0270.0361.613.8550.0290.0352.713.0610.0260.02755.9AAA22211100066556600n1998-10-017386.111-38.184U0.011514.814.11--0.0723445.4866870.6390.7941.4330
343.50016.16522h53m59.94s16d09m54.03s0.070.069022535994+160954014.2150.0250.02879.713.7950.0260.02755.713.6410.0460.04732.7AAA22211100066666600n1998-10-017386.132-38.175U0.77716.415.41--68.2222327.5798420.420.1540.5747
343.48016.11922h53m55.12s16d07m08.40s0.070.069022535512+160708313.8170.020.024115.013.4370.0260.02777.513.4070.0360.03740.6AAA22211100066666600n1998-10-017386.079-38.202U1.012815.714.51--111.754579199.7835530.380.030.4112
343.46116.16222h53m50.61s16d09m42.97s0.220.1910022535061+160942916.4750.1480.1499.915.6670.1390.1399.915.2950.1790.1797.1BBC22211100036352600n1998-10-017386.091-38.156U0.519316.516.02810608114.107665295.6650110.8080.3721.1813
343.52016.13022h54m04.87s16d07m46.75s0.080.06022540487+160746714.0120.0190.02396.113.4660.0260.02778.113.3160.0340.03544.2AAA22211100066666600n1998-10-017486.128-38.215U0.317716.315.21--122.49451123.0480390.5460.150.69614
343.43616.15222h53m44.64s16d09m07.89s0.070.069022534464+160907812.9920.0190.022245.812.5240.0230.024179.612.4430.0170.01998.7AAA22211100066446600n1998-10-017386.058-38.151U0.313815.514.31--189.384005274.3475920.4680.0810.54923
343.43416.13522h53m44.20s16d08m06.36s0.070.069022534420+160806314.8030.0310.03446.414.4230.0420.04331.214.4520.0760.07615.5AAA22211100066660600n1998-10-017386.044-38.165U0.422416.415.61--200.831987256.417140.38-0.0290.35126
343.46316.09922h53m51.04s16d05m54.91s0.070.069022535103+160554912.9450.0170.021256.712.5580.0170.019174.112.4450.0210.02398.5AAA22211100066446600n1998-10-017386.048-38.21U0.312214.814.01--203.161969208.4401160.3870.1130.527
343.45216.10422h53m48.37s16d06m15.62s0.070.069022534836+160615613.8780.0220.025108.713.5130.0260.02772.213.4130.0270.02840.4AAA22211100066445500n1998-10-017386.04-38.199U0.717815.514.81--207.889345220.5683240.3650.10.46528
343.43516.17422h53m44.49s16d10m26.61s0.070.069022534448+161026614.950.0370.03940.514.5010.0470.04829.114.3990.0740.07416.3AAA22211100066552600n1998-10-017386.073-38.133U1.118716.315.61--212.529977295.9745160.4490.1020.55129
343.55216.16422h54m12.43s16d09m49.15s0.10.0817822541243+160949115.9640.0770.07815.915.4480.0860.08712.615.2940.1660.1667.1AAC22211100026060600n1998-10-017486.184-38.203U0.614917.616.81--218.77079975.2688590.5160.1540.6735
343.53316.10322h54m08.02s16d06m09.33s0.080.06022540801+160609313.710.0230.026126.913.2420.0250.02696.013.1180.0310.03253.0AAA22211100066666600n1998-10-017486.122-38.244U0.24715.814.81--221.053726137.974640.4680.1240.59236
343.54616.11522h54m11.04s16d06m54.63s0.080.06022541103+160654610.4160.0180.0222636.59.8330.0180.022216.79.5560.0160.0181409.4AAA22211100066666600n1998-10-017486.144-38.2410--------0--225.435611121.8316060.5830.2770.8639
343.47316.08722h53m53.58s16d05m13.96s0.070.069022535358+160513911.80.0150.02736.911.1920.0190.021612.511.070.0170.019349.5AAA22211100066556600n1998-10-017386.05-38.225U0.116214.813.51--227.661794195.3024810.6080.1220.7340

In [15]:
idx_wise, idx, d2d, d3d = match_all_coord.search_around_sky(c_wise, sep_min)
match_wise = data_wise[idx_wise]
match_wise


Out[15]:
Table masked=True length=14
designationradecclonclatsigrasigdecsigradecw1mprow1sigmprow1snrw1rchi2w2mprow2sigmprow2snrw2rchi2w3mprow3sigmprow3snrw3rchi2w4mprow4sigmprow4snrw4rchi2nbnaw1satw2satw3satw4satpmrasigpmrapmdecsigpmdeccc_flagsext_flgvar_flgph_qualmoon_levw1nmw1mw2nmw2mw3nmw3mw4nmw4mdistangleid
degdegarcsarcsarcsmagmagmagmagmagmagmagmagmaspyrmaspyrmaspyrmaspyrarcsdeg
objectfloat64float64objectobjectfloat64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64int32int32float64float64float64float64int32int32int32int32objectint32objectobjectobjectint32int32int32int32int32int32int32int32float64float64object
J225357.74+160853.7343.49116.14822h53m57.75s16d08m53.70s0.02870.027-0.00239.2630.02150.923.178.1470.01957.631.035.8010.01382.72.7893.3870.0254.31.135100.00.00.00.0-247592236000019964AAAA110024242424131313130.147404349.0462510
J225359.94+160953.9343.50016.16522h53m59.95s16d09m53.97s0.05120.0505-0.005713.5870.02543.41.02513.6150.03233.80.931312.577---0.90.95519.076---2.50.8342100.00.00.00.0-1798-81990h0d000nnAAUU11002525252501401468.22026827.67969417
J225355.13+160708.1343.48016.11922h53m55.14s16d07m08.13s0.05080.0496-0.006413.3670.02543.31.14413.3730.03134.80.909311.9230.3413.20.95798.375--2.00.9141100.00.00.00.004-101914590000d000nnAABU110026262626012013111.940272199.65047653
J225350.60+160943.7343.46116.16222h53m50.60s16d09m43.74s0.06430.0649-0.007914.2540.02937.23.14814.0530.04524.01.04610.680.09811.01.0878.8130.4642.30.9725100.00.00.00.068196-437208000d1000nAAAC110025252424813013114.54805295.98473356
J225404.87+160746.7343.52016.13022h54m04.88s16d07m46.74s0.04940.050.000113.3570.02543.40.92713.4070.03135.11.05212.086--1.10.96899.198---1.00.9408100.00.00.00.00870900000000nnAAUU110024242424112012122.526853123.04281659
J225344.64+160907.8343.43616.15222h53m44.64s16d09m07.83s0.04430.04320.006512.3680.02543.61.23112.3970.02445.10.997611.9770.2793.91.1388.484--1.70.9392100.00.00.00.0-825911600000000nnAABU110027272626215015189.372069274.328968139
J225344.19+160806.2343.43416.13522h53m44.19s16d08m06.29s0.06580.066-0.01114.2410.02937.20.932714.2950.04623.50.939111.889--1.80.77299.199---2.00.8407100.00.00.00.0-124152601550000011nnAAUU110025252425014014200.944968256.403916155
J225351.03+160554.7343.46316.09922h53m51.04s16d05m54.76s0.04340.04210.006612.4310.02446.01.28612.4540.02444.61.15611.9490.2763.90.82348.981--0.20.9719100.00.0010.00.0106126600000000nnAABU110025252525113013203.265143208.409629160
J225348.36+160615.3343.45216.10422h53m48.36s16d06m15.30s0.05230.0511-0.006413.4020.02542.81.09713.4450.03333.30.992612.516---0.10.83129.117--0.00.9759100.00.00.00.0178822880000011nnAAUU110026262626014014208.197903220.531619165
J225344.48+161026.6343.43516.17422h53m44.48s16d10m26.63s0.06970.0696-0.011314.3440.0335.70.91914.4680.05420.10.911412.713---0.70.97868.964--0.20.9111100.00.00.00.033154-1621580000000nnAAUU110027272727014014212.594426295.971024169
J225412.42+160949.1343.55216.16422h54m12.43s16d09m49.15s0.10740.1089-0.030215.3270.04126.80.951115.6320.1338.20.936712.531---0.11.0099.143---1.31.062100.00.00.00.012-404349178359000001nnnABUU11002424524013013218.66326675.261655182
J225408.02+160609.3343.53316.10322h54m08.02s16d06m09.37s0.0460.045-0.003213.0210.02445.11.20313.040.02740.10.956612.194--1.20.89338.73--1.01.081100.00.00.00.0-1337537760000000nnAAUU110024242424012012221.070686137.952897186
J225411.17+160655.0343.54716.11522h54m11.17s16d06m55.01s0.03660.03450.0049.3850.02346.72.0469.1970.0253.11.5859.0310.0336.30.67548.7120.4322.50.8093100.00.00.00.00212238-653600000011nAAAC1100272727271414014226.859215121.496382192
J225353.57+160513.8343.47316.08722h53m53.58s16d05m13.84s0.03930.03720.00711.0080.02346.41.75311.1030.02152.61.25511.2050.1447.60.85478.769--0.41.009100.00.00.00.0-1034587440000000nnAABU110026262626214014227.78803195.304621193

Join table


In [16]:
# joindata = Table([match_2mass['j_m'], 
#                   match_2mass['j_m']-match_2mass['h_m'], 
#                   match_2mass['j_m']-match_2mass['k_m'],
#                   match_2mass['j_m']-match_wise['w1mpro'], 
#                   match_2mass['j_m']-match_wise['w2mpro'],
#                   match_2mass['j_m']-match_wise['w3mpro'],
#                   match_2mass['j_m']-match_wise['w4mpro'],
#                   match_2mass['j_m']-match_galex['NUVmag']], 
#                   names=('J', 'J-H', 'J-K', 'J-W1', 'J-W2', 'J-W3', 'J-W4', 'J-NUV'))

In [17]:
joindata = np.array([match_2mass['j_m'], 
                  match_2mass['j_m']-match_2mass['h_m'], 
                  match_2mass['j_m']-match_2mass['k_m'],
                  match_2mass['j_m']-match_wise['w1mpro'], 
                  match_2mass['j_m']-match_wise['w2mpro'],
                  match_2mass['j_m']-match_wise['w3mpro'],
                  match_2mass['j_m']-match_wise['w4mpro'],
                  match_2mass['j_m']-match_galex['NUVmag']])

joindata = joindata.T

In [18]:
joindata


Out[18]:
array([[ 14.494 ,   0.639 ,   1.433 ,   5.231 ,   6.347 ,   8.693 ,
         11.107 ,  -2.442 ],
       [ 14.215 ,   0.42  ,   0.574 ,   0.628 ,   0.6   ,   1.638 ,
          5.139 ,  -8.6035],
       [ 13.817 ,   0.38  ,   0.41  ,   0.45  ,   0.444 ,   1.894 ,
          5.442 ,  -6.5696],
       [ 16.475 ,   0.808 ,   1.18  ,   2.221 ,   2.422 ,   5.795 ,
          7.662 ,  -4.0011],
       [ 14.012 ,   0.546 ,   0.696 ,   0.655 ,   0.605 ,   1.926 ,
          4.814 ,  -8.1771],
       [ 12.992 ,   0.468 ,   0.549 ,   0.624 ,   0.595 ,   1.015 ,
          4.508 ,  -9.4532],
       [ 14.803 ,   0.38  ,   0.351 ,   0.562 ,   0.508 ,   2.914 ,
          5.604 ,  -7.3016],
       [ 12.945 ,   0.387 ,   0.5   ,   0.514 ,   0.491 ,   0.996 ,
          3.964 ,  -7.299 ],
       [ 13.878 ,   0.365 ,   0.465 ,   0.476 ,   0.433 ,   1.362 ,
          4.761 ,  -7.9779],
       [ 14.95  ,   0.449 ,   0.551 ,   0.606 ,   0.482 ,   2.237 ,
          5.986 ,  -7.1068],
       [ 15.964 ,   0.516 ,   0.67  ,   0.637 ,   0.332 ,   3.433 ,
          6.821 ,  -6.9099],
       [ 13.71  ,   0.468 ,   0.592 ,   0.689 ,   0.67  ,   1.516 ,
          4.98  ,  -7.642 ],
       [ 10.416 ,   0.583 ,   0.86  ,   1.031 ,   1.219 ,   1.385 ,
          1.704 , -11.3695],
       [ 11.8   ,   0.608 ,   0.73  ,   0.792 ,   0.697 ,   0.595 ,
          3.031 , -11.0555]])

Analysis

PCA


In [19]:
from sklearn import datasets
from sklearn.decomposition import PCA
from sklearn.preprocessing import scale

X = scale(joindata)

pca = PCA(n_components=2)
X_r = pca.fit(X).transform(X)

In [20]:
plt.scatter(X_r[:,0], X_r[:,1])
for i, name in enumerate(match_wise['designation']):
    for galaxyname in galaxy['designation']:
        if name == galaxyname:
            plt.scatter(X_r[i,0], X_r[i,1], color="red")


DBSCAN


In [21]:
from sklearn.cluster import DBSCAN
from sklearn.preprocessing import StandardScaler

X = scale(joindata)

db = DBSCAN(eps=2, min_samples=3).fit(X)

core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_

# Number of clusters in labels, ignoring noise if present.
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)

print('Estimated number of clusters: %d' % n_clusters_)
print(labels)


Estimated number of clusters: 1
[-1  0  0 -1  0  0  0  0  0  0  0  0  0  0]

Plot J-W1 vs J


In [22]:
# Black removed and is used for noise instead.
unique_labels = set(labels)
colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))]
for k, col in zip(unique_labels, colors):
    if k == -1:
        # Black used for noise.
        col = [0, 0, 0, 1]

    class_member_mask = (labels == k)

    
    ## J vs J-W1
    
    xy = X[class_member_mask & core_samples_mask]
    plt.plot(xy[:, 3], xy[:, 0], 'o', markerfacecolor=tuple(col), markeredgecolor='k', markersize=14)

    xy = X[class_member_mask & ~core_samples_mask]
    plt.plot(xy[:, 3], xy[:, 0], 'o', markerfacecolor=tuple(col), markeredgecolor='k', markersize=8)
    
    for i, name in enumerate(match_wise['designation']):
        for galaxyname in galaxy['designation']:
            if name == galaxyname:
                plt.plot(X[i,3], X[i,0], marker="X", markerfacecolor='red', markeredgecolor='none', markersize=8)  

plt.title('Estimated number of clusters: %d' % n_clusters_)
plt.show()


t-SNE


In [23]:
from sklearn.manifold import TSNE
X = scale(joindata)
X_r = TSNE(n_components=2).fit_transform(X)

In [24]:
plt.scatter(X_r[:,0], X_r[:,1])
for i, name in enumerate(match_wise['designation']):
    for galaxyname in galaxy['designation']:
        if name == galaxyname:
            plt.scatter(X_r[i,0], X_r[i,1], color="red")



In [ ]: