IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40249


Ignore:
Timestamp:
Dec 7, 2017, 5:54:38 AM (9 years ago)
Author:
eugene
Message:

rework of the assessment of stack detection quality

Location:
branches/eam_branches/ohana.20170822/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20170822/src/libdvo/include/dvo.h

    r40247 r40249  
    248248
    249249  ID_SECF_CHIP_FLAGS             = 0x01003f1f, // all chip-related bits (used to reset the correct bits only)
    250   ID_SECF_STACK_FLAGS            = 0x00004020, // all stack-related bits (
     250  ID_SECF_STACK_FLAGS            = 0x0003c020, // all stack-related bits (
    251251} DVOSecfiltFlags;
    252252
  • branches/eam_branches/ohana.20170822/src/relphot/src/setMrelCatalog.c

    r40248 r40249  
    565565    int haveStack = FALSE;
    566566
    567     off_t stackPrimaryMeasure = -1;
    568 
    569567    int isBad = FALSE;
    570568    int isSuspect = FALSE;
     
    572570    int NstackMeas = 0; // number of stack measurements for this photcode
    573571    int NstackDet  = 0; // number of stack detections for this photcode (not forced)
     572
     573    int   primaryLevelMax = 0;
     574    off_t primaryEntryMax = -1;
     575    float primaryValueMax = 0.0;
    574576
    575577    int   bestLevelMax = 0;
     
    579581    int Nprimary = 0;
    580582
     583    // reset all stack-related values for this secfilt:
    581584    secfilt[Nsec].stackBestOff = -1;
    582585    secfilt[Nsec].stackPrmryOff = -1;
    583 
    584     off_t meas = measureOffset;
    585     for (off_t k = 0; k < Nmeasure; k++, meas++) {
     586    secfilt[Nsec].FpsfStk   = NAN;
     587    secfilt[Nsec].dFpsfStk  = NAN;
     588    secfilt[Nsec].FkronStk  = NAN;
     589    secfilt[Nsec].dFkronStk = NAN;
     590    secfilt[Nsec].FapStk    = NAN;
     591    secfilt[Nsec].dFapStk   = NAN;
     592    secfilt[Nsec].MpsfStk   = NAN;
     593    secfilt[Nsec].MkronStk  = NAN;
     594    secfilt[Nsec].MapStk    = NAN;
     595    secfilt[Nsec].Nstack    = 0;
     596    secfilt[Nsec].NstackDet = 0;
     597    secfilt[Nsec].flags    &= ~ID_SECF_STACK_FLAGS; // reset the stack flags
     598
     599    for (off_t k = 0; k < Nmeasure; k++) {
    586600
    587601      // only examine gpc1 stack data
     
    594608
    595609      NstackMeas ++;
    596       if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++;
     610      if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++; // 0x04 = PM_SOURCE_MODE2_MATCHED
    597611
    598612      // clear this bit for all measurements
     
    603617      haveStackObject = TRUE;
    604618
    605       XXX ??? if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
     619      // if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
    606620
    607621      int isPrimary = FALSE;
     
    610624
    611625      // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement
    612       // is from the primary skycell for this position
    613       if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
     626      // is from the primary skycell for this position. (note that MatchImageSkycellID
     627      // requires the entry in the full Measure table, not just this object)
     628      if (MatchImageSkycellID (measureOffset + k, cat, tessID, projectID, skycellID)) {
    614629        measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
    615630        isPrimary = TRUE;
     
    617632      }
    618633
    619       int psfQFperfAboveLimit = isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95);
     634      // soften the error floor (can dM be 0.0?)
     635      int SNvalue = isfinite(measure[k].dM) ? 1.0 / hypot (measure[k].dM, MIN_ERROR) : NAN;
     636      int psfQFperfAboveLimit = isfinite(SNvalue) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95);
    620637
    621638      // ** determine the BEST level
     
    627644
    628645      // here is the rule for choosing the best value:
    629       // XXX what if dM = 0.0 or NAN? (treat as bestLevel 1 or 2?)
    630       bestValue = (bestLevel > 2) ? 1.0 / measure[k].dM : measure[k].psfQFperf;
     646      float bestValue = (bestLevel > 2) ? SNvalue : measure[k].psfQFperf;
    631647
    632648      // if we have not reached this level before, set the new level
     
    649665
    650666      // here is the rule for choosing the PRIMARY value:
    651       // XXX what if dM = 0.0 or NAN? (treat as bestLevel 1 or 2?)
    652       primaryValue = 0.0;
     667      float primaryValue = 0.0;
    653668      if (primaryLevel == 1) { primaryValue = measure[k].psfQFperf; }
    654       if (primaryLevel == 2) { primaryValue = 1.0 / measure[k].dM; }
     669      if (primaryLevel == 2) { primaryValue = SNvalue; }
    655670
    656671      // if we have not reached this level before, set the new level
     
    672687    // now we have a BEST and a PRIMARY entry (may be the same entry)
    673688
    674     secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset;
    675     myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range");
    676 
    677     meas = bestEntryMax;
     689    off_t meas = bestEntryMax;
    678690    myAssert (meas >= 0, "this should not happen");
    679691
     
    687699      // data for which the associated image has not been loaded (probably because of
    688700      // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
    689       Mmos = Mgrid = 0;
    690       McalPSF = measure[meas].McalPSF; // check that this is zero for loaded REF value
     701      McalPSF  = measure[meas].McalPSF; // check that this is zero for loaded REF value
    691702      McalAPER = McalPSF; // check that this is zero for loaded REF value
     703      Mmos     = 0.0;
     704      Mgrid    = 0.0;
    692705    } else {
    693       McalPSF  = getMcal  (meas, cat, MAG_CLASS_PSF);
    694       if (isnan(McalPSF))  SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip?
    695      
     706      McalPSF   = getMcal  (meas, cat, MAG_CLASS_PSF);
    696707      McalAPER  = getMcal  (meas, cat, MAG_CLASS_KRON);
    697       if (isnan(McalAPER))  SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip?
    698      
    699       Mmos  = getMmos  (meas, cat);
    700       if (isnan(Mmos))  SKIP_THIS_MEAS_STACK(Nmos);
    701       Mgrid = getMgrid (meas, cat);
    702       if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
     708      Mmos      = getMmos  (meas, cat);
     709      Mgrid     = getMgrid (meas, cat);
    703710    }
    704711   
    705     // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
    706     float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF);
    707     if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
    708    
    709     // data quality assessment
    710     isBad |= (measure[meas].photFlags & code->photomBadMask);
    711     isBad |= (measure[meas].psfQF < 0.85);
    712     isBad |= isnan(measure[meas].psfQF);
    713     isBad |= measure[meas].dM > 0.2; // S/N < 5.0
    714 
    715     isSuspect |= (measure[meas].photFlags & code->photomPoorMask);
    716     isSuspect |= (measure[meas].psfQFperf < 0.85);
    717 
    718     if (!isSuspect && !isBad) {
    719       NstackGood ++;
    720     }
    721     if (isSuspect && !isBad) {
    722       NstackSuspect ++;
    723     }
    724      
    725     // we are now populating stackDetectID not stack Image ID in secfilt
    726     // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin      : stackCenterIDmin;
    727     // ID = measure[meas].extID; // for the stack, this is the stackDetectID
    728 
    729712    // ** Here is the math to relate mag,zp to flux
    730713
     
    780763
    781764    // Jy to AB mags
    782     secfilt[Nsec].MpsfStk   = (measure[meas].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN;
     765    secfilt[Nsec].MpsfStk   = (measure[meas].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk)  : NAN;
    783766    secfilt[Nsec].MkronStk  = (measure[meas].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
    784     secfilt[Nsec].MapStk    = (measure[meas].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN;
     767    secfilt[Nsec].MapStk    = (measure[meas].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk)   : NAN;
    785768
    786769    // record the measurement which gave the best value
    787     secfilt[Nsec].stackBestOff = (bestEntryMax > -1) ? bestEntryMax + measureOffset;
     770    secfilt[Nsec].stackBestOff = (bestEntryMax > -1) ? -1 : bestEntryMax + measureOffset;
    788771    myAssert (secfilt[Nsec].stackBestOff <= catalog[0].Nmeasure, "stackBestOff out of range");
    789772
    790     secfilt[Nsec].Nstack    = NstackMeas;
    791     secfilt[Nsec].NstackDet = NstackDet;
    792 
    793     // this is the measurement used by secfilt[]
     773    // record the selected primary measurement
     774    secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset;
     775    myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range");
     776
     777    // this is the selected measurement used by secfilt[]
    794778    measure[meas].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
    795779    if (Nprimary) {
     
    801785
    802786    // stack measurement used for 'best' was a detection (not forced from the other bands)
    803     if ((measure[meas].photFlags2 & 0x00000004) == 0) {
     787    if ((measure[bestEntryMax].photFlags2 & 0x00000004) == 0) {
    804788      secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET;
    805789    }
     790
    806791    // stack measurement used for 'primary' was a detection (not forced from the other bands)
    807792    if ((primaryEntryMax >= 0) && ((measure[primaryEntryMax].photFlags2 & 0x00000004) == 0)) {
     
    810795
    811796    secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK;
     797
     798    // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
     799    // float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF);
     800   
     801    // data quality assessment
     802    isBad |= (measure[meas].photFlags & photcodes[Ns][0].photomBadMask);
     803    isBad |= (measure[meas].psfQF < 0.85);
     804    isBad |= isnan(measure[meas].psfQF);
     805    isBad |= measure[meas].dM > 0.2; // S/N < 5.0
     806
     807    isSuspect |= (measure[meas].photFlags & photcodes[Ns][0].photomPoorMask);
     808    isSuspect |= (measure[meas].psfQFperf < 0.85);
     809
     810    if (!isSuspect && !isBad) {
     811      NstackGood ++;
     812    }
     813    if (isSuspect && !isBad) {
     814      NstackSuspect ++;
     815    }
     816
     817    secfilt[Nsec].Nstack    = NstackMeas;
     818    secfilt[Nsec].NstackDet = NstackDet;
     819
    812820  } // Nsecfilt loop
    813821
     
    820828
    821829  int PrimaryIsBest = TRUE;
    822   for (Ns = 0; Ns < Nphotcodes; Ns++) {
     830  for (int Ns = 0; Ns < Nphotcodes; Ns++) {
    823831    if (!(secfilt[Ns].flags & ID_SECF_HAS_PS1_STACK)) continue; // no stack detection in PS1, nothing is best
    824832    if (secfilt[Ns].flags & ID_SECF_STACK_PRIMARY) continue;    // primary stack detection is best
Note: See TracChangeset for help on using the changeset viewer.