IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 31, 2021, 11:45:18 AM (5 years ago)
Author:
eugene
Message:

major revision of the flagging and resets. cleanup of old cruft and deprecated flag values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/relphot.20210521/src/setMrelFinal.c

    r41624 r41625  
    1313  ResetAverageAndMeasure (catalog);
    1414 
    15   // this sets flags in the measureT element, not the measure element
     15  // This sets ID_MEAS flags in the measureT element, not the measure element
     16  // These bits are thus ephemeral and not saved. 
    1617  setExclusions (catalog, 1, VERBOSE);  /* mark by area */
    17   // XXXXX THis probably does not make sense
    1818
    1919  /* set catalog[0].found[i] = FALSE */
     
    3131  setMrelOutput (catalog, 1); // sets the values secfilt.MpsfChp = <measure.M - image.Mcal - measure.Mflat>
    3232  setMcalOutput (catalog, 1); // sets measure.Mcal = image.Mcal
    33 
    34   // clear ID_OBJ_POOR, ID_OBJ_FEW, ID_MEAS_NOCAL values before writing
    35   // These are internal bits, so they should be cleared
    36   // XXX are these still used?
    37   // XXX eventually: move these internal flags to an internal-only catalog->FOO element (like found)
    38   for (i = 0; i < catalog[0].Naverage; i++) {
    39     catalog[0].average[i].flags &= ~ID_OBJ_FEW;
    40     catalog[0].average[i].flags &= ~ID_OBJ_POOR;
    41     off_t j;
    42     for (j = 0; j < Nsecfilt; j++) {
    43         catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_FEW;
    44         catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_OBJ_POOR;
    45     }
    46     off_t m = catalog[0].average[i].measureOffset;
    47     for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
    48       catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
    49     }
    50   }
    5133}
    52 
    53 /* ID_MEAS_SKIP marks measurements which were not used to calculate Mrel */
    54 // For each star & photcode, we are selecting the measurements to use in the average
    55 // photometry value.  This function is called several times, lowering the bar to
    56 // acceptance on each pass. The rejections at the different passes are:
    57 
    58 // 0 : only use measurements thought to be GOOD (photflags not POOR or BAD)
    59 // 1 : accept measurements thought to be POOR based on photflags
    60 // 2 : accept the measurements marked as outliers; accept images marked as outliers
    61 // 3 : accept measurements thought to be BAD based on photflags
    62 // 4 : accept the measurements outside of the instrumental magnitude limits (eg, SAT)
    63 
    64 // XXX if I'm reading this correctly, passes 0, 1, 2 are identical & accept all
    65 // non-outliers with Imag range
    6634
    6735// int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) {
     
    8452// }
    8553
    86 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure);
    87 
    88 // XXX this function is no longer used:
    89 void skip_measurements (Catalog *catalog, int pass) {
    90 
    91   off_t i, k, m;
    92   off_t Ntot, Ntry, Nkeep, Nskip;
    93   float mag;
    94 
    95   int Nsecfilt = GetPhotcodeNsecfilt ();
    96 
    97   Ntot = Ntry = Nskip = Nkeep = 0;
    98 
    99   /* allow measures from images marked POOR and FEW */
    100   if (pass >= 3) IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
    101  
    102   /* allow measures marked as outliers (POOR) and off image region (AREA) */
    103   if (pass >= 3) {
    104     MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM;
    105   } else {
    106     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    107   }
    108 
    109   /* mark measures which should be ignored on this pass */
    110   for (i = 0; i < catalog[0].Naverage; i++) {
    111     Ntot += catalog[0].average[i].Nmeasure;
    112 
    113     if (FALSE && (catalog[0].average[i].objID == 0x46a4) && (catalog[0].average[i].catID == 0xf40e)) {
    114       fprintf (stderr, "test obj\n");
    115       print_measure_set (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], catalog[0].measure);
    116     }
    117 
    118     // mark measurements for each secfilt separately
    119     int Ns;
    120     for (Ns = 0; Ns < Nphotcodes; Ns++) {
    121      
    122       int thisCode = photcodes[Ns][0].code;
    123       int Nsec = GetPhotcodeNsec(thisCode);
    124      
    125       /* star/photcodes already calibrated */
    126       if (catalog[0].found_t[Nsecfilt*i+Nsec]) continue; 
    127 
    128       m = catalog[0].average[i].measureOffset;
    129       for (k = 0; k < catalog[0].average[i].Nmeasure; k++, m++) {
    130         Ntry++;
    131 
    132         // skip measurements not related to this photcode
    133         PhotCode *code = GetPhotcodebyCode (catalog[0].measure[m].photcode);
    134         if (!code) continue;
    135         if (code->equiv != thisCode) continue;
    136 
    137         // skip measurements by time range (mark as skipped for this secfilt)
    138         // XXX note that this is a bit dangerous : some objects may never get calibrated
    139         if (TimeSelect) {
    140           if (catalog[0].measure[m].t < TSTART) goto skip;
    141           if (catalog[0].measure[m].t > TSTOP) goto skip;
    142         }
    143        
    144         // we now have a measurement relavant to this photcode (and time range)
    145 
    146         // clear SKIP for all measures at first
    147         catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    148         catalog[0].measure [m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    149 
    150         // skip measurements from BAD images and mosaics (not REF mags)
    151         // do NOT skip measurements without a matching image (REF mags)
    152         off_t Nim = getImageEntry (m, 0);
    153         if (Nim > -1) {
    154           if (isnan(getMcal (m, 0, MAG_CLASS_PSF))) goto skip;
    155           if (isnan(getMmos (m, 0))) goto skip;
    156         }
    157 
    158         // PASS 4 : skip measurements by inst mag limit (not REF mags)
    159         if ((pass < 4) && ImagSelect) {
    160           if (Nim > -1) {
    161             mag = PhotInst (&catalog[0].measure[m], MAG_CLASS_PSF);
    162             if (mag < ImagMin) goto skip;
    163             if (mag > ImagMax) goto skip;
    164           }
    165         }
    166 
    167         // PASS 3 : accept bad measurements (eg, SAT, CR), internal outliers
    168         if (pass < 3) {
    169           if (catalog[0].measure[m].photFlags & code->photomBadMask) goto skip;
    170           if ((catalog[0].measure[m].photcode > 10000) && (catalog[0].measure[m].photcode < 10500)) {
    171             if (catalog[0].measure[m].psfQF < 0.85) goto skip;
    172           }
    173         }
    174        
    175         // PASS 2 : (no additional cut)
    176 
    177         // PASS 1 : accept poor measurements as well (eg, POOR FIT, etc)
    178         if ((pass < 1) && (catalog[0].measure[m].photFlags & code->photomPoorMask)) goto skip;
    179 
    180         // PASS 0 : skip poor, outlier, bad measurements as well (eg, POOR FIT, etc)
    181 
    182         Nkeep ++;
    183        
    184         continue;
    185 
    186       skip:
    187         catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
    188         catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
    189         Nskip ++;
    190       }
    191     }
    192   }
    193   if (VERBOSE) fprintf (stderr, "pass %d, Ntot: "OFF_T_FMT", Ntry: "OFF_T_FMT", Nskip: "OFF_T_FMT", Nkeep: "OFF_T_FMT"\n",
    194                         pass, Ntot, Ntry, Nskip, Nkeep);
    195 }
    196 
    197 // XXX review this, especially the good/bad images
    198 // by this point, we have propagated the mosaic and tgroup flags to each image
     54// This function is only called for the final output step.  By this point, we have
     55// propagated the mosaic and tgroup flags to each image.
    19956void setMeasureRank (Catalog *catalog) {
    20057
    20158  int i;
    20259
    203   // make these global
    204   int IMAGE_BAD  = ID_IMAGE_PHOTOM_NOCAL;
    205   int IMAGE_POOR = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    206   int MEAS_BAD   = ID_MEAS_NOCAL        | ID_MEAS_SKIP_PHOTOM;
    207   int MEAS_POOR  = ID_MEAS_POOR_PHOTOM  | ID_MEAS_AREA;
    208 
    20960  Measure     *measure     = catalog[0].measure;
    210   MeasureTiny *measureT    = catalog[0].measureT;
    21161  char        *measureRank = catalog[0].measureRank;
    21262
     
    21565    measureRank[i] = 11; // start at a low rank
    21666
    217     // clear SKIP for all measures at first
    218     measureT[i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    219     measure [i].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    220 
    221     // skip measurements without a valid photcode
     67    // measurements without a valid photcode have lowest rank (should not be used anyway)
    22268    PhotCode *code = GetPhotcodebyCode (measure[i].photcode);
    22369    if (!code) continue;
     
    22571    // measurements outside time range have poor rank
    22672    if (TimeSelect) {
    227       if (measure[i].t < TSTART)                     { measureRank[i] = 10; continue; }
    228       if (measure[i].t > TSTOP)                      { measureRank[i] = 10; continue; }
     73      if (measure[i].t < TSTART)                                        { measureRank[i] = 10; continue; }
     74      if (measure[i].t > TSTOP)                                         { measureRank[i] = 10; continue; }
    22975    }
    23076   
    231     // measurements from BAD images and mosaics (not REF mags)
    232     off_t Nim = getImageEntry (i, 0);
     77    // Nim < 0 for REF mags, imageFlags have bits for IMAGE, MOSAIC, NIGHT
     78    off_t Nim      = getImageEntry (i, 0);
    23379    int imageFlags = getImageFlags (i, 0);
    234     int mosaicFlags = getMosaicFlags (i, 0);
    23580
    23681    if (Nim > -1) {
    237       if (imageFlags  & IMAGE_BAD)                   { measureRank[i] = 9; continue; }
    238 
    239       if (mosaicFlags & IMAGE_BAD)                   { measureRank[i] = 9; continue; }
    240    
    24182      // measurements ranked by inst mag limit (not REF mags)
    24283      if (ImagSelect) {
    24384        float mag = PhotInst (&measure[i], MAG_CLASS_PSF);
    244         if (mag < ImagMin)                           { measureRank[i] = 8; continue; }
    245         if (mag > ImagMax)                           { measureRank[i] = 8; continue; }
     85        if (mag < ImagMin)                                              { measureRank[i] = 9; continue; }
     86        if (mag > ImagMax)                                              { measureRank[i] = 9; continue; }
    24687      }
    24788    }
    24889
    249     // RANK 1 : BAD photFlags
    250     if (measure[i].dbFlags & MEAS_BAD)               { measureRank[i] = 7; continue; }
    251 
    252     // RANK 3 : BAD photFlags (eg, SAT, CR), internal outliers
    253     if (measure[i].photFlags & code->photomBadMask)  { measureRank[i] = 6; continue; }
    254 
     90    // RANK 8 : Poor image
    25591    if (Nim > -1) {
    256       if (imageFlags  & IMAGE_POOR)                  { measureRank[i] = 5; continue; }
    257       if (mosaicFlags & IMAGE_POOR)                  { measureRank[i] = 5; continue; }
     92      if (imageFlags & ID_IMAGE_PHOTOM_POOR)                            { measureRank[i] = 8; continue; }
    25893    }
    25994
    260     // RANK 2 : psfQF value
    261     if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 4; continue; }
     95    // RANK 7 : BAD photFlags (eg, SAT, CR), internal outliers
     96    if (measure[i].photFlags & code->photomBadMask)                     { measureRank[i] = 7; continue; }
     97
     98    // RANK 6 : bad psfQF value
     99    if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85)         { measureRank[i] = 6; continue; }
    262100       
    263     // RANK 1 : POOR photFlags
    264     if (measure[i].dbFlags & MEAS_POOR)              { measureRank[i] = 3; continue; }
     101    // RANK 5 : not in valid chip region
     102    if (measure[i].dbFlags & ID_MEAS_AREA)                              { measureRank[i] = 5; continue; }
    265103
    266     // RANK 1 : POOR photFlags
    267     if (measure[i].photFlags & code->photomPoorMask) { measureRank[i] = 2; continue; }
     104    // RANK 4 : POOR photFlags
     105    if (measure[i].photFlags & code->photomPoorMask)                    { measureRank[i] = 4; continue; }
    268106   
    269     // RANK 1 : psfQFperfect value
    270     if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 1; continue; }
     107    // RANK 3 : bad psfQFperfect value
     108    if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 3; continue; }
    271109       
     110    // RANK 2 : Poor mosaic
     111    if (Nim > -1) {
     112      if (imageFlags & ID_IMAGE_MOSAIC_POOR)                            { measureRank[i] = 2; continue; }
     113    }
     114
     115    // RANK 1 : Poor night
     116    if (Nim > -1) {
     117      if (imageFlags & ID_IMAGE_NIGHT_POOR)                             { measureRank[i] = 1; continue; }
     118    }
    272119    // RANK 0 : perfect measurement:
    273120    measureRank[i] = 0;
Note: See TracChangeset for help on using the changeset viewer.