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 = ["M87", 187.705930, 12.391123, 0.2]
# 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):  182 2230 431

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 [31]:
sep_min = 2.0 * u.arcsec # minimum separation in arcsec

In [32]:
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:  164

Plot W1-J vs W1


In [33]:
# 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 [34]:
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[34]:
<matplotlib.lines.Line2D at 0x7fec06164c18>
  • W1-J < -1.7 => galaxy
  • W1-J > -1.7 => stars

In [35]:
# + 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:  43

Filter


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


Out[36]:
Table masked=True length=43
RAJ2000DEJ2000r.fovbFUVmage_FUVmagNUVmage_NUVmagFaflNaflFexfNexfFrNr
degdegdegmagmagmagmagdegdeg
float64float64float64uint8float64float32float64float32int16int16int16int16float64float64
187.70555412.3913760.453982315.13660.018614.26070.0066010160.0302420.012917
187.68333612.4260300.476495320.31490.224219.56770.097201010.0053300.005089
187.65867312.3766730.5001651----20.90300.17160100--0.004826
187.76622812.4247150.3956271----22.28580.36480000--0.003236
187.67481112.3182720.4904141----22.80010.470101700--0.002694
187.64681912.3324130.515444321.57330.429321.95690.32110128000.0032320.003691
187.74044112.4715740.4263661----20.78170.15020000--0.002711
187.70388212.4867760.4642431----15.66680.01140100--0.001435
187.79674212.4540090.3692541----20.95060.17040000--0.002328
..........................................
187.87564112.3216540.2975801----21.73380.27630000--0.003792
187.78353912.2278160.4140741----17.26190.0239256003--0.001324
187.78734712.2230640.4126661----16.69080.01830003--0.001343
187.84252312.5228670.3439161----18.64170.04710000--0.001215
187.89563812.3596850.2709031----21.39870.22140000--0.002748
187.55191112.5084010.3992011----19.71320.11760000--0.001706
187.53008312.4845520.3742271----22.01460.44960000--0.003407
187.53903712.2832780.4074521----19.01810.07820000--0.001718
187.82829912.5468180.3659931----20.41410.12170000--0.001461
187.89893912.4577550.2718901----20.86620.16390000--0.002676

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


Out[41]:
Table masked=True length=43
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
187.70612.39112h30m49.43s12d23m27.88s0.160.1417912304942+122327811.4390.1090.109926.511.2840.2220.222441.910.7330.1510.152510.8EEE22211100066666620n1999-12-07151283.77874.4910--------0--0.162435162.3594810.1550.5510.7060
187.68312.42612h30m43.90s12d25m32.43s0.280.23412304389+122532416.5250.1430.1438.615.8650.2180.2186.515.356------BDU22011000016260020n1999-12-07151283.65974.517U1.416618.717.21--148.41493326.9531470.66----14
187.65912.37612h30m38.08s12d22m34.95s0.160.13012303807+122234914.460.030.03257.313.9790.0370.03836.914.0210.0480.04924.7AAA22211100066663500n1999-12-07151283.6374.463U0.814816.415.51--174.51546252.2982020.481-0.0420.43919
187.76612.42512h31m03.93s12d25m28.24s0.150.07012310392+122528213.1410.0210.025200.012.6510.0310.032125.512.5420.0310.03296.5AAA22211100066666600n1999-12-07152283.95274.541U2.029115.014.41--244.14833860.4980380.490.1090.59926
187.67512.31912h30m42.01s12d19m06.83s0.230.21212304200+121906816.6790.1470.1477.416.012------16.025------BUU20010000016000000n1999-12-07151283.75174.413U0.24219.818.41--282.894154202.585158------29
187.64712.33212h30m35.28s12d19m55.82s0.230.2117812303527+121955816.6030.140.148.015.6880.1640.1647.715.1150.1250.1259.0BCB22211100016050600n1999-12-07151283.63974.418U0.435219.018.81--296.628512224.3300020.9150.5731.48832
187.74112.47212h30m57.74s12d28m17.97s0.140.13012305773+12281799.8590.0190.0223970.49.2510.0320.0332874.29.1390.0210.0232217.3AAA22211100066666600n1999-12-07151283.80974.5780--------0--314.48333722.7839540.6080.1120.7235
187.70412.48712h30m48.93s12d29m12.13s0.130.139012304893+12291217.0290.0130.02153805.96.6350.0470.04931982.36.4590.0090.01726171.0AAA11111100066666600n1999-12-07151283.66374.582T0.12019.558.652--344.169634358.8085780.3940.1760.5741
187.79712.45412h31m11.18s12d27m14.32s0.290.2617712311117+122714316.4790.130.1319.215.630.1380.1388.115.7040.2280.2285.2BBD22211100006060600n1999-12-07152284.02574.577U0.830918.216.81--390.86291754.6137650.849-0.0740.77550
.......................................................................................................................................
187.87512.32112h31m30.11s12d19m16.39s0.170.0718012313011+121916315.0310.0440.04535.114.5660.0620.06321.514.5920.0860.08614.6AAA22211100066561600n1999-12-07152284.44674.473U0.920716.715.71--647.162855112.8642580.465-0.0260.439143
187.78312.22812h31m08.02s12d13m39.80s0.190.08012310802+121339710.3290.0180.0222665.89.8580.0250.0261643.39.7670.0210.0231243.4AAA22211100066665500n1999-12-07152284.22774.357U0.518512.711.71--648.328968155.1274030.4710.0910.562144
187.78712.22312h31m08.94s12d13m22.42s0.190.08012310893+121322411.7690.0180.022707.711.530.0250.026352.311.4790.0210.023256.9AAA22211100066666600n1999-12-07152284.24574.354U0.331713.212.11--669.74594154.7129380.2390.0510.29154
187.84212.52312h31m22.17s12d31m22.16s0.130.07012312216+123122113.4570.0240.027149.513.2110.030.03174.913.1850.0320.03353.4AAA22211100066666600n1999-12-07152284.10974.656U0.212315.013.51--674.39516345.3142770.2460.0260.272157
187.89612.35912h31m34.96s12d21m33.47s0.130.07012313496+122133414.7050.0280.0354.414.3180.0380.03931.014.3810.0550.05520.4AAA22211100066660600n1998-01-1551284.47674.515U0.116316.215.21--677.01276599.7220170.387-0.0630.324159
187.55112.50812h30m12.35s12d30m30.19s0.090.078912301235+123030113.2850.0230.026169.212.9430.030.03195.912.8650.0280.02971.7AAA22211100066666600n1999-12-07150283.10674.557U1.125814.513.91--687.807526307.8794320.3420.0780.42163
187.53012.48412h30m07.31s12d29m03.56s0.10.088912300730+122903515.3020.0530.05526.414.8970.0710.07215.814.7420.0950.09512.7AAA22211100066161600n1999-12-07150283.0674.528U0.819717.016.11--702.260851298.5598120.4050.1550.56170
187.53912.28312h30m09.31s12d16m58.86s0.10.079012300931+121658812.0340.0190.022535.611.7280.0340.035293.611.6260.0180.02224.4AAA22211100066666600n1999-12-07150283.3274.339U1.418713.712.71--704.914506236.508250.3060.1020.408173
187.82812.54712h31m18.77s12d32m48.06s0.130.07012311876+123248014.1990.0270.0375.513.9310.040.0438.613.750.0310.03231.7AAA22211100066665500n1999-12-07152284.03374.675U0.229615.514.41--705.93707637.4904470.2680.1810.449174
187.89912.45812h31m35.76s12d27m27.13s0.10.0717912313576+122727115.1580.0370.03935.814.7250.0550.05621.314.640.0710.07116.1AAA22211100066361600n1998-01-1551284.38174.61U0.723616.715.71--719.69423870.5756070.4330.0850.518181

