IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31664


Ignore:
Timestamp:
Jun 22, 2011, 12:35:53 AM (15 years ago)
Author:
eugene
Message:

merged from eam_branches/ipp-20110505: plugged some leaks, allow limited density

Location:
trunk/Ohana/src/relastro
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/include/relastro.h

    r31642 r31664  
    120120int    PLOTDELAY;
    121121int    CHIPORDER;
     122
     123int MaxDensityUse;
     124double MaxDensityValue;
    122125
    123126int UserCatalog;
     
    363366
    364367int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
     368int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
    365369
    366370int initializeConstraints();
     
    368372int applyConstraintsB(Catalog *catalog, off_t i);
    369373void setupAreaSelection(SkyRegion *region);
    370 
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r30616 r31664  
    115115    Nlist[i] =   0;
    116116    NLIST[i] = 100;
    117     ALLOCATE (clist[i], int, NLIST[i]);
    118     ALLOCATE (mlist[i], off_t, NLIST[i]);
     117    clist[i] = NULL;  // we allocate these iff they are needed in matchImage
     118    mlist[i] = NULL;  // we allocate these iff they are needed in matchImage
    119119  }
    120120
     
    141141  free (bin);
    142142  for (i = 0; i < Nimage; i++) {
    143     free (clist[i]);
    144     free (mlist[i]);
     143    if (clist[i]) { free (clist[i]); }
     144    if (mlist[i]) { free (mlist[i]); }
    145145  }
    146146  free (clist);
     
    191191  // index for (catalog, measure) -> image
    192192  bin[cat][meas] = idx;
     193
     194  // if we need to allocate an image index table, do so here
     195  if (!clist[idx]) {
     196      ALLOCATE (clist[idx], int, NLIST[idx]);
     197  }
     198  if (!mlist[idx]) {
     199      ALLOCATE (mlist[idx], off_t, NLIST[idx]);
     200  }
    193201
    194202  // index for image, Nentry -> catalog
  • trunk/Ohana/src/relastro/src/args.c

    r31637 r31664  
    102102    remove_argument (N, &argc, argv);
    103103    USE_BASIC_CHECK = TRUE;
     104  }
     105
     106  MaxDensityUse = FALSE;
     107  if ((N = get_argument (argc, argv, "-max-density"))) {
     108    remove_argument (N, &argc, argv);
     109    MaxDensityValue = atof(argv[N]);
     110    remove_argument (N, &argc, argv);
     111    MaxDensityUse = TRUE;
    104112  }
    105113
     
    315323  fprintf (stderr, "  -plotdelay (seconds)\n");
    316324  fprintf (stderr, "  -statmode (mode)\n");
    317   fprintf (stderr, "  -reset");
    318   fprintf (stderr, "  -nloop (N) : number of image-fit iterations");
     325  fprintf (stderr, "  -reset\n");
     326  fprintf (stderr, "  -nloop (N) : number of image-fit iterations\n");
    319327  fprintf (stderr, "  -update : apply new fit to database\n");
    320328  fprintf (stderr, "  -params\n");
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r30616 r31664  
    7070      // allowed.
    7171
     72      // CopyMeasureTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
     73
     74      subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset];
    7275      subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_ASTROM;
    7376      subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
    74       subcatalog[0].measure[Nmeasure]          = catalog[0].measure[offset];
    7577      subcatalog[0].measure[Nmeasure].averef   = Naverage;
    7678      if (RESET) {
     
    9698  REALLOCATE (subcatalog[0].average, Average, MAX (Naverage, 1));
    9799  REALLOCATE (subcatalog[0].measure, Measure, MAX (Nmeasure, 1));
    98   REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1));
     100  REALLOCATE (subcatalog[0].secfilt, SecFilt, MAX (Naverage, 1)*Nsecfilt);
    99101  subcatalog[0].Naverage = Naverage;
    100102  subcatalog[0].Nmeasure = Nmeasure;
     
    103105  assert (Nsecfilt == catalog[0].Nsecfilt);
    104106
     107  // limit the total number of stars in the catalog
     108  if (MaxDensityUse) {
     109    LimitDensityCatalog (subcatalog, catalog);
     110  }
     111
    105112  if (VERBOSE) {
    106113    fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures) for catalog\n",  i,  subcatalog[0].Naverage,  subcatalog[0].Nmeasure);
     
    108115  return (TRUE);
    109116}
     117
     118/* this version does NOT use AverageTiny, MeasureTiny */
     119int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     120
     121  Catalog tmpcatalog;
     122
     123  double Rmin, Rmax, Dmin, Dmax;
     124
     125  int Nsecfilt = GetPhotcodeNsecfilt ();
     126
     127  gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
     128  gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
     129  gfits_scan (&catalog[0].header, "RA1",  "%lf", 1, &Rmax);
     130  gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax);
     131
     132  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     133
     134  float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin));
     135  assert (AREA > 0);
     136
     137  off_t Nmax = MaxDensityValue * AREA;
     138  if (subcatalog[0].Naverage <= Nmax) {
     139    if (VERBOSE) {
     140      fprintf (stderr, "subcatalog has less than the max density\n");
     141    }
     142    return (TRUE);
     143  }
     144
     145  off_t Naverage = subcatalog[0].Naverage;
     146
     147  // select a random subset of Nmax stars from subcatalog using Fisher-Yates
     148
     149  // we are going to select Nmax entries by generating a random-sorted index list
     150  off_t *index, tmp, i, j, ave;
     151  ALLOCATE (index, off_t, Naverage);
     152  for (i = 0; i < Naverage; i++) {
     153    index[i] = i;
     154  }
     155  for (i = 0; i < Naverage; i++) {
     156    j = (Naverage - i) * drand48() + i; // a number between i and Naverage
     157    tmp = index[j];
     158    index[j] = index[i];
     159    index[i] = tmp;
     160  }
     161
     162  // count the number of measurements this selection will yield
     163  off_t NMEASURE = 0;
     164  for (i = 0; i < Nmax; i++) {
     165    ave = index[i];
     166    NMEASURE += subcatalog[0].average[ave].Nmeasure;
     167  }
     168
     169  // allocate the output data
     170  ALLOCATE (tmpcatalog.average, Average, Nmax);
     171  ALLOCATE (tmpcatalog.measure, Measure, NMEASURE);
     172  ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt);
     173
     174  off_t Nmeasure = 0;
     175
     176  // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links)
     177  for (i = 0; i < Nmax; i++) {
     178    ave = index[i];
     179    tmpcatalog.average[i] = subcatalog[0].average[ave];
     180    tmpcatalog.average[i].measureOffset = Nmeasure;
     181    for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) {
     182      off_t offset = subcatalog[0].average[ave].measureOffset + j;
     183      tmpcatalog.measure[Nmeasure] = subcatalog[0].measure[offset];
     184      tmpcatalog.measure[Nmeasure].averef = i;
     185      Nmeasure ++;
     186    }
     187  }
     188
     189  if (VERBOSE) {
     190    fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n",
     191             Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  catalog[0].filename);
     192  }
     193
     194  free (subcatalog[0].average);
     195  free (subcatalog[0].measure);
     196  free (subcatalog[0].secfilt);
     197
     198  subcatalog[0].average = tmpcatalog.average;
     199  subcatalog[0].measure = tmpcatalog.measure;
     200  subcatalog[0].secfilt = tmpcatalog.secfilt;
     201  subcatalog[0].Naverage = Nmax;
     202  subcatalog[0].Nmeasure = Nmeasure;
     203  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     204  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     205
     206  return (TRUE);
     207}
     208
  • trunk/Ohana/src/relastro/src/load_images.c

    r29001 r31664  
    4444  MARKTIME("  select images: %f sec\n", dtime);
    4545
    46   gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
     46  // generate db->vtable from db->ftable based on the selection
     47  // XXX does this simply duplicate the memory needlessly?  we recreate these lines
     48  // in reload_images.  If we had saved the line numbers, we could avoid this
     49  // vtable points *another* copy of the subset rows
     50  // (the later call to 'reload_images' copies the subset elements back on top of
     51  // the rows of the vtable)
     52  // gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
     53  // MARKTIME("converted ftable to vtable: %f sec\n", dtime);
    4754
    4855  initImages (subset, Nsubset);
Note: See TracChangeset for help on using the changeset viewer.