IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2007, 2:27:15 PM (19 years ago)
Author:
eugene
Message:

adding fringe residual measurement in addition to fringe amplitude; clean up ppImageLoop calls to stats and fringe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageLoop.c

    r13924 r13970  
    33#endif
    44
    5 #include <ppStats.h>
    65#include "ppImage.h"
    76#include "ppImageDetrendFringe.h"
     
    109bool ppImageLoop (pmConfig *config, ppImageOptions *options) {
    1110
    12     bool mdok;                      // Status of MD lookup
    1311    bool status;
    1412    pmChip *chip;
    1513    pmCell *cell;
    1614    pmReadout *readout;
    17     psMetadata *stats = NULL;
    18 
    19     const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); // Filename for statistics
    20     FILE *statsFile = NULL;             // File stream for statistics
    21     if (mdok && statsName && strlen(statsName) > 0) {
    22         psString resolved = pmConfigConvertFilename(statsName, config, true); // Resolved filename
    23         statsFile = fopen(resolved, "w");
    24         if (!statsFile) {
    25             psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
    26             psFree(resolved);
    27             return false;
    28         }
    29         stats = psMetadataAlloc();
    30         psFree(resolved);
    31     }
    3215
    3316    pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT");
     
    9679        }
    9780
    98         // Solve the fringe system
     81        // Apply the fringe correction
    9982        if (options->doFringe) {
    100             pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
    101             if (!ppImageDetrendFringeSolve(chip, fringe, options)) {
     83            if (!ppImageDetrendFringeApply (config, chip, view, options)) {
    10284                psFree (view);
    10385                return false;
    10486            }
    105         }
    106 
    107         // Go back over the cells to apply the fringe and do statistics
    108         view->cell = view->readout = -1;
    109         while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
    110             if (!cell->process || !cell->file_exists) {
    111                 continue;
    112             }
    113 
    114             // Apply the fringe correction
    115             if (options->doFringe) {
    116                 psTrace("ppImage", 3, "Applying fringe correction...\n");
    117                 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");
    118                 if (!ppImageDetrendFringeGenerate(cell, fringeCell)) {
    119                     psFree (view);
    120                     return false;
    121                 }
    122             }
    123 
    124             // Perform statistics on the detrended cell
    125             if (stats) {
    126                 bool mdok;              // Status of MD lookup
    127                 pmFPAfile *output = psMetadataLookupPtr(&mdok, config->files, "PPIMAGE.OUTPUT");
    128                 if (!mdok || !output) {
    129                     psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPIMAGE.OUTPUT.");
    130                     psFree (view);
    131                     return false;
    132                 }
    133 
    134                 if (!ppStats(stats, output->fpa, view,
    135                              options->satMask | options->badMask | options->maskValue,
    136                              config)) {
    137                     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
    138                     psFree(stats);
    139                     psFree(view);
    140                     return false;
    141                 }
    142 
    143                 if (options->doFringe && !ppStatsFringe(stats, chip, "FRINGE.SOLUTION")) {
    144                     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to extract fringe solution for image.");
    145                     psFree(stats);
    146                     psFree(view);
    147                     return false;
    148                 }
    149             }
    150 
    151             // Add MD5 information for cell
    152             pmHDU *hdu = pmHDUFromCell(cell); // HDU that owns the cell
    153             while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) {
    154                 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
    155                 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME");
    156 
    157                 psString headerName = NULL; // Header name for MD5
    158                 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
    159 
    160                 psVector *md5 = psImageMD5(readout->image); // md5 hash
    161                 psString md5string = psMD5toString(md5); // String
    162                 psFree(md5);
    163                 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE,
    164                                  "Image MD5", md5string);
    165                 psFree(md5string);
    166                 psFree(headerName);
    167             }
    168         }
     87        }
     88       
     89        // measure various statistics for this image
     90        if (!ppImageStats (config, chip, view, options)) {
     91            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to measures stats for image");
     92            psFree (view);
     93            return false;
     94        }
    16995
    17096        if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT")) {
     
    214140
    215141    // Write out summary statistics
    216     if (stats) {
    217         char *statsMDC = psMetadataConfigFormat(stats);
    218         if (!statsMDC || strlen(statsMDC) == 0) {
    219             psError(PS_ERR_IO, false, "Unable to get statistics MDC file.\n");
    220         } else {
    221             fprintf(statsFile, "%s", statsMDC);
    222         }
    223         psFree(statsMDC);
    224         fclose(statsFile);
    225         psFree(stats);
     142    if (!ppImageStatsOutput (config, input->fpa, options)) {
     143        psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
     144        psFree (view);
     145        return false;
    226146    }
    227147
Note: See TracChangeset for help on using the changeset viewer.