IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 26, 2010, 1:54:17 PM (16 years ago)
Author:
eugene
Message:

add detection->image, image->mosaic optimizations from relastro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/src/select_images.c

    r27435 r27480  
    1313} SkyRegionCoords;
    1414
     15void dsortindex (double *X, off_t *Y, int N);
     16off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     17
    1518Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
    1619 
    1720  Image *image;
    18   off_t i, j, k, m;
    19   off_t *line_number, nimage, NIMAGE;
     21  off_t i, j, k, m, nStart, iSky, nimage, NIMAGE;
     22  off_t *line_number;
    2023  int InRange, ecode, found;
    2124  double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
     
    2326  SkyRegionCoords *skycoords;
    2427 
     28  double *RmaxSky;
     29  off_t *index;
     30
    2531  if (skylist[0].Nregions < 1) {
    2632    *Nimage = 0;
     
    3844
    3945  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     46
     47  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
     48  ALLOCATE (index, off_t, skylist[0].Nregions);
    4049
    4150  /* compare with each region file */
     
    5665    skycoords[i].Yc[4] = skycoords[i].Yc[0];   
    5766
     67    RmaxSky[i] = skylist[0].regions[i][0].Rmax;
     68    index[i] = i;
     69
    5870    dx = 0.02*(skycoords[i].Xc[2] - skycoords[i].Xc[0]);
    5971    dy = 0.02*(skycoords[i].Yc[2] - skycoords[i].Yc[0]);
     
    6577  }
    6678
     79  dsortindex (RmaxSky, index, skylist[0].Nregions);
     80
    6781  if (VERBOSE) fprintf (stderr, "finding images\n");
    6882  BuildChipMatch (timage, Ntimage);
     
    86100    }
    87101   
    88     if (!FindMosaicForImage (timage, Ntimage, i)) continue;
     102    if (!FindMosaicForImage (timage, Ntimage, i)) {
     103      fprintf (stderr, "cannot find mosaic for %lld\n", (long long) i);
     104      continue;
     105    }
    89106
    90107    /* define image corners */
     
    96113    found = FALSE;
    97114
    98     /* transform to ra,dec */
     115    /* transform corners to ra,dec */
     116    double RminImage = 360.0;
    99117    for (j = 0; j < 5; j++) {
    100118      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
    101     }
     119      RminImage = MIN(RminImage, Ri[j]);
     120    }
     121
     122    // RA(nStart) is guaranteed to be < RminImage:
     123    nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions);
    102124
    103125    /* compare with each region file */
    104     for (m = 0; (m < skylist[0].Nregions) && !found; m++) {
     126    for (iSky = 0; (iSky < skylist[0].Nregions) && !found; iSky++) {
     127
     128      m = index[iSky];
    105129
    106130      /* we make positional comparisons in the projection of catalog */
     
    238262}
    239263
     264void dsortindex (double *X, off_t *Y, int N) {
     265
     266# define SWAPFUNC(A,B){ double tmpf; off_t tmpi; \
     267  tmpf = X[A]; X[A] = X[B]; X[B] = tmpf; \
     268  tmpi = Y[A]; Y[A] = Y[B]; Y[B] = tmpi; \
     269}
     270# define COMPARE(A,B)(X[A] < X[B])
     271
     272  OHANA_SORT (N, COMPARE, SWAPFUNC);
     273
     274# undef SWAPFUNC
     275# undef COMPARE
     276
     277}
     278
     279off_t getRegionStartByRA (double R, double *Rref, off_t Nregions) {
     280
     281  // use bisection to find the overlapping mosaic
     282
     283  off_t Nlo, Nhi, N;
     284
     285  // find the last mosaic before start
     286  Nlo = 0; Nhi = Nregions;
     287  while (Nhi - Nlo > 10) {
     288    N = 0.5*(Nlo + Nhi);
     289    if (Rref[N] < R) {
     290      Nlo = MAX(N, 0);
     291    } else {
     292      Nhi = MIN(N, Nregions);
     293    }
     294  }
     295  return (Nlo);
     296}
Note: See TracChangeset for help on using the changeset viewer.