Changeset 26230
- Timestamp:
- Nov 20, 2009, 3:25:23 PM (17 years ago)
- Location:
- branches/eam_branches/20091113/psModules/src/astrom
- Files:
-
- 2 edited
-
pmAstrometryObjects.c (modified) (5 diffs)
-
pmAstrometryObjects.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091113/psModules/src/astrom/pmAstrometryObjects.c
r26197 r26230 37 37 #include "pmKapaPlots.h" 38 38 #include "pmAstrometryVisual.h" 39 40 // XXX this is defined in pmPSFtry.h, which makes no sense 41 float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction); 39 42 40 43 #define PM_ASTROMETRYOBJECTS_DEBUG 1 … … 283 286 return results; 284 287 } 285 psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", results->xStats->clippedMean, results->xStats->clippedStdev, results->xStats->clippedNvalues, x->n); 288 // psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", results->xStats->clippedMean, results->xStats->clippedStdev, results->xStats->clippedNvalues, x->n); 289 psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", results->xStats->robustMedian, results->xStats->robustStdev, results->xStats->clippedNvalues, x->n); 286 290 287 291 if (!psVectorClipFitPolynomial2D (map->y, results->yStats, mask, 0xff, y, wt, X, Y)) { … … 296 300 return results; 297 301 } 298 psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", results->yStats->clippedMean, results->yStats->clippedStdev, results->yStats->clippedNvalues, y->n); 302 // psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", results->yStats->clippedMean, results->yStats->clippedStdev, results->yStats->clippedNvalues, y->n); 303 psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", results->yStats->robustMedian, results->yStats->robustStdev, results->yStats->clippedNvalues, y->n); 299 304 } 300 305 results->xStats->clipIter = stats->clipIter; 301 306 results->yStats->clipIter = stats->clipIter; 302 307 303 # if (0) 304 // XXX calculate the 90%-ile and the systematic scatter for each direction. 308 // *** calculate the 90%-ile and the systematic scatter for each direction. 309 310 // generate the X residual vector 305 311 psVector *xFit = psPolynomial2DEvalVector (map->x, X, Y); 306 312 if (!xFit) abort(); 307 psVector *xRes = psBinaryOp (x, "-", xFit);313 psVector *xRes = (psVector *) psBinaryOp (NULL, x, "-", xFit); 308 314 if (!xRes) abort(); 309 310 float dXsys = psVectorSystematicError (xRes, xErr, 0.05); 311 # endif 315 psFree (xFit); 316 317 psVector *yFit = psPolynomial2DEvalVector (map->y, X, Y); 318 if (!yFit) abort(); 319 psVector *yRes = (psVector *) psBinaryOp (NULL, y, "-", yFit); 320 if (!yRes) abort(); 321 psFree (yFit); 322 323 // extract a high-quality subset (unmasked, S/N > XXX) and position errors 324 // XXX for now, generate a position error based on the magnitude error 325 psVector *xErr = psVectorAllocEmpty (match->n, PS_TYPE_F32); 326 psVector *yErr = psVectorAllocEmpty (match->n, PS_TYPE_F32); 327 psVector *xResGood = psVectorAllocEmpty (match->n, PS_TYPE_F32); 328 psVector *yResGood = psVectorAllocEmpty (match->n, PS_TYPE_F32); 329 330 for (int i = 0; i < match->n; i++) { 331 if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue; 332 pmAstromMatch *pair = match->data[i]; 333 pmAstromObj *rawStar = raw->data[pair->raw]; 334 if (!isfinite(rawStar->dMag)) continue; 335 if (rawStar->dMag > 0.02) continue; 336 337 // two likely failure values: NAN or 0.0 --> use dMag in this case 338 float xErrValue, yErrValue; 339 if (isfinite(rawStar->chip->xErr) && (rawStar->chip->xErr > 0.0)) { 340 xErrValue = rawStar->chip->xErr; 341 } else { 342 xErrValue = PS_MAX(0.005, rawStar->dMag); 343 } 344 if (isfinite(rawStar->chip->yErr) && (rawStar->chip->yErr > 0.0)) { 345 yErrValue = rawStar->chip->yErr; 346 } else { 347 yErrValue = PS_MAX(0.005, rawStar->dMag); 348 } 349 350 psVectorAppend (xErr, xErrValue); 351 psVectorAppend (yErr, yErrValue); 352 psVectorAppend (xResGood, xRes->data.F32[i]); 353 psVectorAppend (yResGood, yRes->data.F32[i]); 354 } 355 356 results->dXsys = psVectorSystematicError (xResGood, xErr, 0.05); 357 results->dYsys = psVectorSystematicError (yResGood, yErr, 0.05); 358 359 results->dXrange = pmAstromVectorRange (xResGood, 0.1, 0.9, results->xStats->clippedStdev); 360 results->dYrange = pmAstromVectorRange (yResGood, 0.1, 0.9, results->yStats->clippedStdev); 361 362 psTrace ("psModules.astrom", 3, "dXsys: %f, dXrange: %f\n", results->dXsys, results->dXrange); 363 psTrace ("psModules.astrom", 3, "dYsys: %f, dYrange: %f\n", results->dYsys, results->dYrange); 364 365 psFree (xErr); 366 psFree (yErr); 367 psFree (xRes); 368 psFree (yRes); 369 psFree (xResGood); 370 psFree (yResGood); 312 371 313 372 psFree (x); … … 321 380 } 322 381 382 // set the bin closest to the corresponding value. if USE_END is +/- 1, 383 // out-of-range saturates on lower/upper bin REGARDLESS of actual value 384 #define PS_BIN_FOR_VALUE(RESULT, VECTOR, VALUE, USE_END) { \ 385 psVectorBinaryDisectResult result; \ 386 psScalar tmpScalar; \ 387 tmpScalar.type.type = PS_TYPE_F32; \ 388 tmpScalar.data.F32 = (VALUE); \ 389 RESULT = psVectorBinaryDisect (&result, VECTOR, &tmpScalar); \ 390 switch (result) { \ 391 case PS_BINARY_DISECT_PASS: \ 392 break; \ 393 case PS_BINARY_DISECT_OUTSIDE_RANGE: \ 394 psTrace("psModules.astrom", 6, "selected bin outside range"); \ 395 if (USE_END == -1) { RESULT = 0; } \ 396 if (USE_END == +1) { RESULT = VECTOR->n - 1; } \ 397 break; \ 398 case PS_BINARY_DISECT_INVALID_INPUT: \ 399 case PS_BINARY_DISECT_INVALID_TYPE: \ 400 psAbort ("programming error"); \ 401 break; \ 402 } } 403 404 # define PS_BIN_INTERPOLATE(RESULT, VECTOR, BOUNDS, BIN, VALUE) { \ 405 float dX, dY, Xo, Yo, Xt; \ 406 if (BIN == BOUNDS->n - 1) { \ 407 dX = 0.5*(BOUNDS->data.F32[BIN+1] - BOUNDS->data.F32[BIN-1]); \ 408 dY = VECTOR->data.F32[BIN] - VECTOR->data.F32[BIN-1]; \ 409 Xo = 0.5*(BOUNDS->data.F32[BIN+1] + BOUNDS->data.F32[BIN]); \ 410 Yo = VECTOR->data.F32[BIN]; \ 411 } else { \ 412 dX = 0.5*(BOUNDS->data.F32[BIN+2] - BOUNDS->data.F32[BIN]); \ 413 dY = VECTOR->data.F32[BIN+1] - VECTOR->data.F32[BIN]; \ 414 Xo = 0.5*(BOUNDS->data.F32[BIN+1] + BOUNDS->data.F32[BIN]); \ 415 Yo = VECTOR->data.F32[BIN]; \ 416 } \ 417 if (dY != 0) { \ 418 Xt = (VALUE - Yo)*dX/dY + Xo; \ 419 } else { \ 420 Xt = Xo; \ 421 } \ 422 Xt = PS_MIN (BOUNDS->data.F32[BIN+1], PS_MAX(BOUNDS->data.F32[BIN], Xt)); \ 423 psTrace("psModules.astrom", 6, "(Xo, Yo, dX, dY, Xt, Yt) is (%.2f %.2f %.2f %.2f %.2f %.2f)\n", \ 424 Xo, Yo, dX, dY, Xt, VALUE); \ 425 RESULT = Xt; } 426 427 float pmAstromVectorRange (psVector *myVector, float minFrac, float maxFrac, float stdevGuess) { 428 429 psStats *stats = psStatsAlloc(PS_STAT_MIN | PS_STAT_MAX); // Statistics for min and max 430 psHistogram *histogram = NULL; // Histogram of the data 431 psHistogram *cumulative = NULL; // Cumulative histogram of the data 432 float min = NAN, max = NAN; // Mimimum and maximum values 433 434 // Get the minimum and maximum values 435 if (!psVectorStats(stats, myVector, NULL, NULL, 0)) { 436 psFree(stats); 437 return NAN; 438 } 439 min = stats->min; 440 max = stats->max; 441 if (isnan(min) || isnan(max)) { 442 psFree(stats); 443 return NAN; 444 } 445 446 psTrace("psModules.astrom", 5, "Data min/max is (%.2f, %.2f)\n", min, max); 447 448 // If all data points have the same value, then we set the appropriate members of stats and return. 449 if (fabs(max - min) <= FLT_EPSILON) { 450 psFree (stats); 451 return 0.0; 452 } 453 454 // Define the histogram bin size. 455 float binSize = 0.001; 456 long numBins = PS_MIN(100000, (max - min) / binSize); // Number of bins 457 psTrace("psModules.astrom", 5, "Numbins is %ld\n", numBins); 458 psTrace("psModules.astrom", 5, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max); 459 460 // allocate the histogram containers 461 histogram = psHistogramAlloc(min, max, numBins); 462 cumulative = psHistogramAlloc(min, max, numBins); 463 464 if (!psVectorHistogram(histogram, myVector, NULL, NULL, 0)) { 465 // if psVectorHistogram returns false, we have a programming error 466 psAbort ("Unable to generate histogram"); 467 } 468 if (psTraceGetLevel("psModules.astrom") >= 8) { 469 PS_VECTOR_PRINT_F32(histogram->bounds); 470 PS_VECTOR_PRINT_F32(histogram->nums); 471 } 472 473 // Convert the specific histogram to a cumulative histogram 474 // The cumulative histogram data points correspond to the UPPER bound value (N < Bin[i+1]) 475 cumulative->nums->data.F32[0] = histogram->nums->data.F32[0]; 476 for (long i = 1; i < histogram->nums->n; i++) { 477 cumulative->nums->data.F32[i] = cumulative->nums->data.F32[i-1] + histogram->nums->data.F32[i]; 478 cumulative->bounds->data.F32[i-1] = histogram->bounds->data.F32[i]; 479 } 480 if (psTraceGetLevel("psModules.astrom") >= 8) { 481 PS_VECTOR_PRINT_F32(cumulative->bounds); 482 PS_VECTOR_PRINT_F32(cumulative->nums); 483 } 484 485 // Find the bin which contains the first data point above the limit 486 long totalDataPoints = cumulative->nums->data.F32[numBins - 1]; 487 psTrace("psModules.astrom", 6, "Total data points is %ld\n", totalDataPoints); 488 489 // find bin which is the lower bound of the limit value (value[bin] < f < value[bin+1] 490 long binMin; 491 PS_BIN_FOR_VALUE(binMin, cumulative->nums, minFrac * totalDataPoints, 0); 492 psTrace("psModules.astrom", 6, "The bin is %ld (%.4f to %.4f)\n", binMin, cumulative->bounds->data.F32[binMin], cumulative->bounds->data.F32[binMin+1]); 493 494 // Linear interpolation to the limit value in bin units 495 float valueMin; 496 PS_BIN_INTERPOLATE (valueMin, cumulative->nums, cumulative->bounds, binMin, totalDataPoints * minFrac); 497 psTrace("psModules.astrom", 6, "limit value is %f\n", valueMin); 498 499 // find bin which is the lower bound of the limit value (value[bin] < f < value[bin+1] 500 long binMax; 501 PS_BIN_FOR_VALUE(binMax, cumulative->nums, maxFrac * totalDataPoints, 0); 502 psTrace("psModules.astrom", 6, "The bin is %ld (%.4f to %.4f)\n", binMax, cumulative->bounds->data.F32[binMax], cumulative->bounds->data.F32[binMax+1]); 503 504 // Linear interpolation to the limit value in bin units 505 float valueMax; 506 PS_BIN_INTERPOLATE (valueMax, cumulative->nums, cumulative->bounds, binMax, totalDataPoints * maxFrac); 507 psTrace("psModules.astrom", 6, "limit value is %f\n", valueMax); 508 509 // Clean up 510 psFree(histogram); 511 psFree(cumulative); 512 psFree(stats); 513 514 return (valueMax - valueMin); 515 } 323 516 324 517 /****************************************************************************** … … 1057 1250 } 1058 1251 1059 psLogMsg ("ps astro", 3, "generate unique matches to reference stars: %ld matches -> %ld matches\n", matches->n, unique->n);1252 psLogMsg ("psModules.astrom", 3, "generate unique matches to reference stars: %ld matches -> %ld matches\n", matches->n, unique->n); 1060 1253 psFree (refstarMatches); 1061 1254 -
branches/eam_branches/20091113/psModules/src/astrom/pmAstrometryObjects.h
r26197 r26230 96 96 int nMatch; ///< 97 97 double nSigma; ///< 98 double dXsys; ///< systematic error in X 99 double dYsys; ///< systematic error in Y 100 double dXrange; ///< 10% - 90% range X residuals (unmasked, high S/N) 101 double dYrange; ///< 10% - 90% range Y residuals (unmasked, high S/N) 98 102 } 99 103 pmAstromFitResults; … … 355 359 ); 356 360 361 float pmAstromVectorRange (psVector *myVector, float minFrac, float maxFrac, float stdevGuess); 362 357 363 /// @} 358 364 #endif // PM_ASTROMETRY_OBJECTS_H
Note:
See TracChangeset
for help on using the changeset viewer.
