
2MASS PSC fields:

ra, dec : obvious

m       -> mag
cmsig   -> dM
msigcom -> dMcal (dMcal^2 + dM^2 = msigcom^2)
stdap   -> Map 
snr     : skipped

err_maj -> fhwm_x
err_min -> fhwm_y
err_ang -> angle

the following 2MASS values are used to set bits in the phot_flags field:

ph_qual:

X = 0x0000  There is a detection at this location, but no valid brightness estimate can be extracted using any algorithm. rd_flg="9" and default magnitude is null.
U = 0x0001  Upper limit on magnitude. Source is not detected in this band (rd_flg="0"), or it is detected, but not resolved in a consistent fashion with other bands (rd_flg="6"). A value of ph_qual="U" does not necessarily mean that there is no flux detected in this band at the location. Whether or not flux has been detected can be determined from the value of rd_flg. When rd_flg="0", no flux has been detected. When rd_flg="6", flux has been detected at the location where the images were not deblended consistently in all three bands (JHKs).
F = 0x0002  This category includes rd_flg="1" or rd_flg="3" sources where a reliable estimate of the photometric error, [jhk]_cmsig, could not be determined. The uncertainties reported for these sources in [jhk]_cmsig and [jhk]_msigcom are flags and have numeric values >8.0.
E = 0x0003  This category includes detections where the goodness-of-fit quality of the profile-fit photometry was very poor (rd_flg=2 and [jhk]psf_chi>10.0), or detections where psf fit photometry did not converge and an aperture magnitude is reported (rd_flg=4), or detections where the number of frames was too small in relation to the number of frames in which a detection was geometrically possible (rd_flg="1" or rd_flg="2").
A = 0x0004  Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>10 AND [jhk]_cmsig<0.10857.
B = 0x0005  Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>7 AND [jhk]_cmsig<0.15510.
C = 0x0006  Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>5 AND [jhk]_cmsig<0.21714.
D = 0x0007  Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with no [jhk]_snr or [jhk]_cmsig requirement.

rd_flag:

0 = 0x0000  Source is not detected in this band. The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20".
1 = 0x0010  The default magnitude is derived from aperture photometry measurements on the 51 ms "Read_1" exposures. The aperture radius is 4", with the sky background measured in an annulus with an inner radius of 14" and an outer radius of 20". Used for sources that saturate one or more of the 1.3s "Read_2" exposures, but are not saturated on at least one of the 51 ms "Read_1" frames.
2 = 0x0020  The default magnitude is derived from a profile-fitting measurement made on the 1.3 sec "Read_2" exposures. The profile-fit magnitudes are normalized to curve-of-growth-corrected aperture magnitudes. This is the most common type in the PSC, and is used for sources that have no saturated pixels in any of the 1.3 sec exposures.
3 = 0x0030  The default magnitude is derived from a 1-d radial profile fitting measurement made on the 51 ms "Read_1" exposures. Used for very bright sources that saturate all of the 51 ms "Read 1" exposures.
4 = 0x0040  The default magnitude is derived from curve-of-growth-corrected 4" radius aperture photometry measurements on the 1.3 s "Read_2" exposures. This is used for sources that are not saturated in any of the Read_2 frames, but where the profile-fitting measurements fail to converge to a solution. These magnitudes are the same as the standard aperture magnitudes (j_m_stdap, h_m_stdap, k_m_stdap), but when they are the default magnitudes, it generally implies that they are low quality measurements.
6 = 0x0050  The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for pairs of sources which are detected and resolved in another band, but are detected and not resolved in this band. This differs from a rd_flg="0" because in this case there is a detection of the source in this band, but it is not consistently resolved across all bands.
9 = 0x0060  The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for sources that were nominally detected in this band, but which could not have a useful brightness measurement from either profile fitting or aperture photometry. This often occurs in highly confused regions, or very near Tile edges where a significant fraction of the measurement aperture of sky annulus falls off the focal plane.

cc_flag:

p = 0x0000  Persistence. Source may be contaminated by a latent image left by a nearby bright star.
c = 0x0100  Photometric Confusion. Source photometry is biased by a nearby star that has contaminated the background estimation. This is very common in high source density regions.
d = 0x0200  Diffraction spike confusion. Source may be contaminated by a diffraction spike from a nearby star.
s = 0x0300  Electronic stripe. Source measurement may be contaminated by a stripe from a nearby bright star.
b = 0x0400  Bandmerge confusion. In the process of merging detections in the different bands for this source, there was more than one possible match between the different band components. This occurs in regions of very high source density, or when multiple sources were split in one band but not another.
0 = 0x0500  Source is unaffected by known artifacts, or is not detected in the band.

