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

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

import hosts
import targeting
import mmthecto
import numpy as np

from astropy import units as u
from astropy.coordinates import *
from astropy import table
from astropy.table import Table
from astropy.io import fits

In [3]:
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import rcParams

rcParams['image.interpolation'] = 'none'
rcParams['figure.figsize'] = (16, 10)

In [4]:
hostlst = hosts.get_saga_hosts_from_google(useobservingsummary=True) #'named' hosts


Using cached version of google hosts list from file "hosts_dl.pkl"

In [5]:
candidates = """
NSAID    RA   DEC Name
   150887      23.2455      4.53406  N/A
    150578.      23.0824      12.3229  N/A
    149781.      22.3942     -3.43167  OBrother
    150307.      22.9283     -5.49535  N/A
    61945.0      23.6087     0.297265  AnaK
    149977.      22.6248      10.5315  N/A
    153017.      23.9904      20.7498  N/A
    126115.    0.0663717      20.7524  N/A
    127226.     0.579656     -8.39644  N/A
    129387.      1.40109      12.9175  N/A
    129237.      1.36327      17.5922  N/A
    132339.      2.63655     -1.31876 Narnia
    130133.      1.65181     -7.51266  N/A
    131531.      2.25767      6.00248  N/A
    130625.      1.88703      4.19576  N/A
"""
candidates = Table.read(candidates,format='ascii')

hostdct = dict([(h.name, h) for h in hostlst])
candhosts = [hostdct[name] if name in hostdct else hosts.NSAHost(int(nsaid)) 
         for nsaid, name in zip(candidates['NSAID'], candidates['Name'])]
candhosts


Out[5]:
[<hosts.NSAHost object w/ name 'NSA150887'>,
 <hosts.NSAHost object w/ name 'NSA150578'>,
 <hosts.NSAHost object w/ name 'OBrother' AKA: ['NSA149781']>,
 <hosts.NSAHost object w/ name 'NSA150307'>,
 <hosts.NSAHost object w/ name 'AnaK' AKA: ['NGC7716', 'NSA61945']>,
 <hosts.NSAHost object w/ name 'NSA149977'>,
 <hosts.NSAHost object w/ name 'NSA153017'>,
 <hosts.NSAHost object w/ name 'NSA126115'>,
 <hosts.NSAHost object w/ name 'NSA127226'>,
 <hosts.NSAHost object w/ name 'NSA129387'>,
 <hosts.NSAHost object w/ name 'NSA129237'>,
 <hosts.NSAHost object w/ name 'Narnia' AKA: ['NGC1015', 'NSA132339']>,
 <hosts.NSAHost object w/ name 'NSA130133'>,
 <hosts.NSAHost object w/ name 'NSA131531'>,
 <hosts.NSAHost object w/ name 'NSA130625'>]

In [6]:
# now set to the latest base catalogs
for h in candhosts:
    h.fnsdss = 'catalogs/base_sql_nsa{0}.fits.gz'.format(h.nsaid)
    h._cached_sdss = None

In [7]:
# actually make sure they're loaded here
for h in candhosts:
    h.get_sdss_catalog()
h.get_sdss_catalog() # just to see


