IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26197


Ignore:
Timestamp:
Nov 19, 2009, 11:32:06 AM (17 years ago)
Author:
eugene
Message:

add function to reduce matches to best unique set

Location:
branches/eam_branches/20091113
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091113/psModules/src/astrom/pmAstrometryObjects.c

    r26164 r26197  
    973973*/
    974974
     975/*****************************************************************************/
     976static void pmAstromMatchInfoFree (pmAstromMatchInfo *info)
     977{
     978    if (info == NULL) return;
     979    return;
     980}
     981
     982
     983/*****************************************************************************/
     984pmAstromMatchInfo *pmAstromMatchInfoAlloc()
     985{
     986    pmAstromMatchInfo *info = psAlloc (sizeof(pmAstromMatchInfo));
     987    psMemSetDeallocator(info, (psFreeFunc) pmAstromMatchInfoFree);
     988
     989    info->match = NULL;
     990    info->radius = NAN;
     991
     992    return (info);
     993}
     994
     995// generate a unique set of matches (choose closest match)
     996psArray *pmAstromRadiusMatchUniq (psArray *rawstars, psArray *refstars, psArray *matches) {
     997
     998    // I have the matches between the refstars and the rawstars. 
     999    // For each refstar, find the single match which has the smallest radius and reject
     1000    // all others. 
     1001
     1002    // create an array of refstars->n arrays, each containing all of the matches for the
     1003    // given refstar. 
     1004
     1005    psArray *refstarMatches = psArrayAlloc (refstars->n);
     1006
     1007    for (int i = 0; i < matches->n; i++) {
     1008
     1009        pmAstromMatch *match = matches->data[i];
     1010       
     1011        // accumulate this refstar match on the array for this refstar (create if needed)
     1012        psArray *refSet = refstarMatches->data[match->ref];
     1013        if (!refSet) {
     1014            refstarMatches->data[match->ref] = psArrayAllocEmpty (8);
     1015            refSet = refstarMatches->data[match->ref];
     1016        }
     1017
     1018        pmAstromMatchInfo *matchInfo = pmAstromMatchInfoAlloc();
     1019
     1020        pmAstromObj *refStar = refstars->data[match->ref];
     1021        pmAstromObj *rawStar = rawstars->data[match->raw];
     1022       
     1023        matchInfo->match = match; // reference to the match of interest
     1024        matchInfo->radius = hypot (refStar->FP->x - rawStar->FP->x, refStar->FP->y - rawStar->FP->y);
     1025
     1026        psArrayAdd (refSet, 8, matchInfo); // matchInfo->match is just a reference
     1027        psFree (matchInfo);
     1028    }
     1029
     1030    // we now have a set of matches for each refstar and their distances; create a new set
     1031    // keeping only the closest entry for each match
     1032
     1033    psArray *unique = psArrayAllocEmpty (PS_MAX(16, matches->n / 2));
     1034    for (int i = 0; i < refstars->n; i++) {
     1035
     1036        psArray *refSet = refstarMatches->data[i];
     1037        if (!refSet) continue;
     1038        if (refSet->n == 0) continue; // not certain how this can happen...
     1039
     1040        if (refSet->n == 1) {
     1041            pmAstromMatchInfo *matchInfo = refSet->data[0];
     1042            psArrayAdd (unique, 32, matchInfo->match);
     1043            continue;
     1044        }
     1045
     1046        pmAstromMatchInfo *matchInfo = refSet->data[0];
     1047        float minRadius = matchInfo->radius;
     1048        pmAstromMatch *minMatch = matchInfo->match;
     1049        for (int j = 1; j < refSet->n; j++) {
     1050            pmAstromMatchInfo *matchInfo = refSet->data[j];
     1051            if (minRadius < matchInfo->radius) continue;
     1052            minMatch = matchInfo->match;
     1053            minRadius = matchInfo->radius;
     1054        }
     1055       
     1056        psArrayAdd (unique, 32, minMatch); // minMatch is just a reference to a match on matches,
     1057    }
     1058
     1059    psLogMsg ("psastro", 3, "generate unique matches to reference stars: %ld matches -> %ld matches\n", matches->n, unique->n);
     1060    psFree (refstarMatches);
     1061
     1062    return unique;
     1063}
  • branches/eam_branches/20091113/psModules/src/astrom/pmAstrometryObjects.h

    r24021 r26197  
    5454typedef struct
    5555{
    56     int raw;                             ///< What is this?
    57     int ref;                             ///< What is this?
     56    int raw;                             ///< reference to the rawstar entry
     57    int ref;                             ///< reference to the refstar entry
    5858}
    5959pmAstromMatch;
     60
     61
     62/*
     63 * The pmAstromMatchInfo structure is used to generate a unique set of matches
     64 */
     65typedef struct
     66{
     67    pmAstromMatch *match;               ///< reference to the match
     68    float radius;                       ///< distance between the object
     69}
     70pmAstromMatchInfo;
    6071
    6172
     
    121132);
    122133
     134psArray *pmAstromRadiusMatchUniq (psArray *refstars, psArray *rawstars, psArray *matches);
    123135
    124136pmAstromStats *pmAstromStatsAlloc(void);
  • branches/eam_branches/20091113/psastro/src/psastroMosaicSetMatch.c

    r26167 r26197  
    2626    double RADIUS = psMetadataLookupF32 (&status, recipe, radiusWord);
    2727    if (!status) {
    28         psError(PS_ERR_IO, false, "Failed to lookup matching radius: %s", radiusWord);
    29         psFree (view);
    30         return false;
     28        psAbort("Failed to lookup matching radius: %s", radiusWord);
     29    }
     30
     31    int uniqIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.UNIQ.ITER");
     32    if (!status) {
     33        psAbort("Failed to lookup matching PSASTRO.MOSAIC.UNIQ.ITER");
    3134    }
    3235
     
    6972                psTrace ("psastro", 4, "Matched %ld refstars\n", matches->n);
    7073
     74                if (iteration >= uniqIter) {
     75                    psArray *unique = pmAstromRadiusMatchUniq (rawstars, refstars, matches);
     76                    if (!unique) {
     77                        psLogMsg ("psastro", 3, "failed to generate a uniq set of matched sources\n");
     78                        return false;
     79                    }
     80                    psFree (matches);
     81                    matches = unique;
     82                }
     83
    7184                pmAstromVisualPlotMosaicMatches(rawstars, refstars, matches, iteration, recipe);
    7285
  • branches/eam_branches/20091113/psastro/src/psastroOneChipFit.c

    r26168 r26197  
    6666
    6767        if (iter >= uniqIter) {
    68           if (!pmAstromRadiusMatchUniq (rawstars, refstars, match)) {
    69             psLogMsg ("psastro", 3, "failed to generate a uniq find radius-matched sources\n");
    70             return false;
    71           }
     68            psArray *unique = pmAstromRadiusMatchUniq (rawstars, refstars, match);
     69            if (!unique) {
     70                psLogMsg ("psastro", 3, "failed to generate a uniq set of matched sources\n");
     71                return false;
     72            }
     73            psFree (match);
     74            match = unique;
    7275        }
    7376
Note: See TracChangeset for help on using the changeset viewer.