bl_flag: (0,1 : not blended)

anything except 0 or 1 -> 0x0008

gal_flag: (0,1 : not extended)

anything except 0 or 1 -> 0x0080

mp_flag: 

anything except 0 or 1 -> 0x0800

dup_flag:

anything except 0 or 1 -> 0x1000

use_flag:

anything except 0 or 1 -> 0x2000


2MASS PSC fields:

ra, dec : obvious

err_maj, err_min, err_ang : I only have ra_err and dec_err.  should I upgrade my tables?
(put these in FHx, FWy, theta)

designation (2mass ID) : ignore this?  potentially derivable from position

j_m -> M
j_cmsig -> dM
j_msigcom : I don't yet have a systematic error term; add this in
j_snr : another way of representing the error : the implied error is the MODE of dM for the scan

(repeat for h, k)

ph_qual[j] : using letters to represent 8 states: (3bit needed)

0x0000 * "X" - There is a detection at this location, but no valid brightness estimate can be extracted using any algorithm. rd_flg="9" and default magnitude is null.
0x0001 * "U" - Upper limit on magnitude. Source is not detected in this band (rd_flg="0"), or it is detected, but not resolved in a consistent fashion with other bands (rd_flg="6"). A value of ph_qual="U" does not necessarily mean that there is no flux detected in this band at the location. Whether or not flux has been detected can be determined from the value of rd_flg. When rd_flg="0", no flux has been detected. When rd_flg="6", flux has been detected at the location where the images were not deblended consistently in all three bands (JHKs).
0x0002 * "F" - This category includes rd_flg="1" or rd_flg="3" sources where a reliable estimate of the photometric error, [jhk]_cmsig, could not be determined. The uncertainties reported for these sources in [jhk]_cmsig and [jhk]_msigcom are flags and have numeric values >8.0.
0x0003 * "E" - This category includes detections where the goodness-of-fit quality of the profile-fit photometry was very poor (rd_flg=2 and [jhk]psf_chi>10.0), or detections where psf fit photometry did not converge and an aperture magnitude is reported (rd_flg=4), or detections where the number of frames was too small in relation to the number of frames in which a detection was geometrically possible (rd_flg="1" or rd_flg="2").
0x0004 * "A" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>10 AND [jhk]_cmsig<0.10857.
0x0005 * "B" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>7 AND [jhk]_cmsig<0.15510.
0x0006 * "C" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with [jhk]_snr>5 AND [jhk]_cmsig<0.21714.
0x0007 * "D" - Detections in any brightness regime where valid measurements were made (rd_flg="1","2" or "3") with no [jhk]_snr or [jhk]_cmsig requirement.

rd_flag[j] : using numbers to represent 7 states:

0x0000 * "0" - Source is not detected in this band. The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20".
0x0010 * "1" - The default magnitude is derived from aperture photometry measurements on the 51 ms "Read_1" exposures. The aperture radius is 4", with the sky background measured in an annulus with an inner radius of 14" and an outer radius of 20". Used for sources that saturate one or more of the 1.3s "Read_2" exposures, but are not saturated on at least one of the 51 ms "Read_1" frames.
0x0020 * "2" - The default magnitude is derived from a profile-fitting measurement made on the 1.3 sec "Read_2" exposures. The profile-fit magnitudes are normalized to curve-of-growth-corrected aperture magnitudes. This is the most common type in the PSC, and is used for sources that have no saturated pixels in any of the 1.3 sec exposures.
0x0030 * "3" - The default magnitude is derived from a 1-d radial profile fitting measurement made on the 51 ms "Read_1" exposures. Used for very bright sources that saturate all of the 51 ms "Read 1" exposures.
0x0040 * "4" - The default magnitude is derived from curve-of-growth-corrected 4" radius aperture photometry measurements on the 1.3 s "Read_2" exposures. This is used for sources that are not saturated in any of the Read_2 frames, but where the profile-fitting measurements fail to converge to a solution. These magnitudes are the same as the standard aperture magnitudes (j_m_stdap, h_m_stdap, k_m_stdap), but when they are the default magnitudes, it generally implies that they are low quality measurements.
0x0050 * "6" - The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for pairs of sources which are detected and resolved in another band, but are detected and not resolved in this band. This differs from a rd_flg="0" because in this case there is a detection of the source in this band, but it is not consistently resolved across all bands.
0x0060 * "9" - The default magnitude is the 95% confidence upper limit derived from a 4" radius aperture measurement taken at the position of the source on the Atlas Image. The sky background is estimated in an annular region with inner radius of 14" and outer radius of 20". This is used for sources that were nominally detected in this band, but which could not have a useful brightness measurement from either profile fitting or aperture photometry. This often occurs in highly confused regions, or very near Tile edges where a significant fraction of the measurement aperture of sky annulus falls off the focal plane.

bl_flag[j] : 3 states:

    * "0" - Source is not detected, or is inconsistently deblended in that band.
    * "1" - One component was fit to the source in R_2 profile-fitting photometry (rd_flg="2"), or default magnitudes are from aperture photometry (rd_flg="1" or "4") or saturated star 1-d radial profile-fitting (rd_flg="3").
    * ">1" - More than one component was fit simultaneously during R2 profile-fit photometry, where the value of the field is the number of components simultaneously fit. The maximum number of components is 7 in any band for the PSC, so this bl_flg is always a three character flag. Multi-component fitting occurs only for profile-fitting, and only when more than one detection is found within ~5". Single detections that are not well-fit by a single PSF are not split.

cc_flag[j] : 6 states:

    * "p" = Persistence. Source may be contaminated by a latent image left by a nearby bright star.
    * "c" = Photometric Confusion. Source photometry is biased by a nearby star that has contaminated the background estimation. This is very common in high source density regions.
    * "d" = Diffraction spike confusion. Source may be contaminated by a diffraction spike from a nearby star.
    * "s" = Electronic stripe. Source measurement may be contaminated by a stripe from a nearby bright star.
    * "b" = Bandmerge confusion. In the process of merging detections in the different bands for this source, there was more than one possible match between the different band components. This occurs in regions of very high source density, or when multiple sources were split in one band but not another.
    * "0" = Source is unaffected by known artifacts, or is not detected in the band.

ndet : number of frames detected, number of frames available (carry this somehow?)

prox : distance to nearest neighbor (unneeded)
pxpa : direction to nearest neighbor (unneeded)
pxcntr : id of nearest neighbor

gal_contam : is source close to or part of an extended source? (3 states)

mp_flg : associated with know Solar System object

pts_key/cntr : 2MASS internal object ID

hemis : (which observatory -- replace with a photcode?)

date -> ignore (not accurate)

scan : scan in which it was detected (unneeded)

glon, glat : derivable

x_scan : pixel location in x direction -> Xccd

jdate : time stamp with ~30 sec accuracy

j_psfchi : fit chi sqare -> psfProb (needs to be changed in measure.d anyway)

j_m_stdap : aperture magnitude -> Mgal (change to Map anyway)

j_msig_stdap : aperture magnitude error (keep ??)

dist_edge_ns, ew, flg : information about distance to scan edge (ns or ew)

dup_src : duplicate scan 
use_src : ??

(ignore the fields for cross-correlation with other surveys)

counting the flag bits (no attempt to account for any duplicate info; ignoring dist_edge info):

ph_qual	   : 3 bits
rd_flag	   : 3 bits
bl_flag	   : 2 bits 
cc_flag	   : 3 bits
gal_contam : 2 bits
mp_flag	   : 1 bit
dup_src	   : 1 bit
use_src	   : 1 bit

total      : 17 bit (1 too many...)

counting the flag bits (trying to minimize duplicate info; ignoring dist_edge info):

ph_qual	   : 3 bits 0x0001 - 0x0007
bl_flag	   : 1 bit  0x0008 (bl_flag = 0 or 1 -> 0; bl_flag > 1 -> 1)
rd_flag	   : 3 bits 0x0010 - 0x0070
gal_contam : 1 bit  0x0080 (gal_contam = 0 or 1 -> 0; gal_contam = 2 -> 1) (set extNsigma to a high value if gal_contam = 1) 
cc_flag	   : 3 bits 0x0100 - 0x0700
mp_flag	   : 1 bit  0x0800
dup_src	   : 1 bit  0x1000 (0 or 1 -> 0; > 1 -> 1)
use_src	   : 1 bit  0x2000 

total      : 14 bits