Out[7]:
<Table masked=False length=68227>
objIDradecflagsspecObjIDugrizu_errg_errr_erri_errz_errAuAgArAiAzfibermag_rfiber2mag_rexpRad_rsb_exp_rpetroR50_rpetroR90_rpetroMag_rsb_petro_rJJerrHHerrKKerrw1w1errw2w2errspec_zspec_z_errspec_z_warnphotozphotoz_errHOST_RAHOST_DECHOST_DISTHOST_VHOSTHOST_MKHOST_NSAIDHOST_FLAGHOST_SAGA_NAMERHOST_ARCMRHOST_KPCOBJ_NSAIDPCLASS_1SATSREMOVETELNAMEMASKNAMEZQUALITYSPEC_REPEATUBVRIrhostrhost_kpctypephot_sg
int64float64float64int64int64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float64float32float32float32float64float32float32float32float32float32float32float32float32float32float32float32float32int32float32float32float64float64float64float64float64int64int64string384float64float64int64int64int64int64string32string384float64string384float32float32float32float32float32float64float64int16string48
123767862223968729328.29218937614.1654677952387097114444048024.886124.538422.964821.945621.31480.9661160.5658630.2382030.1351540.2807910.193710.142530.1033750.07838580.055576522.26122.97410.13222520.56680213240.6418641.3758422.985924.01858371229999.09999.09999.09999.09999.09999.017.94990.20725216.0030.175-1.0-1.0-10.5957910.08232228.30544.1957622.74691733.08.72613062501.9820026609613.114524378-1-1-1-1-1.025.444825.249923.633322.691921.30510.033019848276212.96201855523GALAXY
123767862223968753528.28085317844.17348908215281543964623616024.254923.137921.911421.785821.60710.9755350.2128210.09797780.1201670.3591270.1937230.1425390.1033810.0783910.055580222.295122.77680.21696420.58877813660.5905221.319522.047822.89947970379999.09999.09999.09999.09999.09999.019.49840.8485849999.09999.0-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.72613062501.9857324142813.1392034243-1-1-1-1-1.024.151623.740822.428921.775221.31980.033070632014712.98195383036STAR
123767862223968755128.28923055074.1666156998281543964623104023.53823.673322.798922.260121.72350.6477140.3206250.2016270.1750920.3719330.1936680.1424990.1033520.0783690.055564622.950423.40560.0014911610.6619883934-9999.0-9999.027.000548.99569790599999.09999.09999.09999.09999.09999.017.52890.1373489999.09999.0-1.0-1.0-10.6378830.13766828.30544.1957622.74691733.08.72613062501.9984970286613.2236643743-1-1-1-1-1.023.73924.165923.163322.599521.6560.033291909191813.06881670293GALAXY
123767866143637581528.31787105284.22726178032281543964623616026.157222.157821.486820.018919.58651.650040.27290.2661160.1090580.298410.1960140.1442250.1046040.0793180.056237523.145223.51920.26470921.71037908093.992386.4714221.483926.48551619389999.09999.09999.09999.09999.09999.018.79340.4697929999.09999.0-1.0-1.0-10.95290.18447328.30544.1957622.74691733.08.72613062502.0320936016113.4459663078-1-1-1-1-1.024.202122.586821.762721.145219.4550.033880723416913.29995710213GALAXY
123767866143637582228.33792906844.18852269949281475245277440023.6423.18623.367121.556421.36180.9471160.2588170.5224180.1575880.5182120.1955760.1439030.104370.0791410.056111923.866524.15874.2508927.42103245640.8413041.1010723.562425.18263944879999.09999.09999.09999.09999.09999.017.65420.1575349999.09999.0-1.0-1.0-10.4657910.24836528.30544.1957622.74691733.08.72613062501.9943611526613.1962980939-1-1-1-1-1.022.668423.348323.272322.97321.08430.033272571525313.06122565683GALAXY
123767862223968729228.29176886824.1647939568535253360001296024.885422.432220.839620.158319.7941.140230.1365690.04787440.03727070.09619610.1936630.1424960.103350.07836690.055563121.331621.87340.4972821.36716999560.7398491.428920.998122.33924659979999.09999.09999.09999.09999.09999.016.53480.057011616.0030.175-1.0-1.0-10.3458570.04428628.30544.1957622.74691733.08.72613062502.0291259719913.4263300847-1-1-1-1-1.024.449523.149721.516420.618419.62070.033805136554113.27028530263GALAXY
123767862223968726328.27859066244.1725615376868987912192022.43722.274921.903121.544121.05370.3017610.1114710.1077530.1097590.2585090.1935980.1424480.1033150.07834070.055544522.402922.88650.28426621.26447399930.7152762.1280521.944423.21224125939999.09999.09999.09999.09999.09999.017.90260.1976439999.09999.0-1.0-1.0-10.5180330.23051728.30544.1957622.74691733.08.72613062502.1239167752214.0535422304-1-1-1-1-1.022.071722.610322.048821.731220.95780.035373218062313.88583936073GALAXY
123767862223968735528.3176155984.1603599999768987912448024.652822.420221.032920.118119.63140.9886330.11230.04642210.02986790.06804620.1945320.1431350.1038130.07871840.055812321.414821.88940.13439618.67027149280.6027391.2909821.147222.04332746389999.09999.09999.09999.09999.09999.017.55030.1441169999.09999.0-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.72613062502.2462625390514.8630801279-1-1-1-1-1.024.149623.073421.620420.775919.53320.037448726017214.70058485566STAR
123767862223968754028.28544412874.16744059371281709320864000023.637623.19922.604121.956823.0580.7658820.2467270.2052090.1585460.6630690.1935820.1424360.1033060.0783340.055539823.07723.48390.512723.14884147140.46970.62672523.341423.6959243029999.09999.09999.09999.09999.09999.018.75020.4266669999.09999.0-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.72613062502.0768094950513.741842602-1-1-1-1-1.023.327623.604222.846922.38821.98490.034594103114113.57999596836STAR
123767866143637579028.27436556534.17756344018281543964623616023.045222.920422.209821.03220.53330.8699960.3035030.2848310.1620630.3930950.1936990.1425220.1033690.07838160.055573523.165223.57710.45996222.92375309890.4501750.72617323.303423.56579012919999.09999.09999.09999.09999.09999.017.79190.1781079999.09999.0-1.0-1.0-10.7720220.09980828.30544.1957622.74691733.08.72613062502.1542383441214.2541741001-1-1-1-1-1.022.983423.361822.502921.912620.44250.035874985486314.08280933493GALAXY
..................................................................................................................................................................................................................
123767866251005182428.19789187115.1472318957268987912960022.83522.867922.292321.34821.01730.434580.185450.1897910.1362240.3097030.2328130.1713010.1242420.0942090.066795322.817523.27010.38463822.26348495330.6959141.9337222.490523.69868288769999.09999.09999.09999.09999.09999.017.51790.14659217.0010.42-1.0-1.0-10.7148250.15350328.30544.1957622.74691733.08.726130625057.4496442549380.115399837-1-1-1-1-1.022.735123.267122.526722.030820.82330.957482542474375.8620081473GALAXY
123767866251011728828.3660528395.18434052911475064453693712024.067321.571420.457420.318620.00591.873450.103330.06680430.09732490.2466760.2195710.1615590.1171760.08885080.062996321.594122.26882.4054324.35880355981.853625.2963820.410323.74582340179999.09999.09999.09999.09999.09999.017.1640.12208617.00.412-1.0-1.0-10.3537050.07156628.30544.1957622.74691733.08.726130625059.4257682552393.189137686-1-1-1-1-1.023.207322.13920.92620.319219.80090.990429148022388.7952750983GALAXY
123767866251005190128.23665285615.1710167367168987912192023.413121.80720.545120.115919.72680.6678750.07235580.04060740.0448980.09753060.2307160.1697580.1231230.09336040.066193720.9521.45890.37688120.43399375860.8519061.9869220.54922.19642340899999.09999.09999.09999.09999.09999.017.62850.16016816.9979999.0-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.726130625058.6598300601388.121821481-1-1-1-1-1.023.10522.42121.07820.362419.56870.977658355025383.7820704826STAR
123767866251005176028.17903969485.10886184428158546838815488024.255721.812720.902720.383119.88711.572210.1032210.07750170.08189270.171120.2350480.1729460.1254350.09511360.067436721.660322.23230.93200722.86316457051.131292.3475321.051923.31522362919999.09999.09999.09999.09999.09999.017.11740.10316116.5329999.0-1.0-1.0-10.0777210.03472628.30544.1957622.74691733.08.726130625055.3054351766365.929494562-1-1-1-1-1.023.249222.316621.282520.706219.79460.921741950142361.8319551583GALAXY
123767866251005222828.19645911325.17059183035281543964623104022.856123.835923.091321.243821.3090.5824930.5428780.4989740.1641840.5400720.2343340.1724210.1250540.09482470.067231923.723824.10212.1204926.29226734991.47822.4647722.925925.76997248159999.09999.09999.09999.09999.09999.017.15150.100916.8869999.0-1.0-1.0-10.6481540.13671628.30544.1957622.74691733.08.726130625058.8520693103389.393645328-1-1-1-1-1.023.353224.28823.399222.691720.8720.980856108509385.037356083GALAXY
123767866251005136428.19721376785.18726645925105622137864464023.892324.876622.449220.730619.87290.8216750.6153490.194680.07011220.1000440.234650.1726530.1252220.09495230.067322322.941523.27670.0001973075.920286484530.5619921.0276722.79523.53906275269999.09999.09999.09999.09999.09999.016.58810.059152216.2170.202-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.726130625059.8415908781395.940140938-1-1-1-1-1.025.810125.855423.489122.069320.00250.997348321978391.5114129936STAR
123767866251011698228.33370697955.10776644478316730484326744025.716124.869822.834421.580921.69030.6510580.581950.265010.1357850.440910.2154690.158540.1149860.08719070.061819322.669723.11270.024432616.76971117340.420140.82183723.288923.40136787629999.09999.09999.09999.09999.09999.017.36090.1263417.2289999.0-1.0-1.0-1-1.0-1.028.30544.1957622.74691733.08.726130625054.7465971912362.232246272-1-1-1-1-1.026.424725.725823.703822.525621.22610.912443917985358.1819909216STAR
123767866250998598528.10090610155.10763501063175990882046040024.506222.590721.735121.408821.91261.193350.148640.1206640.1460450.6549290.246980.1817260.1318030.09994190.070860121.857422.51220.52879422.34702084910.8196561.4443821.881423.44503684899999.09999.09999.09999.09999.09999.09999.09999.016.9840.506-1.0-1.0-10.2942650.1801828.30544.1957622.74691733.08.726130625056.0642111907370.949508831-1-1-1-1-1.023.70723.077522.091321.568221.20620.93436838814366.7884928823GALAXY
123767866250998657928.12080073075.16413373448281543964623104025.098223.347721.84321.076820.53021.203130.3199620.1485960.1231310.2507250.2421530.1781740.1292270.09798860.069475122.353622.92750.58884622.6884253080.8446191.2757422.193923.8226364459999.09999.09999.09999.09999.09999.017.04410.092761916.6659999.0-1.0-1.0-10.4142990.0605628.30544.1957622.74691733.08.726130625059.1431466447391.319363668-1-1-1-1-1.024.925524.037722.481521.608720.46880.985689958387386.9348951393GALAXY
123767866251005209828.16527226365.15719765697281543964758272025.385223.242721.703721.472320.91451.020120.2891760.128630.1741220.3330220.2364770.1739980.1261980.09569190.067846722.27922.78860.78178123.25845326091.108173.2668121.619523.83796562699999.09999.09999.09999.09999.09999.017.47950.13953816.4410.249-1.0-1.0-10.384370.09836528.30544.1957622.74691733.08.726130625058.2924947433385.691586949-1-1-1-1-1.025.053123.943322.357121.551320.860.971523519244381.3738263693GALAXY

For September 1


In [8]:
p_column_for_ranking = 'PROBABILITY_CLASS_1' #this is *just* SDSS

