IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 23, 2007, 2:52:55 PM (19 years ago)
Author:
eugene
Message:

finish code re-org, add loading of external psf model

File:
1 edited

Legend:

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

    r14531 r14657  
    11# include "ppSim.h"
    22
    3 bool ppSimInsertSources (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {
     3bool ppSimInsertSources (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config) {
    44
    55    bool mdok;
    66
    77    assert (stars);
     8    assert (readout);
    89   
     10    // XXX is this needed?
     11    // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources
     12
     13    pmCell *cell = readout->parent;
     14    pmChip *chip = cell->parent;
     15
     16    // XXX this is an estimate of the sky noise based on the inputs to the image simulation.
     17    // XXX update this to allow the estimate based on the measured sky background
     18    // XXX this is missing the gain.
    919    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
    1020
    11     float seeing = psMetadataLookupF32(NULL, config->arguments, "SEEING"); // Seeing sigma (pix)
    1221    float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time
    1322    float skyRate = psMetadataLookupF32(NULL, config->arguments, "SKY.RATE"); // Sky rate
     
    2332    }
    2433
     34    // Rough noise estimate, appropriate for entire cell (use for source radius?)
     35    float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);
     36
    2537    int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0");
    2638    int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0");
     
    3547    int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
    3648
    37     // Rough noise estimate, appropriate for entire cell
    38     float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);
     49    pmPSF *psf = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF");
     50    assert (psf);
    3951
    40     pmPSF *psf = psMetadataLookupPtr (NULL, chip->analysis, "PSF");
     52    int dX = PM_CELL_TO_CHIP (0.0, x0Cell, xParityCell, binning);
     53    int dY = PM_CELL_TO_CHIP (0.0, y0Cell, yParityCell, binning);
    4154
     55    psArray *sources = psArrayAllocEmpty (stars->n);
     56
     57    // add sources to the readout image & weight
    4258    for (long i = 0; i < stars->n; i++) {
    4359        ppSimStar *star = stars->data[i];
    4460
     61        // star->x,y are in fpa coordinates
     62
    4563        // Position on the cell and peak flux
    46         float x = PPSIM_FPA_TO_CELL(star->x, x0Cell, xParityCell, binning, x0Chip, xParityChip);
    47         float y = PPSIM_FPA_TO_CELL(star->y, y0Cell, yParityCell, binning, y0Chip, yParityChip);
     64        float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip);
     65        float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip);
    4866
    49         // instantiate a model for the PSF at this location (normalized or not?)
    50         // XXX
    51         pmModel *model = pmModelFromPSFforXY (psf, star->x, star->y, star->flux);
     67        // Position on the cell and peak flux
     68        float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning);
     69        float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning);
     70
     71        if (xCell < 0) continue;
     72        if (yCell < 0) continue;
     73        if (xCell > readout->image->numCols) continue;
     74        if (yCell > readout->image->numRows) continue;
     75        // XXX need to apply col0, row0 if readout is a subarray
     76
     77        // XXX apply the expCorr to the star->flux before setting the model flux
     78
     79        // instantiate a model for the PSF at this location, set desired flux
     80        pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);
     81        pmModelSetFlux (model, star->flux);
     82
     83        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
     84        float radius = model->modelRadius (model->params, roughNoise);
     85        radius = PS_MAX (radius, 1.0);
    5286
    5387        // construct a source, with model flux pixels set, based on the model
    54         pmSource *source = pmSourceFromModel (model);
     88        pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);
    5589
    56         ppSimInsertSource(signal, variance, x, y, star->flux, roughNoise, seeing, expCorr);
     90        // XXX add the sources to a source array
     91
     92        // insert the source flux in the image
     93        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
     94        psArrayAdd (sources, 100,source);
    5795    }
     96
     97    // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT"
     98    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
     99
     100    // XXX many leaks in here, i think
    58101    return true;
    59102}
Note: See TracChangeset for help on using the changeset viewer.