IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2009, 11:49:17 AM (17 years ago)
Author:
Paul Price
Message:

Allow convolution of images to be optional when stacking.

File:
1 edited

Legend:

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

    r23341 r23573  
    1111#include "ppStackLoop.h"
    1212
     13#define BUFFER 16                       // Buffer for name array
     14
     15// Generate an array of input filenames
     16static psArray *stackNameArray(pmConfig *config, // Configuration
     17                               const char *name // Name of file
     18    )
     19{
     20    psAssert(config, "Require configuration");
     21    psAssert(config, "Require file name");
     22
     23    psString regex = NULL;             // Regular expression for selecting file
     24    psStringAppend(&regex, "^%s$", name);
     25    psMetadataIterator *iter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, regex); // Iterator
     26    psFree(regex);
     27    psMetadataItem *item;               // Item from iteration
     28    psArray *array = psArrayAlloc(BUFFER); // Array of file names
     29    while ((item = psMetadataGetAndIncrement(iter))) {
     30        psAssert(item->type == PS_DATA_UNKNOWN, "Should be this type");
     31        pmFPAfile *file = item->data.V; // An input file
     32
     33        psString filename = psStringCopy(file->filename); // Filename of interest
     34        psArrayAdd(array, array->n, filename);
     35        psFree(filename);               // Drop reference
     36    }
     37    psFree(iter);
     38
     39    return array;
     40}
     41
     42
    1343bool ppStackSetup(ppStackOptions *options, pmConfig *config)
    1444{
     
    1848    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    1949    psAssert(recipe, "We've thrown an error on this before.");
     50
     51    options->convolve = psMetadataLookupBool(NULL, config->arguments, "CONVOLVE"); // Convolve images?
     52    if (!psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) {
     53        psWarning("No PSFs provided --- unable to convolve to common PSF.");
     54        options->convolve = false;
     55    }
    2056
    2157    int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs
     
    3672    }
    3773
    38     const char *tempDir = psMetadataLookupStr(NULL, recipe, "TEMP.DIR"); // Directory for temporary images
    39     if (!tempDir) {
    40         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find TEMP.DIR in recipe");
    41         return false;
     74    // Generate temporary names for convolved images
     75    if (options->convolve) {
     76        const char *tempDir = psMetadataLookupStr(NULL, recipe, "TEMP.DIR"); // Directory for temporary images
     77        if (!tempDir) {
     78            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find TEMP.DIR in recipe");
     79            return false;
     80        }
     81
     82        psString outputName = psStringCopy(psMetadataLookupStr(NULL, config->arguments,
     83                                                               "OUTPUT")); // Name for temporary files
     84        const char *tempName = basename(outputName);
     85        if (!tempName) {
     86            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to construct basename for temporary files.");
     87            psFree(outputName);
     88            return false;
     89        }
     90
     91        const char *tempImage = psMetadataLookupStr(NULL, recipe, "TEMP.IMAGE"); // Suffix for images
     92        const char *tempMask = psMetadataLookupStr(NULL, recipe, "TEMP.MASK"); // Suffix for masks
     93        const char *tempVariance = psMetadataLookupStr(NULL, recipe, "TEMP.VARIANCE"); // Suffix for var maps
     94        if (!tempImage || !tempMask || !tempVariance) {
     95            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     96                    "Unable to find TEMP.IMAGE, TEMP.MASK and TEMP.VARIANCE in recipe");
     97            psFree(outputName);
     98            return false;
     99        }
     100
     101        options->imageNames = psArrayAlloc(num);
     102        options->maskNames = psArrayAlloc(num);
     103        options->varianceNames = psArrayAlloc(num);
     104        for (int i = 0; i < num; i++) {
     105            psString imageName = NULL, maskName = NULL, varianceName = NULL; // Names for convolved images
     106            psStringAppend(&imageName, "%s/%s.%d.%s", tempDir, tempName, i, tempImage);
     107            psStringAppend(&maskName, "%s/%s.%d.%s", tempDir, tempName, i, tempMask);
     108            psStringAppend(&varianceName, "%s/%s.%d.%s", tempDir, tempName, i, tempVariance);
     109            psTrace("ppStack", 5, "Temporary files: %s %s %s\n", imageName, maskName, varianceName);
     110            options->imageNames->data[i] = imageName;
     111            options->maskNames->data[i] = maskName;
     112            options->varianceNames->data[i] = varianceName;
     113        }
     114        psFree(outputName);
     115    } else {
     116        options->imageNames = stackNameArray(config, "PPSTACK.INPUT");
     117        options->maskNames = stackNameArray(config, "PPSTACK.INPUT.MASK");
     118        options->varianceNames = stackNameArray(config, "PPSTACK.INPUT.VARIANCE");
    42119    }
    43 
    44     psString outputName = psStringCopy(psMetadataLookupStr(NULL, config->arguments,
    45                                                            "OUTPUT")); // Name for temporary files
    46     const char *tempName = basename(outputName);
    47     if (!tempName) {
    48         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to construct basename for temporary files.");
    49         psFree(outputName);
    50         return false;
    51     }
    52 
    53     const char *tempImage = psMetadataLookupStr(NULL, recipe, "TEMP.IMAGE"); // Suffix for temporary images
    54     const char *tempMask = psMetadataLookupStr(NULL, recipe, "TEMP.MASK"); // Suffix for temporary masks
    55     const char *tempVariance = psMetadataLookupStr(NULL, recipe, "TEMP.VARIANCE"); // Suffix for temp var maps
    56     if (!tempImage || !tempMask || !tempVariance) {
    57         psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    58                 "Unable to find TEMP.IMAGE, TEMP.MASK and TEMP.VARIANCE in recipe");
    59         psFree(outputName);
    60         return false;
    61     }
    62 
    63     options->imageNames = psArrayAlloc(num);
    64     options->maskNames = psArrayAlloc(num);
    65     options->varianceNames = psArrayAlloc(num);
    66     for (int i = 0; i < num; i++) {
    67         psString imageName = NULL, maskName = NULL, varianceName = NULL; // Names for convolved images
    68         psStringAppend(&imageName, "%s/%s.%d.%s", tempDir, tempName, i, tempImage);
    69         psStringAppend(&maskName, "%s/%s.%d.%s", tempDir, tempName, i, tempMask);
    70         psStringAppend(&varianceName, "%s/%s.%d.%s", tempDir, tempName, i, tempVariance);
    71         psTrace("ppStack", 5, "Temporary files: %s %s %s\n", imageName, maskName, varianceName);
    72         options->imageNames->data[i] = imageName;
    73         options->maskNames->data[i] = maskName;
    74         options->varianceNames->data[i] = varianceName;
    75     }
    76     psFree(outputName);
    77120
    78121    if (!pmConfigMaskSetBits(NULL, NULL, config)) {
Note: See TracChangeset for help on using the changeset viewer.