In [138]:
import os, time
import numpy as np
import fitsio
import matplotlib.pyplot as plt
from astropy.table import Table

Check the masking


In [130]:
MASKBITS = dict(
    NPRIMARY   = 0x1,   # not PRIMARY
    BRIGHT     = 0x2,
    SATUR_G    = 0x4,
    SATUR_R    = 0x8,
    SATUR_Z    = 0x10,
    ALLMASK_G  = 0x20,
    ALLMASK_R  = 0x40,
    ALLMASK_Z  = 0x80,
    WISEM1     = 0x100, # WISE masked
    WISEM2     = 0x200,
    BAILOUT    = 0x400, # bailed out of processing
    MEDIUM     = 0x800, # medium-bright star
    GALAXY     = 0x1000, # LSLGA large galaxy
    CLUSTER    = 0x2000, # Cluster catalog source
)

# Bits in the "brightblob" bitmask
IN_BLOB = dict(
    BRIGHT = 0x1,
    MEDIUM = 0x2,
    CLUSTER = 0x4,
    GALAXY = 0x8,
)

In [146]:
gaia = Table.read('check-gaia-decam.fits')
gaia


Out[146]:
Table length=1511710
BRICKNAMEBRICK_PRIMARYBRIGHTBLOBMASKBITSTYPERADECBXBYREF_CATREF_IDGAIA_PHOT_G_MEAN_MAGFLUX_GFLUX_RFLUX_ZFLUX_IVAR_GFLUX_IVAR_RFLUX_IVAR_Z
bytes8boolint16int16bytes4float64float64float32float32bytes2int64float32float32float32float32float32float32float32
1350p335True01PSF134.9284324347869733.375017670938052620.703482.4649700.00.28974920.48604150.638764861476.666474.3932894.09064
1350p335True00PSF134.9288502877206233.3756018875149542615.903390.48913600.00.218217920.524548650.66448811488.9829474.399394.199844
1350p335True00PSF135.131687822277533.375756713164314288.4573793.292946G271328724773595328016.9366598.71353188.55865248.89647142.8348156.93150334.93273
1350p335True22064PSF135.0784614124894733.377421812643824899.2179115.55612G271328814108910169615.411125528.58527719.9368753.515431.10142116.98548.076427
1350p335True22048PSF135.0789719962537833.3755246475573893.3395489.4925G271328814108910208018.12956428.3533564.8151994.44299385.91187127.0532455.148693
1350p335True00PSF134.8790434941723533.375816122806093187.405893.959915G271329037447210291217.2497535.571926128.53609323.0675332.5516480.3347928.643694
1350p335True00PSF135.012132993071533.37553580954661660.280689.3104300.00.14158620.255239550.52623681512.96474.587566.08998
1350p335True00PSF134.9528007158594433.37529864026542341.087286.166214G271329019837694233619.6162598.67069215.92754822.119194561.4854130.4644846.514046
1350p335True00REX134.8878234139838833.375827764624043086.66194.00712600.00.067831010.314736371.98469321303.8052403.5790776.660934
1350p335True00REX134.886277891193633.3770157422160243104.377110.349800.00.66456661.00427351.15968431202.6208382.6942774.90841
......................................................
1402p317True00REX140.1506688309921231.8739597294212343272.12523503.622600.00.204840140.56778930.87899595320.7422387.4082649.80584
1402p317True00REX140.3460516535203631.87441690993176992.286253509.305400.00.374666040.86572781.6007149397.8411378.6143249.497894
1402p317True00PSF140.290283904073531.8745465206304851643.01433510.838600.00.26908891.06201822.0594983458.56357402.6900696.53552
1402p317True00PSF140.2666811428654231.8743947673878441918.42363508.749300.00.08604470.279975950.4321387438.70844645.6694396.82136
1402p317True00PSF140.1573134157982331.8743830333904653194.58573509.35100.00.057906980.329674120.43713838444.53488649.483597.175934
1402p317True00PSF140.2538701396760231.8747597765389482067.90823513.787600.00.0372441560.33452590.50076544438.79602641.903896.25585
1402p317True00REX140.1418441823496231.8748304877799063375.08183515.711200.00.227921680.43560230.88002557288.79156335.3441835.55767
1402p317True00PSF140.3045873400842531.8747607967763431476.11523513.814500.00.143965770.227540850.44686598461.2271635.094697.7847
1402p317True00PSF140.3026366730646331.8748006316588251498.87673514.356200.00.061032860.239468830.4224156462.27548633.2015497.820885
1402p317True00REX140.1636963640364431.874845701108463120.0993515.628700.00.163277460.350340870.88251215215.81064234.5688228.635487

All DUPs should be in an LSLGA blob.


In [132]:
idup = gaia['TYPE'] == 'DUP'
assert(np.all(gaia[idup]['MASKBITS'] & MASKBITS['GALAXY'] != 0))
assert(np.all(gaia[idup]['FLUX_G'] == 0))
for band in ('G', 'R', 'Z'):
    assert(np.all(gaia[idup]['FLUX_{}'.format(band)] == 0))
    assert(np.all(gaia[idup]['FLUX_IVAR_{}'.format(band)] == 0))
gaia[idup]


Out[132]:
Table length=224
BRICKNAMEBRICK_PRIMARYBRIGHTBLOBMASKBITSTYPERADECREF_CATREF_IDGAIA_PHOT_G_MEAN_MAGFLUX_GFLUX_RFLUX_ZFLUX_IVAR_GFLUX_IVAR_RFLUX_IVAR_Z
bytes8boolint16int16bytes4float64float64bytes2int64float32float32float32float32float32float32float32
True04096DUP135.0950054715822833.005760519695784G271326154235483609618.468030.00.00.00.00.00.0
True04096DUP135.4576526348235532.873589504953294G271250030664772800019.0994240.00.00.00.00.00.0
True04096DUP135.35287128138231.67103075440068G271181448627036454418.6032870.00.00.00.00.00.0
True04096DUP135.2826155457824831.764911163291007G271200373970944844818.658610.00.00.00.00.00.0
True04096DUP135.18598850452633.201000037925326G271327319030615859218.7075820.00.00.00.00.00.0
True04096DUP134.9439360211826833.20262044344028G271327920755718579218.0044420.00.00.00.00.00.0
True04096DUP135.7880387571007434.094634915161514G271342887428237977618.2434080.00.00.00.00.00.0
True04096DUP135.2137242376541334.48659323742098G271368925667489113619.51170.00.00.00.00.00.0
True04096DUP135.6011111705638332.953389511233155G271252360255033075218.4467530.00.00.00.00.00.0
True04096DUP135.390672783134532.6203095567898G271248714686794726418.010280.00.00.00.00.00.0
................................................
True04096DUP140.1708542028929434.03667887502455G270232089055978649618.8823450.00.00.00.00.00.0
True04096DUP140.15389142980433.074723429585944G270169152322977203217.5115280.00.00.00.00.00.0
True04320DUP140.5381321627030533.900859250282075G270212569288522892818.248550.00.00.00.00.00.0
True04096DUP140.1095658132579433.51580349274105G270209019927551731217.9253830.00.00.00.00.00.0
True04096DUP140.068632605063132.14587875545463G270082689048141798418.855140.00.00.00.00.00.0
True04320DUP140.2890716713740233.67685297453074G270209892664905280018.4476590.00.00.00.00.00.0
True04320DUP140.191079648078533.704527514844386G270210140055021721618.1668150.00.00.00.00.00.0
True06144DUP140.1193522752982433.65047044919985G270209504399862374418.1441020.00.00.00.00.00.0
True04096DUP140.254905031062933.12666676855378G270164658069340569617.8519940.00.00.00.00.00.0
True04096DUP140.2475736187873633.19526088025481G270206930855466496018.0086570.00.00.00.00.00.0

1) Find all bright Gaia stars.

2) Make sure the magnitude limits are correct.

3) Make sure the masking behavior around them is correct.


In [126]:
ibright = np.where(((gaia['MASKBITS'] & MASKBITS['BRIGHT']) != 0) * (gaia['REF_CAT'] == 'G2') * (gaia['TYPE'] != 'DUP'))[0]
#bb = (gaia['BRIGHTBLOB'][ibright] & IN_BLOB['BRIGHT'] != 0) == False
#gaia[ibright][bb]
#gaia[ibright]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))
_ = ax1.hist(gaia[ibright]['GAIA_PHOT_G_MEAN_MAG'], bins=100)
ax1.set_xlabel('Gaia G')
ax1.set_title('MASKBITS & BRIGHT, REF_CAT==G2, TYPE!=DUP', fontsize=14)

isb = np.where(gaia[ibright]['GAIA_PHOT_G_MEAN_MAG'] < 13.0)[0]
isf = np.where(gaia[ibright]['GAIA_PHOT_G_MEAN_MAG'] >= 13.0)[0]
print(len(isb), len(isf))

ax2.scatter(gaia['RA'][ibright][isb], gaia['DEC'][ibright][isb], s=10, color='green', label='G<13')
ax2.scatter(gaia['RA'][ibright][isf], gaia['DEC'][ibright][isf], s=10, color='red', alpha=0.5, label='G>=13')
ax2.legend(fontsize=14, frameon=True)
ax2.set_title('MASKBITS & BRIGHT, REF_CAT==G2, TYPE!=DUP', fontsize=14)

#ax.set_xlim(136.8, 137.2)
#ax.set_ylim(32.4, 32.8)

print(np.sum(gaia['BRIGHTBLOB'][ibright][isf] & IN_BLOB['BRIGHT'] != 0))
check = np.where(gaia['BRIGHTBLOB'][ibright][isf] & IN_BLOB['BRIGHT'] == 0)[0] # no bright targeting bit set

for key in MASKBITS.keys():
    print(key, np.sum(gaia['MASKBITS'][ibright][isf][check] & MASKBITS[key] != 0))

gaia[ibright][isf][check]


1606 2364
2360
NPRIMARY 0
BRIGHT 4
SATUR_G 0
SATUR_R 0
SATUR_Z 0
ALLMASK_G 0
ALLMASK_R 0
ALLMASK_Z 0
WISEM1 1
WISEM2 1
BAILOUT 0
MEDIUM 4
GALAXY 0
CLUSTER 0
Out[126]:
Table length=4
BRICKNAMEBRICK_PRIMARYBRIGHTBLOBMASKBITSTYPERADECREF_CATREF_IDGAIA_PHOT_G_MEAN_MAG
bytes8boolint16int16bytes4float64float64bytes2int64float32
1324p337True02050PSF132.4504595192292433.786983496163316G271618888898497408018.107346
1337p330True02050PSF133.7106321232034532.94409161567506G271311929303790873619.135618
1373p330True02050PSF137.174000859422132.878714176885104G271237866887787929619.322224
1400p342True02818PSF140.132726224801334.31740242059666G270234030381111065621.172768

Make sure the MASKBITS values are set correctly.


In [156]:
mask = fitsio.read('decam/coadd/132/1325p325/legacysurvey-1325p325-maskbits.fits.fz')
#print(mask.max())
c = plt.imshow(mask > 0, origin='lower')
#plt.colorbar(c)



In [152]:
ww = gaia['BRICKNAME'] == '1325p325'
eq = []
for obj in gaia[ww]:
    eq.append(mask[int(obj['BY']), int(obj['BX'])] == obj['MASKBITS'])
assert(np.all(eq))