IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33610


Ignore:
Timestamp:
Mar 24, 2012, 10:27:28 PM (14 years ago)
Author:
eugene
Message:

setMrelFinal was marking all ref photometry to be skipped, so objects with only SYNTH phot were not getting average photometry; bcatalog sort by Nmeasure

Location:
branches/eam_branches/ipp-20111122/Ohana/src/relphot/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/StarOps.c

    r33605 r33610  
    153153}
    154154
     155int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) {
     156
     157  off_t k;
     158
     159  int Nsecfilt = GetPhotcodeNsecfilt ();
     160
     161  off_t m = average[0].measureOffset;
     162
     163  for (k = 0; k < average[0].Nmeasure; k++, m++) {
     164    fprintf (stderr, "meas: %08x\n", measure[m].dbFlags);
     165  }
     166
     167  int Ns;
     168  for (Ns = 0; Ns < Nsecfilt; Ns++) {
     169    fprintf (stderr, "secf: %08x\n", secfilt[Ns].flags);
     170  }
     171  return 1;
     172}
     173
     174# define MARK_SKIP_MEAS \
     175  catalog[i].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM; \
     176  catalog[i].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
     177
    155178// setMrel and setMrelOutput are extremely similar, but have slightly different implications:
    156179// * setMrel uses the internal Tiny structures only
     
    190213    for (j = 0; j < catalog[i].Naverage; j++) {
    191214
     215      if (FALSE && (catalog[i].average[j].objID == 0x46a4) && (catalog[i].average[j].catID == 0xf40e)) {
     216        fprintf (stderr, "test obj\n");
     217        print_measure_set (&catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt], catalog[i].measure);
     218      }
     219
    192220      int minUbercalDist = 1000;
    193221
     
    205233        int haveSynth = FALSE;
    206234        int haveUbercal = FALSE;
     235        int isRefPhot = FALSE;
    207236
    208237        N = 0;
     
    221250            // these detetions have no image (eg, ref values such as 2MASS)
    222251            Mcal = Mmos = Mgrid = 0;
     252            isRefPhot = TRUE;
    223253          } else {
    224254            Mcal  = getMcal  (m, i, flatcorr, catalog);
    225             if (isnan(Mcal)) continue;
     255            if (isnan(Mcal)) {
     256              MARK_SKIP_MEAS;
     257              continue;
     258            }
    226259            Mmos  = getMmos  (m, i);
    227             if (isnan(Mmos)) continue;
     260            if (isnan(Mmos)) {
     261              MARK_SKIP_MEAS;
     262              continue;
     263            }
    228264            Mgrid = getMgrid (m, i);
    229             if (isnan(Mgrid)) continue;
     265            if (isnan(Mgrid)) {
     266              MARK_SKIP_MEAS;
     267              continue;
     268            }
    230269          }
    231270
    232271          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
    233           if (isnan(Msys)) { continue; }
     272          if (isnan(Msys)) {
     273            if (!isRefPhot) {
     274              MARK_SKIP_MEAS;
     275            }
     276            continue;
     277          }
    234278          list[N] = Msys - Mcal - Mmos - Mgrid;
    235279
     
    255299            if ((pass == 0) && !(catalog[i].measure[m].photFlags & 0x00000007)) {
    256300              // detections without one of these bits should only be used in PASS_1
     301              MARK_SKIP_MEAS;
    257302              continue;
    258303            }
     
    260305          // ignore SYNTH photocdes until PASS == 4 (where we also accept saturated stars)
    261306          if ((catalog[i].measure[m].photcode >= 3001) && (catalog[i].measure[m].photcode <= 3005)) {
    262             if (pass < 4) continue;
     307            if (pass < 4) {
     308              MARK_SKIP_MEAS;
     309              continue;
     310            }
    263311            haveSynth = TRUE;
    264312          }
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/bcatalog.c

    r33564 r33610  
    11# include "relphot.h"
     2
     3int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *oldcatalog);
    24
    35int bcatalog (Catalog *subcatalog, Catalog *catalog) {
     
    212214  // limit the total number of stars in the catalog
    213215  if (MaxDensityUse) {
    214     LimitDensityCatalog (subcatalog, catalog);
     216    LimitDensityCatalog_ByNmeasure (subcatalog, catalog);
    215217  }
    216218
     
    224226}
    225227
    226 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     228// sort by decreasing Nmeasure (X)
     229void sort_by_Nmeasure (int *X, off_t *Y, off_t N) {
     230
     231# define SWAPFUNC(A,B){ int tmpI; off_t tmpT;   \
     232  tmpI = X[A]; X[A] = X[B]; X[B] = tmpI; \
     233  tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT; \
     234}
     235# define COMPARE(A,B)(X[A] > X[B])
     236
     237  OHANA_SORT (N, COMPARE, SWAPFUNC);
     238
     239# undef SWAPFUNC
     240# undef COMPARE
     241
     242}
     243
     244int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *oldcatalog) {
    227245
    228246  Catalog tmpcatalog;
     
    232250  int Nsecfilt = GetPhotcodeNsecfilt ();
    233251
    234   gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
    235   gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
    236   gfits_scan (&catalog[0].header, "RA1",  "%lf", 1, &Rmax);
    237   gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax);
     252  gfits_scan (&oldcatalog[0].header, "RA0",  "%lf", 1, &Rmin);
     253  gfits_scan (&oldcatalog[0].header, "DEC0", "%lf", 1, &Dmin);
     254  gfits_scan (&oldcatalog[0].header, "RA1",  "%lf", 1, &Rmax);
     255  gfits_scan (&oldcatalog[0].header, "DEC1", "%lf", 1, &Dmax);
    238256
    239257  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     
    255273
    256274  // we are going to select Nmax entries by generating a random-sorted index list
    257   off_t *index, tmp, i, j, ave;
     275  int *value;
     276  off_t *index, i, j, ave;
    258277  ALLOCATE (index, off_t, Naverage);
     278  ALLOCATE (value, int, Naverage);
    259279  for (i = 0; i < Naverage; i++) {
    260280    index[i] = i;
    261   }
    262   for (i = 0; i < Naverage; i++) {
    263     j = (Naverage - i) * drand48() + i; // a number between i and Naverage
    264     tmp = index[j];
    265     index[j] = index[i];
    266     index[i] = tmp;
    267   }
     281    value[i] = subcatalog[0].averageT[i].Nmeasure;
     282  }
     283  sort_by_Nmeasure (value, index, Naverage);
    268284
    269285  // count the number of measurements this selection will yield
     
    298314
    299315  if (VERBOSE) {
     316    char *basename = filebasename (oldcatalog[0].filename);
     317    fprintf (stderr, "limited to "OFF_T_FMT" ("OFF_T_FMT" subset, "OFF_T_FMT" total) stars, "OFF_T_FMT" ("OFF_T_FMT" subset, "OFF_T_FMT" total) measures for catalog %s\n",
     318             Nmax, subcatalog[0].Naverage, oldcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  oldcatalog[0].Nmeasure, basename);
     319    free (basename);
     320  }
     321
     322  free (index);
     323  free (value);
     324  free (subcatalog[0].averageT);
     325  free (subcatalog[0].measureT);
     326  free (subcatalog[0].secfilt);
     327
     328  subcatalog[0].averageT = tmpcatalog.averageT;
     329  subcatalog[0].measureT = tmpcatalog.measureT;
     330  subcatalog[0].secfilt = tmpcatalog.secfilt;
     331  subcatalog[0].Naverage = Nmax;
     332  subcatalog[0].Nmeasure = Nmeasure;
     333  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
     334  subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     335
     336  return (TRUE);
     337}
     338
     339int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     340
     341  Catalog tmpcatalog;
     342
     343  double Rmin, Rmax, Dmin, Dmax;
     344
     345  int Nsecfilt = GetPhotcodeNsecfilt ();
     346
     347  gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
     348  gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
     349  gfits_scan (&catalog[0].header, "RA1",  "%lf", 1, &Rmax);
     350  gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax);
     351
     352  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     353
     354  float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin));
     355  assert (AREA > 0);
     356
     357  off_t Nmax = MaxDensityValue * AREA;
     358  if (subcatalog[0].Naverage <= Nmax) {
     359    if (VERBOSE) {
     360      fprintf (stderr, "subcatalog has less than the max density\n");
     361    }
     362    return (TRUE);
     363  }
     364
     365  off_t Naverage = subcatalog[0].Naverage;
     366
     367  // select a random subset of Nmax stars from subcatalog using Fisher-Yates
     368
     369  // we are going to select Nmax entries by generating a random-sorted index list
     370  off_t *index, tmp, i, j, ave;
     371  ALLOCATE (index, off_t, Naverage);
     372  for (i = 0; i < Naverage; i++) {
     373    index[i] = i;
     374  }
     375  for (i = 0; i < Naverage; i++) {
     376    j = (Naverage - i) * drand48() + i; // a number between i and Naverage
     377    tmp = index[j];
     378    index[j] = index[i];
     379    index[i] = tmp;
     380  }
     381
     382  // count the number of measurements this selection will yield
     383  off_t NMEASURE = 0;
     384  for (i = 0; i < Nmax; i++) {
     385    ave = index[i];
     386    NMEASURE += subcatalog[0].averageT[ave].Nmeasure;
     387  }
     388
     389  // allocate the output data
     390  ALLOCATE (tmpcatalog.averageT, AverageTiny, Nmax);
     391  ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE);
     392  ALLOCATE (tmpcatalog.secfilt,  SecFilt, Nmax * Nsecfilt);
     393
     394  off_t Nmeasure = 0;
     395
     396  // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links)
     397  for (i = 0; i < Nmax; i++) {
     398    ave = index[i];
     399    tmpcatalog.averageT[i] = subcatalog[0].averageT[ave];
     400    tmpcatalog.averageT[i].measureOffset = Nmeasure;
     401    for (j = 0; j < tmpcatalog.averageT[i].Nmeasure; j++) {
     402      off_t offset = subcatalog[0].averageT[ave].measureOffset + j;
     403      tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset];
     404      tmpcatalog.measureT[Nmeasure].averef = i;
     405      Nmeasure ++;
     406    }
     407    for (j = 0; j < Nsecfilt; j++) {
     408      tmpcatalog.secfilt[i*Nsecfilt + j] = subcatalog[0].secfilt[ave*Nsecfilt + j];
     409    }
     410  }
     411
     412  if (VERBOSE) {
    300413    fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n",
    301414             Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  catalog[0].filename);
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c

    r33608 r33610  
    230230      MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);
    231231    }
     232
     233    /* at this point, we have correct cal coeffs in the image/mosaic structures */
     234    for (i = 0; i < Ncatalog; i++) {
     235      free_tiny_values (&catalog[i]);
     236      dvo_catalog_free (&catalog[i]);
     237    }
     238    freeImageBins (Ncatalog, TRUE);
     239    freeMosaicBins (Ncatalog, TRUE);
     240    freeGridBins (Ncatalog);
     241
    232242  } // (NLOOP > 0) : this loop determines the offsets per chip
    233243
    234   // only change the real database if -update is requested
     244  reload_images (&db);
     245
     246  // only change the real database files if -update is requested
    235247  if (!UPDATE) exit (0);
    236248 
    237   reload_images (&db);
    238 
    239   /* at this point, we have correct cal coeffs in the image/mosaic structures */
    240   for (i = 0; i < Ncatalog; i++) {
    241     free_tiny_values (&catalog[i]);
    242     dvo_catalog_free (&catalog[i]);
    243   }
    244   freeImageBins (Ncatalog, TRUE);
    245   freeMosaicBins (Ncatalog, TRUE);
    246   freeGridBins (Ncatalog);
    247 
    248249  /* load catalog data from region files, update Mrel include all data */
    249250  reload_catalogs (skylist, flatcorr, 0, NULL);
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/setMrelFinal.c

    r33608 r33610  
    123123// non-outliers with Imag range
    124124
     125// int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure) {
     126//
     127//   off_t k;
     128//
     129//   int Nsecfilt = GetPhotcodeNsecfilt ();
     130//
     131//   off_t m = average[0].measureOffset;
     132//
     133//   for (k = 0; k < average[0].Nmeasure; k++, m++) {
     134//     fprintf (stderr, "meas: %08x\n", measure[m].dbFlags);
     135//   }
     136//
     137//   int Ns;
     138//   for (Ns = 0; Ns < Nsecfilt; Ns++) {
     139//     fprintf (stderr, "secf: %08x\n", secfilt[Ns].flags);
     140//   }
     141//   return 1;
     142// }
     143
     144int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure);
     145
    125146void skip_measurements (Catalog *catalog, int pass, FlatCorrectionTable *flatcorr) {
    126147
     
    137158 
    138159  /* allow measures marked as outliers (POOR) and off image region (AREA) */
    139   if (pass >= 2) MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM;
     160  if (pass >= 2) {
     161    MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_SKIP_PHOTOM;
     162  } else {
     163    MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
     164  }
    140165
    141166  /* mark measures which should be ignored on this pass */
    142167  for (i = 0; i < catalog[0].Naverage; i++) {
    143168    Ntot += catalog[0].average[i].Nmeasure;
     169
     170    if (FALSE && (catalog[0].average[i].objID == 0x46a4) && (catalog[0].average[i].catID == 0xf40e)) {
     171      fprintf (stderr, "test obj\n");
     172      print_measure_set (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], catalog[0].measure);
     173    }
    144174
    145175    // mark measurements for each secfilt separately
     
    173203        // clear SKIP for all measures at first
    174204        catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    175 
    176         // skip measurements from BAD images and mosaics
    177         // do NOT skip measurements without a matching image
    178         if (isnan(getMcal (m, 0, flatcorr, catalog))) goto skip;
    179         if (isnan(getMmos (m, 0))) goto skip;
    180 
    181         // PASS 4 : skip measurements by inst mag limit
     205        catalog[0].measure [m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
     206
     207        // skip measurements from BAD images and mosaics (not REF mags)
     208        // do NOT skip measurements without a matching image (REF mags)
     209        off_t Nim = getImageEntry (m, 0);
     210        if (Nim > -1) {
     211          if (isnan(getMcal (m, 0, flatcorr, catalog))) goto skip;
     212          if (isnan(getMmos (m, 0))) goto skip;
     213        }
     214
     215        // PASS 4 : skip measurements by inst mag limit (not REF mags)
    182216        if ((pass < 4) && ImagSelect) {
    183           mag = PhotInst (&catalog[0].measure[m]);
    184           if (mag < ImagMin) goto skip;
    185           if (mag > ImagMax) goto skip;
     217          if (Nim > -1) {
     218            mag = PhotInst (&catalog[0].measure[m]);
     219            if (mag < ImagMin) goto skip;
     220            if (mag > ImagMax) goto skip;
     221          }
    186222        }
    187223
Note: See TracChangeset for help on using the changeset viewer.