Changeset 14668 for trunk/ppSim/src/ppSimInsertStars.c
- Timestamp:
- Aug 25, 2007, 12:02:59 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimInsertStars.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimInsertStars.c
r14463 r14668 1 1 # include "ppSim.h" 2 2 3 bool ppSimInsertStars (p sImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {3 bool ppSimInsertStars (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config) { 4 4 5 5 bool mdok; 6 6 7 assert (readout); 7 8 assert (stars); 8 9 10 if (!stars->n) { return true; } 11 12 // XXX is this needed? 13 // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources 14 15 pmCell *cell = readout->parent; 16 pmChip *chip = cell->parent; 17 18 // XXX this is an estimate of the sky noise based on the inputs to the image simulation. 19 // XXX update this to allow the estimate based on the measured sky background 20 // XXX this is missing the gain. 9 21 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 10 22 11 float seeing = psMetadataLookupF32(NULL, config->arguments, "SEEING"); // Seeing sigma (pix)12 23 float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time 13 24 float skyRate = psMetadataLookupF32(NULL, config->arguments, "SKY.RATE"); // Sky rate … … 23 34 } 24 35 36 // Rough noise estimate, appropriate for entire cell (use for source radius?) 37 float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime); 38 25 39 int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0"); 26 40 int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0"); … … 35 49 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y 36 50 37 // Rough noise estimate, appropriate for entire cell38 float roughNoise = sqrtf(PS_SQR(readnoise) + (darkRate + skyRate) * expTime);51 pmPSF *psf = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF"); 52 assert (psf); 39 53 54 int dX = PM_CELL_TO_CHIP (0.0, x0Cell, xParityCell, binning); 55 int dY = PM_CELL_TO_CHIP (0.0, y0Cell, yParityCell, binning); 56 57 psArray *sources = psArrayAllocEmpty (stars->n); 58 59 // add sources to the readout image & weight 40 60 for (long i = 0; i < stars->n; i++) { 41 61 ppSimStar *star = stars->data[i]; 42 62 63 // star->x,y are in fpa coordinates 64 43 65 // Position on the cell and peak flux 44 float x = PPSIM_FPA_TO_CELL(star->x, x0Cell, xParityCell, binning, x0Chip, xParityChip); 45 float y = PPSIM_FPA_TO_CELL(star->y, y0Cell, yParityCell, binning, y0Chip, yParityChip); 46 ppSimInsertStar(signal, variance, x, y, star->flux, roughNoise, seeing, expCorr); 66 float xChip = PM_FPA_TO_CHIP(star->x, x0Chip, xParityChip); 67 float yChip = PM_FPA_TO_CHIP(star->y, y0Chip, yParityChip); 68 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); 72 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 78 79 // XXX apply the expCorr to the star->flux before setting the model flux 80 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); 84 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); 88 89 // construct a source, with model flux pixels set, based on the model 90 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR); 91 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; 96 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 101 102 // insert the source flux in the image 103 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY); 104 psArrayAdd (sources, 100,source); 47 105 } 106 107 // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT" 108 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources); 109 110 // XXX many leaks in here, i think 48 111 return true; 49 112 } 113
Note:
See TracChangeset
for help on using the changeset viewer.
