Changeset 41914
- Timestamp:
- Nov 11, 2021, 11:10:31 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-ps1-20211104/psModules/src/astrom/pmAstrometryObjects.c
r41892 r41914 41 41 float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction); 42 42 float pmAstrom2DSystematics (psVector *xPos, psVector *yPos, psVector *value); 43 float pmAstromSubsetSystematics (psVector *value); 43 44 44 45 #define PM_ASTROMETRYOBJECTS_DEBUG 1 … … 442 443 // VAL_COUNT (9) is the (min) goal density, but a single cell may have only MIN_COUNT (7) 443 444 // we have N points. require a min of 9 pts per cell (configurable?). grid is square. 444 // Ncell*Ncell*9 = Npts, Ncell = MIN(sqrt(Npts/9), 5) 445 446 int Ncell = PS_MIN(sqrt((float)(xPos->n / VAL_COUNT)), 2); // have to at least have a 2x2 grid 445 // Ncell*Ncell*9 = Npts, Ncell = MAX(sqrt(Npts/9), 5) 446 447 // XXX : ERROR -- use MAX not MIN 448 int Ncell = PS_MAX(sqrt((float)(xPos->n / VAL_COUNT)), 2); // have to at least have a 2x2 grid 447 449 448 450 // find the range of x,y values 449 float xMin = 1e9, xMax = -1e9, yMin = 1e9, yMax = 1e9;451 float xMin = 1e9, xMax = -1e9, yMin = 1e9, yMax = -1e9; 450 452 for (int i = 0; i < xPos->n; i++) { 451 453 xMin = PS_MIN(xPos->data.F32[i],xMin); … … 479 481 int ix = PS_MIN(PS_MAX(0, (xPos->data.F32[i] - xMin) * xStep), Ncell - 1); 480 482 int iy = PS_MIN(PS_MAX(0, (yPos->data.F32[i] - yMin) * yStep), Ncell - 1); 481 483 482 484 psArray *yBin = xBin->data[ix]; 483 485 psVector *Bin = yBin->data[iy]; … … 504 506 } 505 507 508 // The MIN_COUNT value means that sometimes fewer than 3 bins are any good. 509 // For so few good bins, the stdev is not very meaningful. In that case, let's 510 // just make 3 subgroups and ask about the stdev of those subgroups. 511 if (sample->n < 3) { 512 psFree (xBin); 513 psFree (stats); 514 psFree (sample); 515 516 float result = pmAstromSubsetSystematics (value); 517 return result; 518 } 519 506 520 stats->options = PS_STAT_SAMPLE_STDEV; 507 521 psVectorStats (stats, sample, NULL, NULL, 0); … … 517 531 psFree (sample); 518 532 533 return result; 534 } 535 536 # define SUBSET_NSAMPLE 3 537 // last-ditch attempt to assess the systematic error in the data. Just split into 3 bins, 538 // calculate median in each, and calculate stdev of the subset. The minimum number of 539 // values needed to make this measurement in any sensible way : 3*2 = 6. 540 float pmAstromSubsetSystematics (psVector *value) { 541 542 // give up if too few stars: 543 if (value->n < 2*SUBSET_NSAMPLE) return NAN; 544 545 psVector *sample = psVectorAlloc (SUBSET_NSAMPLE, PS_TYPE_F32); 546 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 547 548 // note that this drops the last 1 or 2 values if value->n % 3 = 1 or 2 549 int nSubset = value->n / SUBSET_NSAMPLE; 550 psVector *subset = psVectorAlloc (nSubset, PS_TYPE_F32); 551 for (int iter = 0; iter < SUBSET_NSAMPLE; iter++) { 552 for (int i = 0; i < nSubset; i++) { 553 subset->data.F32[i] = value->data.F32[i + nSubset*iter]; 554 } 555 556 // psVectorStats resets stats so we can call this repeatedly 557 psVectorStats (stats, subset, NULL, NULL, 0); 558 if (isfinite(stats->sampleMedian)) { 559 sample->data.F32[iter] = stats->sampleMedian; 560 } 561 } 562 563 stats->options = PS_STAT_SAMPLE_STDEV; 564 psVectorStats (stats, sample, NULL, NULL, 0); 565 float result = stats->sampleStdev; 566 567 if (!isfinite(stats->sampleStdev)) { 568 fprintf (stderr, "*** bad solution (2) ***\n"); 569 } 570 571 psFree (stats); 572 psFree (sample); 573 psFree (subset); 574 519 575 return result; 520 576 }
Note:
See TracChangeset
for help on using the changeset viewer.
