IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38298


Ignore:
Timestamp:
May 21, 2015, 7:43:37 PM (11 years ago)
Author:
eugene
Message:

working on setMrelCatalog reorg

Location:
branches/eam_branches/ipp-20150419/Ohana/src/relphot
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h

    r38297 r38298  
    496496int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
    497497int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
    498 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
     498int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr);
    499499int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
    500500
     
    565565int magStatsByRanking (StatDataSet *dataset, StatType *stats);
    566566
    567 SynthZeroPoints *SynthZeroPointsLoad (char *filename);
     567int SynthZeroPointsLoad (char *filename);
     568SynthZeroPoints *SynthZeroPointsGet ();
    568569
    569570int relphot_synthphot (int hostID, char *hostpath);
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c

    r38297 r38298  
    253253
    254254  for (i = 0; i < Ncatalog; i++) {
    255     // pass == -1 for anything other than the final pass
    256     switch (SET_MREL_VERSION) {
    257       case 0:
    258         setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
    259         break;
    260       case 1:
    261         setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
    262         break;
    263       default:
    264         fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
    265         exit (2);
    266     }
     255    setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
    267256    SetMrelInfoAccum (&summary, &results);
    268257  }
     
    274263}
    275264
     265// setMrelOutput is NOT threaded because we read/write catalogs one at a time (for now)
    276266int setMrelOutput (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr) {
    277267
    278268  int i;
    279269
    280   // fprintf (stderr, "this version of setMrel is invalid for now\n");
    281   // exit (1);
    282        
    283270  int Nsecfilt = GetPhotcodeNsecfilt ();
    284271
     
    288275
    289276  for (i = 0; i < Ncatalog; i++) {
    290     switch (SET_MREL_VERSION) {
    291       // case 0:
    292       // setMrel_catalog (catalog, i, pass, flatcorr, &results, Nsecfilt);
    293       // break;
    294       case 1:
    295         setMrel_catalog_alt (catalog, i, TRUE, flatcorr, &results, Nsecfilt);
    296         break;
    297       default:
    298         fprintf (stderr, "invalid setMrel version %d (use 1)\n", SET_MREL_VERSION);
    299         exit (2);
    300     }
     277    setMrel_catalog_alt (catalog, i, TRUE, flatcorr, &results, Nsecfilt);
    301278    SetMrelInfoAccum (&summary, &results);
    302279  }
     
    384361
    385362  while (1) {
    386 
    387363    off_t i = getNextCatalogForThread(threadinfo->Ncatalog);
    388364    if (i == -1) {
     
    394370    FlatCorrectionTable *flatcorr = threadinfo->flatcorr;
    395371
    396     // pass == -1 for anything other than the final pass
    397     switch (SET_MREL_VERSION) {
    398       case 0:
    399         setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
    400         break;
    401       case 1:
    402         setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
    403         break;
    404       default:
    405         fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
    406         exit (2);
    407     }
     372    setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
    408373    SetMrelInfoAccum (&threadinfo->summary, &results);
    409374  }
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c

    r38062 r38298  
    331331  }
    332332
     333  // if -synthphot_zpts is supplied, the map of corrections needed for the synthetic photometry is supplied
     334  // and used to tie down the synthetic magnitudes
     335  SYNTH_ZERO_POINTS = NULL;
     336  if ((N = get_argument (argc, argv, "-synthphot_zpts"))) {
     337    remove_argument (N, &argc, argv);
     338    myAssert (N < argc, "missing argument to -synthphot_means");
     339    SYNTH_ZERO_POINTS = strcreate (argv[N]);
     340    remove_argument (N, &argc, argv);
     341  }
     342
     343  // if -synthphot is chosen, an artificial w-band measurement is generated for each object
     344  // with r and i photometry.  this was used to apply the ubercal photometry to w-band images.
    333345  SyntheticPhotometry = FALSE;
    334346  if ((N = get_argument (argc, argv, "-synthphot"))) {
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c

    r37907 r38298  
    3232    return;
    3333  }
     34
     35  // load the ZP corrections here
     36  if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
    3437
    3538  if (VERBOSE) fprintf (stderr, "re-loading catalog data\n");
     
    230233    if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT);                       strcpy (command, tmpline); }
    231234    if (BOUNDARY_TREE)    { snprintf (tmpline, 1024, "%s -boundary-tree %s",    command, BOUNDARY_TREE);                          strcpy (command, tmpline); }
     235    if (SYNTH_ZERO_POINTS) { snprintf (tmpline, 1024, "%s -synthphot-zpts %s", command, SYNTH_ZERO_POINTS); strcpy (command, tmpline); }
    232236    if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION);                  strcpy (command, tmpline); }
    233237    if (AreaSelect)       { snprintf (tmpline, 1024, "%s -area %f %f %f %f",    command, AreaXmin, AreaXmax, AreaYmin, AreaYmax); strcpy (command, tmpline); }
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_objects.c

    r37807 r38298  
    2929    return TRUE;
    3030  }
     31
     32  // load the ZP corrections here
     33  if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
    3134
    3235  // load data from each region file, only use bright stars
     
    165168    if (!KEEP_UBERCAL) { snprintf (tmpline, 1024, "%s -reset-ubercal",  command);                    strcpy (command, tmpline); }
    166169    if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION); strcpy (command, tmpline); }
     170    if (SYNTH_ZERO_POINTS) { snprintf (tmpline, 1024, "%s -synthphot-zpts %s", command, SYNTH_ZERO_POINTS); strcpy (command, tmpline); }
    167171
    168172    fprintf (stderr, "command: %s\n", command);
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_synthphot.c

    r38062 r38298  
    2828
    2929  // load the ZP corrections here
    30   SynthZeroPoints *zpts = SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
     30  SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
     31  SynthZeroPoints *zpts = SynthZeroPointsGet ();
    3132  if (!zpts) exit (2);
    3233
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c

    r38297 r38298  
    44
    55# define SKIP_THIS_MEAS(REASON) {                       \
    6     measureT[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;         \
    7     if (measure) {                                      \
    8       measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;        \
    9     }                                                   \
    106    results->REASON ++;                                 \
    117    continue; }
    128
    139# define SKIP_THIS_MEAS_STACK(REASON) {                 \
    14     measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;          \
    1510    continue; }
    1611
     
    5752    // only apply Stack operation on setMrelFinal in first pass
    5853    if (isSetMrelFinal && !IS_DIFF_DB) {
    59       setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt, flatcorr, results);
     54      setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt, flatcorr);
    6055    }
    6156
     
    8681// 4) some reference photcode of some kind can be specified as fixed and have a high weight
    8782
    88 static SynthZeroPoints *synthzpts = NULL;
    89 
    9083// set mean of chip measurements (selected by photcode range for now):
    9184int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
     
    9588
    9689  // we are guaranteed to have averageT, but not average
    97   AverageTiny *averageT = &catalog[cat].averageT[ave];
     90  AverageTiny *averageT = &catalog[0].averageT[ave];
    9891
    9992  off_t measureOffset = averageT->measureOffset;
    100   MeasureTiny *measureT = &catalog[cat].measureT[measureOffset];
     93  MeasureTiny *measureT = &catalog[0].measureT[measureOffset];
    10194
    10295  // we are NOT guaranteed to have average, measure, secfilt
    103   Average *average  = catalog[cat].average     ? &catalog[cat].average[ave]               : NULL;
    104   Measure *measure  = catalog[cat].measure     ? &catalog[cat].measure[measureOffset]     : NULL;
    105   SecFilt *secfilt  = catalog[cat].secfilt     ? &catalog[cat].secfilt[ave*Nsecfilt]      : NULL;
    106   char *measureRank = catalog[cat].measureRank ? &catalog[cat].measureRank[measureOffset] : NULL;
     96  Average *average  = catalog[0].average     ? &catalog[0].average[ave]               : NULL;
     97  Measure *measure  = catalog[0].measure     ? &catalog[0].measure[measureOffset]     : NULL;
     98  SecFilt *secfilt  = catalog[0].secfilt     ? &catalog[0].secfilt[ave*Nsecfilt]      : NULL;
     99  char *measureRank = catalog[0].measureRank ? &catalog[0].measureRank[measureOffset] : NULL;
    107100
    108101  // we are measuring means for 3 types of mags: psf, ap, kron.
     
    159152
    160153    // force the use of SYN even if we have PS1 mags?
    161     if (isGPC1synth(measureT[k].photcode)) {
     154    if (isSetMrelFinal && isGPC1synth(measureT[k].photcode)) {
    162155      results->haveSYN[Nsec] = TRUE;
    163156      results->measSYN[Nsec] = k;
     
    185178      Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
    186179    } else {
     180      // getMcal_alt returns image[].Mcal modified by flatcorr(image.photom_map_id,x,y)
    187181      Mcal  = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd);
    188182      if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
     
    240234      results->psfData[Nsec].errlist[Npsf] = dMpsf;
    241235      results->psfData[Nsec].wgtlist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    242       results->psfData[Nsec].ranking[Npsf] = measureRank[k];
     236      results->psfData[Nsec].ranking[Npsf] = measureRank ? measureRank[k] : 0;
    243237      results->psfData[Nsec].measSeq[Npsf] = k;
    244238      results->psfData[Nsec].Nlist ++;
    245     } else {
    246       measureT[k].dbFlags |= ID_MEAS_SKIP_PHOTOM; // XXX is this used outside of relphot?
    247       if (measure) measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;
    248       results->Nsys ++;
    249239    }
    250240
     
    264254    }
    265255  }
     256
     257  SynthZeroPoints *synthzpts = SynthZeroPointsGet();
    266258
    267259  // now calculate the mean stats for the Nsec bands.
     
    325317    int minRank = (Nranking > 0) ? results->psfData[Nsec].ranking[0] : 10;
    326318
    327     // when running -averages, we have no information about the images, so we cannot set this
    328     if (results->minUbercalDist[Nsec] > -1) {
    329       secfilt[Nsec].ubercalDist = results->minUbercalDist[Nsec];
    330     }
    331 
    332319    if (isSetMrelFinal) {
     320      // when running -averages, we have no information about the images, so we cannot set this
     321      if (results->minUbercalDist[Nsec] > -1) {
     322        secfilt[Nsec].ubercalDist = results->minUbercalDist[Nsec];
     323      }
     324
    333325      if (Nranking) {
    334326        secfilt[Nsec].Mstdev = psfstats->sigma;
     
    412404}
    413405
    414 # if (0)
    415 // set mean of chip measurements (selected by photcode range for now):
    416 int setMrelAverageExposure_old (off_t measureOffset, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found) {
    417 
    418   off_t k;
    419   float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
    420 
    421   // we are measuring means for 3 types of mags: psf, ap, kron.  I am using the psf mag
    422   // error for the ap mags, but krons have their own errors.  it is an open question if I
    423   // should be doing weighted or unweighted fits (this is a user option)
    424   double *Mpsflist  = results->Mpsflist;
    425   double *dpsflist  = results->dpsflist;
    426   double *wpsflist  = results->wpsflist;
    427 
    428   double *Maplist   = results->Maplist;
    429   double *daplist   = results->daplist;
    430   double *waplist   = results->waplist;
    431 
    432   double *Mkronlist = results->Mkronlist;
    433   double *dkronlist = results->dkronlist;
    434   double *wkronlist = results->wkronlist;
    435 
    436   StatType *psfstats  = &results->psfstats;
    437   StatType *apstats   = &results->apstats;
    438   StatType *kronstats = &results->kronstats;
    439 
    440   int isSetMrelFinal = (pass >= 0);
    441 
    442   // option for a test print
    443   if (FALSE && (average[0].objID == 0x7146) && (average[0].catID == 0x49d8)) {
    444     fprintf (stderr, "test obj\n");
    445     print_measure_set_alt (average, secfilt, measure);
    446   }
    447 
    448   int GoodPS1 = FALSE;
    449   int Good2MASS = FALSE;
    450   int Galaxy2MASS = FALSE;
    451 
    452   int NextPS1 = 0;
    453   int NpsfPS1 = 0;
    454 
    455   int Ns;
    456   for (Ns = 0; Ns < Nphotcodes; Ns++) {
    457 
    458     int thisCode = photcodes[Ns][0].code;
    459     int Nsec = GetPhotcodeNsec(thisCode);
    460 
    461     /* calculate the average mag in this SEC photcode for a single star */
    462 
    463     /* star/photcodes already calibrated */
    464     if ( isSetMrelFinal && found[Nsec]) continue; 
    465      
    466     // skip bad stars
    467     if (!isSetMrelFinal && (secfilt[Nsec].flags & STAR_BAD)) continue;
    468 
    469     int NexpPS1 = 0;
    470     int Ncode = 0;
    471     int Next = 0;
    472     int haveSynth = FALSE;
    473     int havePS1   = FALSE;
    474 
    475     int forceSynth = FALSE;
    476     int forceSynthEntry = -1;
    477 
    478     int haveUbercal = FALSE;
    479 
    480     int minUbercalDist = 1000;
    481    
    482     off_t meas = measureOffset;
    483 
    484     float psfQfMax = 0.0;
    485     float psfQfPerfMax = 0.0;
    486 
    487     int Nap = 0;
    488     int Npsf = 0;
    489     int Nkron = 0;
    490     for (k = 0; k < averageT[0].Nmeasure; k++, meas++) {
    491 
    492       // skip measurements that do not match the current photcode
    493       PhotCode *code = GetPhotcodebyCode (measureT[k].photcode);
    494       if (!code) continue;
    495       if (code->equiv != thisCode) { continue; }
    496       Ncode ++;
    497 
    498       // are we a PS1 exposure photcode?
    499       if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++;
    500 
    501       // SKIP gpc1 stack data
    502       if (isGPC1stack(measureT[k].photcode)) continue;
    503 
    504       // SKIP gpc1 forced-warp data
    505       if (isGPC1warp(measureT[k].photcode)) continue;
    506 
    507       if (isSetMrelFinal) {
    508         if (measure[k].psfQF     > psfQfMax)     psfQfMax     = measure[k].psfQF;
    509         if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf;
    510       }
    511 
    512       if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
    513 
    514       if (getImageEntry (meas, cat) < 0) {
    515         // measurements without an image are either external reference photometry or
    516         // data for which the associated image has not been loaded (probably because of
    517         // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
    518         Mmos = Mgrid = 0;
    519         Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
    520       } else {
    521         Mcal  = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd);
    522         if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
    523         Mmos  = getMmos  (meas, cat);
    524         if (isnan(Mmos))  SKIP_THIS_MEAS(Nmos);
    525         Mgrid = getMgrid (meas, cat);
    526         if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid);
    527       }
    528 
    529       // skip some absurd values NAN, < 0.0, > 30.0
    530       Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
    531       if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
    532       if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
    533       if (Msys > 30.0) SKIP_THIS_MEAS(Nsys);
    534 
    535       int myUbercalDist = getUbercalDist(meas, cat);
    536       minUbercalDist = MIN(minUbercalDist, myUbercalDist);
    537 
    538       int isUbercal = (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL);
    539       float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
    540 
    541       if (isUbercal) haveUbercal = TRUE; // haveUbercal is set per secfilt, isUbercal is per measure
    542 
    543       if (isSetMrelFinal) {
    544         // special options for PS1 data
    545         if ((measure[k].photcode >= 10000) && (measure[k].photcode <= 10500)) {
    546           // count the extended detections
    547           if (!isnan(measure[k].Map)) {
    548             float dMagAp = measure[k].M - measure[k].Map;
    549             float SigmaAp = hypot(0.1, 2.5*measure[k].dM);
    550             // XXX this is still quite ad hoc, but at least it:
    551             // (a) converges to 0.1 mag offset at the bright end
    552             // (b) converges to 0.5 mag offset at the faint end (dM = 0.2)
    553             if (dMagAp > SigmaAp) {
    554               Next ++;
    555               NextPS1 ++;
    556             } else {
    557               NpsfPS1 ++;
    558             }
    559           }
    560           havePS1 = TRUE;
    561         }
    562 
    563         // count extended detections for 2MASS (XXX NOTE hardwired photcodes 2011, 2012, 2013)
    564         if ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013)) {
    565           if (measure[k].photFlags & 0x00c00000) {
    566             Next ++;
    567             Galaxy2MASS = TRUE;
    568           }
    569           if (pass == 0) {
    570             if (measure[k].photFlags & 0x00000007) {
    571               Good2MASS = TRUE;
    572             } else {
    573               // detections without one of these bits should only be used in PASS_1
    574               SKIP_THIS_MEAS(Nbad);
    575             }
    576           }
    577         }
    578 
    579         // Blindly accepth the SYNTH mags if we are above saturation, otherwise,
    580         // ignore SYNTH photcodes until PASS == 4 (where we also accept saturated stars)
    581         if ((measure[k].photcode >= 3001) && (measure[k].photcode <= 3005)) {
    582           // something of a hack: force object to use synth values if synth mags >>
    583           // saturation (3pi instrumental mags < -15)
    584           float MaxMagForceSynth = NAN;
    585           switch (measure[k].photcode) {
    586             case 3001:
    587               MaxMagForceSynth = 13.64;
    588               break;
    589             case 3002:
    590               MaxMagForceSynth = 13.76;
    591               break;
    592             case 3003:
    593               MaxMagForceSynth = 13.74;
    594               break;
    595             case 3004:
    596               MaxMagForceSynth = 12.94;
    597               break;
    598             case 3005:
    599               MaxMagForceSynth = 12.01;
    600               break;
    601           }
    602           if (measureT[k].M < MaxMagForceSynth) {
    603             forceSynth = TRUE;
    604             forceSynthEntry = Npsf;
    605           } else {
    606             if (pass < 4) {
    607               SKIP_THIS_MEAS(Nbad);
    608             }
    609             haveSynth = TRUE;
    610           }
    611         }
    612 
    613         // Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter
    614         float Map = PhotCat (&measure[k], MAG_CLASS_APER);
    615         if (!isnan(Map)) {
    616             Maplist[Nap] = Map - Mcal - Mmos - Mgrid;
    617             daplist[Nap] = dMpsf;// XXX check on this...
    618             waplist[Nap] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    619             Nap ++;
    620         }
    621 
    622         float Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
    623         if (!isnan(Mkron)) {
    624           Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
    625           dkronlist[Nkron] = measure[k].dMkron;
    626           wkronlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    627           Nkron ++;
    628         }
    629       } // if (isSetMrelFinal)
    630 
    631       // dlist gives the error per measurement, wlist gives the weight
    632       // we can modify the error and weight in a few ways:
    633       // 1) MIN_ERROR guarantees a floor
    634       // 2) photomErrSys is added in quadrature as a sytematic error, set per photcode
    635       // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
    636       // 4) some reference photcode of some kind can be specified as fixed and have a high weight
    637       Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid;
    638       dpsflist[Npsf] = dMpsf;
    639       wpsflist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    640 
    641       // NOTE:
    642       // Msys is measure[i].M + zp corrections
    643       // Mcal is image[j].Mcal
    644       // Mmos and Mgrid are offsets for mosaic and grid
    645 
    646       // tie down reference photometry if the -refcode (code) option is selected
    647       // eg, -refcode g_SDSS
    648       // this probably makes no sense in the context of multifilter analysis
    649       // XXX probably need to use the photocde table to assign reference mag weights.
    650       if (refPhotcode) {
    651         if (code->code == refPhotcode->code) {
    652           wpsflist[Npsf] = UBERCAL_WEIGHT;
    653         }
    654       }
    655       Npsf ++;
    656     }
    657 
    658     int Nminmeas = isSetMrelFinal ? 1 : STAR_TOOFEW + 1;
    659 
    660     // XXX : ugh : another hard-wired photcode entry...
    661     if (isSetMrelFinal && (pass == 0)) {
    662       if ((thisCode < 6) || (thisCode == 9)) {
    663         secfilt[Nsec].Ncode = NexpPS1;
    664       } else {
    665         secfilt[Nsec].Ncode = Ncode; // 2MASS data if it exists
    666       }
    667     }
    668 
    669     // when performing the grid analysis, STAR_TOOFEW should be set to 1;
    670     if (Npsf < Nminmeas) { /* too few measurements */
    671       // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, Npsf, STAR_TOOFEW);
    672       secfilt[Nsec].flags |= ID_STAR_FEW;
    673       if (Ncode == 0) {
    674         results->Ncode ++;
    675       } else {
    676         results->Nfew ++;
    677       }
    678       continue;
    679     } else {
    680       secfilt[Nsec].flags &= ~ID_STAR_FEW;
    681     }   
    682 
    683     if (forceSynth) {
    684       // use the single SYNTH value instead of the other mags here
    685       myAssert ((forceSynthEntry < Npsf) && (forceSynthEntry >= 0), "programming error");
    686       Mpsflist[0] = Mpsflist[forceSynthEntry];
    687       dpsflist[0] = dpsflist[forceSynthEntry];
    688       wpsflist[0] = wpsflist[forceSynthEntry];
    689       Npsf = 1;
    690     }
    691     liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats);
    692 
    693     secfilt[Nsec].M      = psfstats->mean;
    694     secfilt[Nsec].dM     = psfstats->error;
    695     secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
    696 
    697     // when running -averages, we have no information about the images, so we cannot set this
    698     if (minUbercalDist > -1) {
    699       secfilt[Nsec].ubercalDist = minUbercalDist;
    700     }
    701 
    702     if (isSetMrelFinal) {
    703       found[Nsec] = TRUE;
    704 
    705       secfilt[Nsec].Mstdev = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
    706       // secfilt[Nsec].Ncode = Ncode;
    707       secfilt[Nsec].Nused = psfstats->Nmeas;
    708 
    709       secfilt[Nsec].Mmax = psfstats->max;
    710       secfilt[Nsec].Mmin = psfstats->min;
    711 
    712       secfilt[Nsec].psfQfMax     = psfQfMax;
    713       secfilt[Nsec].psfQfPerfMax = psfQfPerfMax;
    714 
    715       // NOTE : use the modified weight for apmags as well as psf mags
    716       liststats (Maplist, daplist, waplist, Nap, apstats);
    717       secfilt[Nsec].Map  = Nap > 0 ? apstats->mean : NAN;
    718       secfilt[Nsec].dMap  = Nap > 0 ? apstats->error : NAN;
    719       secfilt[Nsec].sMap  = Nap > 0 ? apstats->sigma : NAN;
    720       secfilt[Nsec].NusedAp  = Nap;
    721 
    722       liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats);
    723       secfilt[Nsec].Mkron  = Nkron > 0 ? kronstats->mean  : NAN;
    724       secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN;
    725       secfilt[Nsec].sMkron = Nkron > 0 ? kronstats->sigma : NAN;
    726       secfilt[Nsec].NusedKron  = Nkron;
    727 
    728       // NOTE: for 2MASS measurements, Next should be 1, as should N
    729       if ((Next > 0) && (Next > 0.5*Npsf)) {
    730         secfilt[Nsec].flags |= ID_SECF_OBJ_EXT;
    731       }
    732 
    733       switch (pass) {
    734         case 0:
    735           secfilt[Nsec].flags |= ID_PHOTOM_PASS_0;
    736           if (havePS1) GoodPS1 = TRUE;
    737           break;
    738         case 1:
    739           secfilt[Nsec].flags |= ID_PHOTOM_PASS_1;
    740           if (havePS1) GoodPS1 = TRUE;
    741           break;
    742         case 2:
    743           secfilt[Nsec].flags |= ID_PHOTOM_PASS_2;
    744           if (havePS1) GoodPS1 = TRUE;
    745           break;
    746         case 3:
    747           secfilt[Nsec].flags |= ID_PHOTOM_PASS_3;
    748           break;
    749         case 4:
    750           secfilt[Nsec].flags |= ID_PHOTOM_PASS_4;
    751           break;
    752       }
    753       if (haveSynth) {
    754         secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;
    755       }
    756       if (havePS1) {
    757         secfilt[Nsec].flags |= ID_SECF_HAS_PS1;
    758       }
    759       if (haveUbercal) {
    760         secfilt[Nsec].flags |= ID_SECF_USE_UBERCAL;
    761       }
    762     }
    763   }
    764 
    765   if (isSetMrelFinal) {
    766     if (pass == 0) {
    767       DVOAverageFlags flagBits = ID_OBJ_EXT | ID_OBJ_EXT_ALT | ID_OBJ_GOOD | ID_OBJ_GOOD_ALT;
    768       // we attempt to set a few flags here; reset those bits before trying:
    769       average[0].flags &= ~flagBits;
    770     }
    771 
    772     if (NextPS1 && (NextPS1 > NpsfPS1)) {
    773       average[0].flags |= ID_OBJ_EXT;
    774     }
    775     if (GoodPS1) {
    776       average[0].flags |= ID_OBJ_GOOD;
    777     }
    778     if (Galaxy2MASS) {
    779       average[0].flags |= ID_OBJ_EXT_ALT;
    780     }
    781     if (Good2MASS) {
    782       average[0].flags |= ID_OBJ_GOOD_ALT;
    783     }
    784   }
    785   return (TRUE);
    786 }
    787 # endif
    788 
    789406// only apply Stack operation on setMrelFinal in first pass
    790407// this function has 3 goals, not to be confused:
     
    792409// 2) select the BEST detections per filter (regardless of PRIMARY)
    793410// 3) apply the zero point and AB->Jy transformations
    794 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
     411int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr) {
    795412
    796413  // we are guaranteed to have average, measure, secfilt
    797   Average *average = &catalog[cat].average[ave];
     414  Average *average = &catalog[0].average[ave];
    798415  off_t measureOffset = average->measureOffset;
    799416  int Nmeasure = average->Nmeasure;
    800417
    801   Measure *measure = &catalog[cat].measure[measureOffset];
    802   SecFilt *secfilt = &catalog[cat].secfilt[ave*Nsecfilt];
     418  Measure *measure = &catalog[0].measure[measureOffset];
     419  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
    803420
    804421  off_t k;
     
    900517      }
    901518
    902       // NOTE: negative and insignificant vlues values are allowed, but not NAN flux values
     519      // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
    903520      Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF);
    904521      if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
     
    1028645
    1029646  // we are guaranteed to have average, measure, secfilt
    1030   Average *average = &catalog[cat].average[ave];
    1031   Measure *measure = &catalog[cat].measure[measureOffset];
    1032   SecFilt *secfilt = &catalog[cat].secfilt[ave*Nsecfilt];
     647  Average *average = &catalog[0].average[ave];
     648  Measure *measure = &catalog[0].measure[measureOffset];
     649  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
    1033650
    1034651  off_t k;
  • branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/synthetic_zpts.c

    r38062 r38298  
    77static char *extname[5] = {"map_g", "map_r", "map_i", "map_z", "map_y"};
    88
    9 SynthZeroPoints *SynthZeroPointsLoad (char *filename) {
     9static SynthZeroPoints *zpts = NULL;
     10
     11int SynthZeroPointsLoad (char *filename) {
    1012
    1113  FILE *f = fopen (filename, "r");
    1214  if (!f) {
    1315    fprintf (stderr, "ERROR: cannot open file %s\n", filename);
    14     return NULL;
     16    return FALSE;
    1517  }
    1618
     
    2325  // map_y
    2426
    25   SynthZeroPoints *zpts = NULL;
    2627  ALLOCATE (zpts, SynthZeroPoints, 1);
    2728 
     
    2930    if (VERBOSE) fprintf (stderr, "can't read header\n");
    3031    fclose (f);
    31     return NULL;
     32    return FALSE;
    3233  }
    3334
     
    4950  zpts->Ny = zpts->matrix[0].Naxis[1];
    5051
     52  return TRUE;
     53}
     54
     55SynthZeroPoints *SynthZeroPointsGet () {
    5156  return zpts;
    5257}
    53 
Note: See TracChangeset for help on using the changeset viewer.