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 = ["PKS J0006-0623", 1.55789, -6.39315, 1.0]
# 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):  4802 38322 10105

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 = 1.0 * 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:  4292

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

cutw1j = -1.7

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

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

In [10]:
w1j_galaxy = w1j[w1j<cutw1j]
w1_galaxy = w1[w1j<cutw1j]
j_galaxy = j[w1j<cutw1j]

plt.scatter(w1j, w1, marker='o', color='blue')
plt.scatter(w1j_galaxy, w1_galaxy, marker='.', color="red")
          
plt.axvline(x=cutw1j) # https://academic.oup.com/mnras/article/448/2/1305/1055284


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

In [11]:
# + 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:  805

Filter


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


Out[12]:
Table masked=True length=805
RAJ2000DEJ2000r.fovbFUVmage_FUVmagNUVmage_NUVmagFaflNaflFexfNexfFrNr
degdegdegmagmagmagmagdegdeg
float64float64float64uint8float64float32float64float32int16int16int16int16float64float64
1.557781-6.3930410.101573320.63680.160919.95300.075900000.0015490.001684
1.554137-6.3660780.126470322.83890.470421.86620.277200000.0013180.003755
1.553860-6.3536130.1385621----22.17030.27850000--0.002755
1.590100-6.3630290.1419221----20.00850.07370000--0.001814
1.558215-6.3486470.1443651----22.65670.37930000--0.003133
1.502271-6.4330940.0601251----18.39120.031925625600--0.001411
1.614844-6.4450650.1000441----21.14660.1444256000--0.002612
1.605844-6.4737300.0823481----19.07700.04390000--0.001269
1.492365-6.4629680.0411611----21.82850.26840000--0.003980
..........................................
2.078192-7.2451450.1162301----20.70470.13080000--0.002418
2.210007-7.1516980.2684071----17.53700.02460000--0.001371
0.554430-6.3656700.1421151----19.35740.08940000--0.001240
0.737629-5.8186220.340751321.08670.281620.56640.127700000.0027990.005440
1.261392-7.3468850.2561181----19.29890.0911256000--0.004606
2.051938-7.2625970.0906781----20.53850.11670000--0.001507
2.214898-5.6372900.1875191----19.95540.09730000--0.002012
2.135354-7.2113400.1750391----20.72920.13150000--0.002755
0.818013-5.7166240.220099320.22120.173420.14350.100700000.0037350.003502
2.097034-7.2373590.1320031----18.14300.03370000--0.001302

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


