Changeset 17702
- Timestamp:
- May 15, 2008, 12:01:36 PM (18 years ago)
- Location:
- branches/eam_branch_20080511/ppSim
- Files:
-
- 11 edited
-
notes.txt (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/ppSim.h (modified) (2 diffs)
-
src/ppSimAddNoise.c (modified) (1 diff)
-
src/ppSimAddOverscan.c (modified) (1 diff)
-
src/ppSimArguments.c (modified) (2 diffs)
-
src/ppSimCreate.c (modified) (5 diffs)
-
src/ppSimLoop.c (modified) (10 diffs)
-
src/ppSimMakeBias.c (modified) (3 diffs)
-
src/ppSimMakeDark.c (modified) (1 diff)
-
src/ppSimMakeSky.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/notes.txt
r14657 r17702 1 2 2008.05.14 3 4 ppSim needs some work to be a bit more realistic. It currently does 5 not do the correct thing for generating flats or shutter 6 corrections. It is only applying them to the background sky model. 7 It is not applying them to the stellar flux. Also, for adding 8 sources on top of existing images, it needs to apply the Poisson 9 stats to the generated stars and then add the pixel values to the 10 input image. currently, it is placing them directly in the input 11 image. 12 13 1 14 2 15 ppSim development work still needed: -
branches/eam_branch_20080511/ppSim/src/Makefile.am
r17672 r17702 26 26 ppSimLoadSpots.c \ 27 27 ppSimPhotom.c \ 28 ppSimMergeReadouts.c \ 28 29 ppSimMosaicChip.c \ 29 30 ppSimBadPixels.c -
branches/eam_branch_20080511/ppSim/src/ppSim.h
r17672 r17702 95 95 96 96 psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config); 97 psVector *ppSimMakeBias ( pmReadout *readout, pmConfig *config, const psRandom *rng) ;97 psVector *ppSimMakeBias (bool *status, pmReadout *readout, pmConfig *config, const psRandom *rng) ; 98 98 bool ppSimMakeDark (pmReadout *readout, pmConfig *config); 99 99 bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config); … … 174 174 float ppSimGetZeroPoint (psMetadata *recipe, char *filter); 175 175 176 bool ppSimMergeReadouts (pmReadout *outReadout, pmReadout *inReadout); 177 176 178 #endif -
branches/eam_branch_20080511/ppSim/src/ppSimAddNoise.c
r14657 r17702 40 40 return true; 41 41 } 42 -
branches/eam_branch_20080511/ppSim/src/ppSimAddOverscan.c
r14657 r17702 4 4 5 5 bool mdok; 6 7 // skip this step if we did not generate a bias level 8 if (biasCols == NULL) return true; 6 9 7 10 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe -
branches/eam_branch_20080511/ppSim/src/ppSimArguments.c
r17672 r17702 147 147 148 148 char *typeStr = ppSimArgToRecipeStr (&status, options, "IMAGE.TYPE", arguments, "-type"); // Requested exposure type 149 if ( !status) {149 if (typeStr == NULL) { 150 150 psError(PS_ERR_IO, false, "An exposure type must be specified using -type"); 151 151 psFree(arguments); … … 178 178 ppSimArgToRecipeS32(&status, options, "BINNING", arguments, "-bin"); 179 179 180 // XX don't do this: recipe is not yet fully realized (camera options not interpolated) 180 181 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 181 182 -
branches/eam_branch_20080511/ppSim/src/ppSimCreate.c
r17672 r17702 17 17 return NULL; 18 18 } 19 20 simImage = true;21 fpa = pmFPAConstruct(config->camera); // FPA to contain the observation22 if (!fpa) {23 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");24 return NULL;25 }26 19 } else { 20 // If an image is supplied, we still generate a fake image and merge them together downstream 21 // (otherwise, we get the variance wrong). 27 22 simImage = false; 28 23 if (input->type != PM_FPA_FILE_IMAGE) { … … 30 25 return NULL; 31 26 } 32 fpa = psMemIncrRefCounter (input->fpa); 27 } 28 29 // generate the fpa structure used by the output camera (determined from INPUT or specified) 30 assert (config->camera); 31 fpa = pmFPAConstruct(config->camera); // FPA to contain the observation 32 if (!fpa) { 33 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 34 return NULL; 33 35 } 34 36 … … 98 100 99 101 // PPSIM.SOURCES carries the constructed, fake sources with their true parameters 100 // XXX only invoke this code for OBJECT types of images 102 // XXX only invoke this code for OBJECT types of images? 101 103 pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES"); 102 104 if (!simSources) { … … 106 108 simSources->save = true; 107 109 108 // if we have loaded an input image, we d o not need to populate the fpa109 if ( !simImage) {110 // if we have loaded an input image, we derive certain values from the image, if possible 111 if (input) { 110 112 // we need to extract certain metadata from the image and populate the recipe. 111 113 // or else we need to set the fpa concepts based on the recipe options... … … 118 120 float zp = ppSimGetZeroPoint (recipe, filter); 119 121 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 120 121 return output;122 122 } 123 123 -
branches/eam_branch_20080511/ppSim/src/ppSimLoop.c
r17672 r17702 8 8 bool ppSimLoop(pmConfig *config) 9 9 { 10 bool status; 11 10 12 PS_ASSERT_PTR_NON_NULL(config, PS_EXIT_PROG_ERROR); 11 13 … … 13 15 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file 14 16 assert(file); 17 18 // if we have an input image, we need to add the synthetic data on top of it below 19 // XXX we may potentially use this input file to skip missing elements 20 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.INPUT"); 15 21 16 22 pmFPA *fpa = file->fpa; // FPA for file … … 105 111 106 112 psVector *biasCols = ppSimMakeBiassec (cell, config); 113 114 pmCell *inputCell = NULL; 115 if (input) { 116 inputCell = pmFPAviewThisCell (view, input->fpa); 117 } 107 118 108 119 for (int i = 0; i < cell->readouts->n; i++) { … … 125 136 } 126 137 127 psVector *biasRows = ppSimMakeBias (readout, config, rng); 138 psVector *biasRows = ppSimMakeBias (&status, readout, config, rng); 139 if (!status) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure"); 128 140 if (type == PPSIM_TYPE_BIAS) goto done; 129 141 130 ppSimMakeDark (readout, config);142 if (!ppSimMakeDark (readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure"); 131 143 if (type == PPSIM_TYPE_DARK) goto done; 132 144 133 ppSimMakeSky (readout, expCorr, type, config);145 if (!ppSimMakeSky (readout, expCorr, type, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating sky background"); 134 146 if (type == PPSIM_TYPE_FLAT) goto done; 135 147 136 148 if (type == PPSIM_TYPE_OBJECT) { 137 ppSimInsertStars (readout, expCorr, stars, config);149 if (!ppSimInsertStars (readout, expCorr, stars, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting stars"); 138 150 } 139 151 140 152 if (type == PPSIM_TYPE_OBJECT) { 141 ppSimInsertGalaxies (readout, expCorr, galaxies, config);153 if (!ppSimInsertGalaxies (readout, expCorr, galaxies, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting galaxies"); 142 154 } 143 155 … … 145 157 146 158 done: 147 ppSimAddNoise(readout->image, readout->weight, cell, config, rng);148 ppSimSaturate(readout, config);149 150 ppSimBadPixels(readout, config, rng);151 152 ppSimAddOverscan (readout, config, biasCols, biasRows, rng);159 if (!ppSimAddNoise(readout->image, readout->weight, cell, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding noise"); 160 if (!ppSimSaturate(readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem setting saturation levels"); 161 162 if (!ppSimBadPixels(readout, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding bad pixels"); 163 164 if (!ppSimAddOverscan (readout, config, biasCols, biasRows, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding overscan region"); 153 165 psFree(biasRows); 154 166 … … 156 168 readout->parent->data_exists = true; 157 169 readout->parent->parent->data_exists = true; 170 171 if (inputCell && inputCell->readouts->data[i]) { 172 if (!ppSimMergeReadouts (readout, inputCell->readouts->data[i])) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image"); 173 } 158 174 } 159 175 psFree(biasCols); 160 176 161 ppSimUpdateConceptsCell (cell, config);177 if (!ppSimUpdateConceptsCell (cell, config)) ESCAPE (PS_ERR_UNKNOWN, "problem updating cell concepts"); 162 178 163 179 if (cell->hdu) { 164 ppSimInitHeader(config, NULL, NULL, cell); 180 // XXX only do this if there is no INPUT image? 181 if (!ppSimInitHeader(config, NULL, NULL, cell)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 165 182 } 166 183 … … 175 192 176 193 if (chip->hdu) { 177 ppSimInitHeader(config, NULL, chip, NULL); 194 // XXX only do this if there is no INPUT image 195 if (!ppSimInitHeader(config, NULL, chip, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 178 196 } 179 197 180 198 // we perform photometry on the readouts of this chip in the output 181 ppSimPhotom (config, view);199 if (!ppSimPhotom (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem performing photometry"); 182 200 183 201 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { … … 185 203 psFree(rng); 186 204 psFree(view); 187 // return PS_EXIT_SYS_ERROR;188 205 return false; 189 206 } … … 195 212 196 213 if (fpa->hdu) { 197 ppSimInitHeader(config, fpa, NULL, NULL); 214 // XXX only do this if there is no INPUT image 215 if (!ppSimInitHeader(config, fpa, NULL, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 198 216 } 199 217 … … 202 220 psFree(rng); 203 221 psFree(view); 204 // return PS_EXIT_SYS_ERROR;205 222 return false; 206 223 } -
branches/eam_branch_20080511/ppSim/src/ppSimMakeBias.c
r17672 r17702 1 1 # include "ppSim.h" 2 2 3 psVector *ppSimMakeBias ( pmReadout *readout, pmConfig *config, const psRandom *rng) {3 psVector *ppSimMakeBias (bool *status, pmReadout *readout, pmConfig *config, const psRandom *rng) { 4 4 5 5 bool mdok; 6 7 if (status) *status = true; 6 8 7 9 pmCell *cell = readout->parent; … … 9 11 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 10 12 11 bool bias = psMetadataLookupBool(& status, recipe, "BIAS"); // Generate a Bias?12 if (!bias) return true;13 bool bias = psMetadataLookupBool(&mdok, recipe, "BIAS"); // Generate a Bias? 14 if (!bias) return NULL; 13 15 14 16 float biasLevel = psMetadataLookupF32(NULL, recipe, "BIAS.LEVEL"); // Bias level … … 22 24 if (!mdok) { 23 25 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find READNOISE in recipe."); 26 *status = false; 24 27 return NULL; 25 28 } -
branches/eam_branch_20080511/ppSim/src/ppSimMakeDark.c
r17672 r17702 11 11 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 12 12 13 bool dark = psMetadataLookupBool(& status, recipe, "DARK"); // Generate a DARK?13 bool dark = psMetadataLookupBool(&mdok, recipe, "DARK"); // Generate a DARK? 14 14 if (!dark) return true; 15 15 16 float darkRate = psMetadataLookupF32(NULL, recipe, "DARK.RATE"); // Dark rate 17 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time 16 float darkRate = psMetadataLookupF32(&mdok, recipe, "DARK.RATE"); // Dark rate 17 if (isnan(darkRate)) { 18 psError(PS_ERR_UNKNOWN, false, "missing DARK.RATE\n"); 19 return false; 20 } 21 22 float expTime = psMetadataLookupF32(&mdok, recipe, "EXPTIME"); // Exposure time 23 if (isnan(expTime)) { 24 psError(PS_ERR_UNKNOWN, false, "missing EXPTIME\n"); 25 return false; 26 } 27 28 psTrace("ppSim", 6, "darkRate: %f, expTime: %f\n", darkRate, expTime); 18 29 19 30 for (int y = 0; y < signal->numRows; y++) { -
branches/eam_branch_20080511/ppSim/src/ppSimMakeSky.c
r17672 r17702 1 1 # include "ppSim.h" 2 2 3 // XXX add bounds to the inputs? 3 // this function sets the skyRate to a value for the night sky (SKY.RATE or SKY.MAGS) or for a 4 // flat-field image (FLAT.RATE). Include a shutter correction and a scattered light source 5 4 6 bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config) { 5 7 … … 16 18 17 19 bool sky = psMetadataLookupBool(&status, recipe, "SKY"); // Generate a SKY flux? 18 if (!sky) return true;19 20 20 float expTime = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time 21 float flatSigma = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient 22 float flatRate = psMetadataLookupF32(&status, recipe, "FLAT.RATE"); // Flat-field rate 23 float shutterTime = psMetadataLookupF32(&status, recipe, "SHUTTER.TIME"); // Shutter time 24 float skyRate = psMetadataLookupF32(&status, recipe, "SKY.RATE"); // Sky rate 21 float expTime = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time 22 23 float flatSigma = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient 24 float flatRate = psMetadataLookupF32(&status, recipe, "FLAT.RATE"); // Flat-field rate 25 float shutterTime = psMetadataLookupF32(&status, recipe, "SHUTTER.TIME"); // Shutter time 26 float scatterScale = psMetadataLookupF32(&status, recipe, "SCATTER.SCALE"); // scattered light term 27 float skyRate = psMetadataLookupF32(&status, recipe, "SKY.RATE"); // Sky rate 25 28 if (isnan(skyRate)) { 26 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status);27 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); assert (status);28 float skyMags = psMetadataLookupF32(&status, recipe, "SKY.MAGS"); assert (status);29 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status); 30 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); assert (status); 31 float skyMags = psMetadataLookupF32(&status, recipe, "SKY.MAGS"); assert (status); 29 32 skyRate = scale * scale * ppSimMagToFlux (skyMags, zp); 33 } 34 if (type == PPSIM_TYPE_FLAT) { 35 skyRate = flatRate; 30 36 } 31 37 … … 44 50 // Size of FPA 45 51 psRegion *bounds = ppSimFPABounds (fpa); 52 int dXfpa = bounds->x1 - bounds->x0; 53 int dYfpa = bounds->y1 - bounds->y0; 46 54 47 55 // Correct chip offsets so that boresight is in the middle of the FPA 48 x0Chip -= 0.5 * (bounds->x1 - bounds->x0);49 y0Chip -= 0.5 * (bounds->y1 - bounds->y0);56 x0Chip -= 0.5 * dXfpa; 57 y0Chip -= 0.5 * dYfpa; 50 58 51 59 for (int y = 0; y < signal->numRows; y++) { … … 62 70 63 71 // Gaussian flat-field over the FPA 64 float flatValue = expf(-0.5 / PS_SQR(flatSigma) * (PS_SQR(yFPA) + PS_SQR(xFPA))) / 65 flatSigma / sqrtf(2.0 * M_PI); 72 float flatValue = expf(-0.5 / PS_SQR(flatSigma) * (PS_SQR(yFPA) + PS_SQR(xFPA))) / flatSigma / sqrtf(2.0 * M_PI); 66 73 67 if (type == PPSIM_TYPE_FLAT) { 68 float flatFlux = flatRate * flatValue * realExpTime; // Flux from flat-field 69 signal->data.F32[y][x] += flatFlux; 70 variance->data.F32[y][x] += flatFlux; 71 continue; 72 } 74 float scatterRate = 0.0; 73 75 74 expCorr->data.F32[y][x] = realExpTime / expTime; 76 if (sky) { 77 // add a scattered light term to the flat-field images (no 78 if (type == PPSIM_TYPE_FLAT) { 79 float xF = 2.0*(xFPA / dXfpa) - 1.0; 80 scatterRate = scatterScale * PS_SQR(xF); 81 } 75 82 76 // Sky background 77 float skyFlux = skyRate * flatValue * realExpTime; // Flux from sky 78 signal->data.F32[y][x] += skyFlux; 79 variance->data.F32[y][x] += skyFlux; 83 // Sky background 84 float skyFlux = (skyRate * flatValue + scatterRate) * realExpTime; // Flux from sky 85 signal->data.F32[y][x] += skyFlux; 86 variance->data.F32[y][x] += skyFlux; 87 } 88 89 // used later to modify the star and galaxy photometry 90 if (expCorr) { 91 expCorr->data.F32[y][x] = realExpTime / expTime; 92 } 80 93 81 94 // TO DO: Add fringes
Note:
See TracChangeset
for help on using the changeset viewer.
