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]:
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import rcParams

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

In [3]:
for module in ['hosts', 'targeting', 'magellan']:
    if module in globals():
        reload(globals()[module])
    else:
        globals()[module] = __import__(module)
#g = targeting.get_gama() #re-caches the gama catalog

In [4]:
hostlst = hosts.get_saga_hosts_from_google('etollerud', )


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

In [190]:
from astropy import table
from astropy.table import Table, Column
from astropy.coordinates import SkyCoord

Aeneid


In [6]:
aen = [h for h in hostlst if h.name.lower() == 'aeneid'][0]
aen.shortname = 'Ae15B'

First load the base catalog for targeting and select from it


In [292]:
aencatall = aen.load_and_reprocess_sdss_catalog('catalogs/base_sql_nsa148734.fits.gz')
aencat = aencatall[aencatall['REMOVE']==-1]
aencat


Out[292]:
<Table length=158461>
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_NSAIDSATSREMOVETELNAMEMASKNAMEZQUALITYSPEC_REPEATUBVRIrhostrhost_kpctypephot_sg
int64float64float64int64int64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float64float32float32float32float64float32float32float32float32float32float32float32float32float32float32float32float32int32float32float32float64float64float64float64float64int64int64str33float64float64int64int64int64str4str33float64str33float32float32float32float32float32float64float64int16str6
1237652935103480140309.729008176-5.63703653779105587779178512022.957920.742520.355620.26320.12730.4840980.03905530.03931130.05121990.1851510.293020.2156010.1563720.1185720.084069218.326919.17750.27120919.51754740360.5494931.0325620.474921.17018226019999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.0326460.053939309.727-5.6399852.19523900.019.594148734554Aeneid0.2134667167943.24105837693-1-1-1-1.021.619621.082620.507920.224419.81360.003546303179643.211480813543GALAXY
1237652935103480156309.729015174-5.63294356656123214324961296022.038821.508121.560521.40621.13180.2245170.06409260.09772440.1279030.426510.2936410.2160580.1567030.1188230.084247319.484120.3040.37890721.4486046890.5577060.97880221.7222.44746272569999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.0455180.017622309.727-5.6399852.19523900.019.594148734554Aeneid0.438997909686.66529129713-1-1-1-1.021.13921.710721.521721.419920.90320.00731111568356.620840507363GALAXY
1237652935103480169309.727182786-5.6273820308235253394739472024.206923.510521.890920.999820.51120.8516960.2572650.09624950.06835530.2070940.294480.2166750.1571510.1191630.084487921.547522.21210.082331118.46691986850.4839091.1194221.942522.36179779669999.09999.09999.09999.09999.09999.017.41490.162869999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid0.75595694050711.4776701177-1-1-1-1.024.63724.236522.579421.637520.41420.012599134093211.40959341556STAR
1237652935103480174309.732709357-5.63773653869105622138916880023.943522.328922.014921.597220.99150.8396580.1071410.120510.1282180.3409360.2930770.2156430.1564020.1185950.084085520.705421.53780.22614920.7823599310.5097420.95252422.154222.68639318879999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.0713590.03848309.727-5.6399852.19523900.019.594148734554Aeneid0.3665162424615.56480445414-1-1-1-1.022.832222.646122.135521.83420.96640.006089409692625.514481250763GALAXY
1237652935103480189309.727839749-5.65097077162105622138917136025.596723.672122.086921.879820.92490.5941090.2870970.1100720.1394820.2841160.2908940.2140370.1552370.1177120.083459121.584622.30042.57311e-051.134678477170.412160.83008622.259922.33066931359999.09999.09999.09999.09999.09999.021.29165.726549999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid0.66134978563310.0412527215-1-1-1-1.025.408224.387222.760521.938221.11420.01102081208739.980287859016STAR
1237652935103480184309.73514294-5.64477048305105622138916880023.475623.446122.66221.131219.98460.6500230.2729960.2294420.08972610.1508870.2922290.2150190.155950.1182520.083842122.49123.10060.43388822.84426946940.5311610.96566722.77423.39553646579999.09999.09999.09999.09999.09999.016.00780.044488615.8750.192-1.0-1.0-10.7493150.136558309.727-5.6399852.19523900.019.594148734554Aeneid0.5648156926098.57557867751-1-1-1-1.023.521523.910622.987122.310820.29160.00939567999798.508591768653GALAXY
1237652935103480108309.710955994-5.63142256084263951778710288023.297522.73520.899219.767419.17960.529710.1393390.04365940.02606360.06831660.2926010.2152930.1561480.1184030.083948921.246621.7450.23517319.75155531240.4627650.81717221.088321.41057159249999.09999.09999.09999.09999.09999.017.07940.1209239999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid1.086900798916.5023800228-1-1-1-1.023.97423.528621.681820.60919.14350.01813343245616.42137388326STAR
1237652935103481334309.71748837-5.64444657292158398662443520021.010620.541620.410820.491420.69750.08650230.0245080.0296850.04560560.2476930.290820.2139830.1551980.1176820.08343820.712321.23680.11860717.80498477360.5420531.4308620.39621.06162728299999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid0.6279898689019.53475017459-1-1-1-1.020.294820.801520.451720.306120.1740.01048513695559.495188215536STAR
1237652935103481968309.716016186-5.6374890298668987912960021.516922.509821.382821.319320.85240.25450.2428660.1427150.2142210.6502270.2919080.2147830.1557790.1181220.083750122.555723.10681.3124.34350730322.180183.9285421.332325.02022694489999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.3689580.15964309.727-5.6399852.19523900.019.594148734554Aeneid0.67265291774810.2128678141-1-1-1-1.022.342623.081621.85721.256120.7420.011231123362910.17074270513GALAXY
1237652935103482482309.714317909-5.6378744748281543964623616024.682123.54622.510822.203321.79050.8727240.2557340.1593040.1864330.5575490.2916640.2146030.1556480.1180230.083680122.858723.3290.094377619.38033916050.4064730.68902522.782122.82268459919999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid0.76770753672411.6560790423-1-1-1-1.024.408424.08922.945122.346821.64690.012815593852311.60561623926STAR
...............................................................................................................................................................................................................
1237652934566610617309.65399388-5.9422423467668987912960022.960122.505521.98721.823622.24240.3932850.1140930.1045380.1384010.6900590.2988940.2199230.1595070.1209490.085754522.2422.77480.14892319.847298090.5308531.7907421.934222.55448235099999.09999.09999.09999.09999.09999.019.88091.576829999.09999.0-1.0-1.0-10.2189520.107615309.727-5.6399852.19523900.019.594148734554Aeneid18.6522757027283.195519911-1-1-1-1.022.57822.886822.196621.84521.58820.310871467126281.5206996073GALAXY
1237652934566610618309.648872831-5.97890405281140806476399360024.191522.551122.253421.69721.08641.174780.1603930.1884290.1771150.4384480.2998880.2206550.1600370.1213520.086039822.825723.36310.35958822.31174818460.9672122.371622.215424.13840933789999.09999.09999.09999.09999.09999.018.28640.355839999.09999.0-1.0-1.0-10.4344560.15813309.727-5.6399852.19523900.019.594148734554Aeneid20.8636500194316.770190797-1-1-1-1.023.05422.863222.366922.051221.06430.347726818447314.8963721453GALAXY
1237652934566610630309.648761237-5.9900220954672057663025971456024.751921.133220.035419.593519.33050.9010230.03822080.022180.02238510.06917810.2983060.2194910.1591930.1207110.085585720.356820.84470.062014815.99242959620.4957191.0877720.10120.57262830999999.09999.09999.09999.09999.09999.017.37150.1548659999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid21.5158067774326.671678021-1-1-1-1.023.339421.695820.49719.850819.0950.358595937678324.739289156STAR
1237652934566610560309.63886087-5.97727584992527836750414128024.810122.703422.344622.294221.99071.154470.1735690.1893850.2835330.8112570.2986630.2197530.1593840.1208560.085688222.903923.35220.49585822.9209922190.6966571.2733722.466623.67718726899999.09999.09999.09999.09999.09999.018.93720.6724399999.09999.0-1.0-1.0-10.1420270.088537309.727-5.6399852.19523900.019.594148734554Aeneid20.9108362776317.486605031-1-1-1-1.023.500423.034722.484722.219921.780.348512472806315.6078493583GALAXY
1237652934566610637309.646895874-6.0059946197168987912448023.464221.860221.084920.645920.29950.7114730.08217310.06196590.06487050.2051030.2959470.2177550.1579340.1197560.084908821.505222.080.40699421.25685324970.7461381.8796821.042622.40210892129999.09999.09999.09999.09999.09999.018.71960.534669999.09999.0-1.0-1.0-10.055390.020911309.727-5.6399852.19523900.019.594148734554Aeneid22.4756987034341.245388274-1-1-1-1.022.746922.321921.406220.900720.11510.37459378533339.2267083553GALAXY
1237652934566610638309.655735241-5.94445027651281543964623104023.101323.043822.790521.959121.32440.4804470.1957180.233550.1765350.4291220.2991040.2200780.1596190.1210340.085814622.877323.37380.77598223.78732393130.7900421.4634422.510523.99416548999999.09999.09999.09999.09999.09999.019.53141.113699999.09999.0-1.0-1.0-10.7823910.212365309.727-5.6399852.19523900.019.594148734554Aeneid18.7572478709284.789285415-1-1-1-1.022.686123.34222.884722.546321.31710.312621065734283.1051107753GALAXY
1237652934566610723309.664782137-6.019717635268987912960024.847422.771322.047321.922820.7381.016250.1621410.1309850.1798990.2705760.2942230.2164860.1570140.1190590.084414222.436322.94350.44633622.29120600882.098593.1783621.461225.06631226319999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.503560.154176309.727-5.6399852.19523900.019.594148734554Aeneid23.085139041350.498298388-1-1-1-1.023.860223.216922.346221.911321.06850.38475218204348.4260053353GALAXY
1237652934566610724309.671334565-5.9752557009281709320864000022.881122.988722.47722.577523.110.4097830.1905090.1815210.2978260.8522730.3006520.2212170.1604450.121660.086258822.995523.40540.26781921.65785371460.4203560.61573322.9423.05356700439999.09999.09999.09999.09999.09999.019.09070.7618059999.09999.0-1.0-1.0-10.2684910.094955309.727-5.6399852.19523900.019.594148734554Aeneid20.3892773216309.567934845-1-1-1-1.022.76323.367822.683622.375422.3860.339821869969307.7377652573GALAXY
1237652934566610727309.674567264-5.95096245023105622104310544025.156822.950221.931721.79122.22820.8512750.1747310.1077110.1440640.7330390.3010610.2215180.1606630.1218260.086376222.246222.74950.22480620.72477360130.525371.3682721.985722.58352198189999.09999.09999.09999.09999.09999.09999.09999.09999.09999.0-1.0-1.0-10.2648510.178653309.727-5.6399852.19523900.019.594148734554Aeneid18.9197728279287.256859623-1-1-1-1.024.355323.48822.358821.793221.56280.31533048391285.5587206463GALAXY
1237652934566610733309.67711974-5.9499201230268987912448024.86422.433221.185920.627819.8290.8596840.1047090.05213380.07799670.1038080.3013590.2217370.1608220.1219470.086461821.602122.06010.0004033356.209694959840.4109830.76133521.40221.46653871099999.09999.09999.09999.09999.09999.018.05020.2847899999.09999.0-1.0-1.0-1-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid18.8333959398285.945421845-1-1-1-1.024.147723.042621.712520.983519.92250.313890938568284.2550892276STAR

