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/pmSubtraction.c

    r14716 r14738  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-08-30 23:09:52 $
     6 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-09-04 23:56:07 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    548548}
    549549
     550bool pmSubtractionConvolveStamp(pmSubtractionStamp *stamp, const pmSubtractionKernels *kernels, int footprint)
     551{
     552    PS_ASSERT_PTR_NON_NULL(stamp, false);
     553    PS_ASSERT_KERNEL_NON_NULL(stamp->reference, false);
     554    PS_ASSERT_PTR_NON_NULL(kernels, false);
     555    PS_ASSERT_VECTORS_SIZE_EQUAL(kernels->u, kernels->v, false);
     556    PS_ASSERT_INT_NONNEGATIVE(footprint, false);
     557
     558    if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE) {
     559        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Stamp not marked for calculation.");
     560        return false;
     561    }
     562
     563    if (stamp->convolutions) {
     564        // Already done
     565        return true;
     566    }
     567
     568    stamp->convolutions = psArrayAlloc(kernels->num);
     569    psKernel *reference = stamp->reference; // Reference postage stamp
     570
     571    for (int i = 0; i < kernels->num; i++) {
     572        stamp->convolutions->data[i] = convolveRef(kernels, i, reference, footprint);
     573    }
     574
     575    return true;
     576}
     577
    550578
    551579bool pmSubtractionCalculateEquation(psArray *stamps, const pmSubtractionKernels *kernels, int footprint)
     
    591619        psVectorInit(stampVector, 0.0);
    592620
    593         psKernel *reference = stamp->reference; // Reference postage stamp
    594621        psKernel *input = stamp->input; // Input postage stamp
    595622        psKernel *weight = stamp->weight; // Weight map postage stamp
    596623
    597624        // Generate convolutions of the reference
     625        if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) {
     626            psError(PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", i);
     627            return NULL;
     628        }
     629
    598630        psArray *convolutions = stamp->convolutions; // Convolutions of the reference for each kernel
    599         if (!convolutions) {
    600             stamp->convolutions = convolutions = psArrayAlloc(numKernels);
    601         }
    602         for (int j = 0; j < numKernels; j++) {
    603             if (convolutions->data[j]) {
    604                 psFree(convolutions->data[j]);
    605             }
    606             convolutions->data[j] = convolveRef(kernels, j, reference, footprint);
    607 #ifdef TESTING
    608             {
    609                 psKernel *conv = convolutions->data[j]; // Convolution of interest
    610                 psString filename = NULL;
    611                 psStringAppend(&filename, "conv_%03d_%03d.fits", i, j);
    612                 psFits *fits = psFitsOpen(filename, "w");
    613                 psFree(filename);
    614                 psFitsWriteImage(fits, NULL, conv->image, 0, NULL);
    615                 psFitsClose(fits);
    616             }
    617 #endif
    618        }
    619 
    620631        psImage *polyValues = spatialPolyValues(spatialOrder, stamp->xNorm, stamp->yNorm); // Polynomial terms
    621632
     
    900911            stamp->y = 0;
    901912            stamp->status = PM_SUBTRACTION_STAMP_REJECTED;
     913            // Recalculate convolutions
     914            psFree(stamp->convolutions);
     915            stamp->convolutions = NULL;
    902916        }
    903917    }
Note: See TracChangeset for help on using the changeset viewer.