IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:34:39 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201 (substantially changes to the kernel matching code; updates to pmDetection container, added pmPattern, etc)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryObjects.c

    r26359 r26893  
    108108        }
    109109
    110         if (found1->data.S8[i]) {
    111             i++;
    112             continue;
    113         }
    114         if (found2->data.S8[j]) {
    115             j++;
    116             continue;
    117         }
     110        if (found1->data.S8[i]) {
     111            i++;
     112            continue;
     113        }
     114        if (found2->data.S8[j]) {
     115            j++;
     116            continue;
     117        }
    118118
    119119        jStart = j;
     
    128128                continue;
    129129            }
    130             if (found2->data.S8[j]) {
    131                 j++;
    132                 continue;
    133             }
     130            if (found2->data.S8[j]) {
     131                j++;
     132                continue;
     133            }
    134134
    135135            // got a match; add to output list
     
    138138            psFree (match);
    139139
    140             found1->data.S8[i] = 1;
    141             found2->data.S8[j] = 1;
     140            found1->data.S8[i] = 1;
     141            found2->data.S8[j] = 1;
    142142
    143143            j++;
     
    196196    psArray *matches = match_lists(x1, y1, x2, y2, sorted1, sorted2, RADIUS); \
    197197    \
    198     psFree((void *)sorted1); \
    199     psFree((void *)sorted2); \
     198    psFree(sorted1); \
     199    psFree(sorted2); \
    200200    psFree(x1); \
    201201    psFree(y1); \
     
    314314    if (!xRes) abort();
    315315    psFree (xFit);
    316    
     316
    317317    psVector *yFit = psPolynomial2DEvalVector (map->y, X, Y);
    318318    if (!yFit) abort();
     
    322322
    323323    // 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 
     324    // XXX for now, generate a position error based on the magnitude error
    325325    psVector *xErr     = psVectorAllocEmpty (match->n, PS_TYPE_F32);
    326326    psVector *yErr     = psVectorAllocEmpty (match->n, PS_TYPE_F32);
     
    329329
    330330    for (int i = 0; i < match->n; i++) {
    331         if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
     331        if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
    332332        pmAstromMatch *pair = match->data[i];
    333333        pmAstromObj *rawStar = raw->data[pair->raw];
     
    335335        if (rawStar->dMag > 0.02) continue;
    336336
    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]);
     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]);
    354354    }
    355355
     
    434434    // Get the minimum and maximum values
    435435    if (!psVectorStats(stats, myVector, NULL, NULL, 0)) {
    436         psFree(stats);
    437         return NAN;
     436        psFree(stats);
     437        return NAN;
    438438    }
    439439    min = stats->min;
    440440    max = stats->max;
    441441    if (isnan(min) || isnan(max)) {
    442         psFree(stats);
    443         return NAN;
     442        psFree(stats);
     443        return NAN;
    444444    }
    445445
     
    448448    // If all data points have the same value, then we set the appropriate members of stats and return.
    449449    if (fabs(max - min) <= FLT_EPSILON) {
    450         psFree (stats);
    451         return 0.0;
    452     }
    453    
    454     // Define the histogram bin size. 
     450        psFree (stats);
     451        return 0.0;
     452    }
     453
     454    // Define the histogram bin size.
    455455    float binSize = 0.001;
    456456    long numBins = PS_MIN(100000, (max - min) / binSize); // Number of bins
     
    463463
    464464    if (!psVectorHistogram(histogram, myVector, NULL, NULL, 0)) {
    465         // if psVectorHistogram returns false, we have a programming error
    466         psAbort ("Unable to generate histogram");
     465        // if psVectorHistogram returns false, we have a programming error
     466        psAbort ("Unable to generate histogram");
    467467    }
    468468    if (psTraceGetLevel("psModules.astrom") >= 8) {
    469         PS_VECTOR_PRINT_F32(histogram->bounds);
    470         PS_VECTOR_PRINT_F32(histogram->nums);
     469        PS_VECTOR_PRINT_F32(histogram->bounds);
     470        PS_VECTOR_PRINT_F32(histogram->nums);
    471471    }
    472472
     
    475475    cumulative->nums->data.F32[0] = histogram->nums->data.F32[0];
    476476    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];
     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];
    479479    }
    480480    if (psTraceGetLevel("psModules.astrom") >= 8) {
    481         PS_VECTOR_PRINT_F32(cumulative->bounds);
    482         PS_VECTOR_PRINT_F32(cumulative->nums);
     481        PS_VECTOR_PRINT_F32(cumulative->bounds);
     482        PS_VECTOR_PRINT_F32(cumulative->nums);
    483483    }
    484484
     
    837837        }
    838838
    839         if (psTraceGetLevel("psModules.astrom") >= 5) {
    840             char line[16];
    841             psFits *fits = psFitsOpen ("grid.image.fits", "w");
    842             psFitsWriteImage (fits, NULL, gridNP, 0, NULL);
    843             psFitsClose (fits);
    844             fprintf (stderr, "wrote grid image, press return to continue\n");
    845             if (!fgets(line, 15, stdin)) {
    846                 fprintf(stderr, "Something went wrong; continuing.");
     839        if (psTraceGetLevel("psModules.astrom") >= 5) {
     840            char line[16];
     841            psFits *fits = psFitsOpen ("grid.image.fits", "w");
     842            psFitsWriteImage (fits, NULL, gridNP, 0, NULL);
     843            psFitsClose (fits);
     844            fprintf (stderr, "wrote grid image, press return to continue\n");
     845            if (!fgets (line, 15, stdin)) {
     846                fprintf(stderr, "Error waiting for RETURN.");
    847847            }
    848         }
     848        }
    849849
    850850        // only check bins with at least 1/2 of max bin
     
    11911191psArray *pmAstromRadiusMatchUniq (psArray *rawstars, psArray *refstars, psArray *matches) {
    11921192
    1193     // I have the matches between the refstars and the rawstars. 
     1193    // I have the matches between the refstars and the rawstars.
    11941194    // For each refstar, find the single match which has the smallest radius and reject
    1195     // all others. 
     1195    // all others.
    11961196
    11971197    // create an array of refstars->n arrays, each containing all of the matches for the
    1198     // given refstar. 
     1198    // given refstar.
    11991199
    12001200    psArray *refstarMatches = psArrayAlloc (refstars->n);
     
    12021202    for (int i = 0; i < matches->n; i++) {
    12031203
    1204         pmAstromMatch *match = matches->data[i];
    1205        
    1206         // accumulate this refstar match on the array for this refstar (create if needed)
    1207         psArray *refSet = refstarMatches->data[match->ref];
    1208         if (!refSet) {
    1209             refstarMatches->data[match->ref] = psArrayAllocEmpty (8);
    1210             refSet = refstarMatches->data[match->ref];
    1211         }
    1212 
    1213         pmAstromMatchInfo *matchInfo = pmAstromMatchInfoAlloc();
    1214 
    1215         pmAstromObj *refStar = refstars->data[match->ref];
    1216         pmAstromObj *rawStar = rawstars->data[match->raw];
    1217        
    1218         matchInfo->match = match; // reference to the match of interest
    1219         matchInfo->radius = hypot (refStar->FP->x - rawStar->FP->x, refStar->FP->y - rawStar->FP->y);
    1220 
    1221         psArrayAdd (refSet, 8, matchInfo); // matchInfo->match is just a reference
    1222         psFree (matchInfo);
     1204        pmAstromMatch *match = matches->data[i];
     1205
     1206        // accumulate this refstar match on the array for this refstar (create if needed)
     1207        psArray *refSet = refstarMatches->data[match->ref];
     1208        if (!refSet) {
     1209            refstarMatches->data[match->ref] = psArrayAllocEmpty (8);
     1210            refSet = refstarMatches->data[match->ref];
     1211        }
     1212
     1213        pmAstromMatchInfo *matchInfo = pmAstromMatchInfoAlloc();
     1214
     1215        pmAstromObj *refStar = refstars->data[match->ref];
     1216        pmAstromObj *rawStar = rawstars->data[match->raw];
     1217
     1218        matchInfo->match = match; // reference to the match of interest
     1219        matchInfo->radius = hypot (refStar->FP->x - rawStar->FP->x, refStar->FP->y - rawStar->FP->y);
     1220
     1221        psArrayAdd (refSet, 8, matchInfo); // matchInfo->match is just a reference
     1222        psFree (matchInfo);
    12231223    }
    12241224
     
    12291229    for (int i = 0; i < refstars->n; i++) {
    12301230
    1231         psArray *refSet = refstarMatches->data[i];
    1232         if (!refSet) continue;
    1233         if (refSet->n == 0) continue; // not certain how this can happen...
    1234 
    1235         if (refSet->n == 1) {
    1236             pmAstromMatchInfo *matchInfo = refSet->data[0];
    1237             psArrayAdd (unique, 32, matchInfo->match);
    1238             continue;
    1239         }
    1240 
    1241         pmAstromMatchInfo *matchInfo = refSet->data[0];
    1242         float minRadius = matchInfo->radius;
    1243         pmAstromMatch *minMatch = matchInfo->match;
    1244         for (int j = 1; j < refSet->n; j++) {
    1245             pmAstromMatchInfo *matchInfo = refSet->data[j];
    1246             if (minRadius < matchInfo->radius) continue;
    1247             minMatch = matchInfo->match;
    1248             minRadius = matchInfo->radius;
    1249         }
    1250        
    1251         psArrayAdd (unique, 32, minMatch); // minMatch is just a reference to a match on matches,
     1231        psArray *refSet = refstarMatches->data[i];
     1232        if (!refSet) continue;
     1233        if (refSet->n == 0) continue; // not certain how this can happen...
     1234
     1235        if (refSet->n == 1) {
     1236            pmAstromMatchInfo *matchInfo = refSet->data[0];
     1237            psArrayAdd (unique, 32, matchInfo->match);
     1238            continue;
     1239        }
     1240
     1241        pmAstromMatchInfo *matchInfo = refSet->data[0];
     1242        float minRadius = matchInfo->radius;
     1243        pmAstromMatch *minMatch = matchInfo->match;
     1244        for (int j = 1; j < refSet->n; j++) {
     1245            pmAstromMatchInfo *matchInfo = refSet->data[j];
     1246            if (minRadius < matchInfo->radius) continue;
     1247            minMatch = matchInfo->match;
     1248            minRadius = matchInfo->radius;
     1249        }
     1250
     1251        psArrayAdd (unique, 32, minMatch); // minMatch is just a reference to a match on matches,
    12521252    }
    12531253
Note: See TracChangeset for help on using the changeset viewer.