IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 9, 2010, 8:24:35 PM (16 years ago)
Author:
Paul Price
Message:

Adding ppVizPattern to visualise pattern correction from pattern output.

Location:
branches/eam_branches/20091201/ppViz
Files:
3 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/ppViz

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/eam_branches/20091113/ppViz26119-26255
      /branches/pap/ppViz26320
  • branches/eam_branches/20091201/ppViz/src/ppVizPattern/ppVizPatternLoop.c

    r26827 r26837  
    77#include <psmodules.h>
    88
    9 #include "ppVizPSF.h"
     9#include "ppVizPattern.h"
    1010
     11#define MASK_BAD 0xFFFF                 // Mask for bad pixels
    1112
    12 bool ppVizPSFLoop(ppVizPSFData *data // Run-time data
     13bool ppVizPatternLoop(ppVizPatternData *data // Run-time data
    1314    )
    1415{
    1516    pmConfig *config = data->config;                                        // Configuration data
    16     pmFPAfile *psfFile = pmFPAfileSelectSingle(config->files, "PSPHOT.PSF.LOAD", 0); // File with PSF
     17    pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPVIZPATTERN.INPUT", 0); // File with PSF
    1718
    1819    pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy
     
    2223
    2324    pmChip *chip;                       // Chip from FPA
    24     while ((chip = pmFPAviewNextChip(view, psfFile->fpa, 1))) {
     25    while ((chip = pmFPAviewNextChip(view, input->fpa, 1))) {
    2526        if (!chip->process || !chip->file_exists) {
    2627            continue;
     
    3132        }
    3233
    33         if (chip->cells->n != 1) {
    34             psWarning("More than one cell present for chip %d", view->chip);
    35         }
    36 
    3734        pmCell *cell;                   // Cell from chip
    38         while ((cell = pmFPAviewNextCell(view, psfFile->fpa, 1))) {
     35        while ((cell = pmFPAviewNextCell(view, input->fpa, 1))) {
    3936            if (!cell->process || !cell->file_exists) {
    4037                continue;
     
    4542            }
    4643
    47             if (cell->readouts->n == 0) {
    48                 pmReadout *ro = pmReadoutAlloc(cell);
    49                 ro->data_exists = true;
    50                 cell->data_exists = true;
    51                 chip->data_exists = true;
    52                 psFree(ro);             // Drop reference
    53             }
    54 
    55             if (cell->readouts->n > 1) {
    56                 psWarning("More than one readout present for chip %d, cell %d", view->chip, view->cell);
    57             }
    58 
    5944            pmReadout *readout;         // Readout from cell
    60             while ((readout = pmFPAviewNextReadout(view, psfFile->fpa, 1))) {
     45            while ((readout = pmFPAviewNextReadout(view, input->fpa, 1))) {
    6146                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    6247                    psError(PS_ERR_UNKNOWN, false, "Error loading data from files.");
     
    6752                }
    6853
    69                 pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF");              // PSF
    70                 assert(psf);
     54                int numCols = 0, numRows = 0; // Size of image
    7155
    72                 bool mdok;              // Status of MD lookup
    73                 psArray *sources = psMetadataLookupPtr(&mdok, readout->analysis, "PSPHOT.SOURCES"); // Sources
    74                 int numCols = 0, numRows = 0;              // Size of image
    75                 psVector *xOffset = NULL, *yOffset = NULL; // Offset from source to true position
     56                // Get size of image from concepts
     57                if (numCols == 0 || numRows == 0) {
     58                    numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE");
     59                    numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE");
     60                }
    7661
    77                 if (sources || (data->fakeNum > 0 && isfinite(data->fakeMag))) {
    78                   numCols = psf->fieldNx;
    79                   numRows = psf->fieldNy;
    80                   psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image", numCols, numRows);
    81                 }
    82                 if (sources) {
    83                     psMemIncrRefCounter(sources);
    84                     psLogMsg("ppVizPSF", PS_LOG_INFO, "Using %ld input sources", sources->n);
    85                 }
    86                 if (data->fakeNum > 0 && isfinite(data->fakeMag)) {
    87                   long numOld = 0; // Old number of sources
    88                   long numNew = -1; // New number of sources
    89                   psLogMsg("ppVizPSF", PS_LOG_INFO, "Adding %d fake sources", data->fakeNum);
    90                   if (sources) {
    91                     numOld = sources->n;
    92                     numNew = numOld + data->fakeNum;
    93                     sources = psArrayRealloc(sources, numNew);
    94                     sources->n = numNew;
    95                   } else {
    96                     numNew = data->fakeNum;
    97                     sources = psArrayAlloc(numNew);
    98                   }
    99 
    100                   psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    101 
    102                   for (int i = numOld; i < numNew; i++) {
    103                     pmSource *source = pmSourceAlloc(); // Fake source
    104                     sources->data[i] = source;
    105                     float xSrc = psRandomUniform(rng) * numCols, ySrc = psRandomUniform(rng) * numRows; // Position of source
    106 
    107                     pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
    108                     float fluxNorm = model->modelFlux(model->params);               // Flux for peak=1
    109                     float fluxPeak = powf(10.0, -0.4 * data->fakeMag) / fluxNorm; // Peak flux
    110                     source->peak = pmPeakAlloc(xSrc, ySrc, fluxPeak, PM_PEAK_LONE);
    111                     source->psfMag = data->fakeMag;
    112                     psFree(model);
    113                   }
    114                 }                 
    115                 if (!sources) {
    116                   // Generate fake image with only a single realisation of the PSF
    117                     sources = psArrayAlloc(1);
    118                     pmSource *source = pmSourceAlloc(); // Fake source
    119                     sources->data[0] = source;
    120                     float xRel = isfinite(data->x) ? data->x : 0.5; // Relative position in x
    121                     float yRel = isfinite(data->y) ? data->y : 0.5; // Relative position in y
    122                     float xSrc = xRel * psf->fieldNx, ySrc = yRel * psf->fieldNy; // Position of source
    123                     source->peak = pmPeakAlloc(xSrc, ySrc, 1.0, PM_PEAK_LONE);
    124                     pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
    125                     float flux = model->modelFlux(model->params);               // Flux for peak=1
    126                     psFree(model);
    127                     source->psfMag = -2.5 * log10(flux);
    128                     xOffset = psVectorAlloc(1, PS_TYPE_S32);
    129                     yOffset = psVectorAlloc(1, PS_TYPE_S32);
    130                     xOffset->data.S32[0] = data->size - xSrc;
    131                     yOffset->data.S32[0] = data->size - ySrc;
    132                     numCols = 2 * data->size + 1;
    133                     numRows = 2 * data->size + 1;
    134                     psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image with single PSF",
    135                              numCols, numRows);
     62                // Get size of image from TRIMSEC
     63                if (numCols == 0 || numRows == 0) {
     64                    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");
     65                    numCols = trimsec->x1 - trimsec->x0;
     66                    numRows = trimsec->y1 - trimsec->y0;
    13667                }
    13768
     
    14172                }
    14273
    143                 if (!pmReadoutFakeFromSources(readout, numCols, numRows, sources, 0, xOffset, yOffset, psf,
    144                                               data->minFlux, 0, false, true)) {
    145                     psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout.");
     74                readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     75                psImageInit(readout->image, 0.0);
     76
     77                if (!pmPatternRowApply(readout, MASK_BAD) || !pmPatternCellApply(readout, MASK_BAD)) {
     78                    psError(PS_ERR_UNKNOWN, false, "Unable to apply pattern correction.");
    14679                    return false;
    14780                }
    14881
    149                 psFree(sources);
    150                 psFree(xOffset);
    151                 psFree(yOffset);
    152 
    153                 pmHDU *hdu = pmHDUGetLowest(psfFile->fpa, chip, cell); // HDU for readout
     82                pmHDU *hdu = pmHDUGetLowest(input->fpa, chip, cell); // HDU for readout
    15483                if (!hdu) {
    15584                    psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU for data.");
     
    15988                    hdu->header = psMetadataAlloc();
    16089                }
    161                 ppVizPSFVersionHeader(hdu->header);
     90                ppVizPatternVersionHeader(hdu->header);
    16291
    16392
Note: See TracChangeset for help on using the changeset viewer.