IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 31, 2006, 12:56:03 PM (20 years ago)
Author:
Paul Price
Message:

Calculating statistics for combined image wasn't working properly --- was outputting nothing. The statistics calculation was being performed after everything was freed. Moved statistics calculation into the combine loop. Results are still written by the main function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMergeCombine.c

    r8680 r8720  
    44#include <pslib.h>
    55#include <psmodules.h>
     6#include <ppStats.h>
    67
    78#include "ppMerge.h"
     
    9495
    9596    // Iterate over the FPA
    96     int cellNum = -1;                   // Cell number
     97    pmFPA *fpa = data->out;             // Output FPA
     98    pmFPAview *view = pmFPAviewAlloc(0);// View of FPA, for iteration
     99    int cellNum = -1;                   // Cell number in the whole FPA
    97100    pmFPAWrite(data->out, data->outFile, config->database, true, false); // Write header only
    98     psArray *chips = data->out->chips;  // Array of output chips
    99     for (int i = 0; i < chips->n; i++) {
    100         pmChip *chip = chips->data[i];  // Output chip of interest
    101         if (!chip) {
    102             continue;
    103         }
     101    pmChip *chip;                       // Chip of interest
     102    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    104103        pmChipWrite(chip, data->outFile, config->database, true, false); // Write header only
    105         psArray *cells = chip->cells;   // Array of output cells
    106         for (int j = 0; j < cells->n; j++) {
    107             pmCell *cell = cells->data[j]; // Output cell of interest
    108             if (!cell) {
    109                 continue;
    110             }
     104        pmCell *cell;                   // Cell of interest
     105        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    111106            cellNum++;
    112107            pmCellWrite(cell, data->outFile, config->database, true); // Write header only
     
    130125            do {
    131126                numRead = 0;
    132                 for (int k = 0; k < filenames->n; k++) {
    133                     if (! filenames->data[k] || strlen(filenames->data[k]) == 0) {
     127                for (int i = 0; i < filenames->n; i++) {
     128                    if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
    134129                        continue;
    135130                    }
    136                     psFits *fits = data->files->data[k]; // FITS file handle
     131                    psFits *fits = data->files->data[i]; // FITS file handle
    137132                    if (!fits) {
    138133                        psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n",
    139                                 (char *)filenames->data[k]);
     134                                (char*)filenames->data[i]);
    140135                        continue;
    141136                    }
    142137
    143                     if (!stack->data[k]) {
    144                         pmFPA *fpaIn = data->in->data[k]; // Input FPA
    145                         pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
    146                         pmCell *cellIn = chipIn->cells->data[j]; // Input cell
    147                         stack->data[k] = pmReadoutAlloc(cellIn); // Input readout
     138                    if (!stack->data[i]) {
     139                        pmFPA *fpaIn = data->in->data[i]; // Input FPA
     140                        pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
     141                        pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
     142                        stack->data[i] = pmReadoutAlloc(cellIn); // Input readout
    148143                    }
    149144
    150145                    // Only reading and writing the first readout in each cell (plane 0)
    151                     if (pmReadoutReadNext(stack->data[k], fits, 0, options->rows)) {
     146                    if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) {
    152147                        // For anything except BIAS and DARK, we want a mask
    153148                        if (options->scale || options->zero) {
    154                             pmReadoutSetMask(stack->data[k]);
     149                            pmReadoutSetMask(stack->data[i]);
    155150                        }
    156151                        numRead++;
     
    160155                if (numRead > 0) {
    161156                    pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
    162                     psTrace(__func__, 5, "Chip %d, cell %d, scan %d\n", i, j, numScan);
     157                    psTrace(__func__, 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
    163158                }
    164159                numScan++;
     
    169164            // Read whole cells at a time
    170165
    171             printf("Chip %d, cell %d\n", i, j);
     166            printf("Chip %d, cell %d\n", view->chip, view->cell);
    172167            int numRead = 0;  // Number of inputs read
    173             for (int k = 0; k < filenames->n; k++) {
    174                 if (! filenames->data[k] || strlen(filenames->data[k]) == 0) {
    175                     continue;
    176                 }
    177                 psFits *fits = data->files->data[k]; // FITS file handle
     168            for (int i = 0; i < filenames->n; i++) {
     169                if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
     170                    continue;
     171                }
     172                psFits *fits = data->files->data[i]; // FITS file handle
    178173                if (!fits) {
    179174                    psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n",
    180                             filenames->data[k]);
    181                     continue;
    182                 }
    183                 pmFPA *fpaIn = data->in->data[k]; // Input FPA
    184                 pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
    185                 pmCell *cellIn = chipIn->cells->data[j]; // Input cell
     175                            filenames->data[i]);
     176                    continue;
     177                }
     178                pmFPA *fpaIn = data->in->data[i]; // Input FPA
     179                pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
     180                pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
    186181                if (!cellIn->file_exists || !cellIn->data_exists) {
    187182                    continue;
     
    190185                    continue;
    191186                }
    192                 stack->data[k] = cellIn->readouts->data[0];
     187                stack->data[i] = cellIn->readouts->data[0];
    193188                numRead++;
    194189            }
    195190            if (numRead > 0) {
    196191                pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
    197                 psTrace(__func__, 5, "Chip %d, cell %d\n", i, j);
     192                psTrace(__func__, 5, "Chip %d, cell %d\n", view->chip, view->cell);
    198193            }
    199194
     
    204199            psFree(stack);
    205200
     201            // Statistics on the merged cell
     202            if (data->statsFile) {
     203                data->stats = ppStats(data->stats, data->out, view, config); // Statistics for output FPA
     204            }
     205
    206206            // Blow away the cell data
    207             for (int k = 0; k < filenames->n; k++) {
    208                 pmFPA *fpaIn = data->in->data[k]; // Input FPA
    209                 pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
    210                 pmCell *cellIn = chipIn->cells->data[j]; // Input cell
     207            for (int i = 0; i < filenames->n; i++) {
     208                pmFPA *fpaIn = data->in->data[i]; // Input FPA
     209                pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
     210                pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
    211211                pmCellFreeData(cellIn);
    212212            }
     
    221221
    222222        // Blow away the chip data
    223         for (int k = 0; k < filenames->n; k++) {
    224             pmFPA *fpaIn = data->in->data[k]; // Input FPA
    225             pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
     223        for (int i = 0; i < filenames->n; i++) {
     224            pmFPA *fpaIn = data->in->data[i]; // Input FPA
     225            pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
    226226            pmChipFreeData(chipIn);
    227227        }
     
    242242
    243243    // Blow away the FPA data
    244     for (int k = 0; k < filenames->n; k++) {
    245         pmFPA *fpaIn = data->in->data[k]; // Input FPA
     244    for (int i = 0; i < filenames->n; i++) {
     245        pmFPA *fpaIn = data->in->data[i]; // Input FPA
    246246        pmFPAFreeData(fpaIn);
    247247    }
Note: See TracChangeset for help on using the changeset viewer.