IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25208


Ignore:
Timestamp:
Aug 26, 2009, 11:29:27 AM (17 years ago)
Author:
bills
Message:

swap order of loops to speed things up at least 25 %
Now do

for each image { check list of points for ovarlap }

instead of

foreach point { check list of images }

Since the number of images is large and there is some setup time for each
one this is faster

Location:
trunk/Ohana/src/getstar
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h

    r24914 r25208  
    1818Coords *MOSAIC;         // carries the mosaic into ReadImageHeader
    1919
     20typedef struct {
     21    int     id;
     22    double  ra;
     23    double  dec;
     24    int     Nmatches;
     25    int     *matches;
     26    int     arrayLength;
     27} Point;
     28
    2029int WITH_PHU;
    2130int SOLO_PHU;
     
    3342Image *ReadImageFiles (char *filename, int *Nimages);
    3443int ReadImageHeader (Header *header, Image *image);
    35 int *MatchCoords(Image *, int, double, double, int *);
     44int MatchCoords(Image *, int, Point *, int);
    3645
    3746int GetFileMode (Header *header);
    38 // int edge_check (double *x1, double *y1, double *x2, double *y2);
    39 // double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
  • trunk/Ohana/src/getstar/src/MatchCoords.c

    r25106 r25208  
    55
    66/* given coordinate, find images in list that contain the point */
    7 int *MatchCoords (Image *dbImages, int NdbImages, double ra, double dec, int *Nmatch) {
     7int MatchCoords (Image *dbImages, int NdbImages, Point *points, int Npoints) {
    88 
    9   int i, j, N, addtolist, status;
    10   int NMATCH, nmatch, *match;
     9  int i, j, N;
     10  int totalMatches = 0;
    1111  Coords tcoords;
    1212  double r, d;
     
    1515  double xmin, xmax, ymin, ymax;
    1616
    17   *Nmatch = 0;
    18 
    19   /* match represents the subset of overlapping images */
    20   nmatch = 0;
    21   NMATCH = 20;
    22   ALLOCATE (match, int, NMATCH);
    2317
    2418  /* setup links for mosaic WRP and DIS entries */
     
    4943    }
    5044
    51     // transform input point to image coords
    52     double x, y;
    53     int status = RD_to_XY(&x, &y, ra, dec, &dbImages[i].coords);
     45    for (j = 0; j < Npoints; j++) {
     46        Point *pt = points + j;
    5447
    55     if (!status) {
    56         // avoid matching antipodal skycells
    57         continue;
    58     }
     48        // transform input point to image coords
     49        double x, y;
     50        int status = RD_to_XY(&x, &y, pt->ra, pt->dec, &dbImages[i].coords);
    5951
    60     if ((x >= xmin && x <= xmax) && (y >= ymin && y <= ymax)) {
     52        if (!status) {
     53            // avoid matching antipodal skycells
     54            continue;
     55        }
    6156
    62         match[nmatch] = i;
    63         nmatch ++;
    64         if (nmatch == NMATCH) {
    65           NMATCH += 20;
    66           REALLOCATE (match, int, NMATCH);
     57        if ((x >= xmin && x <= xmax) && (y >= ymin && y <= ymax)) {
     58            totalMatches++;
     59
     60            pt->matches[pt->Nmatches] = i;
     61            pt->Nmatches ++;
     62
     63            if (pt->Nmatches == pt->arrayLength) {
     64                pt->arrayLength += 20;
     65                REALLOCATE (pt->matches, int, pt->arrayLength);
     66            }
    6767        }
    6868    }
    69      
    70   }
    71   if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", nmatch);
     69 }
     70 if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", totalMatches);
    7271 
    73   *Nmatch = nmatch;
    74   return (match);
     72 return (totalMatches);
    7573}
    7674 
  • trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r24921 r25208  
    11# include "dvoImagesAtCoords.h"
    22
    3 typedef struct {
    4     int     id;
    5     double  ra;
    6     double  dec;
    7 } Point;
    8 
    93static int readPoints(char *filename, Point **pointsOut);
    10 static int ListImagesAtCoords (Image *dbImages, int id, double ra, double dec, int *matches, int Nmatches);
     4static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints);
    115
    126int main (int argc, char **argv) {
     
    3024  if (astromFile) {
    3125      dbImages = ReadImageFiles(astromFile, &NdbImages);
    32     } else {
     26  } else {
    3327    /*** update the image table ***/
    3428    /* setup image table format and lock */
     
    5347  }
    5448 
    55   Point *pt;
    56   for (i = 0, pt = points; i < Npoints; i++, pt++) {
    57     matches = MatchCoords (dbImages, NdbImages, pt->ra, pt->dec, &Nmatches);
    58     ListImagesAtCoords(dbImages, pt->id, pt->ra, pt->dec, matches, Nmatches);
     49  if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
     50    ListImagesAtCoords(dbImages, points, Npoints);
    5951  }
    60 
     52  // XXX: should we exit with nonzero status if no matches were found?
    6153  exit (0);
    6254}
     
    8375
    8476    while ((Nread = fscanf(f, "%d %lf %lf\n", &pts[Npoints].id, &pts[Npoints].ra, &pts[Npoints].dec)) == 3) {
    85         Npoints++;
    86         if (Npoints >= LEN) {
     77        pts[Npoints].Nmatches = 0;
     78        ALLOCATE(pts[Npoints].matches, int, 20);
     79        pts[Npoints].arrayLength = 20;
     80
     81        if (++Npoints >= LEN) {
    8782            LEN += 20;
    8883            REALLOCATE(pts, Point, LEN);
     
    9994}
    10095
    101 static int ListImagesAtCoords (Image *dbImages, int id, double ra, double dec, int *matches, int Nmatches)
     96static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints)
    10297{
     98  int j;
    10399  int i;
    104   for (i = 0; i < Nmatches; i++) {
    105     int N = matches[i];
     100  for (j = 0; j < Npoints; j++) {
     101      Point *pt = points + j;
     102      for (i = 0; i < pt->Nmatches; i++) {
     103        int N = pt->matches[i];
    106104
    107     char *name;
    108     // output of lookup is filename[class_id.hdr] for astrometry files
    109     char *left_bracket = rindex(dbImages[N].name, '[');
    110     if (left_bracket) {
    111         name = strdup(left_bracket + 1);
    112         // zap the .hdr]
    113         char *dot = index(name, '.');
    114         if (dot) {
    115             *dot = 0;
     105        char *name;
     106        char *copy = NULL;
     107        // output of lookup is filename[class_id.hdr] for astrometry files
     108        char *left_bracket = rindex(dbImages[N].name, '[');
     109        if (left_bracket) {
     110            copy = strdup(left_bracket + 1);
     111            name = copy;
     112            // zap the .hdr]
     113            char *dot = index(name, '.');
     114            if (dot) {
     115                *dot = 0;
     116            }
     117        } else {
     118            name = dbImages[N].name;
    116119        }
    117     } else {
    118         name = dbImages[N].name;
     120        fprintf (stdout, "%d %lf %lf %s\n", pt->id, pt->ra, pt->dec, name);
     121        if  (copy) {
     122            free(copy);
     123        }
    119124    }
    120     fprintf (stdout, "%d %lf %lf %s\n", id, ra, dec, name);
    121125  }
    122126 
Note: See TracChangeset for help on using the changeset viewer.