Plot stats of the band flags

Plot a histogram for some key g and k bands as a function of PanSTARRS g magnitude

In [110]:
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'

import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
from matplotlib import gridspec
from matplotlib.ticker import LogLocator

import pyvo as vo
import time
from astropy.table import Table, Column
import numpy as np
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/__init__.py:1405: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
In [111]:
service = vo.dal.TAPService(
    "https://herschel-vos.phys.sussex.ac.uk/__system__/tap/run/tap"
)
In [112]:
flag_query="""SELECT
m_gpc1_g,
flag_mmt_g, 
flag_omegacam_g, 
flag_suprime_g, 
flag_megacam_g, 
flag_wfc_g, 
flag_gpc1_g, 
flag_decam_g, 
flag_90prime_g, 
flag_sdss_g,
flag_isaac_k, 
flag_moircs_k, 
flag_ukidss_k, 
flag_newfirm_k, 
flag_wircs_k, 
flag_hawki_k,
flag_wircam_ks, 
flag_vista_ks, 
flag_moircs_ks, 
flag_omega2000_ks, 
flag_tifkam_ks
FROM herschelhelp.main
WHERE m_gpc1_g IS NOT NULL"""
In [113]:
job = service.submit_job(flag_query)
job.run()
job_url = job.url
job_result = vo.dal.tap.AsyncTAPJob(job_url)
start_time = time.time()
wait = 5.
while job.phase == 'EXECUTING':
    
    time.sleep(wait) #wait and try again
    #wait *= 2

print('Job {} after {} seconds.'.format(job.phase, round(time.time() - start_time)))

result = job_result.fetch_result()
flags = result.table
Job COMPLETED after 591 seconds.
WARNING: W35: None:2:1052: W35: 'value' attribute required for INFO elements [astropy.io.votable.tree]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-113-362c59643606> in <module>()
     12 print('Job {} after {} seconds.'.format(job.phase, round(time.time() - start_time)))
     13 
---> 14 result = job_result.fetch_result()
     15 flags = result.table

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/pyvo/dal/tap.py in fetch_result(self)
    611         response.raw.read = partial(
    612             response.raw.read, decode_content=True)
--> 613         return TAPResults(votableparse(response.raw.read), url=self.result_uri)
    614 
    615 

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/table.py in parse(source, columns, invalid, pedantic, chunk_size, table_number, table_id, filename, unit_format, datatype_mapping, _debug_python_based_parser)
    135             _debug_python_based_parser=_debug_python_based_parser) as iterator:
    136         return tree.VOTableFile(
--> 137             config=config, pos=(1, 1)).parse(iterator, config)
    138 
    139 

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in parse(self, iterator, config)
   3388             if start:
   3389                 tag_mapping.get(tag, self._add_unknown_tag)(
-> 3390                     iterator, tag, data, config, pos)
   3391             elif tag == 'DESCRIPTION':
   3392                 if self.description is not None:

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in _add_resource(self, iterator, tag, data, config, pos)
   3317         resource = Resource(config=config, pos=pos, **data)
   3318         self.resources.append(resource)
-> 3319         resource.parse(self, iterator, config)
   3320 
   3321     def _add_coosys(self, iterator, tag, data, config, pos):

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in parse(self, votable, iterator, config)
   3139             if start:
   3140                 tag_mapping.get(tag, self._add_unknown_tag)(
-> 3141                     iterator, tag, data, config, pos)
   3142             elif tag == 'DESCRIPTION':
   3143                 if self.description is not None:

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in _add_table(self, iterator, tag, data, config, pos)
   3090         table = Table(self._votable, config=config, pos=pos, **data)
   3091         self.tables.append(table)
-> 3092         table.parse(iterator, config)
   3093 
   3094     def _add_info(self, iterator, tag, data, config, pos):

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in parse(self, iterator, config)
   2386                             'BINARY', data.keys(), config, pos)
   2387                         self.array = self._parse_binary(
-> 2388                             1, iterator, colnumbers, fields, config, pos)
   2389                         break
   2390                     elif tag == 'BINARY2':