In [9]:
hostnames_to_target = [150887, 150578, 'OBrother', 150307, 'AnaK', 149977, 153017, 129387, 129237, 'Narnia', 126115]
hosts_to_target = []
for hostname in hostnames_to_target:
    if isinstance(hostname, basestring):
        for host in candhosts:
            if host.name == hostname:
                hosts_to_target.append(host)
                break
        else:
            raise ValueError('could not find host named {0}'.format(hostname))
    else:
        for host in candhosts:
            if host.nsaid == hostname:
                hosts_to_target.append(host)
                break                
        else:
            raise ValueError('could not find host with nsa number {0}'.format(hostname))
hosts_to_target


Out[9]:
[<hosts.NSAHost object w/ name 'NSA150887'>,
 <hosts.NSAHost object w/ name 'NSA150578'>,
 <hosts.NSAHost object w/ name 'OBrother' AKA: ['NSA149781']>,
 <hosts.NSAHost object w/ name 'NSA150307'>,
 <hosts.NSAHost object w/ name 'AnaK' AKA: ['NGC7716', 'NSA61945']>,
 <hosts.NSAHost object w/ name 'NSA149977'>,
 <hosts.NSAHost object w/ name 'NSA153017'>,
 <hosts.NSAHost object w/ name 'NSA129387'>,
 <hosts.NSAHost object w/ name 'NSA129237'>,
 <hosts.NSAHost object w/ name 'Narnia' AKA: ['NGC1015', 'NSA132339']>,
 <hosts.NSAHost object w/ name 'NSA126115'>]

In [10]:
for hr, hnm in sorted([(h.coords.ra.hour, h.name) for h in hosts_to_target]):
    print('Host', hnm, 'is at', hr, 'hours of RA')


Host NSA126115 is at 0.0663716748178 hours of RA
Host NSA129237 is at 1.36326749391 hours of RA
Host NSA129387 is at 1.40108502691 hours of RA
Host Narnia is at 2.63654460764 hours of RA
Host OBrother is at 22.3942109355 hours of RA
Host NSA149977 is at 22.6247990444 hours of RA
Host NSA150307 is at 22.9282384186 hours of RA
Host NSA150578 is at 23.0824026181 hours of RA
Host NSA150887 is at 23.2455271919 hours of RA
Host AnaK is at 23.6087369353 hours of RA
Host NSA153017 is at 23.9904183433 hours of RA

In [11]:
mlpred = Table.read('catalogs/SAGAobjid_PredictionAug28_SDSS_SDSSwise_v4removed_combinedPs.fits.gz')
mlpred['OBJID'].name = 'objID'
mlpred


Out[11]:
<Table masked=False length=1044550>
objIDRADECDERED_RPROBABILITY_CLASS_1BEST_GUESS_CLASS_1OBJID_2RA_2DEC_2DERED_R_2PROBABILITY_CLASS_1_WISEBEST_GUESS_CLASS_2P_SDSS_PLUS_P_WISEMAX_P_SDSS_OR_P_WISEP_WISE_OR_P_SDSS
int64float64float64float64float64int64int64float64float64float64float64int64float64float64float64
1237667783913832538198.18831076322.833076574615.60270.8726258543111-9223372036854775808nannannannan-92233720368547758080.8726258543110.8726258543110.872625854311
1237650372092690479180.30349599-1.2934919977620.65580.80259896852511237650372092690479180.30349599-1.2934919977620.65580.78270527369711.00.8025989685250.782705273697
1237661356465979552169.5542122145.747930744721.6150.7754183103931-9223372036854775808nannannannan-92233720368547758080.7754183103930.7754183103930.775418310393
1237667212129665196158.07169027427.671138811620.11710.7653916183241-9223372036854775808nannannannan-92233720368547758080.7653916183240.7653916183240.765391618324
1237661851475968027205.87684694643.463633639719.86610.7601723941621-9223372036854775808nannannannan-92233720368547758080.7601723941620.7601723941620.760172394162
1237661970646040623178.9755822366.7436123145519.44670.756658675441-9223372036854775808nannannannan-92233720368547758080.756658675440.756658675440.75665867544
1237674648854593937179.119907353-1.0910617556521.47690.73905798471-9223372036854775808nannannannan-92233720368547758080.73905798470.73905798470.7390579847
1237648704056524899220.693361666-0.34479490242221.04960.7390199268651-9223372036854775808nannannannan-92233720368547758080.7390199268650.7390199268650.739019926865
1237667254545416219165.92988117128.888597176719.12520.7386378241991-9223372036854775808nannannannan-92233720368547758080.7386378241990.7386378241990.738637824199
1237667254007300140162.78287099827.979588966919.2380.73557112774611237667254007300140162.78287099827.979588966919.2380.74700231201311.00.7470023120130.747002312013
.............................................
1237657591394599367174.71784509255.409457241221.18991.61041053102e-0501237657591394599367174.71784509255.409457241221.18998.30960427447e-0509.92001480549e-058.30960427447e-058.30960427447e-05
1237659119860122384216.3971133350.837869669420.93461.59404614019e-0501237659119860122384216.3971133350.837869669420.93463.24230520733e-0504.83635134752e-053.24230520733e-053.24230520733e-05
123767862011455141628.31468140913.2961608939820.47461.55587976146e-050123767862011455141628.31468140913.2961608939820.47462.12388520775e-0503.67976496921e-052.12388520775e-052.12388520775e-05
1237650371555491959179.539594407-1.8308759472320.01361.55587976146e-050-9223372036854775808nannannannan-92233720368547758081.55587976146e-051.55587976146e-051.55587976146e-05
1237667254544171472162.66869750828.523855736920.57161.55587976146e-0501237667254544171472162.66869750828.523855736920.57164.63389280081e-0506.18977256227e-054.63389280081e-054.63389280081e-05
1237667254010511776171.06413029229.052376240620.93571.55587976146e-0501237667254010511776171.06413029229.052376240620.93572.69565444012e-0504.25153420158e-052.69565444012e-052.69565444012e-05
1237648721249239828222.30779985-0.010709766979921.12331.53995461258e-0501237648721249239828222.30779985-0.010709766979921.12332.18080636551e-0503.72076097809e-052.18080636551e-052.18080636551e-05
1237662267533689436219.7913434796.0542733743321.03841.48765011384e-0501237662267533689436219.7913434796.0542733743321.03842.90333283278e-0504.39098294662e-052.90333283278e-052.90333283278e-05
1237680065883603116342.819383844-4.6480705762419.91621.43727612522e-050-9223372036854775808nannannannan-92233720368547758081.43727612522e-051.43727612522e-051.43727612522e-05
1237667731808912074130.82164552114.29621662621.1641.41236727388e-050-9223372036854775808nannannannan-92233720368547758081.41236727388e-051.41236727388e-051.41236727388e-05

In [12]:
joined_catalogs = {}
for h in hosts_to_target:
    #filter on manual remove lists *and* REMOVE!=-1
    cat = targeting.remove_targets_with_remlist(h.get_sdss_catalog(), h, 'catalogs/TargetRemoveAug28_2015.csv')
    
    pre_joined = table.join(cat, mlpred, join_type='left', keys='objID')
    
    tokeep = pre_joined['REMOVE']==-1
    notobserved = pre_joined['ZQUALITY']<3
    print('removed', np.sum(~tokeep),'for remove list and', np.sum(~notobserved),'b/c observed')
    joined_catalogs[h] = pre_joined[tokeep&notobserved]
    highp = pre_joined[p_column_for_ranking]>0.01
    print('n w/ ML pred>0.01 and observed:', np.sum(highp&~notobserved), 'not yet obs:', np.sum(highp&notobserved))