Now combine with the ML satellite probabilities


In [293]:
#this is the OLD one, without WISE or AAT inputs.  Below we replace this with the new one
mlcat = Table.read('catalogs/Nsaid_148734_Prediction.txt.gz', format='ascii.commented_header')
mlcat


Out[293]:
<Table length=22458>
OBJIDRADECDERED_RHOST_NSAIDHOST_SAGA_NAMEPROBABILITY_CLASS_1BEST_GUESS_CLASS
int64float64float64float64int64str6float64int64
1237652935640679317310.48709773-5.2990328220817.8582148734Aeneid0.7031904951831
1237652599023075657309.277627512-6.2521559606620.6097148734Aeneid0.6927276197471
1237652934566347493308.998865433-6.0425937448616.9751148734Aeneid0.6780092905731
1237652935103414657309.530485006-5.5590422819921.3017148734Aeneid0.4986840868960
1237652599023403992310.02399615-6.3799717716116.5403148734Aeneid0.4616308043270
1237652599560471646310.583739707-5.9110763031516.6271148734Aeneid0.4313346879420
1237652599559881170309.236989388-5.7139969232221.6964148734Aeneid0.3943675543560
1237652935103283759309.315312248-5.4711130548919.1434148734Aeneid0.3779740802960
1237652599559816057309.052918228-5.7961482394617.5551148734Aeneid0.3552772705070
1237652599023010739309.167419062-6.0912645736221.3128148734Aeneid0.3100770449310
........................
1237652934566871527310.293684383-6.10243633816.5496148734Aeneid0.00
1237652934566871644310.160649788-6.1068644274817.6383148734Aeneid0.00
1237652934566871531310.30837202-6.0461927254116.3693148734Aeneid0.00
1237652934566871533310.285877202-6.2044241288715.676148734Aeneid0.00
1237652934566871612310.155724051-6.0660192095217.5208148734Aeneid0.00
1237652934566871624310.13824956-6.197778665718.8829148734Aeneid0.00
1237652934566871632310.167581717-6.0349657065317.302148734Aeneid0.00
1237652934566871633310.166551533-6.0355001449218.6466148734Aeneid0.00
1237652934566871639310.149302761-6.1615394756418.1636148734Aeneid0.00
1237652598486204879309.265342298-6.5236508460416.8463148734Aeneid0.00

