###############################################################################
#
#   apogee.tools.bitmask: tools to work with APOGEE bitmasks
#
###############################################################################
_APOGEE_TARGET1={0:"APOGEE_FAINT",
                 1:"APOGEE_MEDIUM",
                 2:"APOGEE_BRIGHT",
                 3:"APOGEE_IRAC_DERED",
                 4:"APOGEE_WISE_DERED",
                 5:"APOGEE_SFD_DERED",
                 6:"APOGEE_NO_DERED",
                 7:"APOGEE_WASH_GIANT",
                 8:"APOGEE_WASH_DWARF",
                 9:"APOGEE_SCI_CLUSTER",
                 10:"APOGEE_EXTENDED",
                 11:"APOGEE_SHORT",
                 12:"APOGEE_INTERMEDIATE",
                 13:"APOGEE_LONG",
                 15:"APOGEE_SERENDIPITOUS",
                 16:"APOGEE_FIRST_LIGHT",
                 17:"APOGEE_ANCILLARY",
                 18:"APOGEE_M31_CLUSTER",
                 19:"APOGEE_MDWARF",
                 20:"APOGEE_HIRES",
                 21:"APOGEE_OLD_STAR",
                 22:"APOGEE_DISK_RED_GIANT",
                 23:"APOGEE_KEPLER_EB",
                 24:"APOGEE_GC_PAL1",
                 25:"APOGEE_MASSIVE_STAR",
                 26:"APOGEE_SGR_DSPH",
                 27:"APOGEE_KEPLER_SEISMO",
                 28:"APOGEE_KEPLER_HOST",
                 29:"APOGEE_FAINT_EXTRA",
                 30:"APOGEE_SEGUE_OVERLAP",
                 31:"APOGEE_CHECKED"}
def apogee_target1_string(bit):
    """
    NAME:
       apogee_target1_string
    PURPOSE:
       return the string name of an APOGEE_TARGET1 bit
    INPUT:
       bit - the bit (integer between 0 and 31)
    OUTPUT:
       string name
    HISTORY:
       2014-08-19 - Written - Bovy (IAS)
    """
    try:
        return _APOGEE_TARGET1[bit]
    except KeyError:
        raise KeyError("bit %i not recognized as an apogee_target1 bit" % bit)


@@ -1455,439 +1455,1473 @@
 D%22%7D%0A
-def apogee_target1_string(bit):%0A    %22%22%22%0A    NAME:%0A       apogee_target1_string%0A    PURPOSE:%0A       return the string name of an APOGEE_TARGET1 bit%0A    INPUT:%0A       bit - the bit (integer between 0 and 31)%0A    OUTPUT:%0A       string name%0A    HISTORY:%0A       2014-08-19 - Written - Bovy (IAS)%0A    %22%22%22%0A    try:%0A        return _APOGEE_TARGET1%5Bbit%5D%0A    except KeyError:%0A        raise KeyError(%22bit %25i not recognized as an apogee_target1
+_APOGEE_TARGET2=%7B1:%22APOGEE_FLUX_STANDARD%22,%0A                 2:%22APOGEE_STANDARD_STAR%22,%0A                 3:%22APOGEE_RV_STANDARD%22,%0A                 4:%22SKY%22,%0A                 9:%22APOGEE_TELLURIC%22,%0A                 10:%22APOGEE_CALIB_CLUSTER%22,%0A                 11:%22APOGEE_BULGE_GIANT%22,%0A                 12:%22APOGEE_BULGE_SUPER_GIANT%22,%0A                 13:%22APOGEE_EMBEDDEDCLUSTER_STAR%22,%0A                 14:%22APOGEE_LONGBAR%22,%0A                 15:%22APOGEE_EMISSION_STAR%22,%0A                 16:%22APOGEE_KEPLER_COOLDWARF%22,%0A                 17:%22APOGEE_MIRCLUSTER_STAR%22,%0A                 31:%22APOGEE_CHECKED%22%7D%0Adef apogee_target1_string(bit):%0A    %22%22%22%0A    NAME:%0A       apogee_target1_string%0A    PURPOSE:%0A       return the string name of an APOGEE_TARGET1 bit%0A    INPUT:%0A       bit - the bit (integer between 0 and 31)%0A    OUTPUT:%0A       string name%0A    HISTORY:%0A       2014-08-19 - Written - Bovy (IAS)%0A    %22%22%22%0A    try:%0A        return _APOGEE_TARGET1%5Bbit%5D%0A    except KeyError:%0A        raise KeyError(%22bit %25i not recognized as an apogee_target1 bit%22 %25 bit)%0A%0Adef apogee_target2_string(bit):%0A    %22%22%22%0A    NAME:%0A       apogee_target2_string%0A    PURPOSE:%0A       return the string name of an APOGEE_TARGET2 bit%0A    INPUT:%0A       bit - the bit (integer between 0 and 31)%0A    OUTPUT:%0A       string name%0A    HISTORY:%0A       2014-08-19 - Written - Bovy (IAS)%0A    %22%22%22%0A    try:%0A        return _APOGEE_TARGET2%5Bbit%5D%0A    except KeyError:%0A        raise KeyError(%22bit %25i not recognized as an apogee_target2
  bit

add target flags for apogee_target2