Changeset 14657 for trunk/ppSim/src/ppSimInsertSources.c
- Timestamp:
- Aug 23, 2007, 2:52:55 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimInsertSources.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimInsertSources.c
r14531 r14657 1 1 # include "ppSim.h" 2 2 3 bool ppSimInsertSources (p sImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {3 bool ppSimInsertSources (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config) { 4 4 5 5 bool mdok; 6 6 7 7 assert (stars); 8 assert (readout); 8 9 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. 9 19 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 10 20 11 float seeing = psMetadataLookupF32(NULL, config->arguments, "SEEING"); // Seeing sigma (pix)12 21 float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time 13 22 float skyRate = psMetadataLookupF32(NULL, config->arguments, "SKY.RATE"); // Sky rate … … 23 32 } 24 33 34 // Rough noise estimate, appropriate for entire cell (use for source radius?) 35 float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime); 36 25 37 int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0"); 26 38 int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0"); … … 35 47 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y 36 48 37 // Rough noise estimate, appropriate for entire cell38 float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);49 pmPSF *psf = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF"); 50 assert (psf); 39 51 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); 41 54 55 psArray *sources = psArrayAllocEmpty (stars->n); 56 57 // add sources to the readout image & weight 42 58 for (long i = 0; i < stars->n; i++) { 43 59 ppSimStar *star = stars->data[i]; 44 60 61 // star->x,y are in fpa coordinates 62 45 63 // 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); 48 66 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); 52 86 53 87 // 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); 55 89 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); 57 95 } 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 58 101 return true; 59 102 }
Note:
See TracChangeset
for help on using the changeset viewer.
