IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30474


Ignore:
Timestamp:
Feb 3, 2011, 9:21:49 AM (15 years ago)
Author:
eugene
Message:

speed up select_images with better range checking; correctly handle bounaries of DIS images

File:
1 edited

Legend:

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

    r29001 r30474  
    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;
     
    4049    return NULL;
    4150  }
     51
     52  gettimeofday (&start, (void *) NULL);
    4253
    4354  // the comparison is made in the catalog local projection. below we set crval1,2
     
    5263  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
    5364  ALLOCATE (index, off_t, skylist[0].Nregions);
     65
     66  RminSkyRegion = +360.0;
     67  RmaxSkyRegion = -360.0;
     68  DminSkyRegion = +90.0;
     69  DmaxSkyRegion = -90.0;
    5470
    5571  /* compare with each region file */
     
    8096    skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy;
    8197    skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy;
    82   }
     98
     99    RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin);
     100    RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax);
     101    DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
     102    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
     103  }
     104  MARKTIME("create sky region coords: %f sec\n", dtime);
    83105
    84106  dsortindex (RmaxSky, index, skylist[0].Nregions);
     107  MARKTIME("sort sky coords: %f sec\n", dtime);
    85108
    86109  if (VERBOSE) fprintf (stderr, "finding images\n");
    87110  BuildChipMatch (timage, Ntimage);
     111  MARKTIME("build chip match: %f sec\n", dtime);
    88112
    89113  nimage = 0;
     
    124148    }
    125149
    126     /* define image corners */
    127     Xi[0] = 0;            Yi[0] = 0;
    128     Xi[1] = timage[i].NX; Yi[1] = 0;
    129     Xi[2] = timage[i].NX; Yi[2] = timage[i].NY;
    130     Xi[3] = 0;            Yi[3] = timage[i].NY;
    131     Xi[4] = 0;            Yi[4] = 0;
     150    /* define image corners - note the DIS images (mosaic phu) are special */
     151    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
     152      Xi[0] = -0.5*timage[i].NX; Yi[0] = -0.5*timage[i].NY;
     153      Xi[1] = +0.5*timage[i].NX; Yi[1] = -0.5*timage[i].NY;
     154      Xi[2] = +0.5*timage[i].NX; Yi[2] = +0.5*timage[i].NY;
     155      Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY;
     156      Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY;
     157    } else {
     158      Xi[0] = 0;            Yi[0] = 0;
     159      Xi[1] = timage[i].NX; Yi[1] = 0;
     160      Xi[2] = timage[i].NX; Yi[2] = timage[i].NY;
     161      Xi[3] = 0;            Yi[3] = timage[i].NY;
     162      Xi[4] = 0;            Yi[4] = 0;
     163    }
    132164    found = FALSE;
    133165
    134166    /* transform corners to ra,dec */
    135167    double RminImage = 360.0;
     168    double RmaxImage =   0.0;
     169    double DminImage = +90.0;
     170    double DmaxImage = -90.0;
    136171    for (j = 0; j < 5; j++) {
    137172      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
    138173      RminImage = MIN(RminImage, Ri[j]);
    139     }
     174      RmaxImage = MAX(RmaxImage, Ri[j]);
     175      DminImage = MIN(DminImage, Di[j]);
     176      DmaxImage = MAX(DmaxImage, Di[j]);
     177    }
     178    if (RmaxImage - RminImage > 180.0) {
     179        double tmp = RminImage;
     180        RmaxImage = RminImage;
     181        RminImage = tmp - 360.0;
     182    }
     183
     184    // check that this image is even in range of the searched region
     185    if (DminImage > DmaxSkyRegion) continue;
     186    if (DmaxImage < DminSkyRegion) continue;
     187   
     188    // the sky region RA is defined to be 0 - 360.0
     189    if (RminImage > RmaxSkyRegion) continue;
     190    if (RmaxImage < RminSkyRegion) continue;
    140191
    141192    // RA(nStart) is guaranteed to be < RminImage:
     
    194245    }
    195246  }
    196      
     247  MARKTIME("finish image selection: %f sec\n", dtime);
     248   
    197249  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n",  nimage);
    198250
Note: See TracChangeset for help on using the changeset viewer.