~/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/votable/tree.py in _parse_binary(self, mode, iterator, colnumbers, fields, config, pos)
   2626                     row_mask_data = list(converters.bitarray_to_bool(
   2627                         mask_bits, len(fields)))
-> 2628                 for i, binparse in enumerate(binparsers):
   2629                     try:
   2630                         value, value_mask = binparse(careful_read)

KeyboardInterrupt: 
In [ ]:
flags.write('./data/flags.fits', overwrite=True)
In [114]:
flags = Table.read('./data/flags.fits')
In [115]:
len(flags)
Out[115]:
16473810
In [116]:
flags[:10].show_in_notebook()
Out[116]:
Table length=10
idxm_gpc1_gflag_mmt_gflag_omegacam_gflag_suprime_gflag_megacam_gflag_wfc_gflag_gpc1_gflag_decam_gflag_90prime_gflag_sdss_gflag_isaac_kflag_moircs_kflag_ukidss_kflag_newfirm_kflag_wircs_kflag_hawki_kflag_wircam_ksflag_vista_ksflag_moircs_ksflag_omega2000_ksflag_tifkam_ks
mag
022.8649997711182TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
121.6070003509521TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
220.7877006530762TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
323.6667995452881TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
421.6905002593994TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
522.8159008026123TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
623.5333995819092TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
722.300500869751TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
816.4899005889893TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
922.5300998687744TrueTrueTrueTrueTrueFalseTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrueTrue
In [117]:
np.unique(flags['flag_mmt_g'])
Out[117]:
<Column name='flag_mmt_g' dtype='bool' description='Flag set to true for sources for which niether the mmt_g aperture nor total flux should be used for SED fitting (see documentation).' length=2>
False
True
In [118]:
bins = np.linspace(10, 30, 100)
In [119]:
flag_cols = [
    "flag_mmt_g", 
    "flag_omegacam_g", 
    "flag_suprime_g", 
    "flag_megacam_g", 
    "flag_wfc_g", 
    "flag_gpc1_g", 
    "flag_decam_g", 
    "flag_90prime_g", 
    "flag_sdss_g",
    "flag_isaac_k", 
    "flag_moircs_k", 
    "flag_ukidss_k", 
    "flag_newfirm_k", 
    "flag_wircs_k", 
    "flag_hawki_k",
    "flag_wircam_ks", 
    "flag_vista_ks", 
    "flag_moircs_ks", 
    "flag_omega2000_ks", 
    "flag_tifkam_ks"
]
In [120]:
def make_flag_counts(table, bins, flag_col):
    frac = np.full(len(bins)-1, np.nan)
    for n, b in enumerate(bins[:-1]):
        mask = table['m_gpc1_g'] > bins[n]
        mask &= table['m_gpc1_g'] < bins[n+1]
        flagged = np.sum(table[mask][flag_col])
        not_flagged = np.sum(~table[mask][flag_col])
        frac[n] = flagged/not_flagged
    return frac
        
