IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 11:22:25 AM (16 years ago)
Author:
eugene
Message:

large update merging in changes for Ohana to support large files

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/relastro/src/select_images.c

    r21508 r27435  
    1313} SkyRegionCoords;
    1414
    15 Image *select_images (SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage) {
     15void dsortindex (double *X, off_t *Y, int N);
     16off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     17
     18Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
    1619 
    1720  Image *image;
    18   int i, j, k, m, found, nimage, NIMAGE;
    19   int InRange;
     21  off_t i, j, k, m, nStart, iSky, nimage, NIMAGE;
     22  int InRange, found;
    2023  double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
    21   int *line_number;
     24  off_t *line_number;
    2225  Coords tcoords;
    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);
     
    7185  NIMAGE = 100;
    7286  ALLOCATE (image, Image, NIMAGE);
    73   ALLOCATE (line_number, int, NIMAGE);
     87  ALLOCATE (line_number, off_t, NIMAGE);
    7488 
    7589  // go through the complete list of images, selecting ones which overlap any region
     
    100114    }
    101115   
    102     if (!FindMosaicForImage (timage, Ntimage, i)) continue;
     116    if (!FindMosaicForImage (timage, Ntimage, i)) {
     117      fprintf (stderr, "cannot find mosaic for %lld\n", (long long) i);
     118      continue;
     119    }
    103120
    104121    /* define image corners */
     
    111128
    112129    /* transform to ra,dec */
     130    double RminImage = 360.0;
     131    // double RmaxImage =   0.0;
    113132    for (j = 0; j < 5; j++) {
    114133      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
    115     }
     134      RminImage = MIN(RminImage, Ri[j]);
     135      // RmaxImage = MIN(RmaxImage, Ri[j]);
     136    }
     137
     138    // RA(nStart) is guaranteed to be < RminImage:
     139    nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions);
    116140
    117141    /* compare with each region file */
    118     for (m = 0; (m < skylist[0].Nregions) && !found; m++) {
     142    for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) {
     143
     144      m = index[iSky];
     145      // if (RmaxImage < skylist[0].regions[m][0].Rmin) {
     146      // break;
     147      // }
    119148
    120149      /* we make positional comparisons in the projection of catalog */
     
    122151      tcoords.crval2 = skycoords[m].Dc;
    123152
    124       /* transform to ra,dec */
     153      /* transform corner coords to X,Y in this catalog system */
    125154      InRange = TRUE;
    126155      for (j = 0; (j < 5) && InRange; j++) {
     
    161190        NIMAGE += 100;
    162191        REALLOCATE (image, Image, NIMAGE);
    163         REALLOCATE (line_number, int, NIMAGE);
     192        REALLOCATE (line_number, off_t, NIMAGE);
    164193      }
    165194    }
    166195  }
    167196     
    168   if (VERBOSE) fprintf (stderr, "found %d images\n", nimage);
     197  if (VERBOSE) fprintf (stderr, "found %lld images\n", (long long) nimage);
    169198
    170199  REALLOCATE (image, Image, MAX (nimage, 1));
    171   REALLOCATE (line_number, int, MAX (nimage, 1));
     200  REALLOCATE (line_number, off_t, MAX (nimage, 1));
    172201  free (skycoords);
    173202
     
    253282}
    254283
     284void dsortindex (double *X, off_t *Y, int N) {
     285
     286# define SWAPFUNC(A,B){ double tmpf; off_t tmpi; \
     287  tmpf = X[A]; X[A] = X[B]; X[B] = tmpf; \
     288  tmpi = Y[A]; Y[A] = Y[B]; Y[B] = tmpi; \
     289}
     290# define COMPARE(A,B)(X[A] < X[B])
     291
     292  OHANA_SORT (N, COMPARE, SWAPFUNC);
     293
     294# undef SWAPFUNC
     295# undef COMPARE
     296
     297}
     298
     299off_t getRegionStartByRA (double R, double *Rref, off_t Nregions) {
     300
     301  // use bisection to find the overlapping mosaic
     302
     303  off_t Nlo, Nhi, N;
     304
     305  // find the last mosaic before start
     306  Nlo = 0; Nhi = Nregions;
     307  while (Nhi - Nlo > 10) {
     308    N = 0.5*(Nlo + Nhi);
     309    if (Rref[N] < R) {
     310      Nlo = MAX(N, 0);
     311    } else {
     312      Nhi = MIN(N, Nregions);
     313    }
     314  }
     315  return (Nlo);
     316}
Note: See TracChangeset for help on using the changeset viewer.