In [383]:
#there are two ML catalogs, one with WISE and the other without
mlcatwowise = Table.read('catalogs/SAGAobjidPrediction_SDSS_148724.fit')
mlcatwwise = Table.read('catalogs/SAGAobjidPrediction_SDSSwise_148724.fit')

#their OBJID columns are strings and are weirdly broken - need to fix:
for cat in (mlcatwowise, mlcatwwise):
    newoid = [int(i) for i in cat['OBJID']]
    del cat['OBJID']
    cat['OBJID'] = newoid
    
mlcatwowisetokeep = np.array([i not in mlcatwwise['OBJID'] for i in mlcatwowise['OBJID']])
mlcat = table.vstack((mlcatwwise, mlcatwowise[mlcatwowisetokeep]))
mlcat


WARNING: MergeConflictWarning: Cannot merge meta key 'DATE-HDU' types <type 'str'> and <type 'str'>, choosing DATE-HDU='2015-08-03T18:09:41' [astropy.utils.metadata]
WARNING:astropy:MergeConflictWarning: Cannot merge meta key 'DATE-HDU' types <type 'str'> and <type 'str'>, choosing DATE-HDU='2015-08-03T18:09:41'
Out[383]:
<Table masked=True length=19770>
RADECDERED_RPROBABILITY_CLASS_1BEST_GUESS_CLASSRA_2DEC_2HOST_NSAIDHOST_SAGA_NAMEGroupIDGroupSizeSeparationOBJID
arcsec
float32float32float32float32int32float64float64str22str6int32int32float64int64
308.999-6.0425916.97510.9125891308.998836225-6.04272276966148734Aeneid180.4800101986941237652934566347493
309.237-5.71421.69640.7001151309.212157944-5.73670291961148734Aeneid248120.8295332011237652599559881170
310.584-5.9110816.62710.6706831310.583718595-5.91110495655148734Aeneid3140.1296894384831237652599560471646
309.278-6.2521620.60970.6010781309.277627512-6.25215596066148734Aeneid4340.03258550964571237652599023075657
310.29-5.1009615.46550.5842631310.290208273-5.10095745073148734Aeneid5130.04982368967831237652600634081483
309.053-5.7961517.55510.558991309.052918228-5.79614823946148734Aeneid6270.002685831976611237652599559816057
310.491-5.5518815.81860.5439161310.491415408-5.55187389302148734Aeneid740.0767960266051237652600097276470
309.53-5.5590421.30170.4794540309.529996725-5.55818889378148734Aeneid833.53962123371237652935103414657
310.388-6.3313717.06880.474910310.388042331-6.33135937857148734Aeneid9100.05904316351911237652599023535135
.......................................
309.232-5.5085220.68280.005883260309.231660322-5.51563330508148734Aeneid3343425.75231369441237652935103285099
308.796-5.7721119.63480.005861950308.901741076-5.74241680076148734Aeneid113131392.4251189051237652599559684663
310.047-5.3720521.99310.005836010310.059665507-5.36099577007148734Aeneid1609461.7014981981237652600097081343
309.686-5.52915.9340.005819070309.6865087-5.53009983743148734Aeneid35854.446240486111237652935103480008
309.172-6.1061619.35950.005819070309.135707037-6.00977195823148734Aeneid4859371.0462204621237652599023010152
310.072-5.0064919.05940.005819070310.081497705-5.01856859082148734Aeneid388154.38531940061237652600633951109
310.317-5.0784318.32820.005819070310.290208273-5.10095745073148734Aeneid1818125.6774087051237652600634082201
310.375-5.4690820.90410.005810780310.419340075-5.46637922841148734Aeneid4420160.942470791237652600097276582
309.392-5.8819520.47480.005810780309.440454512-5.93785250301148734Aeneid31846266.2910459871237652599559947724
309.623-4.9336921.49640.005810780309.67710394-4.96498047879148734Aeneid45518223.7571238911237652600633755095

