Changeset 40523 for trunk/Ohana/src/opihi/dvo/find_matches.c
- Timestamp:
- Aug 30, 2018, 5:07:23 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/find_matches.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/find_matches.c
r37807 r40523 5 5 // attempt to match every RA,DEC entry with an entry in the catalog. the result is stored in 'index' 6 6 // index >= 0 : valid match; index == -2 : no valid match; index == -1 : not contained by this catalog 7 int find_matches_by_vectors (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index) {7 int find_matches_by_vectors_closest (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index) { 8 8 9 9 off_t i, j, J, Jmin, Npoints, Nmatch; … … 148 148 return (TRUE); 149 149 } 150 151 // attempt to match every RA,DEC entry with an entry in the catalog. the result is stored in 'result' 152 AvselectResult *find_matches_by_vectors_allmatch (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *nresult) { 153 154 off_t i, j, J; 155 double dX, dY, dR, Doff, Dmin, Dmax, Rmin, Rmax; 156 int status; 157 double RADIUS2; 158 Coords tcoords; 159 160 // XXX dvoconvert does not correctly maintain 'sorted' 161 // assert(catalog[0].sorted); 162 163 off_t Npoints = RAvec->Nelements; 164 165 /** allocate local arrays (points) **/ 166 ALLOCATE_PTR (X1, double, Npoints); 167 ALLOCATE_PTR (Y1, double, Npoints); 168 ALLOCATE_PTR (N1, off_t, Npoints); 169 170 ALLOCATE_PTR (inCatalog, int, Npoints); 171 172 /** allocate local arrays (catalog) **/ 173 off_t Nave = catalog[0].Naverage; 174 ALLOCATE_PTR (X2, double, Nave); 175 ALLOCATE_PTR (Y2, double, Nave); 176 ALLOCATE_PTR (N2, off_t, Nave); 177 178 off_t Nresult = 0; 179 off_t NRESULT = 1000; 180 ALLOCATE_PTR (result, AvselectResult, NRESULT); 181 182 /* project onto rectilinear grid with 1 arcsec pixels. the choice of ARC projection has 183 * the advantage that every point in R,D has a mapping to a unique X,Y. However, note 184 * that not all possible X,Y points map back to R,D and the local plate scale changes 185 * far from the projection pole. We use the center of the region (catalog) for crval1,2. 186 */ 187 InitCoords (&tcoords, "DEC--ARC"); 188 tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax); 189 if (region[0].Dmax < 90) { 190 tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax); 191 } else { 192 tcoords.crval2 = 90.0; 193 } 194 tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0; 195 196 // this region includes a boundary layer of size RADIUS 197 if (fabs(region[0].Dmin) < fabs(region[0].Dmax)) { 198 Doff = RAD_DEG*region[0].Dmax; 199 } else { 200 Doff = RAD_DEG*region[0].Dmin; 201 } 202 if (Doff < 80) { 203 Rmin = region[0].Rmin - RADIUS / 3600.0 / cos(Doff); 204 Rmax = region[0].Rmax + RADIUS / 3600.0 / cos(Doff); 205 } else { 206 Rmin = 0.0; 207 Rmax = 360.0; 208 } 209 Dmin = region[0].Dmin - RADIUS / 3600.0; 210 Dmax = region[0].Dmax + RADIUS / 3600.0; 211 212 // identify the entries contained by this catalog 213 for (i = 0; i < Npoints; i++) { 214 inCatalog[i] = FALSE; 215 if (RAvec->elements.Flt[i] < Rmin) continue; 216 if (RAvec->elements.Flt[i] > Rmax) continue; 217 if (DECvec->elements.Flt[i] < Dmin) continue; 218 if (DECvec->elements.Flt[i] > Dmax) continue; 219 inCatalog[i] = TRUE; 220 } 221 222 /* build spatial index (RA sort) referencing input array sequence */ 223 for (i = 0; i < Npoints; i++) { 224 // we need to have a finite number for the sort below; inCatalog == 0 entries are skipped 225 // in the matching process 226 X1[i] = Y1[i] = 0.0; 227 N1[i] = i; 228 if (!inCatalog[i]) continue; 229 status = RD_to_XY (&X1[i], &Y1[i], RAvec->elements.Flt[i], DECvec->elements.Flt[i], &tcoords); 230 assert (status); 231 } 232 if (Npoints > 1) sort_coords_index (X1, Y1, N1, Npoints); 233 234 /* build spatial index (RA sort) */ 235 for (i = 0; i < Nave; i++) { 236 RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords); 237 N2[i] = i; 238 } 239 if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave); 240 241 /* choose a radius for matches */ 242 RADIUS2 = RADIUS*RADIUS; 243 244 # define NEXTi { i++; continue; } 245 # define NEXTj { j++; continue; } 246 247 /** find matched stars **/ 248 for (i = j = 0; (i < Npoints) && (j < Nave); ) { 249 if (!inCatalog[N1[i]]) NEXTi; 250 if (!finite(X1[i]) || !finite(Y1[i])) NEXTi; 251 if (!finite(X2[j]) || !finite(Y2[j])) NEXTj; 252 253 /* negative dX: j is too large */ 254 dX = X1[i] - X2[j]; 255 if (dX <= -1.02*RADIUS) NEXTi; 256 257 /* positive dX, i is too large */ 258 if (dX >= 1.02*RADIUS) NEXTj; 259 260 /* within match range; look for matches */ 261 for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) { 262 /* find closest match for this detection */ 263 dX = X1[i] - X2[J]; 264 dY = Y1[i] - Y2[J]; 265 dR = dX*dX + dY*dY; 266 if (dR > RADIUS2) continue; 267 268 /*** a match is found, set the result for this entry ***/ 269 result[Nresult].Ncat = N2[J]; 270 result[Nresult].Nseq = N1[i]; 271 result[Nresult].Roff = sqrt(dR); 272 273 Nresult ++; 274 CHECK_REALLOCATE (result, AvselectResult, NRESULT, Nresult, 1000); 275 } 276 NEXTi; 277 } 278 279 free (X1); 280 free (Y1); 281 free (N1); 282 free (N2); 283 free (X2); 284 free (Y2); 285 286 *nresult = Nresult; 287 return (result); 288 }
Note:
See TracChangeset
for help on using the changeset viewer.
