Point Source Photometric Quality Flagging


I have attached the postgres script that generates the latest photometric
quality column.  What is new is that the former E's are subdivided into
more categories.  With the new definition the distributions in JHK of
the test fields are as follows:

J-band:
 A      | 2197578
 B      |  719340
 C      |  252542
 D      |   27669
 E      |    7886
 U      |  506362
 Z      |  846373

H-band:
 A      | 2286671
 B      |  661211
 C      |  309840
 D      |   72439
 E      |   19554
 U      |  361661
 X      |       1
 Z      |  846373

K-band:
 A      | 1984233
 B      |  492936
 C      |  330649
 D      |  137689
 E      |   13338
 U      |  752525
 X      |       7
 Z      |  846373

The "Catalog" is still defined as any row in which there is an A in any
band of the photometric quality column.

A:	Bright sources (rd_flg 1's and 3's)
        psf_fit sources with snr >= 10 and msig <=0.10857
	psf_fit sources must have psf_chi < 10
        brighter psf_fit sources must pass ndet cuts
        no ghost rejects (use_src=0 dup_src=0)
B:	psf_fit sources with snr>= 7 and msig <= .1551 not classified as A
	Also sources that would have been A's but where downgraded
	to B because use_src=0 and dup_src=0
        psf_fit sources must have psf_chi < 10 and
        brighter psf_fit sources must pass ndet cuts.
C:	psf_fit sources with snr >= 5 and msig <= 0.2171 not classified AB
        psf_fit sources must have psf_chi < 10 and
        brighter psf_fit sources must pass ndet cuts.
D:	psf_fit sources not classified A,B,or C
        psf_fit sources must have psf_chi < 10 and
        brighter psf_fit sources must pass ndet cuts.
E:	sources with rd_flg = 4 (psf_fitting did not converge)
	psf_fit sources with psfchi >= 10
        brighter psf_fit sources not passing ndet cuts
U:	Upper limit reported as magnitude. (rd_flg 0 or 6)
X:	No valid detection.  Default magnitude is null.
Z:	Artifacts and dups--three bands are always ZZZ.  Not to be
	released to the public.

If there is any disagreement between the above paraphrase and the query,
the query should be taken as correct.

Rae

=============================


There are two issues related to the photometric quality column that should
be discussed.


1. Does ph_qual get calculated with the revised _msigs?

2. I think that use of the dup_src=0,use_src=0 condition to downgrade
   the photometric quality of detections is inconsistent with the notion
   of a photometric quality column.  The status of duplicate resolution
   should be in a separate column.  This way the photometric quality
   calculation can be extended to everything in the working survey
   database.   I asked Roc why we were not releasing the dups with
   everything else and his answer was to the effect that something had
   to be saved for the extended mission.  I can't think of any reason
   why we shouldn't release the dups.


==============================================

psql -e -c "DROP TABLE cntr_ph_qual" wsdb
psql -e -c "CREATE TABLE cntr_ph_qual AS
        SELECT cntr,
	CASE
	  WHEN
	   cc_flg ~'[A-Z]'
          OR
           (use_src=0 AND dup_src !=0)  
	  THEN 'Z'
          WHEN substr(rd_flg,1,1)='9'
          THEN 'X'
	  WHEN
	   substr(rd_flg,1,1) ~'[06]'
          THEN 'U'
          WHEN 
	   substr(rd_flg,1,1)='4'
          OR
           substr(rd_flg,1,1)='2' and j_psfchi >= 10.0
          OR
           (substr(rd_flg,1,1) ~'[12]'
            AND
            j_m <= 14.5
            AND
             ((substr(ndet,2,1) between '3' and '4' and substr(ndet,1,1) < '2')
              OR
              (substr(ndet,2,1) > '4' and substr(ndet,1,1) < '3')
             )
            AND NOT (rd_flg='222' and substr(ndet,1,2)='22')
	   )
          THEN 'E'
          WHEN
           ((substr(rd_flg,1,1)='2' AND j_snr >=10.0 AND j_msig <= 0.10857)
            OR
            substr(rd_flg,1,1) ~'[13]'
           )
           AND NOT (use_src=0 and dup_src=0)
          THEN 'A'
          WHEN
           (substr(rd_flg,1,1)='2' AND j_snr >= 7.0 AND j_msig <= 0.1551)
           OR
           (substr(rd_flg,1,1) ~'[13]' AND use_src=0 AND dup_src=0)
          THEN 'B'
          WHEN
           substr(rd_flg,1,1)='2' AND j_snr >= 5.0 AND j_msig <= 0.2171
          THEN 'C'
          WHEN
           substr(rd_flg,1,1)='2'
          THEN 'D'
          ELSE '*'
        END ||
        CASE
	  WHEN
	   cc_flg ~'[A-Z]'
          OR
           (use_src=0 AND dup_src !=0)  
	  THEN 'Z'
          WHEN substr(rd_flg,2,1)='9'
          THEN 'X'
	  WHEN
	   substr(rd_flg,2,1) ~'[06]'
          THEN 'U'
	  WHEN
           substr(rd_flg,2,1)='4'
          OR
           substr(rd_flg,2,1)='2' and h_psfchi >= 10.0 
          OR
           (substr(rd_flg,2,1) ~'[12]'
            AND
            h_m <= 14.0
            AND
             ((substr(ndet,4,1) between '3' and '4' and substr(ndet,3,1) < '2')
              OR
              (substr(ndet,4,1) > '4' and substr(ndet,3,1) < '3')
             )
            AND NOT (rd_flg='222' and substr(ndet,3,2)='22')
	   )
          THEN 'E'
          WHEN
           ((substr(rd_flg,2,1)='2' AND h_snr >=10.0 AND h_msig <= 0.10857)
            OR
            substr(rd_flg,2,1) ~'[13]'
           ) 
           AND NOT (use_src=0 and dup_src=0)
          THEN 'A'
          WHEN
           (substr(rd_flg,2,1)='2' AND h_snr >= 7.0 AND h_msig <= 0.1551)
           OR
           (substr(rd_flg,2,1) ~'[13]' AND use_src=0 AND dup_src=0)
          THEN 'B'
          WHEN
           substr(rd_flg,2,1)='2' AND h_snr >= 5.0 AND h_msig <= 0.2171
          THEN 'C'
          WHEN
           substr(rd_flg,2,1)='2'
          THEN 'D'
          ELSE '*'
        END ||
        CASE
	  WHEN
	   cc_flg ~'[A-Z]'
          OR
           (use_src=0 AND dup_src !=0)  
	  THEN 'Z'
          WHEN substr(rd_flg,3,1)='9'
          THEN 'X'
	  WHEN
	   substr(rd_flg,3,1) ~'[06]'
          THEN 'U'
          WHEN
           substr(rd_flg,3,1)='4'
          OR
           substr(rd_flg,3,1)='2' and k_psfchi >= 10.0 
          OR
           (substr(rd_flg,3,1) ~'[12]'
            AND
            k_m <= 13.5
            AND
             ((substr(ndet,6,1) between '3' and '4' and substr(ndet,5,1) < '2')
              OR
              (substr(ndet,6,1) > '4' and substr(ndet,5,1) < '3')
             )
            AND NOT (rd_flg='222' and substr(ndet,5,2)='22')
	   )
          THEN 'E'
          WHEN
           ((substr(rd_flg,3,1)='2' AND k_snr >=10.0 AND k_msig <= 0.10857)
            OR
            substr(rd_flg,3,1) ~'[13]'
           )
           AND NOT (use_src=0 and dup_src=0)
          THEN 'A'
          WHEN
           (substr(rd_flg,3,1)='2' AND k_snr >= 7.0 AND k_msig <= 0.1551)
           OR
           (substr(rd_flg,3,1) ~'[13]' and use_src=0 and dup_src=0)
          THEN 'B'
          WHEN
           substr(rd_flg,3,1)='2' AND k_snr >= 5.0 AND k_msig <= 0.2171
          THEN 'C'
          WHEN
           substr(rd_flg,3,1)='2'
          THEN 'D'
          ELSE '*'
        END as ph_qual
	FROM input_table
        ORDER BY cntr
	" wsdb