IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 31, 2011, 2:47:28 PM (15 years ago)
Author:
eugene
Message:

speed up mosaic match to detections by limiting the search region and sorting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/relphot/src/select_images.c

    r29001 r30443  
    1515void dsortindex (double *X, off_t *Y, int N);
    1616off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     17
     18# define MARKTIME(MSG,...) { \
     19  float dtime; \
     20  gettimeofday (&stop, (void *) NULL); \
     21  dtime = DTIME (stop, start); \
     22  fprintf (stderr, MSG, __VA_ARGS__); }
    1723
    1824Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
     
    2531  Coords tcoords;
    2632  SkyRegionCoords *skycoords;
    27  
     33  struct timeval start, stop;
     34 
     35  double RmaxSkyRegion, RminSkyRegion, DminSkyRegion, DmaxSkyRegion;
     36
    2837  double *RmaxSky;
    2938  off_t *index;
     
    3544    return NULL;
    3645  }
     46
     47  gettimeofday (&start, (void *) NULL);
    3748
    3849  // the comparison is made in the catalog local projection. below we set crval1,2
     
    4758  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
    4859  ALLOCATE (index, off_t, skylist[0].Nregions);
     60
     61  RminSkyRegion = +360.0;
     62  RmaxSkyRegion = -360.0;
     63  DminSkyRegion = +90.0;
     64  DmaxSkyRegion = -90.0;
    4965
    5066  /* compare with each region file */
     
    7591    skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy;
    7692    skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy;
    77   }
     93
     94    RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin);
     95    RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax);
     96    DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
     97    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
     98  }
     99  MARKTIME("create sky region coords: %f sec\n", dtime);
    78100
    79101  dsortindex (RmaxSky, index, skylist[0].Nregions);
     102  MARKTIME("sort sky coords: %f sec\n", dtime);
    80103
    81104  if (VERBOSE) fprintf (stderr, "finding images\n");
    82105  BuildChipMatch (timage, Ntimage);
     106  MARKTIME("build chip match: %f sec\n", dtime);
    83107
    84108  nimage = 0;
     
    100124    }
    101125   
     126    // this adds 1.3 sec for 3M images
    102127    if (!FindMosaicForImage (timage, Ntimage, i)) {
    103128      fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
     
    113138    found = FALSE;
    114139
    115     /* transform corners to ra,dec */
     140    /* transform corners to ra,dec -- costs ~3sec for 3M images */
    116141    double RminImage = 360.0;
     142    double RmaxImage =   0.0;
     143    double DminImage = +90.0;
     144    double DmaxImage = -90.0;
    117145    for (j = 0; j < 5; j++) {
    118146      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
    119147      RminImage = MIN(RminImage, Ri[j]);
    120     }
    121 
    122     // RA(nStart) is guaranteed to be < RminImage:
     148      RmaxImage = MAX(RmaxImage, Ri[j]);
     149      DminImage = MIN(DminImage, Di[j]);
     150      DmaxImage = MAX(DmaxImage, Di[j]);
     151    }
     152    if (RmaxImage - RminImage > 180.0) {
     153        double tmp = RminImage;
     154        RmaxImage = RminImage;
     155        RminImage = tmp - 360.0;
     156    }
     157   
     158    // check that this image is even in range of the searched region
     159    if (DminImage > DmaxSkyRegion) continue;
     160    if (DmaxImage < DminSkyRegion) continue;
     161   
     162    // the sky region RA is defined to be 0 - 360.0
     163    if (RminImage > RmaxSkyRegion) continue;
     164    if (RmaxImage < RminSkyRegion) continue;
     165
     166    // RA(nStart) is guaranteed to be < RminImage: -- costs 0.5sec for 3M images
    123167    nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions);
    124168
    125169    /* compare with each region file */
    126     for (iSky = 0; (iSky < skylist[0].Nregions) && !found; iSky++) {
     170    for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) {
    127171
    128172      m = index[iSky];
     
    174218    }
    175219  }
    176      
     220  MARKTIME("finish image selection: %f sec\n", dtime);
     221
    177222  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage);
    178223
     
    295340  return (Nlo);
    296341}
     342
     343off_t getRegionStopByRA (double R, double *Rref, off_t Nregions) {
     344
     345  // use bisection to find the overlapping mosaic
     346
     347  off_t Nlo, Nhi, N;
     348
     349  // find the last mosaic before start
     350  Nlo = 0; Nhi = Nregions;
     351  while (Nhi - Nlo > 10) {
     352    N = 0.5*(Nlo + Nhi);
     353    if (Rref[N] < R) {
     354      Nlo = MAX(N, 0);
     355    } else {
     356      Nhi = MIN(N, Nregions);
     357    }
     358  }
     359  return (Nlo);
     360}
Note: See TracChangeset for help on using the changeset viewer.