Changeset 14657
- Timestamp:
- Aug 23, 2007, 2:52:55 PM (19 years ago)
- Location:
- trunk/ppSim
- Files:
-
- 4 added
- 14 edited
-
notes.txt (added)
-
psf.txt (added)
-
src/Makefile.am (modified) (2 diffs)
-
src/ppSim.c (modified) (2 diffs)
-
src/ppSim.h (modified) (4 diffs)
-
src/ppSimAddNoise.c (modified) (3 diffs)
-
src/ppSimAddOverscan.c (modified) (1 diff)
-
src/ppSimArguments.c (modified) (2 diffs)
-
src/ppSimCreate.c (modified) (8 diffs)
-
src/ppSimInsertSource.c (modified) (1 diff)
-
src/ppSimInsertSources.c (modified) (3 diffs)
-
src/ppSimLoop.c (modified) (10 diffs)
-
src/ppSimMakeBias.c (modified) (2 diffs)
-
src/ppSimMakeDark.c (modified) (1 diff)
-
src/ppSimMakeSky.c (modified) (1 diff)
-
src/ppSimMakeSources.c (added)
-
src/ppSimSaturate.c (modified) (1 diff)
-
src/ppSimSetPSF.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/Makefile.am
r14463 r14657 13 13 ppSimMakeDark.c \ 14 14 ppSimMakeSky.c \ 15 ppSimInsertS tars.c\15 ppSimInsertSources.c \ 16 16 ppSimAddOverscan.c \ 17 17 ppSimAddNoise.c \ … … 19 19 ppSimBounds.c \ 20 20 ppSimStars.c \ 21 ppSimSetPSF.c \ 21 22 ppSimUtils.c \ 22 23 ppSimLoop.c -
trunk/ppSim/src/ppSim.c
r14463 r14657 4 4 { 5 5 psLibInit(NULL); 6 if (!pmModelClassInit ()) abort(); 7 6 8 pmConfig *config = pmConfigRead(&argc, argv, NULL); // Configuration 7 9 if (!config) { … … 18 20 } 19 21 20 psExit loopError; 21 if ((loopError = ppSimLoop(config))) { 22 if (!ppSimLoop(config)) { 22 23 psErrorStackPrint(stderr, "Unable to generate data."); 23 24 psFree(config); 24 exit( loopError);25 exit(PS_EXIT_SYS_ERROR); 25 26 } 26 27 -
trunk/ppSim/src/ppSim.h
r14463 r14657 72 72 73 73 /// Loop over the output file, generating simulated data 74 psExitppSimLoop(pmConfig *config ///< Configuration74 bool ppSimLoop(pmConfig *config ///< Configuration 75 75 ); 76 76 … … 89 89 90 90 psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config); 91 psVector *ppSimMakeBias (p sImage *signal, psImage *variance, pmCell *cell, pmConfig *config, const psRandom *rng) ;92 bool ppSimMakeDark (p sImage *signal, psImage *variance, pmConfig *config);93 bool ppSimMakeSky (p sImage *signal, psImage *variance, psImage *expCorr, ppSimType type, pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell);91 psVector *ppSimMakeBias (pmReadout *readout, pmConfig *config, const psRandom *rng) ; 92 bool ppSimMakeDark (pmReadout *readout, pmConfig *config); 93 bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config); 94 94 bool ppSimInsertStars (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell); 95 bool ppSimInsertSources (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config); 95 96 96 97 bool ppSimInitHeader(pmConfig *config, … … 99 100 pmCell *cell); 100 101 101 bool ppSimSaturate(psImage *image, // Image to apply saturation 102 const pmConfig *config, 103 const pmCell *cell); // Saturation level 102 bool ppSimSaturate(pmReadout *readout, // Image to apply saturation 103 const pmConfig *config); // Saturation level 104 104 105 105 bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config); … … 108 108 bool ppSimAddOverscan (pmReadout *readout, pmConfig *config, psVector *biasCols, psVector *biasRows, psRandom *rng); 109 109 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 ); 110 bool ppSimAddNoise(psImage *signal, 111 psImage *variance, 112 const pmCell *cell, 113 const pmConfig *config, 114 const psRandom *rng // Random number generator 115 ); 116 117 bool ppSimSetPSF (pmChip *chip, pmConfig *config); 116 118 117 119 #endif -
trunk/ppSim/src/ppSimAddNoise.c
r14463 r14657 2 2 3 3 // Add noise to an image 4 psImage *ppSimAddNoise(psImage *signal, // Signal image, modified and returned5 const psImage *variance, // Variance image6 const pmConfig *config,7 const pmCell *cell,8 const psRandom *rng // Random number generator4 bool 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 9 9 ) 10 10 { … … 22 22 if (!mdok) { 23 23 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find GAIN in recipe."); 24 return NULL;24 return false; 25 25 } 26 26 } … … 38 38 39 39 // XXX why return this?? 40 return signal;40 return true; 41 41 } 42 42 -
trunk/ppSim/src/ppSimAddOverscan.c
r14463 r14657 29 29 psImageInit(variance, PS_SQR(readnoise)); 30 30 31 ppSimAddNoise(signal, variance, config, readout->parent, rng);31 ppSimAddNoise(signal, variance, readout->parent, config, rng); 32 32 psListAdd(readout->bias, PS_LIST_TAIL, signal); 33 33 -
trunk/ppSim/src/ppSimArguments.c
r14531 r14657 66 66 psMetadataAddF32(arguments, PS_LIST_TAIL, "-starsmag", 0, "Brightest magnitude for fake stars", NAN); 67 67 psMetadataAddF32(arguments, PS_LIST_TAIL, "-starsdensity", 0, "Density of fake stars at magnitude", NAN); 68 psMetadataAddStr(arguments, PS_LIST_TAIL, "-psfclass", 0, "Type of PSF model", NULL); 68 69 psMetadataAddS32(arguments, PS_LIST_TAIL, "-bin", 0, "Binning in x and y", 1); 69 70 … … 194 195 psMetadataAddF32(config->arguments, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)", 195 196 pa * M_PI / 180.0); 197 198 199 const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // Filter name 200 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "PSF.MODEL", 0, "PSF model class", psfClass); 196 201 } 197 202 -
trunk/ppSim/src/ppSimCreate.c
r14531 r14657 1 1 # include "ppSim.h" 2 3 // XXX this function forces us to define the camera (on the command line) and format (via the 4 // PPSIM.OUTPUT entry). In this case, we need to set config->format,formatName based on these 5 // values. This will be a problem when we want to load an input image (in order to add fake 6 // stars). We will need to add some logic in ppSimArguments to distinguish the cases of 1) 7 // input image and 2) specified camera 2 8 3 9 pmFPAfile *ppSimCreate(pmConfig *config) … … 12 18 13 19 pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE); 14 psFree(fpa);15 20 if (!file) { 16 21 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s. " … … 20 25 if (file->type != PM_FPA_FILE_IMAGE) { 21 26 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE); 27 psFree(fpa); 22 28 psFree(file); 23 29 return NULL; … … 25 31 file->save = true; 26 32 33 config->format = psMemIncrRefCounter (file->format); 34 config->formatName = psStringCopy (file->formatName); 35 27 36 // have we supplied a psf model? 28 37 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 29 38 bool status = false; 39 40 // tie the psf file to the chipMosaic 30 41 pmFPAfileBindFromArgs(&status, file, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 31 42 if (!status) { 32 43 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 33 return status; 44 psFree(fpa); 45 psFree(file); 46 return NULL; 34 47 } 35 48 } 49 50 // XXX only invoke this code for OBJECT types of images 51 // PPSIM.SOURCES carries the constructed, fake sources with their true parameters 52 pmFPAfile *simSources = pmFPAfileDefineOutput (config, file->fpa, "PPSIM.SOURCES"); 53 if (!simSources) { 54 psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES"); 55 return false; 56 } 57 simSources->save = true; 36 58 37 59 pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes … … 44 66 psFree(fpa); 45 67 psFree(view); 68 psFree(file); 46 69 return NULL; 47 70 } … … 55 78 psFree(fpa); 56 79 psFree(view); 80 psFree(file); 57 81 return NULL; 58 82 } … … 66 90 psFree(fpa); 67 91 psFree(view); 92 psFree(file); 68 93 return NULL; 69 94 } … … 71 96 } 72 97 } 98 99 psFree(fpa); 73 100 psFree(view); 74 101 -
trunk/ppSim/src/ppSimInsertSource.c
r14531 r14657 1 1 # include "ppSim.h" 2 2 3 bool ppSimInsertSource s(psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) {3 bool ppSimInsertSource (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell) { 4 4 5 5 bool mdok; -
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 } -
trunk/ppSim/src/ppSimLoop.c
r14531 r14657 1 1 #include "ppSim.h" 2 2 3 psExitppSimLoop(pmConfig *config)3 bool ppSimLoop(pmConfig *config) 4 4 { 5 5 PS_ASSERT_PTR_NON_NULL(config, PS_EXIT_PROG_ERROR); … … 29 29 pmFPAview *view = pmFPAviewAlloc(0);// View for iterating over FPA 30 30 31 // XXX if we include the psphot analysis, we will need to activate the correct pmFPAfiles 32 // at the correct times. ppSim operates on PPSIM.OUTPUT and PPSIM.SOURCES 33 31 34 // load any needed files (eg, input image, PSF) 32 35 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 33 psError(PS PHOT_ERR_DATA, false, "failed IO for fpa in ppSim\n");36 psError(PS_ERR_UNKNOWN, false, "failed IO for fpa in ppSim\n"); 34 37 psFree(view); 35 38 return false; … … 43 46 // load any needed files (eg, input image, PSF) 44 47 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 45 psError(PS PHOT_ERR_DATA, false, "failed IO for chip %d in ppSim\n", view->chip);48 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip); 46 49 psFree (view); 47 50 return false; 48 51 } 49 52 50 pmPSF *psf = NULL;51 53 if (type == PPSIM_TYPE_OBJECT) { 52 psf = ppSimSetPSF (config); 54 if (!ppSimSetPSF (chip, config)) { 55 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip); 56 psFree (view); 57 return false; 58 } 53 59 } 54 60 … … 64 70 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.READDIR = 1 is the only supported mode."); 65 71 psFree(rng); 66 return PS_EXIT_CONFIG_ERROR;72 return false; 67 73 } 68 74 … … 74 80 75 81 // TO DO: Decide if cell is to be windowed, reduce numCols, numRows appropriately 76 psImage *signal= psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels77 psImage *variance= psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels82 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels 83 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels 78 84 79 85 psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects … … 82 88 } 83 89 84 psVector *biasRows = ppSimMakeBias ( signal, variance, cell, config, rng);90 psVector *biasRows = ppSimMakeBias (readout, config, rng); 85 91 if (type == PPSIM_TYPE_BIAS) goto done; 86 92 87 ppSimMakeDark ( signal, variance, config);93 ppSimMakeDark (readout, config); 88 94 if (type == PPSIM_TYPE_DARK) goto done; 89 95 90 ppSimMakeSky ( signal, variance, expCorr, type, config, fpa, chip, cell);96 ppSimMakeSky (readout, expCorr, type, config); 91 97 if (type == PPSIM_TYPE_FLAT) goto done; 92 98 93 99 if (type == PPSIM_TYPE_OBJECT) { 94 ppSimInsertS tars (signal, variance, expCorr, stars, config, chip, cell);100 ppSimInsertSources (readout, expCorr, stars, config); 95 101 } 96 102 97 103 done: 98 ppSimAddNoise(signal, variance, config, cell, rng); 99 ppSimSaturate(signal, config, cell); 100 101 readout->image = signal; 102 psFree(variance); 103 psFree(expCorr); 104 ppSimAddNoise(readout->image, readout->weight, cell, config, rng); 105 ppSimSaturate(readout, config); 104 106 105 107 ppSimAddOverscan (readout, config, biasCols, biasRows, rng); … … 123 125 psFree(rng); 124 126 psFree(view); 125 return PS_EXIT_SYS_ERROR; 127 // return PS_EXIT_SYS_ERROR; 128 return false; 126 129 } 127 130 } … … 135 138 psFree(rng); 136 139 psFree(view); 137 return PS_EXIT_SYS_ERROR; 140 // return PS_EXIT_SYS_ERROR; 141 return false; 138 142 } 139 143 … … 148 152 psFree(rng); 149 153 psFree(view); 150 return PS_EXIT_SYS_ERROR; 154 // return PS_EXIT_SYS_ERROR; 155 return false; 151 156 } 152 157 … … 154 159 psFree(view); 155 160 156 return 0;161 return true; 157 162 } -
trunk/ppSim/src/ppSimMakeBias.c
r14463 r14657 1 1 # include "ppSim.h" 2 2 3 psVector *ppSimMakeBias (p sImage *signal, psImage *variance, pmCell *cell, pmConfig *config, const psRandom *rng) {3 psVector *ppSimMakeBias (pmReadout *readout, pmConfig *config, const psRandom *rng) { 4 4 5 5 bool mdok; 6 7 pmCell *cell = readout->parent; 6 8 7 9 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe … … 20 22 } 21 23 } 24 25 psImage *signal = readout->image; 26 psImage *variance = readout->weight; 22 27 23 28 int numRows = signal->numRows; -
trunk/ppSim/src/ppSimMakeDark.c
r14463 r14657 2 2 3 3 // XXX add bounds to the inputs? 4 bool ppSimMakeDark (psImage *signal, psImage *variance, pmConfig *config) { 4 bool ppSimMakeDark (pmReadout *readout, pmConfig *config) { 5 6 psImage *signal = readout->image; 7 psImage *variance = readout->weight; 5 8 6 9 float darkRate = psMetadataLookupF32(NULL, config->arguments, "DARK.RATE"); // Dark rate -
trunk/ppSim/src/ppSimMakeSky.c
r14463 r14657 2 2 3 3 // 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) { 4 bool 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; 5 12 6 13 float expTime = psMetadataLookupF32(NULL, config->arguments, "EXPTIME"); // Exposure time -
trunk/ppSim/src/ppSimSaturate.c
r14463 r14657 2 2 3 3 // Apply saturation limit to image 4 bool ppSimSaturate(psImage *image, // Image to apply saturation 5 const pmConfig *config, 6 const pmCell *cell // Saturation level 4 bool ppSimSaturate(pmReadout *readout, // Image to apply saturation 5 const pmConfig *config // configuration data 7 6 ) 8 7 { 9 8 bool mdok; 9 10 psImage *image = readout->image; 11 pmCell *cell = readout->parent; 10 12 11 13 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
Note:
See TracChangeset
for help on using the changeset viewer.
