IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 11, 2007, 1:01:03 PM (19 years ago)
Author:
Paul Price
Message:

Ensuring consistency between flux scales (peak vs integrated) --- stars now appear on the output image! Some memory fixing too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimInsertStars.c

    r14668 r14816  
    11# include "ppSim.h"
     2
     3// Reset a pointer: free and set to NULL
     4#define RESET(PTR) \
     5    psFree(PTR); \
     6    PTR = NULL;
     7
    28
    39bool ppSimInsertStars (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config) {
     
    2632    float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE");// CCD read noise, e
    2733    if (isnan(readnoise)) {
    28         psWarning("CELL.READNOISE is not set; reverting to recipe value READNOISE.");
    29         readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE");
    30         if (!mdok) {
    31             psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");
    32             return false;
    33         }
     34        psWarning("CELL.READNOISE is not set; reverting to recipe value READNOISE.");
     35        readnoise = psMetadataLookupF32(&mdok, recipe, "READNOISE");
     36        if (!mdok) {
     37            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe.");
     38            return false;
     39        }
    3440    }
    3541
     
    5864
    5965    // add sources to the readout image & weight
     66    psTrace("ppSim", 1, "Inserting %ld stars...\n", stars->n);
    6067    for (long i = 0; i < stars->n; i++) {
    61         ppSimStar *star = stars->data[i];
     68        ppSimStar *star = stars->data[i];
     69        psTrace("ppSim", 10, "Inserting star at %.1f,%.1f --> %.2f\n", star->x, star->y, star->flux);
    6270
    63         // star->x,y are in fpa coordinates
     71        // star->x,y are in fpa coordinates
    6472
    65         // Position on the cell and peak flux
    66         float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip);
    67         float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip);
     73        // Position on the cell and peak flux
     74        float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip);
     75        float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip);
    6876
    69         // Position on the cell and peak flux
    70         float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning);
    71         float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning);
     77        // Position on the cell and peak flux
     78        float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning);
     79        float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning);
    7280
    73         if (xCell < 0) continue;
    74         if (yCell < 0) continue;
    75         if (xCell > readout->image->numCols) continue;
    76         if (yCell > readout->image->numRows) continue;
    77         // XXX need to apply col0, row0 if readout is a subarray
     81        // XXX Note, the below does not put the edges of stars on the readout if they fall slightly off
     82        // This will be visible as cut-off stars at amplifier boundaries (e.g., Megacam)
     83        if (xCell < 0) continue;
     84        if (yCell < 0) continue;
     85        if (xCell > readout->image->numCols) continue;
     86        if (yCell > readout->image->numRows) continue;
     87        // XXX need to apply col0, row0 if readout is a subarray
    7888
    79         // XXX apply the expCorr to the star->flux before setting the model flux
     89        // Apply the expCorr to the star->flux before setting the model flux
     90        float flux = star->flux * expCorr->data.F32[(int)yCell][(int)xCell];
    8091
    81         // instantiate a model for the PSF at this location, set desired flux
    82         pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);
    83         pmModelSetFlux (model, star->flux);
     92        // instantiate a model for the PSF at this location, set desired flux
     93        pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);
     94        pmModelSetFlux (model, flux);
    8495
    85         // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
    86         float radius = model->modelRadius (model->params, roughNoise);
    87         radius = PS_MAX (radius, 1.0);
     96        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
     97        float radius = model->modelRadius (model->params, roughNoise);
     98        radius = PS_MAX (radius, 1.0);
    8899
    89         // construct a source, with model flux pixels set, based on the model
    90         pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);
     100        // construct a source, with model flux pixels set, based on the model
     101        pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);
    91102
    92         // XXX set the mag & err values (should this be done in pmSourceFromModel?)
    93         // XXX i should be applying the gain and the correct effective area
    94         psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);
    95         psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
     103        // XXX set the mag & err values (should this be done in pmSourceFromModel?)
     104        // XXX i should be applying the gain and the correct effective area
     105        psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);
     106        psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
    96107
    97         source->psfMag = -2.5*log10(star->flux);
    98         source->errMag = sqrt(Area*PS_SQR(roughNoise) + star->flux) / star->flux;       
    99        
    100         // XXX add the sources to a source array
     108        source->psfMag = -2.5*log10(flux);
     109        source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux;
    101110
    102         // insert the source flux in the image
    103         pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
    104         psArrayAdd (sources, 100,source);
     111        // XXX add the sources to a source array
     112
     113        // insert the source flux in the image
     114        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
     115        psArrayAdd (sources, 100,source);
     116        psFree(source);                 // Drop reference
     117
     118        // Blow away the image parts of the source, which makes the memory explode
     119        RESET(source->pixels);
     120        RESET(source->weight);
     121        RESET(source->maskObj);
     122        RESET(source->maskView);
     123        RESET(source->modelFlux);
     124        RESET(source->psfFlux);
     125        RESET(source->blends);
    105126    }
    106127
    107128    // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT"
    108129    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
     130    psFree(sources);
    109131
    110     // XXX many leaks in here, i think 
     132    // XXX many leaks in here, i think
    111133    return true;
    112134}
Note: See TracChangeset for help on using the changeset viewer.