In [121]:
flag_counts = {}
for col in flag_cols:
    print("{} total: {}, True: {}, False: {}".format(
        col,
        np.sum(~flags[col].mask), 
        np.sum(flags[col]), 
        np.sum(~flags[col])
    ))
    flag_counts.update({col: make_flag_counts(flags, bins, col)})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-121-62fcc5893bb2> in <module>()
      3     print("{} total: {}, True: {}, False: {}".format(
      4         col,
----> 5         np.sum(~flags[col].mask),
      6         np.sum(flags[col]),
      7         np.sum(~flags[col])

AttributeError: 'Column' object has no attribute 'mask'
In [ ]:
fig, ax = plt.subplots()

ax.plot(bins[:-1]+(bins[1] - bins[0])/2, flag_counts['flag_gpc1_g'], label=f)
    
#ax.legend()
#ax.set_xscale([15,26])
#ax.set_yscale(0,1)
    
In [124]:
gpc_query="""SELECT
m_gpc1_g,
flag_gpc1_g, 
m_gpc1_r,
flag_gpc1_r, 
m_gpc1_i,
flag_gpc1_i, 
m_gpc1_z,
flag_gpc1_z, 
m_gpc1_y,
flag_gpc1_y
FROM herschelhelp.main
WHERE m_gpc1_g IS NOT NULL
OR m_gpc1_r IS NOT NULL
OR m_gpc1_i IS NOT NULL
OR m_gpc1_z IS NOT NULL
OR m_gpc1_y IS NOT NULL
"""
In [125]:
job = service.submit_job(gpc_query)
job.run()
job_url = job.url
job_result = vo.dal.tap.AsyncTAPJob(job_url)
start_time = time.time()
wait = 5.
while job.phase == 'EXECUTING':
    
    time.sleep(wait) #wait and try again
    #wait *= 2

print('Job {} after {} seconds.'.format(job.phase, round(time.time() - start_time)))

result = job_result.fetch_result()
gpcflags = result.table
Job COMPLETED after 592 seconds.
WARNING: W35: None:2:954: W35: 'value' attribute required for INFO elements [astropy.io.votable.tree]
In [126]:
gpcflags.write('./data/gpcflags.fits', overwrite=True)
In [127]:
gpc_counts = {}
for col in ['g','r','i','z','y']:
    col = "flag_gpc1_{}".format(col)
    print("{} total: {}, True: {}, False: {}".format(
        col,
        np.sum(~gpcflags[col].mask), 
        np.sum(gpcflags[col]), 
        np.sum(~gpcflags[col])
    ))
    gpc_counts.update({col: make_flag_counts(gpcflags, bins, col)})
flag_gpc1_g total: 17754704, True: 12682, False: 17742022
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/table/column.py:965: RuntimeWarning: invalid value encountered in greater
  return getattr(self.data, op)(other)
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/table/column.py:965: RuntimeWarning: invalid value encountered in less
  return getattr(self.data, op)(other)
flag_gpc1_r total: 17754704, True: 17004, False: 17737700
flag_gpc1_i total: 17754704, True: 16475, False: 17738229
flag_gpc1_z total: 17754704, True: 14029, False: 17740675
flag_gpc1_y total: 17754704, True: 6485, False: 17748219
In [128]:
17004 + 16475 + 14029 + 6485
Out[128]:
53993
In [129]:
fig, ax = plt.subplots()

ax.plot(bins[:-1]+(bins[1] - bins[0])/2, gpc_counts['flag_gpc1_g'], label='GPC1 $g$')
ax.plot(bins[:-1]+(bins[1] - bins[0])/2, gpc_counts['flag_gpc1_r'], label='GPC1 $r$')
ax.plot(bins[:-1]+(bins[1] - bins[0])/2, gpc_counts['flag_gpc1_i'], label='GPC1 $i$')
ax.plot(bins[:-1]+(bins[1] - bins[0])/2, gpc_counts['flag_gpc1_z'], label='GPC1 $z$')
ax.plot(bins[:-1]+(bins[1] - bins[0])/2, gpc_counts['flag_gpc1_y'], label='GPC1 $y$')

ax.set_xlim(10,18)
ax.set_xlabel("Magnitude [mag]")
ax.set_ylabel("Fraction flagged")
legend = ax.legend( markerscale=2)

plt.rc('font', family='serif', serif='Times')
plt.rc('text') #, usetex=True)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rc('axes', labelsize=12)

column_width_cm = 8.9
width_cm = 1.0 * column_width_cm
hieght_cm = width_cm / 1.0
width_inches = width_cm/2.5
hieght_inches = hieght_cm/2.5
fig.set_size_inches(width_inches, hieght_inches)
plt.savefig('./figs/flags.pdf', bbox_inches='tight')
plt.savefig('./figs/flags.png', bbox_inches='tight')
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Stellarity of GAIA objects

In [80]:
star_query="""SELECT 
m_gpc1_g, 
stellarity
FROM herschelhelp.main
WHERE herschelhelp.main.flag_gaia=3
AND m_gpc1_g IS NOT NULL 
"""
In [81]:
job = service.submit_job(star_query)
job.run()
job_url = job.url
job_result = vo.dal.tap.AsyncTAPJob(job_url)
start_time = time.time()
wait = 5.
while job.phase == 'EXECUTING':
    
    time.sleep(wait) #wait and try again
    #wait *= 2

print('Job {} after {} seconds.'.format(job.phase, round(time.time() - start_time)))

result = job_result.fetch_result()
star_tab = result.table
Job COMPLETED after 455 seconds.
WARNING: W35: None:2:801: W35: 'value' attribute required for INFO elements [astropy.io.votable.tree]
In [82]:
len(star_tab)
Out[82]:
2673020
In [83]:
fig, ax = plt.subplots()
#ax.scatter(star_tab['m_gpc1_g'], star_tab['stellarity'], s=0.1)
ax.hexbin(star_tab['m_gpc1_g'], star_tab['stellarity'], cmap='Reds', bins="log", mincnt=1)#gridsize=200,
           
ax.set_xlim(10,25)
ax.set_ylim(0,1)
ax.set_xlabel("Magnitude [mag]")
ax.set_ylabel("Stellarity")
#legend = ax.legend( markerscale=2)

plt.rc('font', family='serif', serif='Times')
plt.rc('text') #, usetex=True)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rc('axes', labelsize=12)

column_width_cm = 8.9
width_cm = 1.0 * column_width_cm
hieght_cm = width_cm / 1.0
width_inches = width_cm/2.5
hieght_inches = hieght_cm/2.5
fig.set_size_inches(width_inches, hieght_inches)
plt.savefig('./figs/stellarity.pdf', bbox_inches='tight')
plt.savefig('./figs/stellarity.png', bbox_inches='tight')
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [88]:
plt.hist(star_tab[~np.isnan(star_tab['stellarity'] )]['stellarity'], bins=200)
Out[88]:
(array([1.392200e+04, 5.900000e+01, 1.520000e+02, 6.400000e+01,
        1.181000e+03, 8.638000e+03, 5.531000e+03, 3.260000e+02,
        8.240000e+02, 1.630000e+02, 9.327100e+04, 5.190000e+02,
        1.214000e+03, 4.390000e+02, 9.510000e+02, 3.450000e+02,
        8.540000e+02, 3.190000e+02, 8.240000e+02, 2.440000e+02,
        6.810000e+02, 2.500000e+02, 6.660000e+02, 2.770000e+02,
        7.810000e+02, 2.280000e+02, 1.247000e+03, 2.190000e+02,
        7.570000e+02, 1.950000e+02, 6.560000e+02, 1.680000e+02,
        6.020000e+02, 1.590000e+02, 5.240000e+02, 1.740000e+02,
        5.350000e+02, 1.420000e+02, 4.890000e+02, 1.410000e+02,
        4.140000e+02, 1.120000e+02, 4.140000e+02, 1.120000e+02,
        4.140000e+02, 1.330000e+02, 3.830000e+02, 1.050000e+02,
        3.760000e+02, 8.700000e+01, 3.580000e+02, 9.800000e+01,
        3.310000e+02, 1.030000e+02, 3.230000e+02, 7.200000e+01,
        3.530000e+02, 8.700000e+01, 3.270000e+02, 8.500000e+01,
        3.210000e+02, 8.400000e+01, 3.350000e+02, 7.800000e+01,
        2.960000e+02, 7.200000e+01, 3.390000e+02, 7.000000e+01,
        3.270000e+02, 8.800000e+01, 3.790000e+02, 8.600000e+01,
        3.320000e+02, 8.300000e+01, 3.040000e+02, 7.300000e+01,
        3.060000e+02, 7.500000e+01, 2.790000e+02, 6.700000e+01,
        3.280000e+02, 7.600000e+01, 3.180000e+02, 7.400000e+01,
        3.010000e+02, 7.400000e+01, 3.350000e+02, 7.600000e+01,
        2.880000e+02, 5.600000e+01, 3.140000e+02, 6.700000e+01,
        3.340000e+02, 6.900000e+01, 3.290000e+02, 6.200000e+01,
        3.590000e+02, 3.373000e+03, 4.050000e+02, 6.215000e+03,
        3.790000e+02, 9.100000e+01, 3.450000e+02, 7.600000e+01,
        3.450000e+02, 6.500000e+01, 3.260000e+02, 9.000000e+01,
        3.350000e+02, 9.200000e+01, 2.920000e+02, 7.500000e+01,
        3.630000e+02, 7.900000e+01, 3.210000e+02, 7.600000e+01,
        3.140000e+02, 7.700000e+01, 3.590000e+02, 8.000000e+01,
        3.480000e+02, 8.200000e+01, 3.570000e+02, 8.500000e+01,
        3.310000e+02, 8.000000e+01, 3.730000e+02, 9.500000e+01,
        3.340000e+02, 8.400000e+01, 3.530000e+02, 1.010000e+02,
        3.940000e+02, 9.700000e+01, 3.580000e+02, 9.600000e+01,
        3.720000e+02, 1.030000e+02, 3.270000e+02, 8.700000e+01,
        5.500000e+02, 9.700000e+01, 3.480000e+02, 1.060000e+02,
        3.730000e+02, 9.800000e+01, 5.620000e+02, 1.750000e+02,
        4.280000e+02, 9.200000e+01, 4.280000e+02, 1.020000e+02,
        4.170000e+02, 1.070000e+02, 4.500000e+02, 1.190000e+02,
        4.640000e+02, 1.420000e+02, 5.370000e+02, 1.510000e+02,
        6.320000e+02, 1.800000e+02, 7.040000e+02, 2.030000e+02,
        8.480000e+02, 2.670000e+02, 1.055000e+03, 5.320000e+02,
        1.837000e+03, 5.930000e+02, 1.872000e+03, 2.550000e+02,
        1.005000e+03, 2.660000e+02, 1.088000e+03, 3.030000e+02,
        1.265000e+03, 4.460000e+02, 1.354000e+03, 3.860000e+02,
        2.152180e+05, 3.043000e+03, 4.840000e+03, 3.456000e+03,
        4.690000e+03, 2.583000e+03, 4.165000e+03, 2.601000e+03,
        3.022000e+04, 8.507000e+03, 6.442000e+03, 4.311000e+03,
        9.686000e+03, 6.115000e+03, 1.576400e+04, 1.408000e+04,
        9.764300e+04, 7.936000e+03, 1.122240e+05, 1.874616e+06]),
 array([0.   , 0.005, 0.01 , 0.015, 0.02 , 0.025, 0.03 , 0.035, 0.04 ,
        0.045, 0.05 , 0.055, 0.06 , 0.065, 0.07 , 0.075, 0.08 , 0.085,
        0.09 , 0.095, 0.1  , 0.105, 0.11 , 0.115, 0.12 , 0.125, 0.13 ,
        0.135, 0.14 , 0.145, 0.15 , 0.155, 0.16 , 0.165, 0.17 , 0.175,
        0.18 , 0.185, 0.19 , 0.195, 0.2  , 0.205, 0.21 , 0.215, 0.22 ,
        0.225, 0.23 , 0.235, 0.24 , 0.245, 0.25 , 0.255, 0.26 , 0.265,
        0.27 , 0.275, 0.28 , 0.285, 0.29 , 0.295, 0.3  , 0.305, 0.31 ,
        0.315, 0.32 , 0.325, 0.33 , 0.335, 0.34 , 0.345, 0.35 , 0.355,
        0.36 , 0.365, 0.37 , 0.375, 0.38 , 0.385, 0.39 , 0.395, 0.4  ,
        0.405, 0.41 , 0.415, 0.42 , 0.425, 0.43 , 0.435, 0.44 , 0.445,
        0.45 , 0.455, 0.46 , 0.465, 0.47 , 0.475, 0.48 , 0.485, 0.49 ,
        0.495, 0.5  , 0.505, 0.51 , 0.515, 0.52 , 0.525, 0.53 , 0.535,
        0.54 , 0.545, 0.55 , 0.555, 0.56 , 0.565, 0.57 , 0.575, 0.58 ,
        0.585, 0.59 , 0.595, 0.6  , 0.605, 0.61 , 0.615, 0.62 , 0.625,
        0.63 , 0.635, 0.64 , 0.645, 0.65 , 0.655, 0.66 , 0.665, 0.67 ,
        0.675, 0.68 , 0.685, 0.69 , 0.695, 0.7  , 0.705, 0.71 , 0.715,
        0.72 , 0.725, 0.73 , 0.735, 0.74 , 0.745, 0.75 , 0.755, 0.76 ,
        0.765, 0.77 , 0.775, 0.78 , 0.785, 0.79 , 0.795, 0.8  , 0.805,
        0.81 , 0.815, 0.82 , 0.825, 0.83 , 0.835, 0.84 , 0.845, 0.85 ,
        0.855, 0.86 , 0.865, 0.87 , 0.875, 0.88 , 0.885, 0.89 , 0.895,
        0.9  , 0.905, 0.91 , 0.915, 0.92 , 0.925, 0.93 , 0.935, 0.94 ,
        0.945, 0.95 , 0.955, 0.96 , 0.965, 0.97 , 0.975, 0.98 , 0.985,
        0.99 , 0.995, 1.   ], dtype=float32),
 <a list of 200 Patch objects>)
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [108]:
fig = plt.figure()
gs = gridspec.GridSpec(1, 2, width_ratios=[3, 1]) 
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
fig.subplots_adjust(hspace=0, wspace=0)

ax1.hexbin(star_tab['m_gpc1_g'], star_tab['stellarity'], cmap='Reds', bins="log", mincnt=1)#gridsize=200,
           
ax1.set_xlim(10,25)
ax1.set_ylim(0,1)
ax1.set_xlabel("GPC $g$ [mag]")
ax1.set_ylabel("Stellarity")
ax1.set_xticks([10,15,20])
ax1.set_xticklabels([10,15,20])
#legend = ax.legend( markerscale=2)

ax2.hist(star_tab[~np.isnan(star_tab['stellarity'] )]['stellarity'], bins=50, orientation="horizontal")
ax2.set_yticklabels([])
ax2.set_ylim(0,1)


ax2.set_xlabel("N")
ax2.set_xscale('log')

#ax2.set_xticks([0,1000000,2000000])
#ax2.set_xticklabels([0,'','2m'])
#ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())

plt.rc('font', family='serif', serif='Times')
plt.rc('text') #, usetex=True)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rc('axes', labelsize=12)

column_width_cm = 8.9
width_cm = 1.0 * column_width_cm
hieght_cm = width_cm / 1.0
width_inches = width_cm/2.5
hieght_inches = hieght_cm/2.5
fig.set_size_inches(width_inches, hieght_inches)
plt.savefig('./figs/stellarity.pdf', bbox_inches='tight')
plt.savefig('./figs/stellarity.png', bbox_inches='tight')
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

flag_merged stats mags

In [45]:
merged_query="""SELECT TOP 1000000
m_mmt_g, 
m_omegacam_g, 
m_suprime_g, 
m_megacam_g, 
m_wfc_g, 
m_gpc1_g, 
m_decam_g, 
m_90prime_g, 
m_sdss_g, 
m_isaac_k, 
m_moircs_k, 
m_ukidss_k, 
m_newfirm_k, 
m_wircs_k, 
m_hawki_k,
m_wircam_ks, 
m_vista_ks, 
m_moircs_ks, 
m_omega2000_ks, 
m_tifkam_ks,
ra,
dec
FROM herschelhelp.main
WHERE herschelhelp.main.flag_merged='true'
AND NOT herschelhelp.main.field='XMM-LSS'
AND m_suprime_g IS NOT NULL
"""
In [46]:
job = service.submit_job(merged_query)
job.run()
job_url = job.url
job_result = vo.dal.tap.AsyncTAPJob(job_url)
start_time = time.time()
wait = 5.
print(job.phase)
while (job.phase == 'EXECUTING') or (job.phase == 'QUEUED'):
    
    time.sleep(wait) #wait and try again
    #wait *= 2

print('Job {} after {} seconds.'.format(job.phase, round(time.time() - start_time)))

result = job_result.fetch_result()
merged_tab = result.table
EXECUTING
Job COMPLETED after 562 seconds.
WARNING: W35: None:2:1080: W35: 'value' attribute required for INFO elements [astropy.io.votable.tree]
WARNING: W27: None:2:1458: W27: COOSYS deprecated in VOTable 1.2 [astropy.io.votable.tree]
In [47]:
len(merged_tab)
Out[47]:
380940
In [48]:
merged_tab.sort(['ra', 'dec'])
In [49]:
merged_tab[-10:].show_in_notebook()
Out[49]:
Table masked=True length=10
idxm_mmt_gm_omegacam_gm_suprime_gm_megacam_gm_wfc_gm_gpc1_gm_decam_gm_90prime_gm_sdss_gm_isaac_km_moircs_km_ukidss_km_newfirm_km_wircs_km_hawki_km_wircam_ksm_vista_ksm_moircs_ksm_omega2000_ksm_tifkam_ksradec
magmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagdegdeg
0----23.012125015258822.1012001037598--22.366300582885722.1944618225098--22.4326553344727----18.3386859893799----------------353.9500129804710.252475861524957
1----29.3908672332764----------------------------------353.9505265637160.242096950699912
2----26.7245750427246------26.3114223480225--------------------------353.9507323394630.242605446914017
3----24.186573028564524.0468006134033----24.4236335754395--------------------------353.9508541501430.202267173810872
4----25.766899108886725.7334003448486----24.405876159668--------------------------353.9511678205490.236284268456665
5----23.0175704956055----------------------------------353.9511873447840.202264349284832
6----24.699905395507824.355899810791--23.564800262451224.2581672668457--23.9006156921387----20.2742652893066--------20.203483581543------353.9512456808590.235745873574931
7----25.4438171386719----------------------------------353.9515524957360.240695735167614
8----30.3465270996094----------------------------------353.9517579839430.240868705655838
9----23.141723632812524.2817001342773----23.9699153900146--24.5459098815918----------------------353.9522185753670.202695520604337
In [50]:
only_suprime = ~np.isnan(merged_tab['m_suprime_g'])

for band in [
    'm_mmt_g', 
    'm_omegacam_g', 
    #'m_suprime_g, 
    'm_megacam_g', 
    'm_wfc_g', 
    'm_gpc1_g', 
    'm_decam_g', 
    'm_90prime_g', 
    'm_sdss_g']:
    only_suprime &= merged_tab[band].mask
In [51]:
frac_unmatched = np.full(len(bins)-1, np.nan)
for n, b in enumerate(bins[:-1]):
    mask = merged_tab['m_suprime_g'] > bins[n]
    mask &= merged_tab['m_suprime_g'] < bins[n+1]
    frac_unmatched[n] = np.sum(mask & only_suprime)/np.sum(mask)
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:5: RuntimeWarning: invalid value encountered in long_scalars
In [53]:
fig, ax = plt.subplots()

ax.plot(bins[:-1]+(bins[1] - bins[0])/2, frac_unmatched)

ax.set_xlim(18,28)
ax.set_ylim(0,1)
ax.set_xlabel("HSC g magnitude [mag]")
ax.set_ylabel("Fraction of objects")
legend = ax.legend( markerscale=2)

plt.rc('font', family='serif', serif='Times')
plt.rc('text') #, usetex=True)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rc('axes', labelsize=12)

column_width_cm = 8.9
width_cm = 1.0 * column_width_cm
hieght_cm = width_cm / 1.0
width_inches = width_cm/2.5
hieght_inches = hieght_cm/2.5
fig.set_size_inches(width_inches, hieght_inches)
plt.savefig('./figs/merged_unmatched.pdf', bbox_inches='tight')
plt.savefig('./figs/merged_unmatched.png', bbox_inches='tight')
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/axes/_axes.py:545: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [24]:
for band in [
    'm_mmt_g', 
    'm_omegacam_g', 
    #'m_suprime_g, 
    'm_megacam_g', 
    'm_wfc_g', 
    'm_gpc1_g', 
    'm_decam_g', 
    'm_90prime_g', 
    'm_sdss_g']:
    merged_tab[band].fill_value = np.nan
merged_tab = merged_tab.filled()
In [20]:
np.sum(only_suprime)
Out[20]:
142347
In [38]:
merged_tab.add_column(Column(
    data= np.nanstd(np.array([ 
        merged_tab['m_mmt_g'].data,  
        merged_tab['m_omegacam_g'].data,  
        merged_tab['m_suprime_g'].data, 
        merged_tab['m_megacam_g'].data,  
        merged_tab['m_wfc_g'].data,  
        merged_tab['m_gpc1_g'].data,  
        merged_tab['m_decam_g'].data,  
        merged_tab['m_90prime_g'].data,  
        merged_tab['m_sdss_g'].data
    ]), axis=0 ) ,
                             
    name='std'
))
/Users/rs548/anaconda/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/lib/nanfunctions.py:1426: RuntimeWarning: invalid value encountered in subtract
  np.subtract(arr, avg, out=arr, casting='unsafe')
In [39]:
merged_tab[-10:].show_in_notebook()
Out[39]:
Table length=10
idxm_mmt_gm_omegacam_gm_suprime_gm_megacam_gm_wfc_gm_gpc1_gm_decam_gm_90prime_gm_sdss_gradecstd
magmagmagmagmagmagmagmagmagdegdeg
0nannan23.012125015258822.1012001037598nan22.366300582885722.1944618225098nan22.4326553344727353.9500129804710.2524758615249570.31816585885460236
1nannan29.3908672332764nannannannannannan353.9505265637160.2420969506999120.0
2nannan26.7245750427246nannannan26.3114223480225nannan353.9507323394630.2426054469140170.20657634735104935
3nannan24.186573028564524.0468006134033nannan24.4236335754395nannan353.9508541501430.2022671738108720.15554103145745654
4nannan25.766899108886725.7334003448486nannan24.405876159668nannan353.9511678205490.2362842684566650.6338441885065257
5nannan23.0175704956055nannannannannannan353.9511873447840.2022643492848320.0
6nannan24.699905395507824.355899810791nan23.564800262451224.2581672668457nan23.9006156921387353.9512456808590.2357458735749310.3901203310792532
7nannan25.4438171386719nannannannannannan353.9515524957360.2406957351676140.0
8nannan30.3465270996094nannannannannannan353.9517579839430.2408687056558380.0
9nannan23.141723632812524.2817001342773nannan23.9699153900146nan24.5459098815918353.9522185753670.2026955206043370.52772940530094