IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31258


Ignore:
Timestamp:
Apr 10, 2011, 10:20:54 AM (15 years ago)
Author:
eugene
Message:

add a max-density option to limit the operating data volume (randomly selected from reduced subset); add a step to rationalize the zero points: negative clouds get pushed to zero and the impact redistrubted to the rest of the images weighted by overlaps; fixed are error matching images for the 0,360 boundary

Location:
branches/eam_branches/ipp-20110404/Ohana/src/relphot
Files:
9 edited

Legend:

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

    r30616 r31258  
    9090
    9191PhotCode      *refPhotcode;
     92
     93int MaxDensityUse;
     94double MaxDensityValue;
    9295
    9396int AreaSelect;
     
    223226void relphot_usage (void);
    224227void relphot_help (int argc, char **argv);
     228
     229int rationalize_mosaics ();
     230int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/MosaicOps.c

    r30616 r31258  
    302302    return;
    303303  }
    304   fprintf (stderr, "missed measurement\n");
     304  // if we miss a measurement, it might be a REF type of value
     305  // fprintf (stderr, "missed measurement\n");
    305306  return;
    306307}
     
    403404      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
    404405      if (mark) {
    405         if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]); }
     406        if (1 || VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]); }
    406407        mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW;
    407408        Nfew ++;
     
    433434}
    434435 
     436// When we rationalize the images/mosaics, we are driving the negative cloud images back
     437// to 0.0.  At the same time, we make a guess to the effective impact on all other images,
     438// driven by the coupling of common stars.
     439int rationalize_mosaics (Catalog *catalog, int Ncatalog) {
     440
     441  double *imageOffset, *starOffset;
     442  int *starNcount;
     443  int **Slist, *NSlist, *NSLIST;
     444  int i, j, k, m, nMos;
     445
     446  off_t Nimage;
     447  Image *image;
     448
     449  // set a test value for now
     450  float CLOUD_TOLERANCE = 0.025;
     451
     452  if (!MOSAIC_ZEROPT) return (FALSE);
     453  if (FREEZE_MOSAICS) return (FALSE);
     454
     455  image = getimages (&Nimage);
     456
     457  ALLOCATE (imageOffset, double, Nmosaic);
     458
     459  ALLOCATE ( Slist, int *, Nmosaic); // array of calibrated star indexes on this mosaic
     460  ALLOCATE (NSlist, int,   Nmosaic); // number of stars on mosaic
     461  ALLOCATE (NSLIST, int,   Nmosaic); // number of Slist entries allocated
     462
     463  // find the images / mosaics with negative clouds and save their offset
     464  for (i = 0; i < Nmosaic; i++) {
     465 
     466    NSlist[i] =   0;
     467    NSLIST[i] = 100;
     468    ALLOCATE (Slist[i], int, NSLIST[i]);
     469
     470    imageOffset[i] = 0.0;
     471
     472    if (fabs(mosaic[i].Mcal) < CLOUD_TOLERANCE) {
     473      fprintf (stderr, "cloud-free: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     474    }
     475    if (mosaic[i].Mcal < -CLOUD_TOLERANCE) {
     476      imageOffset[i] = -mosaic[i].Mcal;
     477      // NOTE the negative sign: down below, we are going to add in the negative of Mcal
     478      // to this image, and the propagated mean values for other images
     479      fprintf (stderr, "anti-clouds: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     480    }
     481    if (mosaic[i].Mcal > CLOUD_TOLERANCE) {
     482      fprintf (stderr, "cloudy    : %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     483    }
     484  }
     485
     486  // allocate an array for star offset
     487  int Nstars = 0;
     488  int NSTARS = 1000;
     489  ALLOCATE (starOffset, double, NSTARS);
     490  ALLOCATE (starNcount, int,    NSTARS);
     491
     492  // find the mean offset for each star
     493  for (i = 0; i < Ncatalog; i++) {
     494    for (j = 0; j < catalog[i].Naverage; j++) {
     495      starOffset[Nstars] = 0.0;
     496      starNcount[Nstars] = 0;
     497
     498      // skip bad stars
     499      if (catalog[i].average[j].flags & STAR_BAD) continue; 
     500      m = catalog[i].average[j].measureOffset;
     501
     502      // determine the mosaic for each measurement
     503      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     504
     505        // skip unused measurements
     506        if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
     507
     508        // skip REF measurements (not tied to an image)
     509        if (getImageEntry (m, i) < 0) continue;
     510
     511        // find the source of this measurement (skip unassigned measurements)
     512        nMos = bin[i][m];
     513        if (nMos == -1) continue;
     514
     515        // accumulate the offsets from the negative cloud images (others have 0.0 value)
     516        starOffset[Nstars] += imageOffset[nMos];
     517        starNcount[Nstars] ++;
     518       
     519        // record the mosaic->star reference
     520        Slist[nMos][NSlist[nMos]] = Nstars;
     521        NSlist[nMos] ++;
     522        if (NSlist[nMos] == NSLIST[nMos]) {
     523          NSLIST[nMos] += 100;
     524          REALLOCATE (Slist[nMos], int, NSLIST[nMos]);
     525        }         
     526      }
     527      Nstars ++;
     528      if (Nstars == NSTARS) {
     529        NSTARS += 1000;
     530        REALLOCATE (starOffset, double, NSTARS);
     531        REALLOCATE (starNcount, int,    NSTARS);
     532      }
     533    }
     534  }
     535
     536  // find the mean offset of the images without negative clouds
     537  for (i = 0; i < Nmosaic; i++) {
     538
     539    // a negative cloud image (cloud: Mcal > 0; anti-clouds: Mcal < 0; imageOffset = -Mcal)
     540    if (imageOffset[i] > 0.0) continue;
     541
     542    // we need to actually have cross-references to count
     543    if (NSlist[i] < 2) continue;
     544
     545    float dM = 0.0;
     546    for (j = 0; j < NSlist[i]; j++) {
     547      Nstars = Slist[i][j];
     548      if (starNcount[Nstars] > 1) {
     549        dM += (starOffset[Nstars] / starNcount[Nstars]);
     550      }
     551    }
     552    imageOffset[i] = dM / NSlist[i];
     553    fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[imlist[i][0]].name, dM, NSlist[i], imageOffset[i]);
     554  }
     555
     556  for (i = 0; i < Nmosaic; i++) {
     557    fprintf (stderr, "correction: %s : %f\n", image[imlist[i][0]].name, imageOffset[i]);
     558  }
     559
     560  // apply all offset values to the mosaics
     561  // find the images / mosaics with negative clouds and save their offset
     562  for (i = 0; i < Nmosaic; i++) {
     563    mosaic[i].Mcal += imageOffset[i];
     564  }
     565
     566  for (i = 0; i < Nmosaic; i++){
     567    free (Slist[i]);
     568  }
     569  free (NSlist);
     570  free (NSLIST);
     571  free (imageOffset);
     572
     573  return (TRUE);
     574}
     575
    435576StatType statsMosaicM (Catalog *catalog) {
    436577
     
    563704void clean_mosaics () {
    564705
    565   off_t i, N, mark, Nmark;
     706  off_t i, N, mark, Nmark, Nscatter, Noffset;
    566707  double *mlist, *slist, *dlist;
    567708  double MaxOffset, MedOffset, MaxScatter;
     
    592733  fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
    593734 
    594   Nmark = 0;
     735  Nmark = Nscatter = Noffset = 0;
    595736  for (i = 0; i < Nmosaic; i++) {
    596737    mark = FALSE;
    597     mark = (mosaic[i].dMcal > MaxScatter) || (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset);
     738    if (mosaic[i].dMcal > MaxScatter) {
     739      mark = TRUE;
     740      Nscatter ++;
     741    }
     742    if (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset) {
     743      mark = TRUE;
     744      Noffset ++;
     745    }
    598746    if (mark) {
    599747      Nmark ++;
     
    604752  }
    605753
    606   fprintf (stderr, OFF_T_FMT" mosaics marked poor\n",  Nmark);
     754  fprintf (stderr, OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n",  Nmark, Nscatter, Noffset);
    607755  initstats (STATMODE);
    608756  free (mlist);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/StarOps.c

    r29001 r31258  
    55static double *dlist;
    66
     7// When we rationalize the images/mosaics, we are driving the negative cloud images back
     8// to 0.0.  At the same time, we make a guess to the effective impact on all other images,
     9// driven by the coupling of common stars.  This array carries the impact of those offsets
     10// on each star
     11static double *Moffset;
     12
    713void initMrel (Catalog *catalog, int Ncatalog) {
    814
     
    1622  }
    1723
    18   ALLOCATE (list, double, MAX (1, Nmax));
    19   ALLOCATE (dlist, double, MAX (1, Nmax));
     24  ALLOCATE (list,    double, MAX (1, Nmax));
     25  ALLOCATE (dlist,   double, MAX (1, Nmax));
     26  ALLOCATE (Moffset, double, MAX (1, Nmax));
    2027
    2128
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/args.c

    r31160 r31258  
    128128  }
    129129
     130  MaxDensityUse = FALSE;
     131  if ((N = get_argument (argc, argv, "-max-density"))) {
     132    remove_argument (N, &argc, argv);
     133    MaxDensityValue = atof(argv[N]);
     134    remove_argument (N, &argc, argv);
     135    MaxDensityUse = TRUE;
     136  }
     137
    130138  SHOW_PARAMS = FALSE;
    131139  if ((N = get_argument (argc, argv, "-params"))) {
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/bcatalog.c

    r31160 r31258  
    11# include "relphot.h"
     2
     3extern double drand48();
    24
    35int bcatalog (Catalog *subcatalog, Catalog *catalog) {
     
    7072      // check for galaxies
    7173      if (!isnan(catalog[0].measure[offset].Map)) {
    72           if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) {
    73               nEXT ++;
    74           } else {
    75               nPSF ++;
    76           }
     74        if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) {
     75          nEXT ++;
     76        } else {
     77          nPSF ++;
     78        }
    7779      }
    7880
     
    139141  assert (PhotNsec == catalog[0].Nsecfilt);
    140142
     143  // limit the total number of stars in the catalog
     144  if (MaxDensityUse) {
     145    LimitDensityCatalog (subcatalog, catalog);
     146  }
     147
    141148  if (VERBOSE) {
    142149    fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog %s\n",
     
    147154  return (TRUE);
    148155}
     156
     157int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     158
     159  Catalog tmpcatalog;
     160
     161  double Rmin, Rmax, Dmin, Dmax;
     162
     163  gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
     164  gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
     165  gfits_scan (&catalog[0].header, "RA1",  "%lf", 1, &Rmax);
     166  gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax);
     167
     168  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     169
     170  float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin));
     171  assert (AREA > 0);
     172
     173  off_t Nmax = MaxDensityValue * AREA;
     174  if (subcatalog[0].Naverage <= Nmax) {
     175    if (VERBOSE) {
     176      fprintf (stderr, "subcatalog has less than the max density\n");
     177    }
     178    return (TRUE);
     179  }
     180
     181  off_t Naverage = subcatalog[0].Naverage;
     182
     183  // select a random subset of Nmax stars from subcatalog using Fisher-Yates
     184
     185  // we are going to select Nmax entries by generating a random-sorted index list
     186  off_t *index, tmp, i, j, ave;
     187  ALLOCATE (index, off_t, Naverage);
     188  for (i = 0; i < Naverage; i++) {
     189    index[i] = i;
     190  }
     191  for (i = 0; i < Naverage; i++) {
     192    j = (Naverage - i) * drand48() + i; // a number between i and Naverage
     193    tmp = index[j];
     194    index[j] = index[i];
     195    index[i] = tmp;
     196  }
     197
     198  // count the number of measurements this selection will yield
     199  off_t NMEASURE = 0;
     200  for (i = 0; i < Nmax; i++) {
     201    ave = index[i];
     202    NMEASURE += subcatalog[0].average[ave].Nmeasure;
     203  }
     204
     205  // allocate the output data
     206  ALLOCATE (tmpcatalog.average, Average, Nmax);
     207  ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * PhotNsec);
     208  ALLOCATE (tmpcatalog.measure, Measure, NMEASURE);
     209
     210  off_t Nmeasure = 0;
     211
     212  // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links)
     213  for (i = 0; i < Nmax; i++) {
     214    ave = index[i];
     215    tmpcatalog.average[i] = subcatalog[0].average[ave];
     216    tmpcatalog.average[i].measureOffset = Nmeasure;
     217    for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) {
     218      off_t offset = subcatalog[0].average[ave].measureOffset + j;
     219      tmpcatalog.measure[Nmeasure] = subcatalog[0].measure[offset];
     220      tmpcatalog.measure[Nmeasure].averef = i;
     221      Nmeasure ++;
     222    }
     223  }
     224
     225  if (VERBOSE) {
     226    fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n",
     227             Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  catalog[0].filename);
     228  }
     229
     230  free (subcatalog[0].average);
     231  free (subcatalog[0].measure);
     232  free (subcatalog[0].secfilt);
     233
     234  subcatalog[0].average = tmpcatalog.average;
     235  subcatalog[0].measure = tmpcatalog.measure;
     236  subcatalog[0].secfilt = tmpcatalog.secfilt;
     237  subcatalog[0].Naverage = Nmax;
     238  subcatalog[0].Nmeasure = Nmeasure;
     239  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     240  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     241
     242  return (TRUE);
     243}
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/initialize.c

    r30616 r31258  
    5555    exit (0);
    5656  }
     57
     58  // init the random seed
     59  long A, B;
     60  A = time(NULL);
     61  for (B = 0; A == time(NULL); B++);
     62  srand48(B);
    5763}
    58 
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/load_images.c

    r31160 r31258  
    4444  // select the images which overlap the selected sky regions
    4545  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
    46   MARKTIME("selected images: %f sec\n", dtime);
     46  MARKTIME("selected %d overlapping images: %f sec\n", (int) Nsubset, dtime);
    4747
    4848  // generate db->vtable from db->ftable based on the selection
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/relphot.c

    r30616 r31258  
    140140      plot_chisq (catalog, Ncatalog);
    141141    }
    142     if ((i == 1) || (i == 5) || (i ==  9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE);
    143     if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog);
    144     if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics ();
    145     if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images ();
     142    if (i % 6 == 1) rationalize_mosaics (catalog, Ncatalog);
     143    // if (i % 6 == 1) rationalize_images ();
     144    if (i % 6 == 2) clean_measures (catalog, Ncatalog, FALSE);
     145    if (i % 6 == 3) clean_stars (catalog, Ncatalog);
     146    if (i % 6 == 5) clean_mosaics ();
     147    if (i % 6 == 5) clean_images ();
     148
     149    // if ((i == 1) || (i == 5) || (i ==  9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE);
     150    // if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog);
     151    // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics ();
     152    // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images ();
    146153    global_stats (catalog, Ncatalog);
    147154  }
    148155
    149   SAVEPLOT = TRUE;
    150   plot_scatter (catalog, Ncatalog);
    151   plot_grid (catalog);
    152   plot_mosaics ();
    153   plot_images ();
    154   plot_stars (catalog, Ncatalog);
    155   plot_chisq (catalog, Ncatalog);
    156 
     156  if (PLOTSTUFF) {
     157    plot_scatter (catalog, Ncatalog);
     158    plot_grid (catalog);
     159    plot_mosaics ();
     160    plot_images ();
     161    plot_stars (catalog, Ncatalog);
     162    plot_chisq (catalog, Ncatalog);
     163  }
     164 
    157165  if (USE_GRID) dump_grid ();
    158166  if (!UPDATE) exit (0);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/select_images.c

    r31160 r31258  
    6464  DmaxSkyRegion = -90.0;
    6565
     66  // FILE *ftest = fopen ("relphot.dump.dat", "w");
     67
    6668  /* compare with each region file */
    6769  for (i = 0; i < skylist[0].Nregions; i++) {
     
    131133    }
    132134
     135    // XXX temporary test : record center coords for each accepted and rejected chip/mosaic
     136    // double RAo, DECo;
     137
    133138    /* define image corners - note the DIS images (mosaic phu) are special */
    134139    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
     
    138143      Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY;
    139144      Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY;
     145      // XY_to_RD(&RAo, &DECo, 0.0, 0.0, &timage[i].coords);
    140146    } else {
    141147      Xi[0] = 0;            Yi[0] = 0;
     
    144150      Xi[3] = 0;            Yi[3] = timage[i].NY;
    145151      Xi[4] = 0;            Yi[4] = 0;
     152      // XY_to_RD(&RAo, &DECo, 0.5*timage[i].NX, 0.5*timage[i].NY, &timage[i].coords);
    146153    }
    147154    found = FALSE;
    148155
    149156    /* transform corners to ra,dec -- costs ~3sec for 3M images (pikake) */
    150     double RminImage = 360.0;
    151     double RmaxImage =   0.0;
     157    double RminImage = RmidSkyRegion + 180.0;
     158    double RmaxImage = RmidSkyRegion - 180.0;
    152159    double DminImage = +90.0;
    153160    double DmaxImage = -90.0;
     
    218225
    219226  found_it:
     227    // XXX We claim this is a good image: write to a test file
     228    // fprintf (ftest, "%s : %lf %lf  : %f %f %d %x\n", timage[i].name, RAo, DECo, timage[i].Mcal, timage[i].dMcal, timage[i].nstar, timage[i].flags);
     229
    220230    image[nimage] = timage[i];
    221231    /* always allow 'few' images to succeed, if possible */
     
    239249  }
    240250  MARKTIME("finish image selection: %f sec\n", dtime);
     251
     252  // fclose (ftest);
    241253
    242254  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage);
Note: See TracChangeset for help on using the changeset viewer.