Changeset 27435 for trunk/Ohana/src/relastro/src/select_images.c
- Timestamp:
- Mar 24, 2010, 11:22:25 AM (16 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/relastro/src/select_images.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/20091201/Ohana merged eligible /branches/eam_branches/largefiles.20100314/Ohana merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/relastro/src/select_images.c
r21508 r27435 13 13 } SkyRegionCoords; 14 14 15 Image *select_images (SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage) { 15 void dsortindex (double *X, off_t *Y, int N); 16 off_t getRegionStartByRA (double R, double *Rref, off_t Nregions); 17 18 Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) { 16 19 17 20 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; 20 23 double Ri[5], Di[5], Xi[5], Yi[5], dx, dy; 21 int *line_number;24 off_t *line_number; 22 25 Coords tcoords; 23 26 SkyRegionCoords *skycoords; 24 27 28 double *RmaxSky; 29 off_t *index; 30 25 31 if (skylist[0].Nregions < 1) { 26 32 *Nimage = 0; … … 38 44 39 45 ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions); 46 47 ALLOCATE (RmaxSky, double, skylist[0].Nregions); 48 ALLOCATE (index, off_t, skylist[0].Nregions); 40 49 41 50 /* compare with each region file */ … … 56 65 skycoords[i].Yc[4] = skycoords[i].Yc[0]; 57 66 67 RmaxSky[i] = skylist[0].regions[i][0].Rmax; 68 index[i] = i; 69 58 70 dx = 0.02*(skycoords[i].Xc[2] - skycoords[i].Xc[0]); 59 71 dy = 0.02*(skycoords[i].Yc[2] - skycoords[i].Yc[0]); … … 65 77 } 66 78 79 dsortindex (RmaxSky, index, skylist[0].Nregions); 80 67 81 if (VERBOSE) fprintf (stderr, "finding images\n"); 68 82 BuildChipMatch (timage, Ntimage); … … 71 85 NIMAGE = 100; 72 86 ALLOCATE (image, Image, NIMAGE); 73 ALLOCATE (line_number, int, NIMAGE);87 ALLOCATE (line_number, off_t, NIMAGE); 74 88 75 89 // go through the complete list of images, selecting ones which overlap any region … … 100 114 } 101 115 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 } 103 120 104 121 /* define image corners */ … … 111 128 112 129 /* transform to ra,dec */ 130 double RminImage = 360.0; 131 // double RmaxImage = 0.0; 113 132 for (j = 0; j < 5; j++) { 114 133 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); 116 140 117 141 /* 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 // } 119 148 120 149 /* we make positional comparisons in the projection of catalog */ … … 122 151 tcoords.crval2 = skycoords[m].Dc; 123 152 124 /* transform to ra,dec*/153 /* transform corner coords to X,Y in this catalog system */ 125 154 InRange = TRUE; 126 155 for (j = 0; (j < 5) && InRange; j++) { … … 161 190 NIMAGE += 100; 162 191 REALLOCATE (image, Image, NIMAGE); 163 REALLOCATE (line_number, int, NIMAGE);192 REALLOCATE (line_number, off_t, NIMAGE); 164 193 } 165 194 } 166 195 } 167 196 168 if (VERBOSE) fprintf (stderr, "found % d images\n",nimage);197 if (VERBOSE) fprintf (stderr, "found %lld images\n", (long long) nimage); 169 198 170 199 REALLOCATE (image, Image, MAX (nimage, 1)); 171 REALLOCATE (line_number, int, MAX (nimage, 1));200 REALLOCATE (line_number, off_t, MAX (nimage, 1)); 172 201 free (skycoords); 173 202 … … 253 282 } 254 283 284 void 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 299 off_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.
