IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14547


Ignore:
Timestamp:
Aug 19, 2007, 4:21:10 PM (19 years ago)
Author:
eugene
Message:

convert ppSimLoop to use pmReadout, loading psf model, add sources based on psf model

Location:
branches/eam_branch_20070817/ppSim/src
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070817/ppSim/src/Makefile.am

    r14463 r14547  
    1313        ppSimMakeDark.c         \
    1414        ppSimMakeSky.c          \
    15         ppSimInsertStars.c      \
     15        ppSimInsertSources.c    \
    1616        ppSimAddOverscan.c      \
    1717        ppSimAddNoise.c         \
  • branches/eam_branch_20070817/ppSim/src/ppSim.h

    r14463 r14547  
    8989
    9090psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config);
    91 psVector *ppSimMakeBias (psImage *signal, psImage *variance, pmCell *cell, pmConfig *config, const psRandom *rng) ;
    92 bool ppSimMakeDark (psImage *signal, psImage *variance, pmConfig *config);
    93 bool ppSimMakeSky (psImage *signal, psImage *variance, psImage *expCorr, ppSimType type, pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell);
     91psVector *ppSimMakeBias (pmReadout *readout, pmConfig *config, const psRandom *rng) ;
     92bool ppSimMakeDark (pmReadout *readout, pmConfig *config);
     93bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config);
    9494bool ppSimInsertStars (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell);
     95bool ppSimInsertSources (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config);
    9596
    9697bool ppSimInitHeader(pmConfig *config,
     
    99100                     pmCell *cell);
    100101
    101 bool ppSimSaturate(psImage *image,      // Image to apply saturation
    102                    const pmConfig *config,                     
    103                    const pmCell *cell); // Saturation level
     102bool ppSimSaturate(pmReadout *readout,  // Image to apply saturation
     103                   const pmConfig *config); // Saturation level
    104104
    105105bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config);
     
    108108bool ppSimAddOverscan (pmReadout *readout, pmConfig *config, psVector *biasCols, psVector *biasRows, psRandom *rng);
    109109
    110 psImage *ppSimAddNoise(psImage *signal, // Signal image, modified and returned
    111                        const psImage *variance, // Variance image
    112                        const pmConfig *config,                 
    113                        const pmCell *cell,
    114                        const psRandom *rng // Random number generator
    115                        );
     110bool ppSimAddNoise(psImage *signal,
     111                   psImage *variance,
     112                   const pmCell *cell,                 
     113                   const pmConfig *config,                     
     114                   const psRandom *rng // Random number generator
     115    );
    116116
    117117#endif
  • branches/eam_branch_20070817/ppSim/src/ppSimAddNoise.c

    r14463 r14547  
    22
    33// Add noise to an image
    4 psImage *ppSimAddNoise(psImage *signal, // Signal image, modified and returned
    5                        const psImage *variance, // Variance image
    6                        const pmConfig *config,                 
    7                        const pmCell *cell,
    8                        const psRandom *rng // Random number generator
     4bool ppSimAddNoise(psImage *signal, // Signal image, modified and returned
     5                   psImage *variance,
     6                   const pmCell *cell,
     7                   const pmConfig *config,                     
     8                   const psRandom *rng // Random number generator
    99    )
    1010{
     
    2222        if (!mdok) {
    2323            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find GAIN in recipe.");
    24             return NULL;
     24            return false;
    2525        }
    2626    }
     
    3838
    3939    // XXX why return this??
    40     return signal;
     40    return true;
    4141}
    4242
  • branches/eam_branch_20070817/ppSim/src/ppSimAddOverscan.c

    r14463 r14547  
    2929        psImageInit(variance, PS_SQR(readnoise));
    3030
    31         ppSimAddNoise(signal, variance, config, readout->parent, rng);
     31        ppSimAddNoise(signal, variance, readout->parent, config, rng);
    3232        psListAdd(readout->bias, PS_LIST_TAIL, signal);
    3333
  • branches/eam_branch_20070817/ppSim/src/ppSimCreate.c

    r14531 r14547  
    1212
    1313    pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
    14     psFree(fpa);
    1514    if (!file) {
    1615        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s.  "
     
    2019    if (file->type != PM_FPA_FILE_IMAGE) {
    2120        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE);
     21        psFree(fpa);
    2222        psFree(file);
    2323        return NULL;
     
    3131        if (!status) {
    3232            psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    33             return status;
     33            psFree(fpa);
     34            psFree(file);
     35            return NULL;
    3436        }
    3537    }
     
    4446            psFree(fpa);
    4547            psFree(view);
     48            psFree(file);
    4649            return NULL;
    4750        }
     
    5558                psFree(fpa);
    5659                psFree(view);
     60                psFree(file);
    5761                return NULL;
    5862            }
     
    6670                    psFree(fpa);
    6771                    psFree(view);
     72                    psFree(file);
    6873                    return NULL;
    6974                }
     
    7176        }
    7277    }
     78
     79    psFree(fpa);
    7380    psFree(view);
    7481
  • branches/eam_branch_20070817/ppSim/src/ppSimInsertSource.c

    r14531 r14547  
    11# include "ppSim.h"
    22
    3 bool ppSimInsertSources (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {
     3bool ppSimInsertSource (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {
    44
    55    bool mdok;
  • branches/eam_branch_20070817/ppSim/src/ppSimInsertSources.c

    r14531 r14547  
    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
    5     bool mdok;
    65
    76    assert (stars);
    87   
     8    pmCell *cell = readout->parent;
     9    pmChip *chip = cell->parent;
     10
     11    // XXX we probably need this to get the size right
     12# if (0)
     13    bool mdok;
    914    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
    1015
    11     float seeing = psMetadataLookupF32(NULL, config->arguments, "SEEING"); // Seeing sigma (pix)
    1216    float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time
    1317    float skyRate = psMetadataLookupF32(NULL, config->arguments, "SKY.RATE"); // Sky rate
     
    2327    }
    2428
     29    // Rough noise estimate, appropriate for entire cell (use for source radius?)
     30    float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);
     31# endif
     32
    2533    int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0");
    2634    int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0");
     
    3543    int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
    3644
    37     // Rough noise estimate, appropriate for entire cell
    38     float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);
    39 
    4045    pmPSF *psf = psMetadataLookupPtr (NULL, chip->analysis, "PSF");
    4146
     47    int dX = PM_CELL_TO_CHIP (0.0, x0Cell, xParityCell, binning);
     48    int dY = PM_CELL_TO_CHIP (0.0, y0Cell, yParityCell, binning);
     49
     50    // add sources to the readout image & weight
    4251    for (long i = 0; i < stars->n; i++) {
    4352        ppSimStar *star = stars->data[i];
    4453
     54        // star->x,y are in fpa coordinates
     55
    4556        // 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);
     57        float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip);
     58        float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip);
    4859
    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);
     60        // Position on the cell and peak flux
     61        float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, binning);
     62        float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, binning);
     63
     64        if (xCell < 0) continue;
     65        if (yCell < 0) continue;
     66        if (xCell > readout->image->numCols) continue;
     67        if (yCell > readout->image->numRows) continue;
     68        // XXX need to apply col0, row0 if readout is a subarray
     69
     70        // XXX apply the expCorr to the star->flux before setting the model flux
     71
     72        // instantiate a model for the PSF at this location, set desired flux
     73        pmModel *model = pmModelFromPSFforXY (psf, xChip, yChip, 1.0);
     74        pmModelSetFlux (model, star->flux);
    5275
    5376        // construct a source, with model flux pixels set, based on the model
    54         pmSource *source = pmSourceFromModel (model);
     77        pmSource *source = pmSourceFromModel (model, readout, PM_SOURCE_TYPE_STAR);
    5578
    56         ppSimInsertSource(signal, variance, x, y, star->flux, roughNoise, seeing, expCorr);
     79        // XXX add the sources to a source array
     80
     81        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
    5782    }
     83
     84    // XXX add the source array to the readout analysis
     85
    5886    return true;
    5987}
  • branches/eam_branch_20070817/ppSim/src/ppSimLoop.c

    r14531 r14547  
    3131    // load any needed files (eg, input image, PSF)
    3232    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    33         psError(PSPHOT_ERR_DATA, false, "failed IO for fpa in ppSim\n");
     33        psError(PS_ERR_UNKNOWN, false, "failed IO for fpa in ppSim\n");
    3434        psFree(view);
    3535        return false;
     
    4343        // load any needed files (eg, input image, PSF)
    4444        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    45             psError(PSPHOT_ERR_DATA, false, "failed IO for chip %d in ppSim\n", view->chip);
     45            psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
    4646            psFree (view);
    4747            return false;
    4848        }
    4949
    50         pmPSF *psf = NULL;
     50        // XXX check for a supplied PSF, otherwise generate a basic one
    5151        if (type == PPSIM_TYPE_OBJECT) {
    52             psf = ppSimSetPSF (config);
     52            // XXX TBD : ppSimSetPSF (chip, config);
    5353        }
    5454
     
    7474
    7575                // TO DO: Decide if cell is to be windowed, reduce numCols, numRows appropriately
    76                 psImage *signal = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels
    77                 psImage *variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
     76                readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels
     77                readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
    7878
    7979                psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects
     
    8282                }
    8383
    84                 psVector *biasRows = ppSimMakeBias (signal, variance, cell, config, rng);
     84                psVector *biasRows = ppSimMakeBias (readout, config, rng);
    8585                if (type == PPSIM_TYPE_BIAS) goto done;
    8686               
    87                 ppSimMakeDark (signal, variance, config);
     87                ppSimMakeDark (readout, config);
    8888                if (type == PPSIM_TYPE_DARK) goto done;
    8989
    90                 ppSimMakeSky (signal, variance, expCorr, type, config, fpa, chip, cell);
     90                ppSimMakeSky (readout, expCorr, type, config);
    9191                if (type == PPSIM_TYPE_FLAT) goto done;
    9292
     93                // if (type == PPSIM_TYPE_OBJECT) {
     94                // ppSimInsertStars (readout, expCorr, stars, config, chip, cell);
     95                // }
     96
    9397                if (type == PPSIM_TYPE_OBJECT) {
    94                     ppSimInsertStars (signal, variance, expCorr, stars, config, chip, cell);
     98                    ppSimInsertSources (readout, expCorr, stars, config);
    9599                }
    96100
    97101            done:
    98                 ppSimAddNoise(signal, variance, config, cell, rng);
    99                 ppSimSaturate(signal, config, cell);
    100 
    101                 readout->image = signal;
    102                 psFree(variance);
    103                 psFree(expCorr);
     102                ppSimAddNoise(readout->image, readout->weight, cell, config, rng);
     103                ppSimSaturate(readout, config);
    104104
    105105                ppSimAddOverscan (readout, config, biasCols, biasRows, rng);
  • branches/eam_branch_20070817/ppSim/src/ppSimMakeBias.c

    r14463 r14547  
    11# include "ppSim.h"
    22
    3 psVector *ppSimMakeBias (psImage *signal, psImage *variance, pmCell *cell, pmConfig *config, const psRandom *rng) {
     3psVector *ppSimMakeBias (pmReadout *readout, pmConfig *config, const psRandom *rng) {
    44
    55    bool mdok;
     6
     7    pmCell *cell = readout->parent;
    68
    79    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
     
    2022        }
    2123    }
     24
     25    psImage *signal = readout->image;
     26    psImage *variance = readout->weight;
    2227
    2328    int numRows = signal->numRows;
  • branches/eam_branch_20070817/ppSim/src/ppSimMakeDark.c

    r14463 r14547  
    22
    33// XXX add bounds to the inputs?
    4 bool ppSimMakeDark (psImage *signal, psImage *variance, pmConfig *config) {
     4bool ppSimMakeDark (pmReadout *readout, pmConfig *config) {
     5
     6    psImage *signal = readout->image;
     7    psImage *variance = readout->weight;
    58
    69    float darkRate = psMetadataLookupF32(NULL, config->arguments, "DARK.RATE"); // Dark rate
  • branches/eam_branch_20070817/ppSim/src/ppSimMakeSky.c

    r14463 r14547  
    22
    33// XXX add bounds to the inputs?
    4 bool ppSimMakeSky (psImage *signal, psImage *variance, psImage *expCorr, ppSimType type, pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell) {
     4bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config) {
     5
     6    psImage *signal = readout->image;
     7    psImage *variance = readout->weight;
     8
     9    pmCell *cell = readout->parent;
     10    pmChip *chip = cell->parent;
     11    pmFPA  *fpa  = chip->parent;
    512
    613    float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time
  • branches/eam_branch_20070817/ppSim/src/ppSimSaturate.c

    r14463 r14547  
    22
    33// Apply saturation limit to image
    4 bool ppSimSaturate(psImage *image, // Image to apply saturation
    5                    const pmConfig *config,                     
    6                    const pmCell *cell // Saturation level
     4bool ppSimSaturate(pmReadout *readout, // Image to apply saturation
     5                   const pmConfig *config // configuration data
    76    )
    87{
    98    bool mdok;
     9
     10    psImage *image = readout->image;
     11    pmCell *cell = readout->parent;
    1012
    1113    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
Note: See TracChangeset for help on using the changeset viewer.