In [43]:
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[43]:
Table masked=True length=43
designationradecclonclatsigrasigdecsigradecw1mprow1sigmprow1snrw1rchi2w2mprow2sigmprow2snrw2rchi2w3mprow3sigmprow3snrw3rchi2w4mprow4sigmprow4snrw4rchi2nbnaw1satw2satw3satw4satpmrasigpmrapmdecsigpmdeccc_flagsext_flgvar_flgph_qualmoon_levw1nmw1mw2nmw2mw3nmw3mw4nmw4mdistangleid
degdegarcsarcsarcsmagmagmagmagmagmagmagmagmaspyrmaspyrmaspyrmaspyrarcsdeg
objectfloat64float64objectobjectfloat64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64int32int32float64float64float64float64int32int32int32int32objectint32objectobjectobjectint32int32int32int32int32int32int32int32float64float64object
J123049.43+122328.0187.70612.39112h30m49.43s12d23m28.04s0.02840.0291-0.00558.2370.02249.1111.98.1590.01957.178.626.9750.01475.521.245.0460.03531.35.511100.00.00.00.0-30833-5863300005n211AAAA122230302525131314140.12298284.2876260
J123043.89+122533.2187.68312.42612h30m43.90s12d25m33.22s0.06970.0732-0.005914.2130.03135.44.32614.4750.06117.70.881510.7910.09910.90.95118.591--1.30.9951100.00.00.00.01731768518800003000nAAAU122230302125913014149.088795327.109751209
J123038.08+122234.8187.65912.37612h30m38.08s12d22m34.86s0.06530.0665-0.010413.8440.02937.41.43114.1080.05420.20.886812.452--0.00.93668.844--0.40.9972100.00.00.00.0011001190000200nnAAUU122229292424013114174.436209252.255996295
J123103.89+122528.1187.76612.42412h31m03.90s12d25m28.14s0.04390.0431-0.010112.4640.02446.21.07812.5560.02642.40.966212.5330.492.20.92088.613--1.20.9314100.00.0010.00.02853-2550000211nnAACU124432322626013114243.69347560.464001626
J123042.01+121907.2187.67512.31912h30m42.02s12d19m07.30s0.31430.34460.060416.8580.10710.10.885916.461--1.90.865712.558---0.90.86969.052---1.51.071100.00.00.00.0-1641236555134800002nnnnAUUU1222731025012014282.405271202.594872708
J123035.26+121955.4187.64712.33212h30m35.27s12d19m55.46s0.07190.0762-0.001714.7230.03234.11.05114.4280.05121.30.964811.610.2145.11.1098.931--0.30.8999100.00.00.00.0511892712040000011nnAABU122231312526213014296.974558224.29915740
J123057.68+122816.4187.74012.47112h30m57.68s12d28m16.42s0.03510.0345-0.00659.0570.02347.21.369.1220.01955.71.5119.0250.03135.10.76068.208--1.70.9555100.00.00.00.0835-19335HH000nn1nAAAU1244313125251212013312.7354222.752056780
J123048.91+122912.0187.70412.48712h30m48.91s12d29m12.03s0.03420.032-0.0076.3950.08413.00.2776.4020.02446.11.766.4460.01666.91.2516.370.05918.41.038100.1170.0530.00.0-232379935000000000AAAA12223131252513131414344.079121358.753293851
J123111.14+122713.4187.79612.45412h31m11.14s12d27m13.41s0.14990.16110.021215.9860.05320.30.957616.0680.2095.21.00312.308--0.90.92769.1290.5282.11.121100.00.00.00.0-656517632560000000nnnABUC12442531124014014389.90046654.677417966
......................................................................................................................................................
J123130.11+121915.9187.87512.32112h31m30.12s12d19m15.93s0.06770.071-0.005814.5880.0336.30.946514.5260.05420.21.01612.732---1.11.0289.074---1.30.9188100.00.00.00.0-108156-221720000000nnAAUU124434342627016017647.35333112.9016581886
J123108.01+121339.4187.78312.22812h31m08.02s12d13m39.44s0.03780.0372-0.00859.6690.02346.41.7849.6930.02150.91.4519.5820.04822.70.86888.849--0.21.045100.00.00.00.01435-233500000000nAAAU1244363629291313014648.61707155.1470691891
J123108.93+121322.3187.78712.22312h31m08.93s12d13m22.33s0.03970.0394-0.00911.430.02346.31.63611.4560.02248.71.24911.3570.2015.40.80628.482--1.30.9839100.00.00.00.02541-7942hh00001nnAABU124435352828013014669.791617154.722771975
J123122.17+123121.8187.84212.52312h31m22.17s12d31m21.88s0.04660.0477-0.01213.1760.02346.40.97213.2190.0336.20.904111.92--1.80.95979.141---0.30.9073100.00.00.00.0426936760000000nnAAUU124430302424014014674.26437145.3365342000
J123134.96+122133.4187.89612.35912h31m34.96s12d21m33.47s0.06210.063-0.005614.2580.02839.30.889514.3590.05220.70.966312.548--0.20.90278.634--1.00.9683100.00.00.00.07122551340000000nnAAUU124434342426015116676.99755799.7220842012
J123012.34+123030.0187.55112.50812h30m12.34s12d30m30.07s0.04610.0457-0.009112.830.02445.41.41412.8470.02739.71.04512.5330.4942.20.91258.954--0.21.157100.00.00.00.0-4463-70670000011nnAACU122227272424012012687.840739307.8645242067
J123007.29+122903.4187.53012.48412h30m07.30s12d29m03.47s0.07670.0809-0.006114.7660.03234.41.05514.8210.07115.30.955412.357--0.60.98398.935--0.10.9351100.00.00.00.080197762160000000nnAAUU122226261723012012702.344308298.5479572128
J123009.31+121658.8187.53912.28312h30m09.31s12d16m58.83s0.04040.0391-0.007911.590.02445.71.18411.6340.02249.91.14611.7150.2244.91.0188.718--0.71.104100.00.00.00.0-5444-12440000011nnAABU122231312626014015704.973852236.5082162139
J123118.77+123247.9187.82812.54712h31m18.77s12d32m47.93s0.05320.0549-0.01313.7690.02543.21.09113.8110.03729.21.02412.292--0.61.018.484--1.11.104100.00.00.00.0-8398-1101060000001nnAAUU124428282323012013705.85697237.4996842143
J123135.75+122727.0187.89912.45812h31m35.76s12d27m27.07s0.07380.0763-0.012114.7440.0335.71.0814.8160.07215.00.980912.109--0.40.83478.851---0.81.026100.00.00.00.0102179931950000001nnAAUU124431321826013013719.58647870.5778152222

Join table


In [44]:
# 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 [45]:
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 [46]:
# 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 [47]:
len(match_2mass['j_m'])


Out[47]:
43

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


Out[48]:
43

Analysis

PCA


In [49]:
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 [50]:
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 [51]:
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: 2
[-1 -1  0  0  1 -1  0  0  1  0 -1  0  0  0  0  0 -1  0 -1  0  0  0  0  0
  0 -1  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]

Plot J-W1 vs J


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

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


In [ ]:


In [ ]: