This notebook is for re-computing a subset of the master list that is in the NSA footprint, including K-corrections


In [1]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
import tempfile

if 'saga_base_dir' not in locals():
    saga_base_dir = os.path.abspath('..')

if saga_base_dir not in sys.path:
    os.chdir(saga_base_dir)

In [2]:
from __future__ import print_function, division

from collections import Counter, OrderedDict

import numpy as np

from astropy import units as u
from astropy.coordinates import *
from astropy import table, cosmology, constants as cnst
from astropy.visualization import hist as ahist

#SAGA imports
import hosts
import targeting
import kcorrect
from masterlist import masterlist as masterlist_module

In [3]:
%matplotlib inline
from matplotlib import style, pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

plt.rcParams['image.cmap'] = 'viridis'
plt.rcParams['image.origin'] = 'lower'
plt.rcParams['axes.prop_cycle'] = style.library['seaborn-deep']['axes.prop_cycle']
plt.rcParams['figure.figsize'] = (14, 8)
plt.rcParams['axes.titlesize'] =  plt.rcParams['axes.labelsize'] = 16
plt.rcParams['xtick.labelsize'] =  plt.rcParams['ytick.labelsize'] = 14

Preliminaries/definitions


In [4]:
# bands used here ugrizJHK
# these are Rx = Ax/E(B-V) for R_V~=3.1

# SFD 98 values 
sfd_Rx = np.array([5.155,3.793,2.751,2.086,1.479,0.902,0.576,0.367])

# Schlafly & FInkbeiner 2011
sandf_Rx = np.array([4.239, 3.303, 2.285, 1.698, 1.263, 0.709, 0.449,0.302])

#from Yuan+ 13 : https://arxiv.org/abs/1301.1427v1
yuan_FN_Rx = np.array([4.89, 7.24])

In [5]:
A_MAG = 2.5/np.log(10)
def flux_ivar_to_mag(flux, ivar):
    mag = -2.5 * np.log10(flux)
    
    sd = ivar**-0.5
    mag_err = A_MAG * sd/flux
    
    return mag, mag_err

def mag_err_to_maggies(mag, mag_err):
    flux = 10**(mag/-2.5)
    flux_err_sd = mag_err * flux/A_MAG
    
    return flux, flux_err_sd**-2

Set up the K-correction machinery


In [6]:
kcorrect.load_templates()

def load_filters_by_name(bandnmfns, band_shift=0.0, verbose=False):
    with tempfile.NamedTemporaryFile() as ntf:
        ntf.write('KCORRECT_DIR\n')
        for bandnm in bandnmfns:
            fn = 'data/filters/{}'.format(bandnm)
            truefn = os.path.join(os.environ['KCORRECT_DIR'], fn)
            if not os.path.isfile(truefn):
                raise IOError('Filter file {} does not exist'.format(truefn))
            ntf.write(fn)
            ntf.write('\n')

        ntf.seek(0)
        if verbose:
            !cat $ntf.name
        kcorrect.load_filters(ntf.name, band_shift)

In [7]:
# used way below when actually computing k-corrections
FNugrizJHK_filters = ['galex_{}UV.par'.format(bandnm) for bandnm in 'FN']
FNugrizJHK_filters.extend(['sdss_{}0.par'.format(bandnm) for bandnm in 'ugriz'])
FNugrizJHK_filters.extend(['twomass_{}.par'.format(bandnm) for bandnm in ('J','H','Ks')])

In [8]:
def do_kcorrs(maggies, maggie_ivars, redshifts, filternames, band_shift_to=None):
    
    if filternames is not None:
        load_filters_by_name(filternames)
    
    if np.isscalar(redshifts):
        maggies = [maggies]
        maggie_ivars = [maggie_ivars]
        redshifts = [redshifts]
    if len(maggies) != len(maggie_ivars) or len(maggies) != len(redshifts):
        raise ValueError('maggies, maggie_ivars, and redshifts must all be matching length')
        
    coeffs = []
    rms = []
    rm0s = []
    
    for m, mi, z in zip(maggies, maggie_ivars, redshifts):
        coeffs.append(kcorrect.fit_nonneg(z, m, mi))
        rms.append(kcorrect.reconstruct_maggies(coeffs[-1]))
        
    if band_shift_to:
        load_filters_by_name(filternames, band_shift=band_shift_to)
        
    for coeff in coeffs:
        rm0s.append(kcorrect.reconstruct_maggies(coeff, redshift=0.))
        
    flux_kcorr = np.array(rms)[:, 1:]/np.array(rm0s)[:, 1:]
    mag_kcorr = -2.5*np.log10(flux_kcorr)
    return mag_kcorr, flux_kcorr

Load masterlist and associated bits


In [9]:
# this is for the masterlist from dropbox

# masterlist = table.Table.read('SAGADropbox/hosts/masterlist.csv', data_start=2)

# units = table.Table.read('SAGADropbox/hosts/masterlist.csv', data_end=2)
# for c in masterlist.colnames:
#     masterlist[c].unit = units[c][0].replace('#', '').replace('degrees', 'degree')

    
# masterlist

In [10]:
# uncomment this to load the "old" masterlist but make it look like the new one
masterlist = table.Table.read('masterlist/masterlist.csv', data_start=2)

units = table.Table.read('SAGADropbox/hosts/masterlist.csv', data_end=2)
for c in masterlist.colnames:
    if c in units.colnames:
        masterlist[c].unit = units[c][0].replace('#', '').replace('degrees', 'degree')
    else:
        del masterlist[c]
        
vhe_col = np.zeros_like(masterlist['vhelio'])
vhe_col.name = 'vhelio_err'
vhe_col.mask[:] = True
masterlist.add_column(vhe_col, masterlist.colnames.index('vhelio')+1)
masterlist


Out[10]:
<Table masked=True length=18161>
RADecPGC#NSAIDothernamevheliovhelio_errdistancerizIK
degdegstringkm / skm / sMpcmagmagmagmagmag
float64float64int64int64str28float64float64float64float64float64float64float64float64
155.4118006990.900255164384--464--700.781494141--12.944350242617.84091313317.859253243817.9387725156----
168.044331058-0.979240347779--858--3976.91381836--62.274604797416.110251571216.012892867615.9054061427--13.32
167.573676285-0.263963231217--878--3859.34301758--59.689205169718.378421354218.297853040618.1733050822--13.476
176.53220815-0.457941560233--1189--3915.22314453--61.129993438717.604281618317.4981929817.3905078909--13.562
175.8278850170.212515965092--1212--63.835975647--2.1578984260613.255274238713.135555687112.8214039231----
185.86139022-0.411951305215--1398---35.2995071411--1.5616883039516.700818048716.694526659216.7462901938----
188.1174627810.388846619893--1498--1514.17663574--23.868576049813.188979202512.945252472112.936596924----
189.186292190.563405647876--1539--3739.31225586--60.003284454318.308250681618.220816866618.1446879069----
189.1278272820.22202937172--1540--3724.88232422--59.749282836916.239768190216.161439103916.0785190294----
.......................................
338.8252917-45.5136667----g2235181-4530483020.10922189--43.9110241265--------12.596
338.7727917-46.4604722----g2235056-462738936.551638792--13.5436535358--------13.413
336.2564167-51.79575----g2225015-5147451905.78065551--27.6294136391--------12.343
345.6082917-50.0628889----g2302259-5003463674.25636525--53.5121354687----------
343.6907083-49.8007222----g2254457-4948023757.59866857--54.7376695699--------12.217
347.8368333-43.4229444----g2311207-4325231558.9207816--22.580401005--------12.992
336.8646667-42.9764444----g2227276-4258343137.92765789--45.6379196917----------
339.1618333-43.03375----g2236389-4302012737.10514154--39.7672014637----------
255.6157083-24.36075----g1702281-24213525.6241787502--0.369675390547--------12.397
256.3733333-21.7145----g1705296-21425227.7952577435--0.400999433819--------12.647

In [11]:
nsa = table.Table(hosts.get_nsa())

In [12]:
#for NSA we have this round-about but simple way to get E(B-V) so we can get the S&F extinction
# See end of the notebook for proof that it works

nsa['E(B-V)'] = np.mean(np.array(nsa['EXTINCTION'])[:,-5:]/sfd_Rx[:5], axis=1)

In [13]:
twomassxsc = masterlist_module.load_2mass_xsc('masterlist/2mass_xsc_irsa.tab')
twomassxsc


Out[13]:
<Table masked=True length=1646844>
radecr_k20fej_m_k20fej_msig_k20fej_flg_k20feh_m_k20feh_msig_k20feh_flg_k20fek_m_k20fek_msig_k20fek_flg_k20fek_bak_phij_m_extj_msig_exth_m_exth_msig_extk_m_extk_msig_extcc_flg
float64float64float64float64float64int64float64float64int64float64float64int64float64int64float64float64float64float64float64float64str1
161.902771-1.1851825.015.1240.109014.3160.135013.8750.15601.09014.970.18413.990.19113.6120.2320
176.17416424.9015855.015.5080.102014.7990.129014.4460.1601.09015.2940.14814.5140.17514.1690.2210
122.197197-10.1826865.015.5730.1380------14.1980.1901.09015.2980.19714.9790.013.9860.2910
67.092613-39.65342711.412.9630.036012.2390.041011.9070.07300.6-4012.7750.04112.1360.04711.8440.0790
58.178047-48.6426096.314.3770.067313.580.072312.980.07930.92514.00.08213.2740.09912.8560.1170
321.14444-47.2382356.414.7540.095013.9840.112013.490.10501.09014.4760.13213.6060.14913.3040.1680
73.605751-22.8397228.415.2030.126014.5230.145013.6160.12700.5-5515.0140.18914.3850.2313.2410.1670
163.98437551.7580995.015.3460.096014.750.153014.0430.11801.09015.1140.1414.7270.27813.7880.1720
312.112518-65.0920728.515.0030.091114.2770.108313.7070.11130.4-3514.9220.16414.0770.16213.2610.1330
266.161621-58.2798426.614.8610.103214.1980.116213.8830.14320.67514.7040.15914.0310.18113.660.2110
...............................................................
205.39334130.4131055.015.6710.121314.7190.119314.2250.13231.09015.510.19614.6980.21514.1180.2230
254.751343-9.5253235.215.0580.081014.2350.075013.9470.1200.78014.8710.13214.210.13213.8920.2140
171.49125710.3860366.014.3940.064013.5970.061013.3480.100.8-2014.1790.08613.4540.09213.2140.1540
73.760513-9.5186175.415.9680.1350------14.5540.17100.5-3015.4360.15515.0890.014.3940.310
227.05172717.9917459.513.990.052013.2540.053012.820.08400.7-2013.9230.07912.9940.06712.6260.1050
249.71566857.0957765.314.7190.059014.1180.075013.7320.09400.8-8014.4420.07613.7860.09813.5950.1450
106.57493620.801215.814.8210.062014.0550.075013.9060.10100.7014.6190.09113.7860.10613.6620.1490
115.48401657.3542755.015.5870.1240------14.1530.12301.09015.5730.22814.9580.014.0830.2130
19.17658640.4934775.015.3180.095014.6780.128014.1130.1301.09015.10.18414.3720.18114.070.230
300.324829-55.9836015.014.860.102314.0630.105313.9040.15231.09014.7650.17114.0180.18513.9040.1520

Build the sub-master list and add in the relevant photometry


In [14]:
colstokeep = ['RA', 'Dec', 'NSAID', 'othername', 'vhelio', 'vhelio_err', 'distance']
submaster0 = masterlist[~masterlist['NSAID'].mask][colstokeep]
submaster0


Out[14]:
<Table masked=True length=9325>
RADecNSAIDothernamevheliovhelio_errdistance
degdegstringkm / skm / sMpc
float64float64int64str28float64float64float64
155.4118006990.900255164384464--700.781494141--12.9443502426
168.044331058-0.979240347779858--3976.91381836--62.2746047974
167.573676285-0.263963231217878--3859.34301758--59.6892051697
176.53220815-0.4579415602331189--3915.22314453--61.1299934387
175.8278850170.2125159650921212--63.835975647--2.15789842606
185.86139022-0.4119513052151398---35.2995071411--1.56168830395
188.1174627810.3888466198931498--1514.17663574--23.8685760498
189.186292190.5634056478761539--3739.31225586--60.0032844543
189.1278272820.222029371721540--3724.88232422--59.7492828369
.....................
197.62134460434.2365738574143073[MU2012]J1310+34B850.001342773--16.2950172424
21.17007057413.85743178299129446UM1022188.00341797--29.1069145203
137.44493743233.1429985898135710PGC50659341970.00305176--31.2207012177
170.5995894253.8647827749139275PGC50659383059.00488281--44.9665794373
209.37500578529.0581355972144164PGC50659392250.00341797--32.8402786255
258.2313729772.0666627063147813PGC50659401307.0020752--23.3953380585
349.7047238747.0984132704151085PGC50659513252.00512695--45.7964935303
349.8951595038.76137739156151136PGC50659523117.00488281--43.6976165771
350.1712064288.75078330124151187PGC50659533029.00463867--42.3650932312
351.4752184918.545669686151492PGC50659541506.00231934--19.911945343

In [15]:
#integrate NSA photometry

nsatoadd = nsa[('NSAID', 'E(B-V)')]
for i, band in enumerate('FNugriz'):
    nsatoadd[band+'_flux'] = maggies = nsa['SERSICFLUX'][:, i]/1e9
    nsatoadd[band+'_flux_ivar'] = ivar = nsa['SERSICFLUX_IVAR'][:, i]*1e18
    nsatoadd[band+'_flux'].unit = nsatoadd[band+'_flux_ivar'].unit = 'maggie'
    nsatoadd['NSA_kcorrect_' + band] = nsa['KCORRECT'][:, i]
    
    mag, mag_err = flux_ivar_to_mag(maggies, ivar)
    nsatoadd[band] = mag
    nsatoadd[band+'_err'] = mag_err
    
    
submaster1 = table.join(submaster0, nsatoadd, 'NSAID')
submaster1


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:3: RuntimeWarning: divide by zero encountered in log10
  app.launch_new_instance()
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:3: RuntimeWarning: invalid value encountered in log10
  app.launch_new_instance()
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:6: RuntimeWarning: divide by zero encountered in true_divide
Out[15]:
<Table masked=True length=9325>
RADecNSAIDothernamevheliovhelio_errdistanceE(B-V)F_fluxF_flux_ivarNSA_kcorrect_FFF_errN_fluxN_flux_ivarNSA_kcorrect_NNN_erru_fluxu_flux_ivarNSA_kcorrect_uuu_errg_fluxg_flux_ivarNSA_kcorrect_ggg_errr_fluxr_flux_ivarNSA_kcorrect_rrr_erri_fluxi_flux_ivarNSA_kcorrect_iii_errz_fluxz_flux_ivarNSA_kcorrect_zzz_err
degdegstringkm / skm / sMpcmaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggiemaggie
float64float64int64str28float64float64float64float64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32
147.176446949-0.3540304166432PGC11454361883.54833984--29.59018516540.08770285438819.7141e-093.07981e+180.00029350720.03150.06368831.46447e-085.0814e+180.0032266819.58580.0328896.418e-083.19377e+170.020464717.98150.02993461.8737e-071.05967e+180.004334116.81830.005629093.02488e-074.82708e+170.0035403416.29820.005166243.81385e-072.2234e+17-0.00080159616.04660.006037434.27964e-072.09357e+16-0.0013040815.92150.0175337
146.193241319-0.6893913949616PGC11371641223.25012207--20.85656356810.06365147247033.93608e-088.62594e+17-0.0022127918.51230.02975.12427e-081.63739e+180.00089800118.22590.01655831.55028e-071.08292e+170.010768717.0240.02128224.00652e-071.09318e+160.0007452615.99310.02591865.23994e-071.52134e+170.0013152515.70170.005312336.24827e-077.01852e+16-0.0017833915.51060.006559066.81238e-076.39879e+15-0.0018749915.41680.019924
146.007801384-0.642259223227PGC0278641431.89880371--23.66155624390.06305272849112.73263e-071.05155e+17-0.0068617516.40850.01225263.24842e-072.15838e+17-0.0056007416.22080.007194285.74697e-071.29828e+170.0024102815.60140.005243261.08117e-062.38812e+17-0.0060129714.91530.002054969.93737e-072.26204e+170.0019408815.00680.002297225.41217e-074.53568e+17-0.006650515.66660.002978736.29883e-072.47482e+16-0.0040029315.50190.010957
146.619063376-0.4343454581689PGC11433971809.7376709--28.6515178680.1069285270262.45369e-081.25217e+18-0.00084330419.02540.03954324.06546e-082.79773e+180.0032966218.47720.01596661.48096e-071.96303e+170.0170617.07360.01654694.35641e-075.22774e+170.0029218315.90220.003446986.74417e-072.94652e+170.0025172115.42770.00296588.3668e-072.40224e+17-0.0014227215.19360.002647631.00119e-061.07042e+16-0.0018974214.99870.0104817
145.3209626640.77110265139630PGC11750271975.47937012--30.88039779660.1146711652015.43166e-099.08762e+18-0.00031417220.66270.06630817.6787e-092.25418e+190.0028918820.28680.02978123.19299e-081.44307e+180.020704518.73950.02830639.06743e-083.4354e+180.0022409617.60630.006460281.36714e-071.78682e+180.003232117.16050.005941151.65712e-078.25998e+17-0.0026774516.95160.007209081.94639e-071.05222e+17-0.0026543516.77690.0171965
145.5136903770.33645158509632NGC_29671912.34655762--30.03735160830.09953077871895.82052e-076.12737e+16-9.65589e-0515.58760.007535731.19249e-065.91133e+160.008599614.80890.003744794.89467e-068.50241e+150.012780213.27570.002405631.59454e-052.10607e+160.0083550811.99340.0004691932.89876e-057.44139e+150.0021952411.34450.0004341963.97876e-053.8533e+150.0021449911.00060.0004396035.0046e-053.33341e+142.48502e-0510.75160.00118826
146.2657811451.2304125281543SDSSJ094503.80+011349.51905.23034668--29.97554206850.1605405657689.76453e-101.2036e+190.023079822.52590.3205031.36736e-091.52237e+190.0088018322.16030.2035081.61847e-081.63852e+180.026272819.47720.05240744.98293e-084.79183e+180.0021916218.25630.00995387.59066e-082.31665e+180.0037059717.79930.009397559.3876e-081.81206e+18-0.0034260417.56860.008591791.13913e-071.40325e+14-0.0029783817.35860.804604
146.0454410160.17976640614948PGC11590963334.94750977--50.95557022090.1404346375175.8921e-095.64901e+180.0087615120.57430.07752971.10258e-081.11396e+190.0094091719.8940.02950395.83417e-081.01087e+180.039320118.08510.01850961.60756e-073.72037e+180.0033061616.98460.003501592.58361e-071.5772e+180.008507416.46940.003346212.96465e-078.0071e+17-0.0068581616.32010.004092743.68226e-074.96904e+16-0.0060192216.08470.0132274
146.7253227960.50827908573359UGC052381775.37475586--28.2532882690.1782538602172.93045e-085.48221e+170.0064271918.83270.05003936.54208e-087.29351e+170.0083697217.96070.0194334.79624e-072.52176e+160.017694215.79770.01425511.4439e-061.00223e+170.0053960914.60120.002375222.71907e-064.17478e+160.0026671213.9140.001954283.73612e-061.68088e+160.00023191413.56890.002241484.36663e-061.34426e+15-0.00086279813.39960.00678166
.................................................................................................................................
199.97668137-1.5675409892173005---149.896240234--1.254573464390.0262738737974.58115e-094.30784e+140.020.847611.41886.60626e-095.53695e+150.020.45012.208683.27438e-086.69435e+150.018.71220.4052671.40208e-077.30037e+150.017.13310.09063122.75409e-077.40557e+150.016.40010.04581074.01733e-074.86562e+150.015.99020.03874523.61288e-081.31386e+140.018.60542.62178
198.863202147-2.64376833326173014--0.0--1.794210791590.0284640699485-9.13889e-093.59184e+160.0nan-0.626862-1.04482e-081.15257e+170.0nan-0.3060894.11879e-071.24952e+150.015.96310.07457322.29029e-073.81908e+140.016.60030.242585.74159e-071.19055e+150.015.60240.05480471.49931e-063.12073e+140.014.56030.0409926-9.67229e-075.5207e+130.0nan-0.151077
207.783203623-1.96230151557173074--0.0--1.980375766750.04932166179692.40552e-102.44973e+140.024.047288.374-2.91951e-091.51058e+150.0nan-9.568499.35182e-072.11803e+140.015.07280.0797742.9526e-071.65275e+150.016.32450.09045174.16118e-075.97632e+130.015.9520.3375146.60402e-072.96859e+140.015.45050.09542031.59941e-069.14575e+120.014.49010.224468
212.5009035140.481619866014173100--0.0--2.178158998490.03518214392215.58096e-091.50709e+170.020.63320.5011241.14081e-081.94335e+170.019.8570.2158921.12971e-073.95047e+150.017.36760.1529091.61545e-072.38111e+160.016.97930.04355543.75778e-071.50038e+160.016.06270.0235889.46937e-074.17298e+150.015.05920.01774921.15111e-064.33252e+140.014.84720.0453144
212.295995247-0.105540374984173104--0.0--2.154515504840.0385355912198-2.23474e-091.32381e+170.0nan-1.33532-3.51414e-091.89736e+170.0nan-0.70936.11788e-081.37176e+140.018.03351.515252.04925e-078.68272e+150.016.7210.05685936.59995e-073.02109e+150.015.45110.02992971.41776e-061.12646e+150.014.6210.02281731.16876e-061.33948e+140.014.83070.0802658
214.838729164-0.205569176155173199--659.543457031--10.68798923490.0504349232631.17163e-081.571e+18-0.0014339919.8280.07393452.0813e-081.75584e+180.00087058419.20420.03936845.90669e-083.45498e+170.003453918.07160.03127212.05897e-079.8524e+170.0028417916.71590.005312564.23226e-073.93025e+170.0014485215.93360.004092066.30463e-071.54194e+170.0014063815.50090.004385628.09673e-071.50258e+160.0010976615.22920.0109395
218.4640693970.773551666667173235--2488.27734375--34.99753952030.03769728164952.486e-099.37275e+18-0.001564921.51120.1426564.81409e-091.27578e+190.0093483520.79370.06314262.03295e-086.41162e+170.018647419.22970.06669816.25886e-082.70357e+180.014719118.00880.01055021.36481e-079.69691e+170.0082893217.16230.008078591.98578e-073.46497e+170.0077620516.75520.009288452.76392e-073.60368e+160.006322216.39620.0206931
222.918676148-0.307385552943173237--569.605712891--9.407885551450.05120613345061.75863e-091.97429e+19-0.0012105221.88710.1389462.58238e-092.93939e+190.00086295421.46990.07754881.08485e-081.49535e+180.0037193919.91160.08184294.78349e-085.2367e+180.0031282118.30060.009918611.09152e-071.73565e+180.0018270517.40490.007550221.81547e-077.71179e+170.0016637116.85250.006810162.69863e-076.83752e+160.0014302916.42210.0153862
219.748796246-2.65469736351173289--89.9377441406--2.93756413460.0644125858595-1.07207e-093.56567e+170.0nan-1.696027.50633e-092.87937e+170.020.31140.2695558.68983e-088.93523e+140.017.65250.4179841.08122e-079.76101e+150.017.41520.101642.7001e-073.91782e+150.016.42160.06424258.60875e-079.55031e+140.015.16270.0408108-4.83772e-073.22089e+130.0nan-0.395454
5.72621015706-12.2946394622173318--0.0--3.053197145460.0328903347742-7.41976e-091.17242e+150.0nan-4.27359-5.10691e-097.3407e+150.0nan-2.48144.91263e-064.0926e+130.013.27170.0345478.07127e-079.29059e+140.015.23260.04413271.30818e-063.72879e+140.014.70830.04298071.57745e-061.13383e+140.014.50510.0646389-3.75588e-061.13345e+120.0nan-0.271526

Now add in the 2MASS JHK

Requires X-matching NSA to 2MASS XSC


In [16]:
scsubm = SkyCoord(submaster1['RA'], submaster1['Dec'])
sc2mass = SkyCoord(twomassxsc['ra'], twomassxsc['dec'], unit=u.deg)

idx, d2d, _ = scsubm.match_to_catalog_sky(sc2mass)

fig, (ax1, ax2) = plt.subplots(2, 1)

ax1.hist(d2d.arcsec, histtype='step',bins=100, log=True)
ax2.hist(d2d.arcsec, histtype='step',bins=100, range=(0,60), log=True)

fig.tight_layout()


Why are there so many NSA objects not in 2MASS? For now we'll just accept these but keep around the distance to possibly mask later


In [17]:
submaster2 = submaster1.copy()
submaster2['dist_2MASS_NSA'] = d2d.to(u.arcsec)

In [18]:
idx2mass = twomassxsc[idx]

for band in 'jhk':
    twomass_col = '{}_m_ext'.format(band)
    twomass_err_col = '{}_msig_ext'.format(band)
    
    submaster2[band.upper()] = mag = idx2mass[twomass_col]
    submaster2[band.upper()+"_err"] = mag_err = idx2mass[twomass_err_col]
    
    flux, flux_ivar = mag_err_to_maggies(mag, mag_err)
    
    submaster2[band.upper() + '_flux'] = flux
    submaster2[band.upper() + '_flux_ivar'] = flux_ivar

In [19]:
# this is the "correction" one for use with extinction and kcorrecting
submaster3 = submaster2.copy()

In [20]:
submaster3['othername'].fill_value = ''
submaster3['othername'] = submaster3['othername'].filled()


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/astropy/table/column.py:1095: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
  ma.MaskedArray.__setitem__(self, index, value)

And compute extinction for all the bands


In [21]:
for i, bandnm in enumerate('FNugrizJHK'):
    if bandnm in 'FN':
        submaster3['A_'+bandnm] = Ax = submaster3['E(B-V)']*yuan_FN_Rx[i]
    else:
        submaster3['A_'+bandnm] = Ax = submaster3['E(B-V)']*sandf_Rx[i-2]
    
    # this is X in $F_intrinsic = F X$ , that's why the - is missing from 2.5
    submaster3['A_'+bandnm+'_flux'] = 10**(Ax/2.5)

Now compute the kcorrection


In [22]:
maggies = np.array([submaster3[bandnm+'_flux'] for bandnm in 'FNugrizJHK']).T
ivars = np.array([submaster3[bandnm+'_flux_ivar'] for bandnm in 'FNugrizJHK']).T
zs = (u.Quantity(submaster3['vhelio'])/cnst.c).decompose()

mag_kcorrs, flux_kcorrs = do_kcorrs(maggies, ivars, zs, FNugrizJHK_filters)

for i, bandnm in enumerate('FNugrizJHK'):
    submaster3['kcorr_' + bandnm] = mag_kcorrs[:, i]

Now choose the columns for the final submaster


In [23]:
for bandnm in 'ugrizJHK':
    extinction = submaster3['A_'+bandnm]
    kcorr = submaster3['kcorr_'+bandnm]
    distmod = Distance(submaster3['distance']).distmod.value
    submaster3['M_' + bandnm] = submaster3[bandnm] - extinction - kcorr - distmod

In [24]:
infocols = ['RA', 'Dec', 'NSAID', 'othername', 
            'vhelio', 'vhelio_err',  'distance', 'dist_2MASS_NSA']
magcols = []
for bandnm in 'ugrizJHK':
    magcols.append(bandnm)
    magcols.append(bandnm+'_err')
    magcols.append('A_'+bandnm)
    magcols.append('M_'+bandnm)
    
# reset the units
for colnm in magcols:
    submaster3[colnm].unit = 'mag'
    
submaster = submaster3[infocols + magcols]
submaster


Out[24]:
<Table masked=True length=9325>
RADecNSAIDothernamevheliovhelio_errdistancedist_2MASS_NSAuu_errA_uM_ugg_errA_gM_grr_errA_rM_rii_errA_iM_izz_errA_zM_zJJ_errA_JM_JHH_errA_HM_HKK_errA_KM_K
degdegstringkm / skm / sMpcarcsecmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
float64float64int64str28float64float64float64float64float32float32float64float64float32float32float64float64float32float32float64float64float32float32float64float64float32float32float64float64float64float64float64float64float64float64float64float64float64float64float64float64
147.176446949-0.3540304166432PGC11454361883.54833984--29.5901851654271.1265947617.98150.02993460.371772399751-14.763894588116.81830.005629090.289682528044-15.835012087416.29820.005166240.200401022277-16.261115396516.04660.006037430.148919446751-16.459590579515.92150.01753370.110768705092-16.545039301113.1360.0680.0621813237612-19.277534591612.240.080.0393785816203-20.151611746312.070.1070.0264862620252-20.2975449006
146.193241319-0.6893913949616PGC11371641223.25012207--20.8565635681259.72383506217.0240.02128220.269818591802-14.851594830715.99310.02591860.21024081357-15.816236578515.70170.005312330.145443614595-16.04137037715.51060.006559060.108080200255-16.193650342215.41680.0199240.08039180973-16.259244789414.380.1720.0451288939815-17.25813327813.4830.1950.0285795111392-18.139390872912.6790.1520.019222744686-18.9268949287
146.007801384-0.642259223227PGC0278641431.89880371--23.6615562439495.11620898215.60140.005243260.267280516074-16.54003758914.91530.002054960.208263162206-17.158587602515.00680.002297220.144075484602-17.009385446315.66660.002978730.107063532978-16.305163355715.50190.0109570.0796355960842-16.444805902614.1540.1040.0447043845002-17.755527397513.6420.1610.0283106750925-18.253529218813.330.2150.0190419240043-18.5477950063
146.619063376-0.4343454581689PGC11433971809.7376709--28.651517868380.95653765617.07360.01654690.453270026063-15.681539562515.90220.003446980.353184924767-16.743278571215.42770.00296580.244331684254-17.104975800715.19360.002647630.18156463889-17.274703758414.99870.01048170.135050729634-17.421730221714.5130.1270.0758123256614-17.844178500613.5780.1230.0480109086346-18.752216739313.3430.1840.0322924151618-18.9608643805
145.3209626640.77110265139630PGC11750271975.47937012--30.8803977966297.46644717818.73950.02830630.486091069287-14.215763291817.60630.006460280.378758858659-15.227102944117.16050.005941150.262023612484-15.553295597416.95160.007209080.194711638511-15.691843434416.77690.01719650.144829681649-15.815574622814.7880.2070.0813018561274-17.736719773314.1250.2140.0514873531752-18.371144344513.370.2450.0346306918907-19.0976487226
145.5136903770.33645158509632NGC_29671912.34655762--30.03735160830.7102822067413.27570.002405630.421910970989-19.54913286911.99340.0004691930.328750162108-20.735053051711.34450.0004341960.227427829373-21.275571419111.00060.0004396030.169003262265-21.560946366210.75160.001188260.125707373522-21.76493646739.7650.0190.0705673221117-22.691263279.1040.0180.0446893196448-23.32743719128.8830.0340.0300582951731-23.5218249121
146.2657811451.2304125281543SDSSJ094503.80+011349.51905.23034668--29.9755420685364.54120135219.47720.05240740.680531458291-13.613110241118.25630.00995380.530265488732-14.665054396117.79930.009397550.36683519278-14.95568662917.56860.008591790.272597880674-15.088481643717.35860.8046040.202762734565-15.227820176314.5530.1320.11382326113-17.940070073214.170.1820.0720827140299-18.282620422113.2650.1610.048483250862-19.15247361
146.0454410160.17976640614948PGC11590963334.94750977--50.955570220970.779874473618.08510.01850960.595302428436-16.094165852216.98460.003501590.46385560772-17.024866996216.46940.003346210.320893146727-17.398880079616.32010.004092740.238458014504-17.454635810316.08470.01322740.177368947184-17.629724694614.7130.1480.0995681579998-18.915030864713.760.1220.0630551522453-19.837658679513.3040.1640.0424112605302-20.2503596212
146.7253227960.50827908573359UGC052381775.37475586--28.25328826913.103996925915.79770.01425510.755618113462-17.227341955314.60120.002375220.588772500298-18.255133393913.9140.001954280.407310070597-18.752316784313.56890.002241480.302675054649-18.992718056213.39960.006781660.225134625455-19.082303024713.9270.1460.126381986894-18.451332696813.080.1520.0800359832376-19.252579600112.6780.1850.0538326657857-19.617544576
........................................................................................................................
199.97668137-1.5675409892173005-149.896240234--1.2545734643924.139757902518.71220.4052670.111374951026-6.8916781618717.13310.09063120.0867826051516-8.4461988225916.40010.04581070.0600358016262-9.1524632647915.99020.03874520.0446130377074-9.5469373514618.60542.621780.0331839026057-6.9202967295415.1620.1910.0186281765221-10.34910866414.620.2420.0117969693349-10.884277456813.6620.2220.00793470988671-11.8384151973
198.863202147-2.643768333261730140.0--1.79421079159115.80759027515.96310.07457320.120659192511-10.426948969816.60030.242580.0940168230397-9.7631110131515.60240.05480470.0650403998322-10.731988822714.56030.04099260.0483319907725-11.7574251891nan-0.1510770.0359501203449nan12.8940.0560.0201810255935-13.39554834811.9810.0470.0127803674069-14.301147689811.5430.0640.00859614912443-14.7349634716
207.783203623-1.962301515571730740.0--1.98037576675584.92312892115.07280.0797740.209074524357-11.620052912916.32450.09045170.162909448915-10.322157872215.9520.3375140.112699997206-10.64447840415.45050.09542030.0837481817311-11.117007644814.49010.2244680.0622932588494-12.055933276114.5640.1060.034969058214-11.95470707513.9660.1290.0221454261468-12.53988344313.4930.1710.0148951418627-13.0056331587
212.5009035140.4816198660141731000.0--2.17815899849250.3628473417.36760.1529090.149137108086-9.4720007728516.97930.04355540.116206621375-9.8273873942916.06270.0235880.080391198862-10.708167430815.05920.01774920.0597392803797-11.690990701514.84720.04531440.0444350477736-11.887678732714.7250.150.0249441400408-11.990392033314.8840.00.015796782621-11.822244675913.7030.2560.0106250074645-12.9980729007
212.295995247-0.1055403749841731040.0--2.15451550484339.19126254518.03351.515250.163352371181-8.7966017261916.7210.05685930.127283057799-10.07301715415.45110.02992970.0880538259372-11.303652958214.6210.02281730.0654334338912-12.111189846114.83070.08026580.0486704517106-11.884732955214.5450.1110.0273217341748-12.149069853213.8450.1240.0173024804577-12.839050599513.0280.1250.0116377485484-13.6503858676
214.838729164-0.205569176155173199659.543457031--10.6879892349617.97800844518.07160.03127210.213793639712-12.291183582716.71590.005312560.166586551538-13.599046179415.93360.004092060.115243799656-14.328276322915.50090.004385620.0856384997005-14.731270108615.22920.01093950.0636993080811-14.980636849413.7840.0720.0357583605935-16.395785747913.1430.0760.0226452805451-17.024271519912.9380.140.0152313468254-17.2179015796
218.4640693970.7735516666671732352488.27734375--34.9975395203125.12521411819.22970.06669810.159798776912-13.686034554518.00880.01055020.124514121288-14.851251564317.16230.008078590.0861382885691-15.658040380816.75520.009288450.0640099842409-16.039338876416.39620.02069310.0476116667233-16.381637793513.2250.0690.0267273726895-19.521923413512.4580.0690.0169260794606-20.282387193712.2740.1170.0113845790582-20.4421462645
222.918676148-0.307385552943173237569.605712891--9.407885551450.44471852490119.91160.08184290.217062799697-10.178204012118.30060.009918610.169133858787-11.739847980517.40490.007550220.117006014935-12.582125303516.85250.006810160.0869480145991-13.104148236216.42210.01538620.0646733465481-13.512026824214.9330.1790.0363051486165-14.970737190214.0530.1830.0229915539193-15.837870273513.5540.2020.0154642523021-16.3259701543
219.748796246-2.6546973635117328989.9377441406--2.9375641346453.23678644117.65250.4179840.273044951459-9.9605101948617.41520.101640.212754771094-10.137477018316.42160.06424250.147182758689-11.065568793715.16270.04081080.10937257079-12.2866592482nan-0.3954540.0813530959406nan14.6460.1030.0456685233744-12.739605309114.0050.1480.0289212510509-13.363858036813.6710.2010.0194526009296-13.6883893867
5.72621015706-12.29463946221733180.0--3.05319714546413.34671696613.27170.0345470.139422129108-14.29148215715.23260.04413270.108636775759-12.299765979314.70830.04298070.075154414959-12.790595637914.50510.06463890.0558477884466-12.9745131935nan-0.2715260.0415404928198nan15.1270.250.0233192473549-12.320093485714.3420.3020.0147677603136-13.096541998713.140.1660.0099328811018-14.2937071195

And write it all out


In [62]:
fill_values = [('--', '-1')]
submaster.write('masterlist/submaster.ecsv', format='ascii.ecsv', fill_values=fill_values)
submaster3.write('masterlist/submaster_all.ecsv', format='ascii.ecsv', fill_values=fill_values)

In [63]:
!gzip -f masterlist/submaster.ecsv
!gzip -f masterlist/submaster_all.ecsv

In [64]:
!cp masterlist/submaster.ecsv.gz SAGADropbox/hosts/
!cp masterlist/submaster_all.ecsv.gz SAGADropbox/hosts/

In [67]:
table = table.Table.read('masterlist/submaster.ecsv.gz', format='ascii.ecsv')

Appendix/consistency checks

Is the difference between vdist and z significant enough to worry about?


In [113]:
z = (u.Quantity(submaster['vhelio'])/cnst.c).decompose()
dmz = Distance(cosmology.WMAP9.luminosity_distance(z), allow_negative=True).distmod
dmd = Distance(submaster['distance']).distmod
dd = dmd - dmz

ahist(dd[np.isfinite(dd)], bins='knuth', histtype='step', range=(-.0003, .001))
plt.xlabel('$DM_{dist} - DM_{vhelio}$')
plt.tight_layout()


Looks like totally-ignorable

Checking assumptions about extintion in NSA

Is it true that the sfd_Rx values above give the same E(B-V) values for all 5 bands? If yes, it means Blanton got them straight from the SFD paper


In [131]:
np.array(nsa['EXTINCTION'])[:,-5:]/sfd_Rx[:5]


Out[131]:
array([[ 0.05472223,  0.05472223,  0.05472223,  0.05472223,  0.05472223],
       [ 0.0521579 ,  0.05215789,  0.05215789,  0.05215789,  0.05215789],
       [ 0.08770286,  0.08770285,  0.08770285,  0.08770286,  0.08770285],
       ..., 
       [ 0.05120614,  0.05120613,  0.05120613,  0.05120613,  0.05120613],
       [ 0.06441259,  0.06441259,  0.06441258,  0.06441258,  0.06441259],
       [ 0.03289034,  0.03289033,  0.03289033,  0.03289033,  0.03289033]])

Some consistency checks of kcorrections w/ what's already in NSA


In [21]:
maggies = np.array([submaster3[bandnm+'_flux'] for bandnm in 'FNugriz']).T
ivars = np.array([submaster3[bandnm+'_flux_ivar'] for bandnm in 'FNugriz']).T
zs = (u.Quantity(submaster3['vhelio'])/cnst.c).decompose()

mag_kcorrs_sdss, flux_kcorrs_sdss = do_kcorrs(maggies, ivars, zs, FNugrizJHK_filters[:7])

In [22]:
maggies = np.array([submaster3[bandnm+'_flux'] for bandnm in 'JHK']).T
ivars = np.array([submaster3[bandnm+'_flux_ivar'] for bandnm in 'JHK']).T
zs = (u.Quantity(submaster3['vhelio'])/cnst.c).decompose()

mag_kcorrs_2mass, flux_kcorrs_2mass = do_kcorrs(maggies, ivars, zs, FNugrizJHK_filters[-3:])

In [28]:
plt.hist((submaster3['NSA_kcorrect_r'] - mag_kcorrs[:, 4])/submaster3['NSA_kcorrect_r'], 
         bins=100, range=(-3,3), histtype='step')
plt.hist((submaster3['NSA_kcorrect_r'] - mag_kcorrs_sdss[:, 4])/submaster3['NSA_kcorrect_r'], 
         bins=100, range=(-3,3), histtype='step')
plt.tight_layout()


Looks like yes, so that's a consistent way to get E(B-V)

Compare "old" and "new" masterlists


In [33]:
omaster = table.Table.read('masterlist/masterlist.csv')
nmaster = table.Table.read('SAGADropbox/hosts/masterlist.csv', data_start=2)

In [34]:
omaster


Out[34]:
<Table masked=True length=18162>
RADecPGC#NSAIDothernamevheliodistancerizIKK_err
float64float64int64int64str28float64float64float64float64float64float64float64float64
148.3353425990.62856766514--112--3934.5761718861.589656829817.623301097817.399429866717.3146577568--13.7020.213
155.4118006990.900255164384--464--700.78149414112.944350242617.84091313317.859253243817.9387725156------
168.044331058-0.979240347779--858--3976.9138183662.274604797416.110251571216.012892867615.9054061427--13.320.184
167.573676285-0.263963231217--878--3859.3430175859.689205169718.378421354218.297853040618.1733050822--13.4760.21
176.53220815-0.457941560233--1189--3915.2231445361.129993438717.604281618317.4981929817.3905078909--13.5620.198
175.8278850170.212515965092--1212--63.8359756472.1578984260613.255274238713.135555687112.8214039231------
185.86139022-0.411951305215--1398---35.29950714111.5616883039516.700818048716.694526659216.7462901938------
188.1174627810.388846619893--1498--1514.1766357423.868576049813.188979202512.945252472112.936596924------
189.186292190.563405647876--1539--3739.3122558660.003284454318.308250681618.220816866618.1446879069------
189.1278272820.22202937172--1540--3724.8823242259.749282836916.239768190216.161439103916.0785190294------
.......................................
338.8252917-45.5136667----g2235181-4530483020.1092218943.9110241265--------12.5960.146
338.7727917-46.4604722----g2235056-462738936.55163879213.5436535358--------13.4130.276
336.2564167-51.79575----g2225015-5147451905.7806555127.6294136391--------12.3430.115
345.6082917-50.0628889----g2302259-5003463674.2563652553.5121354687------------
343.6907083-49.8007222----g2254457-4948023757.5986685754.7376695699--------12.2170.119
347.8368333-43.4229444----g2311207-4325231558.920781622.580401005--------12.9920.152
336.8646667-42.9764444----g2227276-4258343137.9276578945.6379196917------------
339.1618333-43.03375----g2236389-4302012737.1051415439.7672014637------------
255.6157083-24.36075----g1702281-24213525.62417875020.369675390547--------12.3970.135
256.3733333-21.7145----g1705296-21425227.79525774350.400999433819--------12.6470.134

In [35]:
nmaster


Out[35]:
<Table masked=True length=17792>
RADecPGC#NSAIDothernamevheliovhelio_errdistancerizIK
float64float64int64int64str28float64float64float64float64float64float64float64float64
155.4118006990.900255164384--464--897.302368164190.00030517612.977812297817.846519298717.864859409517.9443786814----
175.8278850170.212515965092--1212--149.58552551395.00015258792.1611634501113.258557317813.138838766212.8246870023----
185.86139022-0.411951305215--1398--108.25623321570.00011444091.5637121124216.703630261116.697338871616.7491024061----
170.835578635-3.13086875479--2996--2707.15625160.00024414139.332504565817.498640325317.369473722217.1953413751----
179.301669033-2.68650062571--3272--1536.73803711142.50021362322.259597248917.461637986617.522198213117.5233359465----
178.369363427-3.22968533309--3276--1586.27331543142.50021362322.980961813417.050313104816.970791925616.9346038----
190.414321924-1.44519645427--3526--146.17066955687.50012969972.111798698237.737384979916.791362946217.93538874883----
191.530258224-3.26911585606--3537--1156.52880859172.50027465816.739013325117.39693430217.169390471117.0419090105--13.254
190.497254971-3.66736412411--3549--2826.93212891147.50024414141.083128508718.809361584519.39880860619.3847695664----
236.3099755710.772172002704--3818--3652.25463867190.00030517653.190207805914.810244021814.545401034714.4503769258--13.746
.......................................
338.8252917-45.5136667----g2235181-4530483020.1092218995.9335865643.9110241265--------12.596
338.7727917-46.4604722----g2235056-462738936.55163879295.9335865613.5436535358--------13.413
336.2564167-51.79575----g2225015-5147451905.780655510.027.6294136391--------12.343
345.6082917-50.0628889----g2302259-5003463674.256365250.053.5121354687----------
343.6907083-49.8007222----g2254457-4948023757.598668570.054.7376695699--------12.217
347.8368333-43.4229444----g2311207-4325231558.92078160.022.580401005--------12.992
336.8646667-42.9764444----g2227276-4258343137.927657890.045.6379196917----------
339.1618333-43.03375----g2236389-4302012737.105141540.039.7672014637----------
255.6157083-24.36075----g1702281-24213525.62417875020.00.369675390547--------12.397
256.3733333-21.7145----g1705296-21425227.79525774350.00.400999433819--------12.647

In [110]:
omaster_nsa = omaster[~omaster['NSAID'].mask]
nmaster_nsa = nmaster[~nmaster['NSAID'].mask]

merged = table.join(omaster_nsa, nmaster_nsa, ['NSAID'], 'left')
sub_merged = merged['NSAID', 'vhelio_1', 'vhelio_2', 'distance_1', 'distance_2']
sub_merged


Out[110]:
<Table masked=True length=9326>
NSAIDvhelio_1vhelio_2distance_1distance_2
int64float64float64float64float64
21883.548339842051.1916503929.590185165429.7514014598
61223.250122071445.7769775420.856563568120.9358094095
71431.898803711640.2191162123.661556243923.7665552411
91809.73767091986.1231689528.65151786828.8038324065
301975.479370122140.6291503930.880397796631.0538478259
321912.346557622082.1892089830.037351608330.0
431905.230346682077.9045410229.975542068530.1404117443
483334.947509773532.2402343850.955570220951.4263961604
591775.374755861958.5179443428.25328826936.5
1001896.798706052065.1479492229.791517257729.9546420546
...............
173005-149.89624023486.96703338621.254573464391.2559579698
1730140.0124.3746948241.794210791591.79671867785
1730740.0137.2796478271.980375766751.98327114477
1731000.0150.9899749762.178158998492.18146600463
1731040.0149.3510131842.154515504842.15777336775
173199659.543457031740.89141845710.687989234910.7090111649
1732352488.277343752426.0295410234.997539520335.2236042412
173237569.605712891652.1546020519.407885551459.42624229288
17328989.9377441406203.6319427492.93756413462.94245203454
1733180.0211.6476287843.053197145463.05832583925

In [111]:
sub_merged[sub_merged['NSAID']==129461]


Out[111]:
<Table masked=True length=1>
NSAIDvhelio_1vhelio_2distance_1distance_2
int64float64float64float64float64
1294612379.003662112379.4260253934.325244903624.0

In [112]:
sub_merged[sub_merged['NSAID']==2]


Out[112]:
<Table masked=True length=1>
NSAIDvhelio_1vhelio_2distance_1distance_2
int64float64float64float64float64
21883.548339842051.1916503929.590185165429.7514014598

Wha? Why are only some of them different??

Understanding the Submaster/masterlist missing-K problem

This section is getting at why the submaster list seems to have more objects with K-band (2MASS) detections than the masterlist. Or more broadly, why there aren't K-band detections for all the targets, given that 2MASS is supposed to be complete for $M_K<-19.6$ and $cz < 3000$ km/s

First we take a look at two sets of objects in the 2MASS and SDSS image browser: those from the sub-master that have a 2MASS match, and those that do not.


In [25]:
def get_2mass_url(row, show_in_browser=True):
    twomass_url_templ = 'http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS={0[RA]:.6f}d+{0[Dec]:.6f}d&subsz=&date=&scan=&coadd=&key=&band=K'
    url = twomass_url_templ.format(row)
    
    if show_in_browser:
        import webbrowser
        webbrowser.open(url)
        
    return url

def get_sdss_url(row, show_in_browser=True):
    sdss_url_templ = 'http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra={0[RA]:.6f}&dec={0[Dec]:.6f}'
    url = sdss_url_templ.format(row)
    
    if show_in_browser:
        import webbrowser
        webbrowser.open(url)
        
    return url

In [38]:
kvmsk = (submaster['M_K']<-19.6)&(submaster['vhelio']<3000)

goodmatches = submaster[kvmsk&(submaster['dist_2MASS_NSA']<10*u.arcsec)]
badmatches = submaster[kvmsk&(submaster['dist_2MASS_NSA']>60*u.arcsec)]


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in less
  if __name__ == '__main__':

In [36]:
goodsubset = goodmatches[np.random.permutation(len(goodmatches))[:3]]
for row in goodsubset:
    print('NSAID', row['NSAID'], 'othername', row['othername'])
    print('2MASS:', get_2mass_url(row))
    print('SDSS:', get_sdss_url(row))
    print('')


NSAID 158036 othername NGC_3169
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=153.562643d+3.466152d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=153.562643&dec=3.466152

NSAID 133324 othername PGC012468
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=50.042228d+41.351128d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=50.042228&dec=41.351128

NSAID 76834 othername 09202038+6406106
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=140.084882d+64.103066d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=140.084882&dec=64.103066

As an aside... This last one (NSAID 76834/NGC 2805) is a fascinating-looking galaxy (apparently in the group Holmberg Holmberg 124)! Is it ram-pressure stripping? If so what's with the funky corner-like morphology? But I digress...


In [37]:
badsubset = badmatches[np.random.permutation(len(badmatches))[:3]]
for row in badsubset:
    print('NSAID', row['NSAID'], 'othername', row['othername'])
    print('2MASS:', get_2mass_url(row))
    print('SDSS:', get_sdss_url(row))
    print('')


NSAID 142657 othername PGC044474
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=194.650140d+1.707247d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=194.650140&dec=1.707247

NSAID 138996 othername PGC166109
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=168.498318d+11.329474d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=168.498318&dec=11.329474

NSAID 37364 othername PGC2592225
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=170.024503d+59.595984d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=170.024503&dec=59.595984

Examination of these two subsets makes it clear that they are not the same subsets of objects: the "no-match" objects are all notably fainter/lower SB than the matched ones.

So now lets check the subset that are bright in r in addition to being bright in K.


In [40]:
# 3.28 and 4.67 are K and r-band solar magnitudes, so here implicitly assuming the average galaxy has sun-like r-K color
solar_rmK = 4.67 - 3.28
rbrightmsk = (submaster['M_r'] - solar_rmK)<-19.6


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:3: RuntimeWarning: invalid value encountered in less
  app.launch_new_instance()

In [70]:
plt.figure()
_, b, _ = plt.hist(submaster[rbrightmsk&kvmsk]['dist_2MASS_NSA'], 
                   bins=100, range=(0,1400), log=True, 
                   histtype='step', label='with $r$ cut')
plt.hist(submaster[kvmsk]['dist_2MASS_NSA'],  bins=b, log=True, 
                   histtype='step', label='without $r$ cut', 
                   color=list(plt.rcParams['axes.prop_cycle'])[2]['color'])
plt.legend()
plt.xlabel('distance of closest NSA/2MASS match [arcsec]')

plt.figure()
_, b, _ = plt.hist(submaster[rbrightmsk&kvmsk]['dist_2MASS_NSA'], 
                   bins=100, range=(0,60), log=True, 
                   histtype='step', label='with $r$ cut')
plt.hist(submaster[kvmsk]['dist_2MASS_NSA'],  bins=b, log=True, 
                   histtype='step', label='without $r$ cut', 
                   color=list(plt.rcParams['axes.prop_cycle'])[2]['color'])
plt.legend()
plt.xlabel('distance of closest NSA/2MASS match [arcsec]')

print('Fraction > 30 arcsec', np.sum(submaster[rbrightmsk&kvmsk]['dist_2MASS_NSA']>30*u.arcsec)/np.sum(rbrightmsk&kvmsk))
print('Fraction > 30 arcsec', np.sum(submaster[kvmsk]['dist_2MASS_NSA']>30*u.arcsec)/np.sum(kvmsk))


Fraction > 30 arcsec 0.0746835443038
Fraction > 30 arcsec 0.291091593476

So what are those remaining 7%?


In [76]:
boundaryobjs = submaster[(submaster['dist_2MASS_NSA']>30*u.arcsec)&rbrightmsk&kvmsk]
boundarysubset = boundaryobjs[np.random.permutation(len(boundaryobjs))[:5]]
for row in boundarysubset:
    print('NSAID', row['NSAID'], 'othername', row['othername'])
    print('2MASS:', get_2mass_url(row))
    print('SDSS:', get_sdss_url(row))
    print('')


NSAID 169804 othername UGC06717
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=176.191046d+9.212555d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=176.191046&dec=9.212555

NSAID 124893 othername 
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=114.278675d+65.610897d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=114.278675&dec=65.610897

NSAID 149474 othername PGC1077281
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=329.567842d+-3.058465d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=329.567842&dec=-3.058465

NSAID 134208 othername PGC017304
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=81.788625d+-6.119133d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=81.788625&dec=-6.119133

NSAID 23964 othername 
2MASS: http://irsa.ipac.caltech.edu/cgi-bin/2MASS/IM/nph-im_pos?type=at&ds=asky&POS=40.691597d+-0.023605d&subsz=&date=&scan=&coadd=&key=&band=K
SDSS: http://skyserver.sdss.org/dr13/en/tools/chart/navi.aspx?ra=40.691597&dec=-0.023605

All either artifacts due to nearby bright stars/shredding, or faint things close to the edge of detectability.

Conclusion: the reason why there are a large number of "missing" NSA/2MASS matches is that if there's not a K-band magnitude, our K-band magnitude cut did not remove them! If we instead cut on r-band ~= to the expected K-band cut, "missing" objects go away. So the alternative aproach we've taken of saying "if it has K and meets the cut, it's in the sample" is OK, because those that don't have a K-band magnitude are almost invariably faint (or a small fraction of artifacts).