IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23233


Ignore:
Timestamp:
Mar 9, 2009, 2:51:27 PM (17 years ago)
Author:
Paul Price
Message:

Adding extra parameter to pmSourceMatchSources: a boolean indicating whether to cull the single sources from the list of matches. Added a function, pmSourceMatchMerge, to merge source lists.

Location:
trunk/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceMatch.c

    r23212 r23233  
    152152
    153153
    154 psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius)
     154psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius, bool cullSingles)
    155155{
    156156    PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL);
     
    220220
    221221        // Match with the master list
    222 
    223         psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
    224         long numMatch = 0;              // Number of matches
    225 
    226         long size = numMaster + numSources; // New size
    227         xMaster = psVectorRealloc(xMaster, size);
    228         yMaster = psVectorRealloc(yMaster, size);
    229         matches = psArrayRealloc(matches, size);
    230 
    231         psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup
    232         for (int j = 0; j < numSources; j++) {
    233             coords->data.F32[0] = xImage->data.F32[j];
    234             coords->data.F32[1] = yImage->data.F32[j];
    235             long index = psTreeNearestWithin(tree, coords, radius); // Match index
    236             if (index >= 0) {
    237                 // Record the match
    238                 pmSourceMatch *match = matches->data[index]; // Match data
    239                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    240                 numMatch++;
    241             } else {
    242                 // Add to the master list
    243                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
    244                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    245                 xMaster->data.F32[numMaster] = xImage->data.F32[j];
    246                 yMaster->data.F32[numMaster] = yImage->data.F32[j];
    247                 matches->data[numMaster] = match;
    248                 numMaster++;
    249                 xMaster->n = yMaster->n = matches->n = numMaster;
    250             }
    251 
    252         }
    253         psFree(coords);
    254         psFree(tree);
    255 
     222        {
     223            psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
     224            long numMatch = 0;              // Number of matches
     225
     226            long size = numMaster + numSources; // New size
     227            xMaster = psVectorRealloc(xMaster, size);
     228            yMaster = psVectorRealloc(yMaster, size);
     229            matches = psArrayRealloc(matches, size);
     230
     231            psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup
     232            for (int j = 0; j < numSources; j++) {
     233                coords->data.F32[0] = xImage->data.F32[j];
     234                coords->data.F32[1] = yImage->data.F32[j];
     235                long index = psTreeNearestWithin(tree, coords, radius); // Match index
     236                if (index >= 0) {
     237                    // Record the match
     238                    pmSourceMatch *match = matches->data[index]; // Match data
     239                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
     240                    numMatch++;
     241                } else {
     242                    // Add to the master list
     243                    pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     244                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
     245                    xMaster->data.F32[numMaster] = xImage->data.F32[j];
     246                    yMaster->data.F32[numMaster] = yImage->data.F32[j];
     247                    matches->data[numMaster] = match;
     248                    numMaster++;
     249                    xMaster->n = yMaster->n = matches->n = numMaster;
     250                }
     251
     252            }
     253            psFree(coords);
     254            psFree(tree);
     255        }
    256256
    257257    match_image_done:
     
    263263    }
    264264
    265     // Now cull the matches that contain only a single star
    266     int numGood = 0;                    // Number of good matches
     265    if (cullSingles) {
     266        // Now cull the matches that contain only a single star
     267        int numGood = 0;                    // Number of good matches
     268        for (int i = 0; i < matches->n; i++) {
     269            pmSourceMatch *match = matches->data[i]; // Match of interest
     270            if (match->num > 1) {
     271                if (i != numGood) {
     272                    psFree(matches->data[numGood]);
     273                    matches->data[numGood] = psMemIncrRefCounter(match);
     274                }
     275                numGood++;
     276            }
     277        }
     278        matches->n = numGood;
     279        for (int i = numGood; i < numMaster; i++) {
     280            psFree(matches->data[i]);
     281            matches->data[i] = NULL;
     282        }
     283    }
     284
     285    return matches;
     286}
     287
     288
     289psArray *pmSourceMatchMerge(psArray *sourceArrays, float radius)
     290{
     291    PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL);
     292    PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, NULL);
     293
     294    psArray *matches = pmSourceMatchSources(sourceArrays, radius, false); // Source matches
     295    if (!matches) {
     296        psError(PS_ERR_UNKNOWN, false, "Unable to match source lists.");
     297        return NULL;
     298    }
     299
     300    int index = 0;                      // Index to current position on list
    267301    for (int i = 0; i < matches->n; i++) {
     302        pmSource *source = NULL;        // Source to put in merged list
    268303        pmSourceMatch *match = matches->data[i]; // Match of interest
    269         if (match->num > 1) {
    270             if (i != numGood) {
    271                 psFree(matches->data[numGood]);
    272                 matches->data[numGood] = psMemIncrRefCounter(match);
    273                 //                psFree(match);
    274             }
    275             numGood++;
    276         }
    277     }
    278     matches->n = numGood;
    279     for (int i = numGood; i < numMaster; i++) {
    280         psFree(matches->data[i]);
    281         matches->data[i] = NULL;
    282     }
     304        for (int j = 0; j < match->num && !source; j++) {
     305            if (!isfinite(match->mag->data.F32[j]) || !isfinite(match->magErr->data.F32[j])) {
     306                continue;
     307            }
     308            int image = match->image->data.S32[j]; // Index of image
     309            int index = match->index->data.S32[j]; // Index of source for image
     310            psArray *list = sourceArrays->data[image]; // List of interest
     311            source = list->data[index];
     312            break;
     313        }
     314
     315        if (source) {
     316            psFree(matches->data[index]);
     317            matches->data[index] = psMemIncrRefCounter(source);
     318            index++;
     319        }
     320    }
     321
     322    // Clear out the rest of the list
     323    int num = index;                    // Number of good sources
     324    for (; index < matches->n; index++) {
     325        psFree(matches->data[index]);
     326        matches->data[index] = NULL;
     327    }
     328    matches->n = num;
    283329
    284330    return matches;
    285331}
    286 
    287332
    288333// Iterate on the star magnitudes and image transparencies
  • trunk/psModules/src/objects/pmSourceMatch.h

    r23212 r23233  
    4848///
    4949/// Returns an array of psSourceMatch
    50 psArray *pmSourceMatchSources(const psArray *sourceArrays, // Array of arrays of sources on each image
    51                               float radius // Correlation radius
     50psArray *pmSourceMatchSources(const psArray *sourceArrays, ///< Array of arrays of sources on each image
     51                              float radius, ///< Matching radius
     52                              bool cullSingles ///< Cull "matches" with only a single source?
    5253                              );
     54
     55/// Merge two source lists
     56///
     57/// Sources are pulled from the lists into a new list, with no effort made to adjust them.
     58psArray *pmSourceMatchMerge(psArray *sourceArrays, ///< Array of arrays of sources on each image
     59                            float radius ///< Matching radius
     60    );
    5361
    5462/// Perform relative photometry to calibrate images
Note: See TracChangeset for help on using the changeset viewer.