Out[13]:
Table masked=True length=805
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
1.558-6.39300h06m13.89s-06d23m35.53s0.120.124500061388-062335514.7360.0360.03752.913.8390.0390.0449.912.8780.030.03261.7AAA22211100066666600s1998-10-078693.505-66.647U0.723019.117.81--0.207142200.2070.8970.9611.8580
1.554-6.36600h06m13.00s-06d21m57.42s0.280.263300061299-062157417.2130.2090.2095.416.2970.2070.2075.215.6140.2330.2335.0CCD22211100006060500s1998-10-078693.527-66.62U0.725719.518.41--98.830962352.214490.9160.6831.5991
1.554-6.35300h06m12.97s-06d21m12.43s0.120.18800061297-062112413.7680.0240.027128.913.3120.0320.03481.113.1810.0370.03846.7AAA22211100066666600s1998-10-078693.541-66.609U0.921116.115.01--143.570458354.4985880.4560.1310.5872
1.590-6.36300h06m21.62s-06d21m47.34s0.120.119000062161-062147312.1770.0190.022558.011.8830.0250.027302.511.7930.0230.025167.6AAA22211100066665500s1998-10-078693.611-66.634U0.813414.713.01--157.88912146.8410740.2940.090.3845
1.558-6.34900h06m13.97s-06d20m56.07s0.150.148400061397-062056016.0340.0810.08216.015.8370.1440.1457.915.4720.2150.2155.7ABC22211100016060600s1998-10-078693.555-66.607U0.517617.516.91--159.2793370.4324510.1970.3650.5626
1.502-6.43300h06m00.56s-06d25m59.63s0.130.12000060056-062559612.530.0210.024403.112.2540.0220.024214.912.2080.0240.026114.4AAA22211100066665500s1998-10-078693.336-66.658U0.923014.613.31--245.570685234.0127110.2760.0460.32219
1.615-6.44500h06m27.60s-06d26m42.45s0.20.197700062760-062642416.2880.1010.10212.715.9780.1580.1587.015.589------ACU22011000016060000s1998-10-078793.576-66.718U0.919317.816.61--277.08834132.4774570.31----22
1.606-6.47400h06m25.41s-06d28m26.14s0.080.079000062540-062826112.4180.0220.025446.912.1850.0250.026229.012.1110.0250.026125.0AAA22211100066666600s1998-10-078793.524-66.74U0.410714.613.21--337.656046149.4592810.2330.0740.30733
1.492-6.46300h05m58.12s-06d27m46.12s0.140.12100055812-062746115.6030.0830.08423.814.9350.0890.08918.214.4170.0970.09715.0AAA22211100066666600s1998-10-078693.28-66.68U0.417817.515.31474915343.740799223.147670.6680.5181.18635
.......................................................................................................................................
2.078-7.24500h08m18.80s-07d14m43.24s0.090.07000081879-071443215.1130.0460.04730.414.5080.070.0719.814.530.10.111.7AAA22211100066140600s1998-10-162893.738-67.639U0.427316.715.61--3587.84807148.7988570.605-0.0220.5834770
2.210-7.15200h08m50.39s-07d09m06.25s0.140.06000085039-070906212.0530.0270.03526.311.7440.020.022260.811.7350.0270.028159.4AAA22211100066665500s1998-10-163094.154-67.611U0.920314.012.91--3590.514636139.5538720.3090.0090.3184777
0.555-6.36600h02m13.08s-06d21m56.89s0.080.07000021308-062156810.7790.0210.0242093.310.2980.020.0221348.110.2020.0190.021777.4AAA22211100066666600s1998-10-077291.317-66.169U1.48913.312.41--3591.153468271.5151960.4810.0960.5774778
0.737-5.81900h02m56.98s-05d49m07.14s0.270.229200025697-054907116.680.1480.1488.215.8810.1830.1847.115.3510.1880.1886.1BCC22211100005050600s1998-09-17992.335-65.767U0.826017.516.91--3592.131351305.1084340.7990.531.3294780
1.261-7.34700h05m02.74s-07d20m49.56s0.070.07800050273-072049512.3950.0210.024456.512.1280.0240.025241.412.0250.0230.025140.1AAA222111s0s66665500s1998-10-078491.728-67.364U0.720214.313.41--3593.991102197.1311520.2670.1030.374784
2.052-7.26300h08m12.50s-07d15m45.96s0.080.06000081249-071545911.6990.0190.023704.411.3370.0230.024366.511.2170.0170.019248.1AAA22211100066666600s1998-10-162893.657-67.643U1.421414.312.91--3594.586985150.5951150.3620.120.4824786
2.215-5.63700h08m51.59s-05d38m14.92s0.120.1000085158-053814913.4490.0180.022172.913.0840.0270.029107.213.10.0270.02955.8AAA22211100066665500s1998-09-172895.788-66.239U0.713815.314.41--3596.4470540.8855990.365-0.0160.3494791
2.135-7.21200h08m32.50s-07d12m41.55s0.10.06000083249-071241514.8720.0350.03737.914.5660.0660.06718.714.4960.0830.08312.1AAA22211100066260600s1998-10-162993.911-67.633U0.213216.515.81--3597.471036145.0151570.3060.070.3764797
0.818-5.71700h03m16.37s-05d42m59.84s0.310.258900031637-054259816.8440.170.1717.316.153------15.570.2270.2285.2CUD20210100005000600s1998-09-171092.622-65.713U0.22417.217.11--3597.649849312.567567----1.2744798
2.097-7.23700h08m23.30s-07d14m14.98s0.090.06000082329-071414912.5010.0190.023336.512.2150.020.022163.312.220.0240.02698.5AAA22211100066666600s1998-10-162993.791-67.64U0.116514.413.61--3599.16787147.6539220.286-0.0050.2814801

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