Removed 4 objects for NSA150887
removed 250 for remove list and 722 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 124
No matches found for host "NSA150578" in remove list. Maybe you mis-typed something?
removed 58 for remove list and 47 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 205
Removed 3 objects for OBrother
removed 280 for remove list and 411 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 198
No matches found for host "NSA150307" in remove list. Maybe you mis-typed something?
removed 80 for remove list and 2 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 61
Removed 18 objects for AnaK
removed 479 for remove list and 2060 b/c observed
n w/ ML pred>0.01 and observed: 3 not yet obs: 127
No matches found for host "NSA149977" in remove list. Maybe you mis-typed something?
removed 52 for remove list and 225 b/c observed
n w/ ML pred>0.01 and observed: 1 not yet obs: 162
No matches found for host "NSA153017" in remove list. Maybe you mis-typed something?
removed 89 for remove list and 3 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 94
Removed 7 objects for NSA129387
removed 282 for remove list and 317 b/c observed
n w/ ML pred>0.01 and observed: 1 not yet obs: 124
Removed 2 objects for NSA129237
removed 218 for remove list and 532 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 183
Removed 5 objects for Narnia
removed 469 for remove list and 1185 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 131
Removed 2 objects for NSA126115
removed 52 for remove list and 5 b/c observed
n w/ ML pred>0.01 and observed: 0 not yet obs: 79

In [22]:
# fix up the rhost columns, which are wrong near the 0-360 boundary
for h in hosts_to_target:
    cat = joined_catalogs[h]
    catsc = SkyCoord(u.Quantity(cat['ra'], u.deg), u.Quantity(cat['dec'], u.deg))

    seps = catsc.separation(h.coords)
    
    
    dsep = seps - u.Quantity(cat['RHOST_ARCM'], u.arcmin)
    if np.abs(np.mean(dsep)) > 1*u.arcsec:
        print('Host', h.name, 'has >10" offsets from calculated and catalog separation. Issues? Showing histogram')
    
        plt.figure()
        plt.hist(dsep.to(u.arcsec), bins=100, histtype='step')
        plt.axvline(0, color='k')
        plt.axvline(np.mean(dsep).to(u.arcsec).value, color='r', ls='--')
        plt.title(h.name)
    joined_catalogs[h]['RHOST_ARCM'][:] = seps.to(u.arcmin).value
    joined_catalogs[h]['RHOST_KPC'][:] = (seps.radian*h.dist).to(u.kpc).value


Host NSA153017 has >10" offsets from calculated and catalog separation. Issues? Showing histogram
Host NSA126115 has >10" offsets from calculated and catalog separation. Issues? Showing histogram

No redmapper


In [115]:
# compute ranks, which includes filtering on mag
rankdct = {}
for h in hosts_to_target:
    cat = joined_catalogs[h]
    
    
    highprob = cat[p_column_for_ranking].filled(0) > 0.5
    medprob = (cat[p_column_for_ranking].filled(0) > 0.05) & ~highprob
    lowprob = (cat[p_column_for_ranking].filled(0) > 0.01) & ~highprob & ~medprob
    inside = cat['RHOST_KPC']<300
    
    rankdct[h] = ranks = np.ones(len(cat), dtype=int)*-1 #the -1 will be re-set at the end
    
    # rank 1 reserved for flux stars
    ranks[inside&highprob] = 2
    ranks[~inside&highprob] = 3
    ranks[inside&medprob] = 4
    ranks[~inside&medprob] = 5
    ranks[inside&lowprob] = 6
    ranks[~inside&lowprob] = 7
    
    validtarget = (cat['r'] < 21.5) & (cat['fibermag_r']<23) & (cat['phot_sg']=='GALAXY')
    other = ranks < 0
    colorcutmsk = targeting.colorcut_mask(cat,  targeting.bossanova_color_cuts)
    
    ranks[validtarget&other&colorcutmsk] = 8
    ranks[validtarget&other&~colorcutmsk] = 9
    
#informational
for h, ranks in rankdct.items():
    cat = joined_catalogs[h]
    
    hranks = dict(enumerate(np.bincount(ranks[ranks>-1])))
    del hranks[0]
    del hranks[1]
    hranks[-1] = np.sum(ranks==-1)
    
    print(h.name,'rank counts:', hranks)
    
    nother =  np.sum(ranks==8)
    nprob = np.sum((ranks<8)&(ranks>0))
    nother_obs = 270-np.sum((ranks<8)&(ranks>0)&(cat['RHOST_ARCM']<30))
    print('fraction not "other": {0:.1%}, nprob_obs={1}\n'.format(nprob/(nprob+nother), nother_obs))


NSA153017 rank counts: {2: 1, 3: 0, 4: 7, 5: 4, 6: 45, 7: 36, 8: 9128, 9: 6531, -1: 46391}
fraction not "other": 1.0%, nprob_obs=257

NSA129387 rank counts: {2: 0, 3: 0, 4: 4, 5: 11, 6: 25, 7: 80, 8: 10178, 9: 6188, -1: 53562}
fraction not "other": 1.2%, nprob_obs=237

NSA150307 rank counts: {2: 0, 3: 1, 4: 4, 5: 11, 6: 3, 7: 39, 8: 8331, 9: 5399, -1: 42785}
fraction not "other": 0.7%, nprob_obs=259

NSA150578 rank counts: {2: 1, 3: 1, 4: 3, 5: 12, 6: 40, 7: 148, 8: 7583, 9: 6723, -1: 46127}
fraction not "other": 2.6%, nprob_obs=228

NSA149977 rank counts: {2: 0, 3: 0, 4: 1, 5: 13, 6: 22, 7: 123, 8: 6619, 9: 4629, -1: 51931}
fraction not "other": 2.3%, nprob_obs=239

NSA150887 rank counts: {2: 1, 3: 2, 4: 11, 5: 19, 6: 28, 7: 53, 8: 9592, 9: 7613, -1: 51964}
fraction not "other": 1.2%, nprob_obs=226

NSA126115 rank counts: {2: 0, 3: 0, 4: 5, 5: 17, 6: 14, 7: 42, 8: 8439, 9: 6008, -1: 43115}
fraction not "other": 0.9%, nprob_obs=255

OBrother rank counts: {2: 0, 3: 0, 4: 2, 5: 24, 6: 26, 7: 143, 8: 9288, 9: 6216, -1: 63548}
fraction not "other": 2.1%, nprob_obs=233

NSA129237 rank counts: {2: 1, 3: 1, 4: 5, 5: 33, 6: 26, 7: 114, 8: 7184, 9: 4897, -1: 45893}
fraction not "other": 2.4%, nprob_obs=231

AnaK rank counts: {2: 1, 3: 0, 4: 2, 5: 21, 6: 15, 7: 88, 8: 10101, 9: 5463, -1: 60737}
fraction not "other": 1.2%, nprob_obs=252

Narnia rank counts: {2: 0, 3: 0, 4: 3, 5: 36, 6: 11, 7: 74, 8: 10958, 9: 5910, -1: 56543}
fraction not "other": 1.1%, nprob_obs=251


In [116]:
# quick checks: are the ML-selected objects meeting the fibermag and r cuts?
for h in hosts_to_target:
    cat = joined_catalogs[h]
    ranks = rankdct[h]

    plt.figure()
    
    msk = (ranks>0)&(ranks<8)
    plt.subplot(1,2,1)
    plt.hist(cat[msk]['r'],bins=25, histtype='step')
    plt.axvline(21,c='r')
    plt.xlabel('r')
    plt.title(h.name, fontsize=24)
    
    plt.subplot(1,2,2)
    plt.hist(cat[msk]['fibermag_r'],bins=25, histtype='step')
    plt.axvline(23,c='r')
    plt.xlabel('fibermag_r')
    plt.title(h.name, fontsize=24)
    
    plt.tight_layout()



In [117]:
generated_cats = {}
for h in hosts_to_target:
    print('On host', h.name)
    sys.stdout.flush()

    cat = joined_catalogs[h]
    ranks = rankdct[h]
    
    fnout = 'mmthecto/{0}_sep2015.cat'.format(h.name)
    fluxfnout = fnout.replace('.cat', '.fluxstars')
    print('Going to write', fnout)
    
    msk = (cat['RHOST_ARCM']<40) & (ranks>0) & (ranks<9)
    generated_cats[h] = mmthecto.generate_catalog(h, cat[msk], ranks[msk], 
                                         repeatflux=3, removefluxdistance=1*u.arcmin,
                                         fnout=fnout, fluxfnout=fluxfnout)


On host NSA150887
Going to write mmthecto/NSA150887_sep2015.cat
Including 4398 targets
Could not find psf mags so falling back on regular mags...
Found 73 Flux stars
Removing 34 Flux stars too close to program stars
Found 255 guide stars
On host NSA150578
Going to write mmthecto/NSA150578_sep2015.cat
Including 3371 targets
Could not find psf mags so falling back on regular mags...
Found 57 Flux stars
Removing 23 Flux stars too close to program stars
Found 248 guide stars
On host OBrother
Going to write mmthecto/OBrother_sep2015.cat
Including 4301 targets
Could not find psf mags so falling back on regular mags...
Found 110 Flux stars
Removing 47 Flux stars too close to program stars
Found 282 guide stars
On host NSA150307
Going to write mmthecto/NSA150307_sep2015.cat
Including 3595 targets
Could not find psf mags so falling back on regular mags...
Found 99 Flux stars
Removing 32 Flux stars too close to program stars
Found 295 guide stars
On host AnaK
Going to write mmthecto/AnaK_sep2015.cat
Including 4639 targets
Could not find psf mags so falling back on regular mags...
Found 79 Flux stars
Removing 41 Flux stars too close to program stars
Found 72 guide stars
On host NSA149977
Going to write mmthecto/NSA149977_sep2015.cat
Including 2993 targets
Could not find psf mags so falling back on regular mags...
Found 128 Flux stars
Removing 48 Flux stars too close to program stars
Found 397 guide stars
On host NSA153017
Going to write mmthecto/NSA153017_sep2015.cat
Including 2576 targets
Could not find psf mags so falling back on regular mags...
Found 64 Flux stars
Removing 20 Flux stars too close to program stars
Found 292 guide stars
On host NSA129387
Going to write mmthecto/NSA129387_sep2015.cat
Including 4813 targets
Could not find psf mags so falling back on regular mags...
Found 60 Flux stars
Removing 24 Flux stars too close to program stars
Found 136 guide stars
On host NSA129237
Going to write mmthecto/NSA129237_sep2015.cat
Including 3124 targets
Could not find psf mags so falling back on regular mags...
Found 49 Flux stars
Removing 17 Flux stars too close to program stars
Found 155 guide stars
On host Narnia
Going to write mmthecto/Narnia_sep2015.cat
Including 4879 targets
Could not find psf mags so falling back on regular mags...
Found 46 Flux stars
Removing 23 Flux stars too close to program stars
Found 107 guide stars
On host NSA126115
Going to write mmthecto/NSA126115_sep2015.cat
Including 3536 targets
Could not find psf mags so falling back on regular mags...
Found 86 Flux stars
Removing 35 Flux stars too close to program stars
Found 303 guide stars

Version including redmapper


In [23]:
redmappertargs = table.Table.read('catalogs/redmagic_targets_0828.fit')
redmappertargs


Out[23]:
<Table masked=False length=631>
OBJIDRADECRMAG
int64float64float64float32
1237678776862507491348.5797776054.3278351404419.8827
1237678776862507396348.5248722724.3710496266420.2401
1237679005021766016348.4086321434.4864746187420.4682
1237679005021766095348.4341886954.5141557261620.0641
1237679005021766194348.4679628264.5172302080619.6637
1237678776862441902348.3756649024.3029249898420.5198
1237679005021700367348.3455920874.410483310918.9509
1237679005021701029348.3920771474.4384921914319.3736
1237679005021765999348.4078589654.4197279147119.4642
1237679005021766015348.4092094864.4703605164620.134
............
12376795043195132531.5804017444520.523302398119.6759
12376802473519351471.5978578456120.61336039819.9404
12376802473519353631.5672215343120.613519999919.7791
12376802473519354171.5893188504520.60142020619.9253
12376802468149337601.371879119420.291729315920.0632
12376802468149988931.3959075458620.319034508119.0755
12376802468149335571.3027878118320.257884137319.3816
12376802468149334421.2528969199620.238066210920.7478
12376802473515422090.62827009413620.637392107520.5838
12376795048559907170.60183053611820.792932545620.4004

In [24]:
# sanity checks to make sure redmapper targets are in the catalog 
rmscs = SkyCoord(redmappertargs['RA']*u.deg, redmappertargs['DEC']*u.deg)

for h in hosts_to_target:
    jcat = joined_catalogs[h]
    rmhs = redmappertargs[rmscs.separation(h.coords)<2*u.deg]
    
    incat = np.in1d(rmhs['OBJID'], jcat['objID'])
    print(h.name, np.sum(incat), np.sum(~incat))
    
    incat2 = np.in1d(rmhs['OBJID'], h.get_sdss_catalog()['objID'])
    print(np.sum(incat2), np.sum(~incat2))
    
    catinrmmsk = np.in1d(jcat['objID'], redmappertargs['OBJID'])
    print(np.sum(catinrmmsk), np.sum(~catinrmmsk))


NSA150887 94 0
94 0
94 69189
NSA150578 47 1
47 1
47 60591
OBrother 66 2
68 0
66 79181
NSA150307 24 0
24 0
24 56549
AnaK 75 1
75 1
75 76353
NSA149977 38 0
38 0
38 63300
NSA153017 66 69
66 69
66 62077
NSA129387 49 0
49 0
49 69999
NSA129237 36 0
36 0
36 58118
Narnia 63 0
63 0
63 73472
NSA126115 62 73
62 73
62 57578

In [25]:
# compute ranks, which includes filtering on mag
rankdct = {}
for h in hosts_to_target:
    cat = joined_catalogs[h]
    
    highprob = cat[p_column_for_ranking].filled(0) > 0.5
    medprob = (cat[p_column_for_ranking].filled(0) > 0.05) & ~highprob
    lowprob = (cat[p_column_for_ranking].filled(0) > 0.01) & ~highprob & ~medprob
    inside = cat['RHOST_KPC']<300
    
    rankdct[h] = ranks = np.ones(len(cat), dtype=int)*-1 #the -1 will be re-set at the end
    
    # rank 1 reserved for flux stars
    ranks[inside&highprob] = 2
    ranks[~inside&highprob] = 3
    ranks[inside&medprob] = 4
    ranks[~inside&medprob] = 5
    ranks[inside&lowprob] = 6
    ranks[~inside&lowprob] = 7
    
    validtarget = (cat['r'] < 21.5) & (cat['fibermag_r']<23) & (cat['phot_sg']=='GALAXY')
    other = ranks < 0
    colorcutmsk = targeting.colorcut_mask(cat,  targeting.bossanova_color_cuts)
    
    ranks[validtarget&other&colorcutmsk] = 9
    ranks[validtarget&other&~colorcutmsk] = 10
    redmappertarg = np.in1d(cat['objID'], redmappertargs['OBJID'])
    rg7 = ranks>7
    ranks[validtarget&redmappertarg&rg7] = 8
    
#informational
for h, ranks in rankdct.items():
    cat = joined_catalogs[h]
    
    hranks = dict(enumerate(np.bincount(ranks[ranks>-1])))
    del hranks[0]
    del hranks[1]
    hranks[-1] = np.sum(ranks==-1)
    
    print(h.name,'rank counts:', hranks)
    
    nother =  np.sum(ranks==8)
    nprob = np.sum((ranks<8)&(ranks>0))
    nother_obs = 270-np.sum((ranks<8)&(ranks>0)&(cat['RHOST_ARCM']<30))
    print('fraction not "other": {0:.1%}, nprob_obs={1}\n'.format(nprob/(nprob+nother), nother_obs))


OBrother rank counts: {2: 0, 3: 0, 4: 3, 5: 23, 6: 26, 7: 143, 8: 66, 9: 9288, 10: 6150, -1: 63548}
fraction not "other": 74.7%, nprob_obs=233

NSA150307 rank counts: {2: 0, 3: 1, 4: 4, 5: 11, 6: 3, 7: 39, 8: 24, 9: 8331, 10: 5375, -1: 42785}
fraction not "other": 70.7%, nprob_obs=259

NSA126115 rank counts: {2: 0, 3: 0, 4: 5, 5: 17, 6: 13, 7: 43, 8: 62, 9: 8439, 10: 5946, -1: 43115}
fraction not "other": 55.7%, nprob_obs=255

Narnia rank counts: {2: 0, 3: 0, 4: 3, 5: 36, 6: 13, 7: 72, 8: 63, 9: 10958, 10: 5847, -1: 56543}
fraction not "other": 66.3%, nprob_obs=251

NSA153017 rank counts: {2: 1, 3: 0, 4: 1, 5: 10, 6: 20, 7: 61, 8: 66, 9: 9128, 10: 6465, -1: 46391}
fraction not "other": 58.5%, nprob_obs=248

NSA150578 rank counts: {2: 1, 3: 1, 4: 3, 5: 12, 6: 41, 7: 147, 8: 46, 9: 7583, 10: 6677, -1: 46127}
fraction not "other": 81.7%, nprob_obs=228

NSA129387 rank counts: {2: 0, 3: 0, 4: 4, 5: 11, 6: 25, 7: 80, 8: 49, 9: 10178, 10: 6139, -1: 53562}
fraction not "other": 71.0%, nprob_obs=237

AnaK rank counts: {2: 1, 3: 0, 4: 2, 5: 21, 6: 15, 7: 88, 8: 75, 9: 10101, 10: 5388, -1: 60737}
fraction not "other": 62.9%, nprob_obs=252

NSA149977 rank counts: {2: 0, 3: 0, 4: 1, 5: 13, 6: 22, 7: 123, 8: 38, 9: 6619, 10: 4591, -1: 51931}
fraction not "other": 80.7%, nprob_obs=239

NSA150887 rank counts: {2: 1, 3: 2, 4: 11, 5: 19, 6: 28, 7: 53, 8: 94, 9: 9592, 10: 7519, -1: 51964}
fraction not "other": 54.8%, nprob_obs=226

NSA129237 rank counts: {2: 1, 3: 1, 4: 5, 5: 33, 6: 27, 7: 113, 8: 35, 9: 7184, 10: 4862, -1: 45893}
fraction not "other": 83.7%, nprob_obs=231


In [36]:
hh.coords.ra.deg


Out[36]:
359.8562751500014

In [28]:
generated_cats = {}
for h in hosts_to_target:
    print('On host', h.name)
    sys.stdout.flush()

    cat = joined_catalogs[h]
    ranks = rankdct[h]
    
    def names_from_suffix(suffix, verbose=True):
        fnout = 'mmthecto/{0}_{1}.cat'.format(h.name, suffix)
        fluxfnout = fnout.replace('.cat', '.fluxstars')
        if verbose:
            print('Going to write', fnout, fluxfnout)
        return fnout, fluxfnout
    
    fnout, fluxfnout = names_from_suffix('sep2015_w_redmapper')
    msk = (cat['RHOST_ARCM']<40) & (ranks>0) & (ranks<10)
    generated_cats[h] = gcat = mmthecto.generate_catalog(h, cat[msk], ranks[msk], 
                                         repeatflux=3, removefluxdistance=20*u.arcsec,
                                         fnout=fnout, fluxfnout=fluxfnout)
    
    check_msk = (gcat['type'] == 'TARGET')&(gcat['rank']=='8')&(gcat['object']!='qso_candidate')
    gids = np.array(gcat[check_msk]['object']).astype(int)
    print('Check: N in redmapper:', np.sum(np.in1d(gids, redmappertargs['OBJID'])), 'out of n that are rank 8:', len(gids))
    print('')
    
    #these can be used to apply fibermag cuts... but at least when last run *all* of the high-p object already meet the cut
    #fnout, fluxfnout = names_from_suffix('sep2015_w_redmapper_fibermag22p5')
    #brightfibmag = cat['fibermag_r']<22.5
    #print('fibermag<22.5 cut removes', np.sum((1<ranks)&(ranks<8)&msk&~brightfibmag), 'of', np.sum((1<ranks)&(ranks<8)&msk))
    #generated_cats[h] = gids = mmthecto.generate_catalog(h, cat[msk&brightfibmag], ranks[msk&brightfibmag], 
    #                                     repeatflux=3, removefluxdistance=20*u.arcsec,
    #                                     fnout=fnout, fluxfnout=fluxfnout)
    
    #fnout, fluxfnout = names_from_suffix('sep2015_w_redmapper_fibermag23')
    #brightfibmag = cat['fibermag_r']<23
    #print('fibermag<23 cut removes', np.sum((1<ranks)&(ranks<8)&msk&~brightfibmag), 'of', np.sum((1<ranks)&(ranks<8)&msk))
    #generated_cats[h] = gids = mmthecto.generate_catalog(h, cat[msk&brightfibmag], ranks[msk&brightfibmag], 
    #                                     repeatflux=3, removefluxdistance=20*u.arcsec,
    #                                     fnout=fnout, fluxfnout=fluxfnout)


skipping NSA150887
skipping NSA150578
skipping OBrother
skipping NSA150307
skipping AnaK
skipping NSA149977
On host NSA153017
Going to write mmthecto/NSA153017_sep2015_w_redmapper.cat mmthecto/NSA153017_sep2015_w_redmapper.fluxstars
Including 4167 targets
Found 64 Flux stars
Removing 6 Flux stars too close to program stars
Could not find psf mags so falling back on regular mags...
Found 292 guide stars
Check: N in redmapper: 19 out of n that are rank 8: 19

skipping NSA129387
skipping NSA129237
skipping Narnia
skipping NSA126115

In [435]:
#now *just* for AnaK we manually insert a line for the high-Z QSO candidate and the decals LSB
print(SkyCoord(354.42221684 *u.deg, 0.22783437*u.deg).to_string('hmsdms',sep=':'))
linestoadd = ['23:37:41.332\t0:13:40.204\tqso_candidate\t7\tTARGET\t21.89', 
              '23:37:07.90\t0:12:40.86\tDECALS_target_1\t2\tTARGET\t21.3']

anakfns = !ls mmthecto/AnaK_sep2015_w_redmapper*.cat
for catfn in anakfns:
    print('Adding to', catfn)
    lines = []
    with open(catfn) as f:
        for l in f:
            lines.append(l)
    with open(catfn, 'w') as f:
        for l in lines:
            f.write(l)
        for linetoadd in linestoadd:
            f.write('\n')
            f.write(linetoadd)


23:37:41.332 +00:13:40.2037
Adding to mmthecto/AnaK_sep2015_w_redmapper.cat
Adding to mmthecto/AnaK_sep2015_w_redmapper_fibermag22p5.cat
Adding to mmthecto/AnaK_sep2015_w_redmapper_fibermag23.cat

Checking outputs


In [399]:
for h in hosts_to_target:
    gc = generated_cats[h]

    fixrank = []
    for r in gc['rank']:
        try:
            fixrank.append(int(r))
        except ValueError:
            fixrank.append(-2)
    fixrank = np.array(fixrank)

    msk = fixrank==1#(fixrank>1)&(fixrank<8)

    #targeting.sampled_imagelist(gc['ra'][msk], gc['dec'][msk], names=gc['rank'][msk],n=200)
    
    wrapat = 180*u.deg if h.ra>358 else 360*u.deg

    plt.figure()
    plt.scatter(Angle(gc['ra'][msk], u.deg).wrap_at(wrapat).deg, gc['dec'][msk], color='b')
    plt.xlim(h.coords.ra.wrap_at(wrapat).deg-1, h.coords.ra.wrap_at(wrapat).deg+1)
    plt.ylim(h.coords.dec.deg-1, h.coords.dec.deg+1)
    plt.title(h.name)



In [400]:
for h in hosts_to_target:
    fnout = 'mmthecto/{0}_sep2015_w_redmapper.cat'.format(h.name)
    fluxfnout = fnout.replace('.cat', '.fluxstars')
    cattab = Table.read(fnout, format='ascii',data_start=2)
    fxtab = Table.read(fluxfnout, format='ascii')
    
    catsc = SkyCoord(Longitude(cattab['ra'], u.hourangle), Latitude(cattab['dec'], u.deg))
    fxsc = SkyCoord(fxtab['RA']*u.deg, fxtab['DEC']*u.deg)
    catfx = catsc[cattab['rank']==1]
    
    plt.figure()
    plt.title(h.name)
    plt.scatter(catfx.ra.deg, catfx.dec.deg, color='r') #in the catalog
    plt.scatter(fxsc.ra.deg, fxsc.dec.deg, edgecolor='k', facecolor='none', marker='s',s=100)



In [401]:
for h in hosts_to_target:
    fnout = 'mmthecto/{0}_sep2015_w_redmapper.cat'.format(h.name)
    cattab = Table.read(fnout, format='ascii',data_start=2)
    
    msk = (cattab['type'] == 'TARGET')&(cattab['rank']>1)&(cattab['rank']<10)&(cattab['object']!='qso_candidate')
    ids = np.array(cattab[msk]['object']).astype(int)
    
    print('n w/id in redmagic:', np.sum(np.in1d(ids, redmappertargs['OBJID'])), 
          'of', np.sum(cattab['rank']==8), 'rank 8 objects')


n w/id in redmagic: 94 of 94 rank 8 objects
n w/id in redmagic: 46 of 46 rank 8 objects
n w/id in redmagic: 66 of 66 rank 8 objects
n w/id in redmagic: 24 of 24 rank 8 objects
n w/id in redmagic: 75 of 75 rank 8 objects
n w/id in redmagic: 38 of 38 rank 8 objects
n w/id in redmagic: 10 of 10 rank 8 objects
n w/id in redmagic: 49 of 49 rank 8 objects
n w/id in redmagic: 35 of 35 rank 8 objects
n w/id in redmagic: 63 of 63 rank 8 objects
n w/id in redmagic: 50 of 50 rank 8 objects

In [440]:
for h in hosts_to_target:
    fnout = 'mmthecto/{0}_sep2015_w_redmapper.cat'.format(h.name)
    cattab = Table.read(fnout, format='ascii',data_start=2)
    
    msk = (cattab['type'] == 'TARGET')&(cattab['rank']>1)&(cattab['rank']<10)&(cattab['object']!='qso_candidate')
    ids = np.array(cattab[msk]['object']).astype(int)
    scat = h.get_sdss_catalog()
    jcat = joined_catalogs[h]
    
    scatincat = scat[np.in1d(scat['objID'], ids)]
    jcatincat = jcat[np.in1d(jcat['objID'], ids)]
    print(h.name)
    print('targs w/ zqal>2:', np.sum(scatincat['ZQUALITY']>2), 'of', len(scatincat))
    print('targs w/ remove!=-1:', np.sum(scatincat['REMOVE']!=-1), 'of', len(scatincat))
    print('targs w/ fibermag>22.5', np.sum(scatincat['fibermag_r']>22.5), 'of', len(scatincat))
    goodp = jcatincat[p_column_for_ranking]>0.01
    print('high-p targs w/ fibermag>22.5', np.sum((jcatincat['fibermag_r']>22.5)&goodp), 'of', np.sum(goodp))
    #scatincat[scatincat['ZQUALITY']>2].show_in_browser()


NSA150887
targs w/ zqal>2: 0 of 4492
targs w/ remove!=-1: 0 of 4492
targs w/ fibermag>22.5 121 of 4492
high-p targs w/ fibermag>22.5 0 of 65
NSA150578
targs w/ zqal>2: 0 of 3417
targs w/ remove!=-1: 0 of 3417
targs w/ fibermag>22.5 60 of 3417
high-p targs w/ fibermag>22.5 0 of 77
OBrother
targs w/ zqal>2: 0 of 4367
targs w/ remove!=-1: 0 of 4367
targs w/ fibermag>22.5 105 of 4367
high-p targs w/ fibermag>22.5 0 of 74
NSA150307
targs w/ zqal>2: 0 of 3619
targs w/ remove!=-1: 0 of 3619
targs w/ fibermag>22.5 81 of 3619
high-p targs w/ fibermag>22.5 0 of 20
AnaK
targs w/ zqal>2: 0 of 4714
targs w/ remove!=-1: 0 of 4714
targs w/ fibermag>22.5 109 of 4714
high-p targs w/ fibermag>22.5 0 of 39
NSA149977
targs w/ zqal>2: 0 of 3031
targs w/ remove!=-1: 0 of 3031
targs w/ fibermag>22.5 66 of 3031
high-p targs w/ fibermag>22.5 0 of 65
NSA153017
targs w/ zqal>2: 0 of 2586
targs w/ remove!=-1: 0 of 2586
targs w/ fibermag>22.5 46 of 2586
high-p targs w/ fibermag>22.5 0 of 24
NSA129387
targs w/ zqal>2: 0 of 4862
targs w/ remove!=-1: 0 of 4862
targs w/ fibermag>22.5 83 of 4862
high-p targs w/ fibermag>22.5 0 of 56
NSA129237
targs w/ zqal>2: 0 of 3159
targs w/ remove!=-1: 0 of 3159
targs w/ fibermag>22.5 125 of 3159
high-p targs w/ fibermag>22.5 0 of 79
Narnia
targs w/ zqal>2: 0 of 4942
targs w/ remove!=-1: 0 of 4942
targs w/ fibermag>22.5 108 of 4942
high-p targs w/ fibermag>22.5 0 of 43
NSA126115
targs w/ zqal>2: 0 of 3586
targs w/ remove!=-1: 0 of 3586
targs w/ fibermag>22.5 60 of 3586
high-p targs w/ fibermag>22.5 0 of 34

Test rounds


In [70]:
mlpred = Table.read('catalogs/SAGAobjid_Prediction_SDSSwise_gt0.txt.fits.gz')
objids = mlpred['OBJID'].astype(int)
mlpred.remove_column('OBJID')
mlpred.add_column(table.Column(name='objID', data=objids), index=0)
mlpred


Out[70]:
<Table masked=False length=283765>
objIDRADECDERED_RPROBABILITY_CLASS_1BEST_GUESS_CLASS
int64float32float32float32float32int32
1237661417677586534219.7152.272615.20030.9987711
1237661957760614535210.93648.766316.12110.9987641
1237665566078402826233.78716.87115.62010.9982181
1237661357002719237168.92346.128515.82870.997381
1237664667899723842159.07336.425316.45190.9972591
1237661435925692576207.52146.450416.37280.9971261
1237659326017831104216.14856.249416.40420.9969221
1237660635462369383168.60346.132516.17450.9966181
1237663277925204111354.1950.62340415.91470.9964151
1237661958297157819210.149.444315.82570.9954841
..................
1237655369295331962217.38257.796120.40480.001712790
1237664669514137993169.44939.700920.79860.001712790
1237654399701025167223.1359.440820.60850.001712790
1237667322180010422176.64926.41320.41390.001706580
12376802967444524770.39306621.336120.34660.001706580
1237662340553835773248.9121.930720.43630.001706580
1237661852013363645207.51643.504221.03750.001706580
1237671769610126059229.62459.466920.35390.001706580
1237655467524817642227.5710.7042920.31350.001706580
1237648721785585683221.0220.29709920.25460.001706580

In [74]:
joined_catalogs = {}
for h in candhosts:
    joined_catalogs[h] = table.join(h.get_sdss_catalog(), mlpred, join_type='left', keys='objID')

Try actually constructing catalogs for use with hectospec


In [184]:
rankdct = {}
for h in candhosts:
    print('On host', h.name)
    sys.stdout.flush()
    
    cat = joined_catalogs[h]
    highprob = cat['PROBABILITY_CLASS_1'].filled(0) > 0.3
    medprob = (cat['PROBABILITY_CLASS_1'].filled(0) > 0.05) & ~highprob
    inside = cat['RHOST_KPC']<300
    
    rankdct[h] = ranks = np.ones(len(cat))*6 # all not set below are 5
    ranks[~inside] = 5 #up-weight those inside
    ranks[highprob&inside] = 1
    ranks[medprob&inside] = 2
    ranks[highprob&~inside] = 3
    ranks[medprob&~inside] = 4
    
    fnout = 'mmthecto/{0}_sep2015_test.cat'.format(h.name)
    fluxfnout = fnout.replace('.cat', '.fluxstars')
    print('Going to write', fnout)
    
    msk = ranks<5
    stoutcat = mmthecto.generate_catalog(h, cat[msk], ranks[msk]+1, 
                                         repeatflux=5, removefluxdistance=1*u.arcmin,
                                         fnout=fnout)#, fluxfnout=fluxfnout)


On host NSA150887
Going to write mmthecto/NSA150887_sep2015_test.cat
Including 137 targets
Found 73 Flux stars
Removing 2 Flux stars too close to program stars
Found 255 guide stars
On host NSA150578
Going to write mmthecto/NSA150578_sep2015_test.cat
Including 125 targets
Found 57 Flux stars
Removing 3 Flux stars too close to program stars
Found 248 guide stars
On host OBrother
Going to write mmthecto/OBrother_sep2015_test.cat
Including 168 targets
Found 110 Flux stars
Removing 1 Flux stars too close to program stars
Found 282 guide stars
On host NSA150307
Going to write mmthecto/NSA150307_sep2015_test.cat
Including 75 targets
Found 99 Flux stars
Removing 2 Flux stars too close to program stars
Found 295 guide stars
On host AnaK
Going to write mmthecto/AnaK_sep2015_test.cat
Including 221 targets
Found 79 Flux stars
Removing 6 Flux stars too close to program stars
Found 72 guide stars
On host NSA149977
Going to write mmthecto/NSA149977_sep2015_test.cat
Including 108 targets
Found 128 Flux stars
Removing 3 Flux stars too close to program stars
Found 397 guide stars
On host NSA153017
Going to write mmthecto/NSA153017_sep2015_test.cat
Including 106 targets
Found 64 Flux stars
Removing 3 Flux stars too close to program stars
Found 292 guide stars
On host NSA126115
Going to write mmthecto/NSA126115_sep2015_test.cat
Including 99 targets
Found 86 Flux stars
Removing 2 Flux stars too close to program stars
Found 303 guide stars
On host NSA127226
Going to write mmthecto/NSA127226_sep2015_test.cat
Including 116 targets
Found 52 Flux stars
Found 211 guide stars
On host NSA129387
Going to write mmthecto/NSA129387_sep2015_test.cat
Including 158 targets
Found 60 Flux stars
Removing 1 Flux stars too close to program stars
Found 136 guide stars
On host NSA129237
Going to write mmthecto/NSA129237_sep2015_test.cat
Including 173 targets
Found 49 Flux stars
Removing 5 Flux stars too close to program stars
Found 155 guide stars
On host Narnia
Going to write mmthecto/Narnia_sep2015_test.cat
Including 258 targets
Found 46 Flux stars
Removing 6 Flux stars too close to program stars
Found 107 guide stars
On host NSA130133
Going to write mmthecto/NSA130133_sep2015_test.cat
Including 160 targets
Found 60 Flux stars
Removing 1 Flux stars too close to program stars
Found 180 guide stars
On host NSA131531
Going to write mmthecto/NSA131531_sep2015_test.cat
Including 176 targets
Found 58 Flux stars
Removing 1 Flux stars too close to program stars
Found 155 guide stars
On host NSA130625
Going to write mmthecto/NSA130625_sep2015_test.cat
Including 156 targets
Found 47 Flux stars
Removing 5 Flux stars too close to program stars
Found 180 guide stars

Experiments


In [164]:
from matplotlib import patches

def scplot(sc, **kwargs):
    x = sc.ra.wrap_at(180*u.deg).deg
    y = sc.dec
    kwargs.setdefault('edgecolor', 'none')
    kwargs.setdefault('s', 5)
    kwargs.setdefault('alpha', .5)
    return plt.scatter(x, y, **kwargs)

In [176]:
for i, h in enumerate(candhosts):    
    cat = joined_catalogs[h]
    sc =  SkyCoord(u.Quantity(cat['ra'], u.deg), u.Quantity(cat['dec'], u.deg))
    
    highprob = cat['PROBABILITY_CLASS_1'].filled(0) > 0.3
    medprob = (cat['PROBABILITY_CLASS_1'].filled(0) > 0.05) & ~highprob
    inside = cat['RHOST_KPC']<300
    
    ranks = np.ones(len(cat))*6 # all not set below are 5
    ranks[~inside] = 5 #up-weight those inside
    ranks[highprob&inside] = 1
    ranks[medprob&inside] = 2
    ranks[highprob&~inside] = 3
    ranks[medprob&~inside] = 4
    
    fig = plt.figure()
    ax = fig.add_subplot(111)

    scplot(sc[ranks==6], color='c', label='rank=6')
    scplot(sc[ranks==5], color='k', label='rank=5')
    scplot(sc[ranks==4], color='m', alpha=1,s=30, label='rank=4')
    scplot(sc[ranks==3], color='b', alpha=1,s=30, label='rank=3')
    scplot(sc[ranks==2], color='g', alpha=1,s=30, label='rank=2')
    scplot(sc[ranks==1], color='r', alpha=1,s=30, label='rank=1')
    plt.legend(loc=0)
    
    ell = patches.Ellipse((Angle(h.ra, u.deg).wrap_at(180*u.deg).deg, h.dec), 1/np.cos(h.dec*u.deg), 1, facecolor='none', lw=3, edgecolor='r')
    ax.add_patch(ell)
    plt.title(h.name)


Testing on the hectospec xfitfibs confirms the fairly obvious from above: we can get basically everything within the FOV with a high ML prob

Assorted other checks

NSA153017 is near the 0-360 boundary. Check for sanity


In [47]:
n153017 = [h for h in hosts_to_target if h.nsaid == 153017][0]

cat = joined_catalogs[n153017]
arcmin_cat = u.Quantity(cat['RHOST_ARCM'], u.arcmin)
kpc_cat = u.Quantity(cat['RHOST_KPC'], u.kpc)
catsc = SkyCoord(u.Quantity(cat['ra'], u.deg), u.Quantity(cat['dec'], u.deg))

seps = catsc.separation(n153017.coords)
dsep = seps - arcmin_cat
sep_kpc = seps.radian*n153017.dist
dsep_kpc = sep_kpc - kpc_cat

In [44]:
plt.hist(dsep, bins=100, histtype='step')
None



In [45]:
plt.hist(dsep[np.abs(dsep)<10*u.deg].arcsec, bins=100, histtype='step')
None



In [51]:
plt.hist(dsep_kpc[np.abs(dsep)<10*u.deg].to(u.kpc), bins=100, histtype='step')
None