IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6113


Ignore:
Timestamp:
Jan 20, 2006, 6:33:38 PM (20 years ago)
Author:
Paul Price
Message:

Fixed up freeing an FPA hierarchy at lower levels (and retaining the upper level); fixed the weights to provide variance in DN

Location:
branches/eam_rel9_p0/psModules/src/astrom
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c

    r6080 r6113  
    132132
    133133// Mosaic a chip together into a single image
    134 static bool mosaicChip(pmChip *chip,// Chip to mosaic
    135                        int xBinChip, int yBinChip // Binning of mosaic image in x and y
    136                       )
     134int pmChipMosaic(pmChip *chip,// Chip to mosaic
     135                 int xBinChip, int yBinChip // Binning of mosaic image in x and y
     136                )
    137137{
    138138
     
    149149
    150150    // Set up the required inputs
     151    psTrace(__func__, 1, "Mosaicking %d cells...\n", cells->n);
    151152    for (int i = 0; i < cells->n; i++) {
    152153        pmCell *cell = cells->data[i];  // The cell of interest
    153154        x0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0");
    154155        y0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0");
    155         psTrace(__func__, 9, "Cell %d: x0=%d y0=%d\n", i, x0->data.S32[i], y0->data.S32[i]);
     156        psTrace(__func__, 5, "Cell %d: x0=%d y0=%d\n", i, x0->data.S32[i], y0->data.S32[i]);
    156157        xBin->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN");
    157158        yBin->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN");
     
    204205    psFree(weights);
    205206    psFree(masks);
     207    int nCells = cells->n;
     208    psFree(cells);
    206209
    207210    // Chop off all the component cells, and put in a new one
     
    228231    //psFree(readout);
    229232
    230     return true;
    231 }
    232 
    233 
    234 int pmFPAMosaicChips(pmFPA *fpa,        // FPA
     233    return nCells;
     234}
     235
     236
     237int pmFPAMosaicCells(pmFPA *fpa,        // FPA
    235238                     int xBinChip, int yBinChip // Binning of mosaic image in x and y
    236239                    )
     
    247250
    248251        numChips++;
    249         mosaicChip(chip, xBinChip, yBinChip); // Mosaic of cells within the chip
     252        pmChipMosaic(chip, xBinChip, yBinChip); // Mosaic of cells within the chip
    250253
    251254    }
  • branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.h

    r6062 r6113  
    1414                        );
    1515
     16// Mosaic a chip together into a single cell with single readout
     17int pmChipMosaic(pmChip *chip,// Chip to mosaic
     18                 int xBinChip, int yBinChip // Binning of mosaic image in x and y
     19                );
     20
    1621// Mosaic all the cells in all (valid) chips together (neglecting the overscans); return number of chips
    17 int pmFPAMosaicChips(pmFPA *fpa,        // FPA
     22int pmFPAMosaicCells(pmFPA *fpa,        // FPA
    1823                     int xBinChip, int yBinChip // Binning of mosaic image in x and y
    1924                    );
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c

    r6080 r6113  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-01-20 09:47:06 $
     14*  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-01-21 04:33:38 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3636{
    3737    if (readout != NULL) {
     38        psTrace(__func__, 9, "Removing readout %x from cell %x...\n", (unsigned)readout, (unsigned)readout->parent);
     39        if (readout->parent) {
     40            psArray *readouts = readout->parent->readouts;
     41            for (int i = 0; i < readouts->n; i++) {
     42                if (readouts->data[i] == readout) {
     43                    readouts->data[i] = NULL;
     44                    break;
     45                }
     46            }
     47        }
     48        psTrace(__func__, 9, "Freeing readout %x\n", (unsigned)readout);
    3849        psFree(readout->image);
    3950        psFree(readout->mask);
    4051        psFree(readout->weight);
    4152        psFree(readout->analysis);
    42         #if 0
    43 
    44         psFree(readout->parent);
     53        #if 1
     54
     55        psMemDecrRefCounter(readout->parent);
    4556        #endif
    4657
    47         readout->parent = NULL;
    4858    }
    4959}
     
    5262{
    5363    if (cell != NULL) {
     64        psTrace(__func__, 9, "Removing cell %x from chip %x...\n", (unsigned)cell, (unsigned)cell->parent);
     65        if (cell->parent) {
     66            psArray *cells = cell->parent->cells;
     67            for (int i = 0; i < cells->n; i++) {
     68                if (cells->data[i] == cell) {
     69                    cells->data[i] = NULL;
     70                    break;
     71                }
     72            }
     73        }
     74        psTrace(__func__, 9, "Freeing cell %x\n", (unsigned)cell);
    5475        psFree(cell->toChip);
    5576        psFree(cell->toFPA);
     
    5879        psFree(cell->analysis);
    5980        psFree(cell->camera);
     81        #if 1
    6082        //
    6183        // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
    6284        // in order to avoid memory reference counter problems.
    6385        //
    64         #if 0
    65 
    66         for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
    67             pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
     86        psArray *readouts = cell->readouts;
     87        for (psS32 i = 0 ; i < readouts->n ; i++) {
     88            pmReadout *tmpReadout = readouts->data[i];
     89            readouts->data[i] = NULL;
    6890            tmpReadout->parent = NULL;
    6991            if (PS_FREE_HIERARCHY == 1) {
     92                psTrace(__func__, 9, "Will now free readout %x...\n", (unsigned)tmpReadout);
    7093                psFree(tmpReadout);
    7194            }
    7295        }
    73         psFree(cell->parent);
     96        psMemDecrRefCounter(cell->parent);
    7497        #endif
    7598
    76         cell->parent = NULL;
    77 
    78         psFree(cell->readouts);
    7999        psFree(cell->hdu);
    80 
    81100    }
    82101}
     
    85104{
    86105    if (chip != NULL) {
     106        psTrace(__func__, 9, "Removing chip %x from fpa %x...\n", (unsigned)chip, (unsigned)chip->parent);
     107        if (chip->parent) {
     108            psArray *chips = chip->parent->chips;
     109            for (int i = 0; i < chips->n; i++) {
     110                if (chips->data[i] == chip) {
     111                    chips->data[i] = NULL;
     112                    break;
     113                }
     114            }
     115        }
     116        psTrace(__func__, 9, "Freeing chip %x\n", (unsigned)chip);
     117
    87118        psFree(chip->toFPA);
    88119        psFree(chip->fromFPA);
    89120        psFree(chip->concepts);
    90121        psFree(chip->analysis);
     122        #if 1
    91123        //
    92124        // Set the parent to NULL in all chip->cells before psFree(chip->cells)
    93125        // in order to avoid memory reference counter problems.
    94126        //
    95         #if 0
    96 
    97         for (psS32 i = 0 ; i < chip->cells->n ; i++) {
    98             pmCell *tmpCell = (pmCell *) chip->cells->data[i];
     127        psArray *cells = chip->cells;
     128        for (psS32 i = 0 ; i < cells->n ; i++) {
     129            pmCell *tmpCell = cells->data[i];
     130            cells->data[i] = NULL;
    99131            tmpCell->parent = NULL;
    100132            if (PS_FREE_HIERARCHY == 1) {
     
    102134            }
    103135        }
    104         psFree(chip->parent);
     136        psMemDecrRefCounter(chip->parent);
    105137        #endif
    106138
    107         chip->parent = NULL;
    108         psFree(chip->cells);
    109139        psFree(chip->hdu);
    110140    }
     
    115145{
    116146    if (fpa != NULL) {
     147        psTrace(__func__, 9, "Freeing fpa %x\n", (unsigned)fpa);
    117148        psFree(fpa->fromTangentPlane);
    118149        psFree(fpa->toTangentPlane);
     
    121152        psFree(fpa->analysis);
    122153        psFree(fpa->camera);
     154        #if 1
    123155        //
    124156        // Set the parent to NULL in all fpa->chips before psFree(fpa->chips)
    125157        // in order to avoid memory reference counter problems.
    126158        //
    127         #if 0
    128 
    129         for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
    130             pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
     159        psArray *chips = fpa->chips;
     160        for (psS32 i = 0 ; i < chips->n ; i++) {
     161            pmChip *tmpChip = chips->data[i];
     162            chips->data[i] = NULL;
    131163            tmpChip->parent = NULL;
    132164            if (PS_FREE_HIERARCHY == 1) {
     
    135167        }
    136168        #endif
    137         psFree(fpa->chips);
    138169        psFree(fpa->hdu);
    139170        psFree(fpa->phu);
     
    167198    tmpReadout->bias = psListAlloc(NULL);
    168199    tmpReadout->analysis = psMetadataAlloc();
    169     tmpReadout->parent = cell;
     200    tmpReadout->parent = psMemIncrRefCounter(cell);
    170201    if (cell != NULL) {
    171202        cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
     
    197228    tmpCell->analysis = psMetadataAlloc();
    198229    tmpCell->readouts = psArrayAlloc(0);
    199     tmpCell->parent = chip;
     230    tmpCell->parent = psMemIncrRefCounter(chip);
    200231    if (chip != NULL) {
    201232        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
     
    230261    tmpChip->analysis = psMetadataAlloc();
    231262    tmpChip->cells = psArrayAlloc(0);
    232     tmpChip->parent = fpa;
     263    tmpChip->parent = psMemIncrRefCounter(fpa);
    233264    if (fpa != NULL) {
    234265        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
     
    562593
    563594        // Set weight image to the variance = g*f + rn^2
    564         psBinaryOp(readout->weight, image, "*", psScalarAlloc(gain, PS_TYPE_F32));
    565         psBinaryOp(readout->weight, readout->weight, "+", psScalarAlloc(readnoise*readnoise, PS_TYPE_F32));
     595        psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32));
     596        psBinaryOp(readout->weight, readout->weight, "+",
     597                   psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
    566598    }
    567599
Note: See TracChangeset for help on using the changeset viewer.