IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23576


Ignore:
Timestamp:
Mar 27, 2009, 1:26:55 PM (17 years ago)
Author:
Paul Price
Message:

Can now combine images without convolving, but it doesn't apply any rejection yet.

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/Makefile.am

    r23341 r23576  
    2929        ppStackPrepare.c        \
    3030        ppStackConvolve.c       \
     31        ppStackCombinePrepare.c \
    3132        ppStackCombineInitial.c \
    3233        ppStackReject.c         \
  • trunk/ppStack/src/ppStackCamera.c

    r23371 r23576  
    5151    bool status = false;                // Status of file definition
    5252
     53    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim
     54    if (!recipe) {
     55        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSTACK_RECIPE);
     56        return false;
     57    }
     58    bool convolve = psMetadataLookupBool(NULL, recipe, "CONVOLVE"); // Convolve images before stack?
     59
    5360    psArray *runImages = pmFPAfileDefineMultipleFromRun(&status, NULL, config,
    5461                                                        "PPSTACK.INPUT"); // Input images from previous run
     
    98105        }
    99106        if (!runSrc) {
    100             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define input sources from RUN metadta.");
     107            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define input sources from RUN metadata.");
    101108            psFree(runImages);
    102109            return false;
     
    104111        psFree(runSrc);
    105112
    106         psArray *runKernel = pmFPAfileDefineMultipleFromRun(&status, runImages, config,
    107                                                             "PPSTACK.CONV.KERNEL"); // Convolution kernels
    108         if (!status) {
    109             psError(PS_ERR_UNKNOWN, false, "Unable to define convolution kernels from RUN metadata.");
    110             psFree(runImages);
    111             return false;
    112         }
    113         if (!runSrc) {
    114             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define convolution kernels from RUN metadta.");
    115             psFree(runImages);
    116             return false;
    117         }
    118         psFree(runKernel);
     113        if (convolve) {
     114            psArray *runKernel = pmFPAfileDefineMultipleFromRun(&status, runImages, config,
     115                                                                "PPSTACK.CONV.KERNEL"); // Convolution kernels
     116            if (!status) {
     117                psError(PS_ERR_UNKNOWN, false, "Unable to define convolution kernels from RUN metadata.");
     118                psFree(runImages);
     119                return false;
     120            }
     121            if (!runKernel) {
     122                psError(PS_ERR_UNEXPECTED_NULL, true,
     123                        "Unable to define convolution kernels from RUN metadata.");
     124                psFree(runImages);
     125                return false;
     126            }
     127            psFree(runKernel);
     128        }
    119129
    120130        psFree(runImages);
     
    200210            }
    201211
    202             pmFPAfile *kernel = pmFPAfileDefineOutput(config, imageFile->fpa, "PPSTACK.CONV.KERNEL");
    203             if (!kernel) {
    204                 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.CONV.KERNEL"));
    205                 return false;
    206             }
    207             kernel->save = true;
     212            if (convolve) {
     213                pmFPAfile *kernel = pmFPAfileDefineOutput(config, imageFile->fpa, "PPSTACK.CONV.KERNEL");
     214                if (!kernel) {
     215                    psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.CONV.KERNEL"));
     216                    return false;
     217                }
     218                kernel->save = true;
     219            }
    208220
    209221            i++;
     
    300312    }
    301313    jpeg2->save = true;
    302 
    303 
    304     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim
    305     if (!recipe) {
    306         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSTACK_RECIPE);
    307         return false;
    308     }
    309314
    310315    // For photometry, we operate on the chip-mosaicked image
  • trunk/ppStack/src/ppStackCombineInitial.c

    r23573 r23576  
    2323    psTimerStart("PPSTACK_INITIAL");
    2424
    25     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    26     psAssert(recipe, "We've thrown an error on this before.");
    27 
    2825    psMetadata *ppsub = psMetadataLookupMetadata(NULL, config->recipes, "PPSUB"); // PPSUB recipe
    2926    int overlap = 2 * psMetadataLookupS32(NULL, ppsub,
    3027                                          "KERNEL.SIZE"); // Overlap by kernel size between consecutive scans
    3128
    32     pmFPAview *view = NULL;             // View to readout
    33 
    34     int row0, col0;                 // Offset for readout
    35     int numCols, numRows;           // Size of readout
    36     ppStackThread *thread = stack->threads->data[0]; // Representative thread
    37     if (!pmReadoutStackSetOutputSize(&col0, &row0, &numCols, &numRows, thread->readouts)) {
    38         psError(PS_ERR_UNKNOWN, false, "problem setting output readout size.");
    39         return false;
    40     }
    41 
    42     pmFPAfileActivate(config->files, false, NULL);
    43     ppStackFileActivation(config, PPSTACK_FILES_COMBINE, true);
    44     view = ppStackFilesIterateDown(config);
    45     if (!view) {
    46         return false;
    47     }
    48 
    49     pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT"); // Output cell
    50     options->outRO = pmReadoutAlloc(outCell); // Output readout
    51     psFree(view);
    52 
    53     psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
    54     psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
    55     if (!pmReadoutStackDefineOutput(options->outRO, col0, row0, numCols, numRows, true, true, maskBad)) {
    56         psError(PS_ERR_UNKNOWN, false, "Unable to prepare output.");
    57         return false;
    58     }
    59 
    60     psFree(options->cells); options->cells = NULL;
    6129
    6230    bool status;                    // Status of read
  • trunk/ppStack/src/ppStackLoop.c

    r23367 r23576  
    5959    if (!stack) {
    6060        psError(PS_ERR_IO, false, "Unable to initialise stack threads.");
     61        psFree(options);
     62        return false;
     63    }
     64    psFree(options->cells); options->cells = NULL;
     65
     66    // Prepare for combination
     67    if (!ppStackCombinePrepare(stack, options, config)) {
     68        psError(PS_ERR_UNKNOWN, false, "Unable to prepare for combination.");
     69        psFree(stack);
    6170        psFree(options);
    6271        return false;
  • trunk/ppStack/src/ppStackLoop.h

    r23368 r23576  
    3030// Convolve inputs to match target PSF
    3131bool ppStackConvolve(
     32    ppStackOptions *options,            // Options
     33    pmConfig *config                    // Configuration
     34    );
     35
     36// Prepare for combination
     37bool ppStackCombinePrepare(
     38    ppStackThreadData *stack,           // Stack
    3239    ppStackOptions *options,            // Options
    3340    pmConfig *config                    // Configuration
  • trunk/ppStack/src/ppStackReadout.c

    r23346 r23576  
    185185    assert(outRO);
    186186    assert(readouts);
    187     assert(rejected);
    188     assert(readouts->n == rejected->n);
     187    assert(!rejected || readouts->n == rejected->n);
    189188    assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK);
    190189    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
     
    207206    psArray *stack = psArrayAlloc(num); // Array for stacking
    208207
    209     int numGood = num;                  // Number of good inputs: images that haven't been completely rejected
     208    bool entire = (rejected ? false : true); // Combine entire image?
    210209    for (int i = 0; i < num; i++) {
    211210        pmReadout *ro = readouts->data[i];
    212         if (!ro || !rejected->data[i] || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
    213             // Image completely rejected
    214             numGood--;
     211        if (mask->data.U8[i] & (PPSTACK_MASK_REJECT | PPSTACK_MASK_BAD)) {
     212            // Image completely rejected since previous combination
     213            entire = true;
     214            continue;
     215        } else if (mask->data.U8[i]) {
     216            // Image completely rejected before original combination
    215217            continue;
    216218        }
     
    234236        pmStackData *data = pmStackDataAlloc(ro, weightings->data.F32[i],
    235237                                             addVariance ? addVariance->data.F32[i] : NAN);
    236         data->reject = psMemIncrRefCounter(rejected->data[i]);
     238        data->reject = rejected ? psMemIncrRefCounter(rejected->data[i]) : NULL;
    237239        stack->data[i] = data;
    238240    }
    239241
    240242    if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, 0, 0, NAN, NAN, NAN,
    241                         numGood != num, useVariance, false)) {
     243                        entire, useVariance, false)) {
    242244        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts.");
    243245        psFree(stack);
  • trunk/ppStack/src/ppStackSetup.c

    r23573 r23576  
    1414
    1515// Generate an array of input filenames
    16 static psArray *stackNameArray(pmConfig *config, // Configuration
     16static psArray *stackNameArray(const ppStackOptions *options, // Stack options
     17                               pmConfig *config, // Configuration
    1718                               const char *name // Name of file
    1819    )
     
    2122    psAssert(config, "Require file name");
    2223
    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
     24    psArray *array = psArrayAllocEmpty(options->num); // Array with filenames
     25    pmFPAview *view = pmFPAviewAlloc(0);// View to readout
     26    view->chip = view->cell = view->readout = -1;
    3227
    33         psString filename = psStringCopy(file->filename); // Filename of interest
     28    for (int i = 0; i < options->num; i++) {
     29        pmFPAfile *file = pmFPAfileSelectSingle(config->files, name, i); // File of interest
     30
     31        psString filename = pmFPAfileName(file, view, config); // Filename of interest
     32        psAssert(filename, "Can't determine filename");
    3433        psArrayAdd(array, array->n, filename);
    3534        psFree(filename);               // Drop reference
    3635    }
    37     psFree(iter);
    3836
    3937    return array;
     
    114112        psFree(outputName);
    115113    } else {
    116         options->imageNames = stackNameArray(config, "PPSTACK.INPUT");
    117         options->maskNames = stackNameArray(config, "PPSTACK.INPUT.MASK");
    118         options->varianceNames = stackNameArray(config, "PPSTACK.INPUT.VARIANCE");
     114        options->imageNames = stackNameArray(options, config, "PPSTACK.INPUT");
     115        options->maskNames = stackNameArray(options, config, "PPSTACK.INPUT.MASK");
     116        options->varianceNames = stackNameArray(options, config, "PPSTACK.INPUT.VARIANCE");
    119117    }
    120118
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r23447 r23576  
    635635}
    636636
     637psString pmFPAfileName(const pmFPAfile *file, const pmFPAview *view, pmConfig *config)
     638{
     639    PS_ASSERT_PTR_NON_NULL(file, NULL);
     640    PS_ASSERT_PTR_NON_NULL(view, NULL);
     641    PS_ASSERT_PTR_NON_NULL(config, NULL);
     642
     643    psString filename = pmFPAfileNameFromRule(file->filerule, file, view); // Filename, based on rule
     644    if (!filename) {
     645        psError(PS_ERR_IO, true, "Cannot determine file name from rule");
     646        return false;
     647    }
     648
     649    // indirect filenames: these come from a list on the command line or elsewhere
     650    if (!strcasecmp(filename, "@FILES")) {
     651        psString filesrc = pmFPAfileNameFromRule(file->filesrc, file, view); // Source of file name
     652        if (!filesrc) {
     653            psError(PS_ERR_IO, false, "error converting filesrc to name %s", file->filesrc);
     654            return false;
     655        }
     656        psFree(filename);
     657        filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, file->names, filesrc));
     658        if (!filename) {
     659            psError(PS_ERR_IO, false, "filename lookup error (@FILES) for %s : %s", file->filesrc, filesrc);
     660            psFree(filesrc);
     661            return false;
     662        }
     663        psFree(filesrc);
     664    }
     665
     666    // get name from detrend database
     667    // file->detrend->detID contains the desired -det_id detID -iteration iter string
     668    if (!strcasecmp(filename, "@DETDB")) {
     669        if (!file->detrend) {
     670            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find information about selected detrend.");
     671            return false;
     672        }
     673        psMetadata *menu = psMetadataLookupMetadata(NULL, file->camera, "CLASSID"); // Menu of class IDs
     674        if (!menu) {
     675            psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
     676            return false;
     677        }
     678        const char *rule = psMetadataLookupStr(NULL, menu, file->detrend->level); // Rule for class_id
     679        if (!rule || strlen(rule) == 0) {
     680            psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration",
     681                    file->detrend->level);
     682            return false;
     683        }
     684        psString classId = pmFPAfileNameFromRule(rule, file, view); // The class identifier, for pmDetrendFile
     685        if (!classId) {
     686            psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
     687            return false;
     688        }
     689
     690        psTrace("psModules.camera", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
     691        psFree(filename);
     692        filename = pmDetrendFile(file->detrend->detID, classId, config);
     693        if (!filename) {
     694            psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s",
     695                    file->detrend->detID, classId);
     696            psFree(classId);
     697            return false;
     698        }
     699
     700        psTrace("psModules.camera", 6, "got detrend file %s", filename);
     701        psFree(classId);
     702    }
     703
     704    return filename;
     705}
     706
    637707// open file (if not already opened).
    638708// this function is only called only within pmFPAfileRead or pmFPAfileWrite.
     
    672742
    673743    // determine the file name, free a name allocated earlier
    674     psFree (file->filename);
    675     file->filename = pmFPAfileNameFromRule (file->filerule, file, view);
    676     if (file->filename == NULL) {
    677         psError(PS_ERR_IO, true, "Filename is NULL");
    678         return false;
    679     }
    680 
    681     // indirect filenames: these come from a list on the command line or elsewhere
    682     if (!strcasecmp (file->filename, "@FILES")) {
    683         char *filesrc = pmFPAfileNameFromRule (file->filesrc, file, view);
    684         if (filesrc == NULL) {
    685             psError(PS_ERR_IO, false, "error converting filesrc to name %s\n", file->filesrc);
    686             return false;
    687         }
    688 
    689         psFree (file->filename);
    690         file->filename = psMetadataLookupStr (&status, file->names, filesrc);
    691 
    692         if (file->filename == NULL) {
    693             psError(PS_ERR_IO, true, "filename lookup error (@FILES) for %s : %s\n", file->filesrc, filesrc);
    694             psFree (filesrc);
    695             return false;
    696         }
    697         // psMetadataLookupStr just returns a view, file->filename must be protected
    698         psMemIncrRefCounter (file->filename);
    699         psFree (filesrc);
    700     }
    701 
    702     // get name from detrend database
    703     // file->detrend->detID contains the desired -det_id detID -iteration iter string
    704     if (!strcasecmp (file->filename, "@DETDB")) {
    705         if (!file->detrend) {
    706             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find information about selected detrend.");
    707             return false;
    708         }
    709 
    710         psString classId = NULL;        // The class identifier, to pass to pmDetrendFile
    711         psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "CLASSID"); // Menu of class IDs
    712         if (!status || !menu) {
    713             psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
    714             return false;
    715         }
    716         const char *rule = psMetadataLookupStr(&status, menu, file->detrend->level); // Rule for class_id
    717         if (!status || !rule || strlen(rule) == 0) {
    718             psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration", file->detrend->level);
    719             return false;
    720         }
    721         classId = pmFPAfileNameFromRule(rule, file, view);
    722         if (!classId) {
    723             psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
    724             return false;
    725         }
    726         psTrace ("psModules.camera", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
    727         psFree (file->filename);
    728 
    729         file->filename = pmDetrendFile(file->detrend->detID, classId, config);
    730         if (file->filename == NULL) {
    731             psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s\n", file->detrend->detID, classId);
    732             psFree (classId);
    733             return false;
    734         }
    735 
    736         psTrace ("psModules.camera", 6, "got detrend file %s\n", file->filename);
    737         psFree (classId);
     744    psFree(file->filename);
     745    file->filename = pmFPAfileName(file, view, config);
     746    if (!file->filename) {
     747        psError(PS_ERR_IO, true, "Unable to determine filename");
     748        return false;
    738749    }
    739750
  • trunk/psModules/src/camera/pmFPAfileIO.h

    r18364 r23576  
    1515/// @addtogroup Camera Camera Layout
    1616/// @{
     17
     18// Determine appropriate file name
     19psString pmFPAfileName(const pmFPAfile *file, const pmFPAview *view, pmConfig *config);
    1720
    1821// open the real file corresponding to the given pmFPAfile appropriate to the current view
Note: See TracChangeset for help on using the changeset viewer.