In [399]:
#oh wait, now there's a catalog that's pre-combined them in a better way.  Use that.
mlcat = Table.read('catalogs/SAGAobjidMaxPrediction_148724.fit')
mlcat


Out[399]:
<Table length=19770>
OBJIDRADECDERED_RPROBABILITY_CLASS_1BEST_GUESS_CLASSRA_2DEC_2HOST_NSAIDHOST_SAGA_NAMEGROUPIDGROUPSIZESEPARATION
str19float32float32float32float32int32float64float64str22str6int32int32float64
1237652598486205507309.304-6.5316218.16110.006307230309.315527052-6.51527362412148734Aeneid3371672.6463592797
1237652598486205712309.287-6.5273518.74010.0172820309.285888875-6.50752854953148734Aeneid2131571.4392858465
1237652598486206390309.273-6.5248221.69560.006291460309.285888875-6.50752854953148734Aeneid302877.576988043
1237652598486206421309.281-6.5250920.60510.006660240309.285888875-6.50752854953148734Aeneid302865.9821048409
1237652598486206468309.293-6.5347420.43770.006637060309.285888875-6.50752854953148734Aeneid3028100.93140246
1237652598486270003309.311-6.5366416.81720.002021790309.315527052-6.51527362412148734Aeneid3371678.3727441071
1237652598486270043309.322-6.5496918.53560.01316870309.315527052-6.51527362412148734Aeneid39827125.854517801
1237652598486270356309.404-6.5614621.35340.01320890309.46721702-6.58526689242148734Aeneid9072240.480682401
1237652598486270373309.42-6.5455120.3740.02587960309.46721702-6.58526689242148734Aeneid9072222.324141205
1237652598486270518309.435-6.5735315.92920.001954620309.46721702-6.58526689242148734Aeneid17061124.056957686
.......................................
1237652936177485664310.419-4.9264421.22920.01897180310.369787181-4.94935423278148734Aeneid10653194.364643434
1237652936177485691310.425-4.9306420.85740.01291530310.401563345-4.97892512762148734Aeneid10426193.205102104
1237652936177485714310.429-4.9332521.64950.01975150310.401563345-4.97892512762148734Aeneid10426192.282845814
1237652936177485727310.432-4.9288920.25250.004408060310.401563345-4.97892512762148734Aeneid12126210.227044846
1237652936177485748310.428-4.9671921.25980.00641790310.401563345-4.97892512762148734Aeneid10426104.031795768
1237652936177485785310.443-4.9520521.49280.006417410310.401563345-4.97892512762148734Aeneid10426177.392213351
1237652936177485798310.447-4.9474321.48450.006604240310.401563345-4.97892512762148734Aeneid10426199.297930768
1237652936177485851310.456-4.9679221.00080.00637440310.401563345-4.97892512762148734Aeneid10426198.870482683
1237652936177549339310.481-4.9793717.56350.00659470310.463385767-5.02847194581148734Aeneid11742187.196450653
1237652936177549932310.48-4.988417.38530.01065490310.463385767-5.02847194581148734Aeneid3734155.676572973

