IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33481


Ignore:
Timestamp:
Mar 11, 2012, 10:56:40 PM (14 years ago)
Author:
eugene
Message:

speed up select_images and initMosaic

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

Legend:

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

    r33406 r33481  
    3636
    3737/* find mosaic frames (unique time periods & photcode name matches mosaic) */
    38 void initMosaics (Image *image, off_t Nimage) {
     38void initMosaics_old (Image *image, off_t Nimage) {
    3939
    4040  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
     
    129129
    130130  initMosaicGrid (image, Nimage);
     131
     132  fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
    131133  return;
     134}
     135
     136off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
     137
     138void sort_times (unsigned int *T, int N) {
     139
     140# define SWAPFUNC(A,B){ unsigned int tmp; \
     141  tmp = T[A]; T[A] = T[B]; T[B] = tmp; \
     142}
     143# define COMPARE(A,B)(T[A] < T[B])
     144
     145  OHANA_SORT (N, COMPARE, SWAPFUNC);
     146
     147# undef SWAPFUNC
     148# undef COMPARE
     149
     150}
     151
     152/* find mosaic frames (unique time periods & photcode name matches mosaic) */
     153void initMosaics (Image *image, off_t Nimage) {
     154
     155  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
     156  unsigned int start, stop, *startTimes, *startTimesMosaic;
     157  char *pname;
     158
     159  if (!MOSAIC_ZEROPT) return;
     160
     161  /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no
     162   * entry in the image table that represents this mosaic.  Instead, it is an
     163   * internal construct that defines a group of related images
     164   */
     165
     166  // generate a list of unique start times (these define the mosaics)
     167  ALLOCATE (startTimes, unsigned int, Nimage);
     168  for (i = 0; i < Nimage; i++) {
     169    startTimes[i] = image[i].tzero;
     170  }
     171  sort_times (startTimes, Nimage);
     172 
     173  Nmosaic = 0;
     174  NMOSAIC = 1000;
     175  ALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     176  startTimesMosaic[0] = startTimes[0];
     177
     178  for (i = 0; i < Nimage; i++) {
     179    if (startTimes[i] < startTimesMosaic[Nmosaic]) {
     180      fprintf (stderr, "error?\n");
     181      abort();
     182    }
     183    if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
     184    Nmosaic ++;
     185    if (Nmosaic >= NMOSAIC) {
     186      NMOSAIC += 1000;
     187      REALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     188    }
     189    startTimesMosaic[Nmosaic] = startTimes[i];
     190  }
     191  Nmosaic ++;
     192
     193  // now I have a list of uniq start times, and they are in order
     194  // create the mosaic arrays for these times
     195  ALLOCATE (mosaic, Mosaic, Nmosaic);
     196
     197  ALLOCATE (MosaicToImage, off_t *, Nmosaic);
     198  ALLOCATE (MosaicN_Image, off_t,   Nmosaic);
     199  ALLOCATE (MosaicN_IMAGE, off_t,   Nmosaic);
     200
     201  for (i = 0; i < Nmosaic; i++) {
     202    /* a new mosaic, define ranges */
     203    mosaic[i].start = startTimesMosaic[i];
     204    mosaic[i].stop  = 0;
     205    mosaic[i].Mcal  = 0.0;
     206    mosaic[i].dMcal = 0.0;
     207    mosaic[i].dMsys = 0.0;
     208    mosaic[i].Xm    = 0.0;
     209    mosaic[i].flags = 0;
     210    mosaic[i].secz  = NAN;
     211    mosaic[i].photcode = 0;
     212
     213    MosaicN_IMAGE[i] = 10;
     214    MosaicN_Image[i] = 0;
     215    ALLOCATE (MosaicToImage[i], off_t, MosaicN_IMAGE[i]);
     216    MosaicToImage[i][0] = -1;
     217  }
     218
     219  ALLOCATE (ImageToMosaic, off_t, Nimage); // mosaic to which image belongs
     220
     221  // assign each image to a mosaic
     222  for (i = 0; i < Nimage; i++) {
     223    ImageToMosaic[i] = -1;
     224
     225    /* select valid mosaic images by photcode */
     226    pname = GetPhotcodeNamebyCode (image[i].photcode);
     227    status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
     228    if (status) continue;
     229
     230    /* set image time range */
     231    // start = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1);
     232    // stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
     233
     234    start = image[i].tzero;
     235    stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
     236
     237    j = findMosaic(startTimesMosaic, Nmosaic, start);
     238    if (j == -1) {
     239      fprintf (stderr, "error?\n");
     240      abort();
     241    }
     242
     243    // add reference from image to mosaic
     244    ImageToMosaic[i] = j;
     245
     246    // have we already found this mosaic?
     247    found = (MosaicN_Image[j] > 0);
     248
     249    /* add image to mosaic image list */
     250    MosaicToImage[j][MosaicN_Image[j]] = i;
     251    MosaicN_Image[j] ++;
     252    if (MosaicN_Image[j] == MosaicN_IMAGE[j]) {
     253      MosaicN_IMAGE[j] += 10;
     254      REALLOCATE (MosaicToImage[j], off_t, MosaicN_IMAGE[j]);
     255    }
     256    if (found) continue;
     257   
     258    /* a new mosaic, define ranges */
     259    if (mosaic[j].start != start) {
     260      fprintf (stderr, "error?\n");
     261      abort();
     262    }
     263    mosaic[j].stop  = stop;
     264    mosaic[j].Mcal  = 0.0;
     265    mosaic[j].dMcal = 0.0;
     266    mosaic[j].dMsys = 0.0;
     267    mosaic[j].Xm    = 0.0;
     268    mosaic[j].flags  = image[i].flags;
     269    mosaic[j].secz  = image[i].secz;
     270    mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     271  }
     272
     273  // free this or not?
     274  free (MosaicN_IMAGE);
     275  free (startTimes);
     276  free (startTimesMosaic);
     277
     278  initMosaicGrid (image, Nimage);
     279
     280  fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
     281  return;
     282}
     283
     284// use bisection to find the overlapping mosaic
     285off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start) {
     286
     287  off_t Nlo, Nhi, N;
     288
     289  // find the last mosaic before start
     290  Nlo = 0; // startTimes[Nlo] guaranteed to be <= start
     291  Nhi = Nmosaic - 1; // startTimes[Nhi] guaranteed to be >= start
     292  while (Nhi - Nlo > 10) {
     293    N = 0.5*(Nlo + Nhi);
     294    if (startTimes[N] < start) {
     295      Nlo = MAX(N, 0);
     296    } else {
     297      Nhi = MIN(N, Nmosaic - 1);
     298    }
     299  }
     300
     301  // check for the matched mosaic starting from Nlo
     302  for (N = Nlo; N < Nmosaic; N++) {
     303    if (start > startTimes[N])  continue;
     304    return (N);
     305  }
     306  return (-1);
    132307}
    133308
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/select_images.c

    r33452 r33481  
    2525 
    2626  Image *image;
    27   off_t i, j, k, m, nStart, iSky, nimage, NIMAGE;
     27  off_t i, j, k, m, nStart, iSky, nimage, NIMAGE, D_NIMAGE;
    2828  off_t *line_number;
    2929  int InRange, ecode, found;
     
    6363  DminSkyRegion = +90.0;
    6464  DmaxSkyRegion = -90.0;
     65
     66  D_NIMAGE = 6000;
    6567
    6668  // FILE *ftest = fopen ("relphot.dump.dat", "w");
     
    110112
    111113  nimage = 0;
    112   NIMAGE = 100;
     114  NIMAGE = D_NIMAGE;
    113115  ALLOCATE (image, Image, NIMAGE);
    114116  ALLOCATE (line_number, off_t, NIMAGE);
     
    117119  for (i = 0; i < Ntimage; i++) {
    118120     
     121    if (!(i % 300000)) fprintf (stderr, ".");
     122
    119123    /* exclude images by photcode */
    120124    ecode = GetPhotcodeEquivCodebyCode (timage[i].photcode);
     
    248252    nimage ++;
    249253    if (nimage == NIMAGE) {
    250       NIMAGE += 100;
     254      NIMAGE += D_NIMAGE;
     255      D_NIMAGE = MAX (100000, D_NIMAGE * 1.5);
    251256      REALLOCATE (image, Image, NIMAGE);
    252257      REALLOCATE (line_number, off_t, NIMAGE);
Note: See TracChangeset for help on using the changeset viewer.