IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 4, 2007, 1:56:07 PM (19 years ago)
Author:
Paul Price
Message:

Consolidating some code. Making it so that the convolutions of the reference don't have to be performed twice if the optimum kernel is computed (before, the convolutions were calculated twice --- once in getting the optimum kernel set, and once in calculating the least-squares matrix).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r14713 r14738  
    214214    // Putting important variable declarations here, since they are freed after a "goto" if there is an error.
    215215    psImage *subMask = NULL;            // Mask for subtraction
    216     psArray *stamps = NULL;             // Stamps for matching PSF
    217216    psRegion *region = NULL;            // Iso-kernel region
    218217    psString regionString = NULL;       // String for region
     218    psArray *stamps = NULL;             // Stamps for matching PSF
    219219    psVector *solution = NULL;          // Solution to match PSF
    220220    pmSubtractionKernels *kernels = NULL; // Kernel basis functions
     
    224224    if (stampsName && strlen(stampsName) > 0) {
    225225        psTrace("psModules.imcombine", 3, "Reading stamps from %s...\n", stampsName);
    226         psVector *xStamp = NULL, *yStamp = NULL; // Stamp positions and fluxes
    227226        if (input) {
    228227            // We have x, y because the target is provided by the input image
     
    234233        if (!stampsData) {
    235234            psError(PS_ERR_IO, false, "Unable to read stamps file %s", stampsName);
    236             goto ERROR;
     235            return false;
    237236        }
    238237
    239238        // Correct for IRAF/FITS (unit-offset) positions to C (zero-offset) positions
    240         xStamp = stampsData->data[0];
    241         yStamp = stampsData->data[1];
     239        psVector *xStamp = stampsData->data[0]; // x positions
     240        psVector *yStamp = stampsData->data[1]; // y positions
    242241        psBinaryOp(xStamp, xStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32));
    243242        psBinaryOp(yStamp, yStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32));
     
    251250
    252251    memCheck("mask");
    253 
    254     if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) {
    255         if (!getStamps(&stamps, stampsData, reference, input, subMask, weight, NULL,
    256                        threshold, stampSpacing, targetWidth, size, footprint)) {
    257             goto ERROR;
    258         }
    259         kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder,
    260                                                   stamps, footprint, optThreshold);
    261         // XXX This is not quite the best thing to do here--- we'll find the same set of stamps again later,
    262         // but since we may not be interested in the entire image on the first pass through, we have to blow
    263         // the whole lot away.  The alternative is to mark stamps that are outside the region of interest, and
    264         // ignore them when generating sums and rejecting.
    265         psFree(stamps);
    266         stamps = NULL;
    267 
    268         if (!kernels) {
    269             psErrorClear();
    270             psWarning("Unable to derive optimum ISIS kernel --- switching to default.");
    271         }
    272     }
    273 
    274     if (kernels == NULL) {
    275         // Not an ISIS/GUNK kernel, or the optimum kernel search failed
    276         kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
    277                                                inner, binning, ringsOrder);
    278     }
    279 
    280     psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL", PS_DATA_UNKNOWN,
    281                      "Subtraction kernels", kernels);
    282 
    283     memCheck("kernels");
    284252
    285253    // Get region of interest
     
    307275                        regionString, numCols, numRows);
    308276            }
     277
     278            // Define kernel basis functions
     279            if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) {
     280                if (!getStamps(&stamps, stampsData, reference, input, subMask, weight, NULL,
     281                               threshold, stampSpacing, targetWidth, size, footprint)) {
     282                    goto ERROR;
     283                }
     284                kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder,
     285                                                          stamps, footprint, optThreshold);
     286                if (!kernels) {
     287                    psErrorClear();
     288                    psWarning("Unable to derive optimum ISIS kernel --- switching to default.");
     289                }
     290            }
     291            if (kernels == NULL) {
     292                // Not an ISIS/GUNK kernel, or the optimum kernel search failed
     293                kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
     294                                                       inner, binning, ringsOrder);
     295            }
     296            psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL",
     297                             PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "Subtraction kernels", kernels);
     298
     299            memCheck("kernels");
    309300
    310301            int numRejected = -1;               // Number of rejected stamps in each iteration
     
    422413                goto ERROR;
    423414            }
     415            psFree(kernels);
     416            kernels = NULL;
    424417
    425418            // Put the solution on the metadata
     
    466459        goto ERROR;
    467460    }
    468     psFree(kernels);
    469461
    470462    memCheck("convolution");
Note: See TracChangeset for help on using the changeset viewer.