In [400]:
#now xmatch in the sense of ML things with matches in aencat
catsc = SkyCoord(aencat['ra'], aencat['dec'], unit=u.deg)
mlsc = SkyCoord(mlcat['RA'], mlcat['DEC'], unit=u.deg)

idxsc, d2d, _ = mlsc.match_to_catalog_sky(catsc)

In [401]:
plt.hist(d2d.arcsec, bins=100, histtype='step',range=(0,60))
plt.tight_layout()
np.sum(d2d<1*u.arcsec),np.sum(d2d>1*u.arcsec), mlcat[d2d>1*u.arcsec]['PROBABILITY_CLASS_1']


Out[401]:
(19765, 5, <Column name='PROBABILITY_CLASS_1' dtype='float32' length=5>
  0.0328935
 0.00810233
 0.00666758
 0.00377329
  0.0120457)

In [402]:
#add probabilities to catalog
probs = -np.ones(len(aencat), dtype=float)  #-1 for those w/o
probs[idxsc[d2d<1*u.arcsec]] = mlcat['PROBABILITY_CLASS_1'][d2d<1*u.arcsec]

if 'ML_prob' in aencat.colnames:
    aencat['ML_prob'] = probs
else:
    aencat.add_column(Column(name='ML_prob', data=probs))

Now Selection


In [403]:
gricolorcuts = {'g-r': (None, 0.8, 2),
                'r-i': (None, 0.5, 2)}
sagacolorcuts = gricolorcuts.copy()
sagacolorcuts['r-K'] = (None, 2.0, 2)
sagacolorcuts['r-w1'] = (None, 2.6, 2)

def uggrline_cut(cat, sl=1.5, inter=-0.2):
    gt = cat['u']-cat['g']+2*(cat['u_err']+cat['g_err'])
    lt = sl*(cat['g']-cat['r']-2*(cat['g_err']+cat['r_err'])) + inter
    return gt > lt
sagacolorcuts['funcs'] = [uggrline_cut]

In [404]:
aen.environskpc


Out[404]:
300.00000000000006

In [405]:
magcut = 22
aentargs = targeting.select_targets(aen, colorcuts=gricolorcuts, outercutrad=aen.environskpc*u.kpc, 
                                    galvsallcutoff=magcut, faintlimit=magcut, verbose=True,
                                    removespecstars=False, removegalsathighz =False,
                                    catalog=aencat) #do these because the fits catalogs don't have spec_class
len(aentargs)


Colorcut for g-r removed 45025 objects
Colorcut for r-i removed 46120 objects
Out[405]:
1386

In [406]:
goodprob = 0.05
closegoodprob_aencatmsk = (aencat['ML_prob']>goodprob)&(aencat['rhost_kpc']<aen.environskpc)&(aencat['r']<magcut)
np.sum(aentargs['ML_prob']>goodprob), np.sum(closegoodprob_aencatmsk)


Out[406]:
(21, 79)

In [407]:
#so need to add in the missing ones...
print(len(aentargs))
torem = aentargs['ML_prob']>goodprob # first remove them
aentargs = aentargs[~torem]
print(len(aentargs))
#then add them back in
aentargs = table.vstack((aentargs, aencat[closegoodprob_aencatmsk]))
print(len(aentargs))


1386
1365
1444

And compute priorities


In [408]:
pris = np.zeros(len(aentargs), dtype=int)
pris[aentargs['r']<22] = 4
pris[aentargs['r']<21.5] = 3
pris[aentargs['r']<21] = 2
pris[aentargs['ML_prob']>goodprob] = 1
if 'imacs_pri' in aentargs.colnames:
    aentargs['imacs_pri'] = pris
else:
    aentargs.add_column(Column(name='imacs_pri', data=pris))
np.bincount(pris)


Out[408]:
array([  0,  79, 397, 326, 642])

Identify previously-observed targets


In [409]:
allspectaken = Table.read('SAGADropbox/data/allspectaken_v3.fits.gz')
allspectaken = allspectaken[allspectaken['HOST_NSAID'] == aen.nsaid]
allspectaken


Out[409]:
<Table length=767>
objIDradecphot_sgflagsspecObjIDugrizu_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_NSAIDSATSREMOVETELNAMEMASKNAMEZQUALITYSPEC_REPEAT
int64float64float64int16int64int64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float64float32float32float32float64float32float32float32float32float32float32float32float32float32float32float32float32int32float32float32float64float64float64float64float64int64int64str47float64float64int64int64int64str4str47float64str47
1237652599560274145310.050003311-5.9295464273233525336013672071386620672504012818.317816.159815.072714.549714.11250.03552720.003820810.002726260.002633170.004806150.2810950.2068270.1500080.1137470.080647816.964117.60364.3006220.62205700284.8329215.777915.072720.489166785814.1640.07313.2690.07912.7810.05911.48140.0013898212.1130.0240.0451133-1.000.1045270.017398309.727-5.6399852.19523900.019.594148734554Aeneid25.9586056905394.124940047213372-1NSAsdss4.0
1237652934566543592309.458202309-6.0907868974333521900039784071388654769015398415.877914.127213.356912.961512.70030.007762150.001968360.001825160.001844610.002802990.3152060.2319260.1682120.127550.090434515.600916.30894.8532419.12278397124.7332215.038113.471518.842764882413.3020.09112.520.10912.2070.08210.37060.0005689811.0920.0230.0128386-1.000.056060.023641309.727-5.6399852.19523900.019.594148734554Aeneid31.4499469854477.496885247213472-1NSAsdss4.0
1237652934566477855309.254267802-5.9970758705531161153267503124016.689914.72113.835513.381113.00310.01873060.002604470.002198750.002179610.003944290.2549240.187570.1360420.1031560.073139116.795217.52336.2607520.35309836296.5542820.591614.069620.147668140713.970.12213.1540.10612.7820.10410.73880.0010359911.4690.0220.0358979-1.000.0612250.018878309.727-5.6399852.19523900.019.594148734554Aeneid35.4374079454538.035510086213442-1NSAsdss4.0
1237652599023206466309.515074039-6.2698893871433525336013620871388489842271232018.466716.490115.591315.167814.82930.03023820.004102850.003140510.003104270.005641540.2820150.2075040.1504990.1141190.080911817.132917.79962.3878519.77383345882.196386.1350315.797619.501628760714.6740.08114.0890.10913.5390.07912.45370.0026804112.8360.030.0448721-1.000.0636150.015932309.727-5.6399852.19523900.019.594148734554Aeneid39.8560181863605.119101702213422-1NSAsdss4.0
1237652599023141374309.48038284-6.3000715448433521900039784071388187476573593616.263414.563213.735513.288912.87520.01046940.002355890.002041960.00201950.002913770.2893190.2128780.1543970.1170740.083007216.378117.12166.1880220.03695088826.161218.71213.846519.790280037613.7930.12212.7660.11912.3860.08810.32860.00056541110.8010.020.0263784-1.000.0587530.030601309.727-5.6399852.19523900.019.594148734554Aeneid42.2539393929641.524066246213452-1NSAsdss4.0
1237652599023337800309.909967378-6.281828642343263951812264208023.811722.797822.531822.000221.48311.210950.3205130.3152430.2692020.5043080.2471590.1818570.1318980.1000140.070911418.015918.890.31045421.98719066030.6343661.1354522.659323.66642556215.0930.16114.2710.21813.8530.13411.9920.02411.7910.0230.0266385-1.00-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid39.9935478235607.207068996148737-12NSAned4.0
1237652599023337797309.909967378-6.2818286423431161187626717272016.362215.062814.419114.058413.78120.01385430.002756610.002401380.002422460.00449940.2471310.1818370.1318830.1000030.070903517.642518.39468.214420.98745975776.6698113.667814.394220.51019371815.0930.16114.2710.21813.8530.13411.29160.0014276111.7910.0230.0266385-1.000.0693290.027834309.727-5.6399852.19523900.019.594148734554Aeneid40.030823903607.772992193148737-1-1NSAned4.0
1237652599023076348309.286501039-6.1224317003433528986735822471388407378899148818.232917.218816.815316.57116.36960.02811030.006316820.006098780.006975570.02009270.283850.2088540.1514780.1148620.081438318.754519.48913.5065921.53516529863.288627.1686216.806521.38702809859999.09999.09999.09999.09999.09999.014.04230.012518514.6090.0760.0361055-1.000.0388630.011444309.727-5.6399852.19523900.019.594148734554Aeneid39.111431922593.814817762213432-1NSAsdss4.0
1237652600633755048309.558394412-4.95656739254310565861153186471393300205642752019.240617.98917.553717.390817.13270.07543680.01330820.01259450.01830830.04562620.2491460.1833190.1329580.1008180.071481419.872420.65955.2928523.16762136013.967848.3813717.560522.5487090149999.09999.09999.09999.09999.09999.015.55040.050257215.5720.1730.0268554-1.000.0562490.021235309.727-5.6399852.19523900.019.594148734554Aeneid42.2189752379640.9932466562136622NSAsdss4.0
1237652600633755052309.558394412-4.956567392543387099262058768022.590723.055823.120522.917722.82690.314040.2513350.334670.4197090.764880.2490380.183240.1329010.1007750.071450420.141620.95670.58818623.80550497380.5666691.0318123.129623.89174083399999.09999.09999.09999.09999.09999.015.9870.0815.5720.1730.0268554-1.00-1.0-1.0309.727-5.6399852.19523900.019.594148734554Aeneid42.1768017959640.352976865213662-1NSAsdss4.0
.......................................................................................................................................................................................
1237652600096884707309.563770908-5.3491897112633525550762036823923.150822.455221.656620.898320.44890.5978830.148340.09968120.07450410.2295730.2930460.215620.1563860.1185830.084076621.847222.43130.63175522.65476502290.7009221.2286821.79423.01775344599999.09999.09999.09999.09999.09999.016.41680.064715116.8960.5420.68296-1.0-10.6357330.157323309.727-5.6399852.19523900.019.594148734554Aeneid19.9850797018303.431121038-10-1AAT/Spectra/Final/AAT/Aeneid_1.zlog1.0
1237652600096884536309.512914163-5.37714985457319358303453185623021.700620.804420.028919.685819.8160.2290520.04660330.03412580.03613870.1851090.2940690.2163730.1569320.1189970.084370220.54921.19660.97866921.97753591821.020221.9988920.097722.13662959459999.09999.09999.09999.09999.09999.016.43340.067196315.3640.1340.290002-1.0-10.2566840.074291309.727-5.6399852.19523900.019.594148734554Aeneid20.3000278515308.212886705-10-1AAT/Spectra/Final/AAT/Aeneid_1.zlog4.0
1237652600097080770309.92511374-5.462677516936898791244831822.794821.325720.466620.066620.46730.6314450.07550590.04902720.05098960.3258610.2934920.2159490.1566240.1187630.084204721.238321.81490.78074122.18526403541.43674.8013520.261323.04356701589999.09999.09999.09999.09999.09999.018.09830.3447489999.09999.00.20143-1.0-10.2821260.127389309.727-5.6399852.19523900.019.594148734554Aeneid15.9091830252241.547758235-10-1AAT/Spectra/Final/AAT/Aeneid_3.zlog4.0
1237652600097080886309.951730602-5.464453243463105622104310288922.186721.252920.939620.903620.34180.2264420.04471670.04271450.05998360.1654840.2921090.2149310.1558860.1182040.083807921.214821.72990.055079916.64004339120.5527911.2607720.97721.68529904369999.09999.09999.09999.09999.09999.09999.09999.09999.09999.00.479972-1.0-10.1066450.107485309.727-5.6399852.19523900.019.594148734554Aeneid17.0579163878258.988739808-10-1AAT/Spectra/Final/AAT/Aeneid_1.zlog1.0
1237652600097080923309.958295049-5.4518739601133525336013288032822.873921.512420.997220.634220.49440.5507950.07418440.06454860.07025980.2762090.2926060.2152970.1561510.1184050.083950321.517622.10040.78978622.48020572690.7512361.228121.275622.64991980679999.09999.09999.09999.09999.09999.019.09150.7789969999.09999.00.194597-1.0-10.0764360.01538309.727-5.6399852.19523900.019.594148734554Aeneid17.8357083347270.797778122-10-1AAT/Spectra/Final/AAT/Aeneid_2.zlog3.0
1237652600097080930309.964934361-5.4116869085336898804787231722.584721.289720.37219.912719.8260.5242220.07466320.04593810.04575540.1866970.2895480.2130470.1545190.1171670.083073121.09421.72011.2413422.83692299371.091982.1152420.463922.65039569279999.09999.09999.09999.09999.09999.017.04550.1297329999.09999.00.201159-1.0-10.2379430.049199309.727-5.6399852.19523900.019.594148734554Aeneid19.7347748395299.630813683-10-1AAT/Spectra/Final/AAT/Aeneid_3.zlog3.0
1237652600097080959309.97022777-5.41437997524310562428521704031424.688622.261220.955920.511219.77762.134720.2082660.09960560.09600750.2215590.2900120.2133880.1547670.1173550.08320621.839922.49161.5141523.8521637931.562253.7563720.8423.80419339479999.09999.09999.09999.09999.09999.018.20850.3492349999.09999.00.417957-1.0-10.3140370.081503309.727-5.6399852.19523900.019.594148734554Aeneid19.852995322301.425721759-10-1AAT/Spectra/Final/AAT/Aeneid_1.zlog4.0
1237652600097081082309.983964147-5.4997814730636898791219235225.791121.913920.917420.405520.14350.8758010.1068890.06022350.05728520.2010260.2869160.211110.1531150.1161020.08231821.4922.03850.45370821.36663097390.8550772.27720.956522.61192949319999.09999.09999.09999.09999.09999.018.01110.279649999.09999.00.249809-1.0-10.1209470.033414309.727-5.6399852.19523900.019.594148734554Aeneid17.4978402001265.668004709-10-1AAT/Spectra/Final/AAT/Aeneid_2.zlog1.0
1237652600097081269310.02142727-5.50812547817310562425166260833222.161821.605220.900320.962620.99580.2620310.06976470.05011430.0797230.3536920.2890680.2126930.1542630.1169730.082935321.308121.83840.55432321.61457042880.7260391.5158220.929822.23006415549999.09999.09999.09999.09999.09999.018.92570.6522099999.09999.00.322541-1.0-10.2390530.119072309.727-5.6399852.19523900.019.594148734554Aeneid19.2781940027292.698672946-10-1AAT/Spectra/Final/AAT/Aeneid_3.zlog4.0
1237652934566610680309.665232628-5.9564761157436898791219210422.395821.56620.828520.718220.56930.4658370.09905880.1227650.1121490.4453640.3000730.2207910.1601360.1214260.086092821.517222.16261.4046623.56179638481.020221.8909720.94422.98287249929999.09999.09999.09999.09999.09999.017.87320.2379179999.09999.00.286956-1.0-10.2056850.112292309.727-5.6399852.19523900.019.594148734554Aeneid19.3445946457293.706815893-10-1AAT/Spectra/Final/AAT/Aeneid_3.zlog4.0

In [410]:
# now ID those with a good enough zquality
okzqual = 3
goodspectaken = allspectaken[allspectaken['ZQUALITY'] >= okzqual]

In [411]:
#x-match with the target list
goodspecsc = SkyCoord(goodspectaken['ra'], goodspectaken['dec'], unit=u.deg)
aentargssc = SkyCoord(aentargs['ra'], aentargs['dec'], unit=u.deg)
idx, d2d, _  = aentargssc.match_to_catalog_sky(goodspecsc)

plt.hist(d2d.arcsec, bins=100,range=(0,10),log=True,histtype='step')
alreadyobserved = d2d<1*u.arcsec
np.sum(alreadyobserved), np.sum(~alreadyobserved)


Out[411]:
(330, 1114)

Then do stuff


In [412]:
!rm imacs_targets/Ae15B.cat imacs_targets/Ae15B_ini.obs
magellan.build_imacs_targeting_files(aen, 'Marchi/Munoz', targs=aentargs[~alreadyobserved], date='2015-9-5',
                                     refmagrange={'r':(17, 17.5)}, inclhost=False, onlygals=False)


Wrote catalog to imacs_targets/Ae15B.cat
Wrote obs file to imacs_targets/Ae15B_ini.obs

In [414]:
plt.figure(figsize=(10,8))
magellan.plot_imacs_masks(aen, eastleft=True, plotpris =True)
plt.tight_layout()


['imacs_targets/Ae15B_1.SMF', 'imacs_targets/Ae15B_2.SMF', 'imacs_targets/Ae15B_3.SMF', 'imacs_targets/Ae15B_4.SMF']
Total targets already observed= 489
Priority distribution of slitted targets:
Priority 1.0 : 37 targeted, 26 remaining: 58.7301587302 %
Priority 2.0 : 55 targeted, 28 remaining: 66.265060241 %
Priority 3.0 : 183 targeted, 143 remaining: 56.1349693252 %
Priority 4.0 : 214 targeted, 428 remaining: 33.3333333333 %
All priorities: 489 targeted, 625 remaining: 43.8958707361 %