IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 26, 2008, 4:56:07 PM (18 years ago)
Author:
Paul Price
Message:

Adding command-line option -debug-stack to use previously calculated convolved images and convolution kernel instead of convolving again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackMatch.c

    r19210 r19231  
    1515                     PM_SOURCE_MODE_CR_LIMIT) // Mask to apply to input sources
    1616
    17 //#define TESTING
     17//#define TESTING                         // Enable debugging output
     18
     19
     20
     21#ifdef TESTING
     22// Read a FITS image
     23static bool readImage(psImage **target, // Target for image
     24                      const char *name, // Name of FITS file
     25                      const pmConfig *config // Configuration
     26    )
     27{
     28    psString resolved = pmConfigConvertFilename(name, config, false, false); // Resolved filename
     29    psFits *fits = psFitsOpen(resolved, "r");
     30    psFree(resolved);
     31    if (!fits) {
     32        psError(PS_ERR_IO, false, "Unable to open previously produced image: %s", name);
     33        return false;
     34    }
     35    psImage *image = psFitsReadImage(fits, psRegionSet(0,0,0,0), 0); // Image of interest
     36    if (!image) {
     37        psError(PS_ERR_IO, false, "Unable to read previously produced image: %s", name);
     38        psFitsClose(fits);
     39        return false;
     40    }
     41    psFitsClose(fits);
     42
     43    psFree(*target);
     44    *target = image;
     45
     46    return true;
     47}
     48#endif
    1849
    1950bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels,
     
    2556    assert(config);
    2657
    27     pmReadout *output = pmReadoutAlloc(NULL); // Output readout, for holding results temporarily
    28 
    2958    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    3059    psAssert(recipe, "We've thrown an error on this before.");
     
    5483    }
    5584
     85#ifdef TESTING
     86    // Read previously produced kernel
     87    static int numInput = 0;            // Index of input file
     88    if (psMetadataLookupBool(NULL, config->arguments, "PPSTACK.DEBUG.STACK")) {
     89        const char *outName = psMetadataLookupStr(NULL, config->arguments, "OUTPUT"); // Output root
     90        assert(outName);
     91        // Read convolution kernel
     92        {
     93            psString filename = NULL;   // Output filename
     94            psStringAppend(&filename, "%s.%d.kernel", outName, numInput);
     95            psString resolved = pmConfigConvertFilename(filename, config, false, false); // Resolved filename
     96            psFree(filename);
     97            psFits *fits = psFitsOpen(resolved, "r"); // FITS file for subtraction kernel
     98            psFree(resolved);
     99            if (!fits || !pmReadoutReadSubtractionKernels(readout, fits)) {
     100                psError(PS_ERR_IO, false, "Unable to read previously produced kernel");
     101                psFitsClose(fits);
     102                numInput++;
     103                return false;
     104            }
     105            psFitsClose(fits);
     106        }
     107
     108        // Read image, mask, weight
     109        const char *tempImage = psMetadataLookupStr(NULL, recipe, "TEMP.IMAGE"); // Suffix for image
     110        const char *tempMask = psMetadataLookupStr(NULL, recipe, "TEMP.MASK"); // Suffix for mask
     111        const char *tempWeight = psMetadataLookupStr(NULL, recipe, "TEMP.WEIGHT"); // Suffix for weight map
     112        psString imageName = NULL, maskName = NULL, weightName = NULL; // Names for convolved images
     113        psStringAppend(&imageName, "%s.%d.%s", outName, numInput, tempImage);
     114        psStringAppend(&maskName, "%s.%d.%s", outName, numInput, tempMask);
     115        psStringAppend(&weightName, "%s.%d.%s", outName, numInput, tempWeight);
     116
     117        if (!readImage(&readout->image, imageName, config) || !readImage(&readout->mask, maskName, config) ||
     118            !readImage(&readout->weight, weightName, config)) {
     119            psError(PS_ERR_IO, false, "Unable to read previously produced image.");
     120            psFree(imageName);
     121            psFree(maskName);
     122            psFree(weightName);
     123            numInput++;
     124            return false;
     125        }
     126        psFree(imageName);
     127        psFree(maskName);
     128        psFree(weightName);
     129
     130        numInput++;
     131        return true;
     132    }
     133#endif
     134
     135    // Normal operations here
     136    pmReadout *output = pmReadoutAlloc(NULL); // Output readout, for holding results temporarily
    56137    if (psMetadataLookupBool(&mdok, config->arguments, "HAVE.PSF")) {
    57138        assert(psf);
     
    116197        pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
    117198
    118         if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources, NULL,
    119                                       NULL, psf, minFlux, 0, false)) {
     199        if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources,
     200                                      NULL, NULL, psf, minFlux, 0, false)) {
    120201            psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
    121202            psFree(fake);
     
    193274
    194275#ifdef TESTING
    195         {
    196             static int num = 0;         // Image counter
    197             psString filename = NULL;   // Output filename
    198             psStringAppend(&filename, "stack_kernel_%d.fits", num++);
    199             psFits *fits = psFitsOpen(filename, "w"); // FITS file for subtraction kernel
    200             psFree(filename);
    201             pmReadoutWriteSubtractionKernels(output, fits);
    202             psFitsClose(fits);
    203         }
    204 #endif
    205 
    206     // Extract the regions and solutions used in the image matching
    207     // This stops them from being freed when we iterate back up the FPA
     276    {
     277        psString filename = NULL;   // Output filename
     278        psStringAppend(&filename, "stack_kernel_%d.fits", numInput);
     279        psFits *fits = psFitsOpen(filename, "w"); // FITS file for subtraction kernel
     280        psFree(filename);
     281        pmReadoutWriteSubtractionKernels(output, fits);
     282        psFitsClose(fits);
     283    }
     284#endif
     285
     286// Extract the regions and solutions used in the image matching
     287// This stops them from being freed when we iterate back up the FPA
    208288    *regions = psArrayAllocEmpty(ARRAY_BUFFER); // Array of regions
    209289    {
Note: See TracChangeset for help on using the changeset viewer.