idx_wise, idx, d2d, d3d = c_2mass.search_around_sky(c_wise, sep_min)
match_wise = data_wise[idx_wise]
match_wise


Out[17]:
Table masked=True length=805
designationradecclonclatsigrasigdecsigradecw1mprow1sigmprow1snrw1rchi2w2mprow2sigmprow2snrw2rchi2w3mprow3sigmprow3snrw3rchi2w4mprow4sigmprow4snrw4rchi2nbnaw1satw2satw3satw4satpmrasigpmrapmdecsigpmdeccc_flagsext_flgvar_flgph_qualmoon_levw1nmw1mw2nmw2mw3nmw3mw4nmw4mdistangleid
degdegarcsarcsarcsmagmagmagmagmagmagmagmagmaspyrmaspyrmaspyrmaspyrarcsdeg
objectfloat64float64objectobjectfloat64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64int32int32float64float64float64float64int32int32int32int32objectint32objectobjectobjectint32int32int32int32int32int32int32int32float64float64object
J000613.88-062335.21.558-6.39300h06m13.89s-06d23m35.29s0.03390.03270.003812.1510.02346.51.86811.0090.0255.11.5758.0220.02152.31.1165.520.04226.00.8461100.00.00.00.0-69129-12046000009800AAAA110023232323131313130.106915298.3458190
J000613.00-062157.51.554-6.36600h06m13.00s-06d21m57.51s0.11280.1167-0.030915.4120.04424.50.823515.0610.08712.50.980511.9120.3163.41.0378.688--0.71.13100.00.00.00.01243942774110000011nnAABU11002424122411301398.725263352.28405823
J000612.96-062112.51.554-6.35300h06m12.96s-06d21m12.56s0.05080.05090.006913.1770.02543.01.03113.2280.03233.40.881712.037--1.20.86048.738--0.60.9099100.00.00.00.02882-1840000011nnAAUU110025252525013013143.45453354.43971554
J000621.63-062147.21.590-6.36300h06m21.63s-06d21m47.27s0.03960.03770.007211.7480.02248.51.4211.7810.02150.70.912412.3190.4072.70.99188.894--0.40.9516100.00.00.00.0195052490000000nnAACU110024242525014014158.04856446.86325172
J000613.98-062056.11.558-6.34900h06m13.98s-06d20m56.14s0.12520.131-0.033815.5950.04723.01.02515.670.1447.50.846112.532---1.50.94618.836--0.20.9917100.00.00.00.0-207424779448000000nnnABUU11002626226014014159.2069880.46612775
J000600.55-062559.51.502-6.43300h06m00.55s-06d25m59.53s0.04150.04050.009312.1630.02446.11.26512.180.02347.50.911212.2510.4372.50.85178.529--0.70.9465100.00.00.00.0-16055600000001nnAACU110022222222013013245.63661234.052195176
J000627.58-062643.01.615-6.44500h06m27.59s-06d26m43.07s0.15590.1602-0.04415.9130.05519.81.00815.9170.1845.90.869512.413--0.40.98788.935---0.61.031100.00.00.00.0-286604-102625D0000nnnnABUU11002223223013013277.306481132.610592220
J000625.41-062825.81.606-6.47400h06m25.42s-06d28m25.86s0.0420.04020.003712.060.02346.81.47412.1130.02346.31.12611.5820.2294.70.95848.814---0.30.8055100.00.00.00.0-2957158570000011nnAABU110023232323013013337.47995149.414127327
J000558.12-062745.91.492-6.46300h05m58.13s-06d27m45.95s0.05590.0554-0.004913.7820.02641.32.2913.5520.03630.01.13811.923--1.20.99358.289--1.41.02100.00.00.00.069118-3331220000000nnAAUU110022222222012013343.582513223.160154337
......................................................................................................................................................
J000818.79-071443.12.078-7.24500h08m18.79s-07d14m43.10s0.07930.081-0.02114.6450.03332.61.02614.6380.06417.01.0812.601---0.80.92638.881--0.00.878100.00.00.00.0542181272280000000nnAAUU2200222221220131133587.685479148.79893638033
J000850.38-070906.32.210-7.15200h08m50.39s-07d09m06.39s0.04070.03820.006511.7150.02346.81.22411.7490.02249.81.05711.4260.2095.20.80429.137--0.01.077100.00.00.00.0215218510000011nnAABU2200262625251140153590.565637139.55641338101
J000213.11-062156.80.555-6.36600h02m13.12s-06d21m56.86s0.03820.03560.005310.150.02248.51.32510.2180.0253.11.51210.150.06616.41.099.064---0.11.276100.00.00.00.004304200000010nAAAU34002121212111110113590.663527271.51583238104
J000257.01-054907.00.738-5.81900h02m57.01s-05d49m07.06s0.08330.0849-0.01914.90.03531.11.06514.7210.0715.61.01110.4390.08412.91.0348.5480.3583.00.8331100.00.00.00.014929044229900000000nAAAC34002323172313140143591.736218305.11440538139
J000502.73-072049.41.261-7.34700h05m02.74s-07d20m49.50s0.0420.04070.008212.0160.02347.31.83312.0810.02446.01.24112.271--0.60.86978.318--1.30.7709100.00.00.00.0-1475776560000000nnAAUU2200232323230130133593.927626197.13114338184
J000812.49-071546.22.052-7.26300h08m12.49s-07d15m46.22s0.040.03850.005511.1760.02346.44.87111.2550.02249.71.14411.1120.1696.40.95898.819---0.10.9838100.00.00.00.0-1150125510000110nnAABU2200212121214110113594.778226150.59817738198
J000851.59-053814.82.215-5.63700h08m51.59s-05d38m14.89s0.04760.04630.006713.0050.02444.81.07813.0310.02838.31.08612.265--0.40.8548.981--0.11.161100.00.00.00.0397473750000011nnAAUU1100262626260120123596.4955540.88589738245
J000316.36-054300.10.818-5.71700h03m16.37s-05d43m00.20s0.10090.1023-0.031815.1910.03828.41.07114.8770.09111.90.822111.6430.2963.70.8798.148--1.20.8215100.00.00.00.0-3143501863580000011nnAABU1100212110210110113597.492733312.56215538269
J000832.50-071241.52.135-7.21200h08m32.50s-07d12m41.57s0.07630.0783-0.016414.5330.03134.60.840814.6830.0715.60.845612.562---0.80.9458.42--1.10.8246100.00.00.00.0-233200-2352090000000nnAAUU2200212116210120123597.545643145.01398238271
J000823.30-071415.02.097-7.23700h08m23.31s-07d14m15.00s0.04290.04130.006312.1430.02347.21.35112.1820.02543.70.946912.024--0.90.98029.011---0.20.9598100.00.00.00.0110577570000000nnAAUU2200242424241130143599.254058147.65240238303

Join table


In [18]:
# 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 [19]:
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 [20]:
# joindata = np.array([match_2mass['j_m'], match_2mass['h_m'], match_2mass['k_m'], 
#                      match_wise['w1mpro'], match_wise['w2mpro'], match_wise['w3mpro'], match_wise['w4mpro'],
#                      match_galex['NUVmag']])

# joindata = joindata.T

In [21]:
len(match_2mass['j_m'])


Out[21]:
805

In [22]:
len(match_wise['w3mpro'])


Out[22]:
805

Analysis

PCA


In [23]:
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 [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")


DBSCAN


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

X = scale(joindata)

db = DBSCAN(eps=0.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: 13

Plot J-W1 vs J


In [34]:
# 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 [35]:
from sklearn.manifold import TSNE
X = scale(joindata)
X_r = TSNE(n_components=2).fit_transform(X)

In [36]:
plt.scatter(X_r[:,0], X_r[:,1], marker='.', color="blue")
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], marker='.', color="red")



In [ ]: