Changeset 18011 for trunk/ppSim/src/ppSimLoop.c
- Timestamp:
- Jun 8, 2008, 4:03:31 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimLoop.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimLoop.c
r15482 r18011 1 1 #include "ppSim.h" 2 3 # define ESCAPE(CODE,MSG) { \ 4 psError(CODE, false, MSG); \ 5 psFree (rng); \ 6 return false; } 2 7 3 8 bool ppSimLoop(pmConfig *config) 4 9 { 10 bool status; 11 12 // XXX if we are supplying a PSF, then we should use that to specify the seeing. 13 // we will need to force the psf to be loaded here (deactivate everyone, activate psf, load 14 // it, then calculate seeing as appropriate). 15 5 16 PS_ASSERT_PTR_NON_NULL(config, PS_EXIT_PROG_ERROR); 6 17 7 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file 18 // in this program, we are looping over the output image, rather than the input as in ppImage 19 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file 8 20 assert(file); 21 9 22 pmFPA *fpa = file->fpa; // FPA for file 10 23 assert(fpa); 11 24 12 p pSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate25 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 13 26 14 27 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator 15 28 16 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y 17 18 // Load catalogue stars 29 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate 30 ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate 31 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 32 19 33 psArray *stars = psArrayAllocEmpty (1); 20 if (type == PPSIM_TYPE_OBJECT) {21 ppSimLoadStars (stars, fpa, config);22 }23 24 // Add random stars25 if (type == PPSIM_TYPE_OBJECT) {26 ppSimMakeStars (stars, fpa, config, rng);27 }28 29 // Add random galaxies30 34 psArray *galaxies = psArrayAllocEmpty (1); 31 35 if (type == PPSIM_TYPE_OBJECT) { 32 ppSimMakeGalaxies (galaxies, fpa, config, rng); 36 // Load forced-photometry positions (these are placed on fpa->analysis for use in ppSimPhotomReadout) 37 if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots"); 38 39 // Load catalogue stars 40 if (!ppSimLoadStars (stars, fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load catalog stars"); 41 42 // Add random stars 43 if (!ppSimMakeStars (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars"); 44 45 // Add random galaxies 46 if (!ppSimMakeGalaxies (galaxies, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random galaxies"); 33 47 } 34 48 … … 46 60 47 61 ppSimUpdateConceptsFPA (fpa, config); 62 if (fpa->hdu) { // XXX only do this if there is no INPUT image 63 if (!ppSimInitHeader(config, fpa, NULL, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 64 } 48 65 49 66 pmChip *chip; // Chip from FPA … … 98 115 psVector *biasCols = ppSimMakeBiassec (cell, config); 99 116 100 for (int i = 0; i < cell->readouts->n; i++) { 101 102 pmReadout *readout = cell->readouts->data[i]; 103 assert (readout); 117 pmReadout *readout; 118 while ((readout = pmFPAviewNextReadout (view, fpa, 1))) { 104 119 105 120 // if we have not read in a weight or generated a fake image above, we need to … … 117 132 } 118 133 119 psVector *biasRows = ppSimMakeBias (readout, config, rng); 134 psVector *biasRows = ppSimMakeBias (&status, readout, config, rng); 135 if (!status) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure"); 120 136 if (type == PPSIM_TYPE_BIAS) goto done; 121 137 122 ppSimMakeDark (readout, config);138 if (!ppSimMakeDark (readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating dark structure"); 123 139 if (type == PPSIM_TYPE_DARK) goto done; 124 140 125 ppSimMakeSky (readout, expCorr, type, config);141 if (!ppSimMakeSky (readout, expCorr, type, config)) ESCAPE (PS_ERR_UNKNOWN, "problem generating sky background"); 126 142 if (type == PPSIM_TYPE_FLAT) goto done; 127 143 128 144 if (type == PPSIM_TYPE_OBJECT) { 129 ppSimInsertStars (readout, expCorr, stars, config);145 if (!ppSimInsertStars (readout, expCorr, stars, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting stars"); 130 146 } 131 147 132 148 if (type == PPSIM_TYPE_OBJECT) { 133 ppSimInsertGalaxies (readout, expCorr, galaxies, config);149 if (!ppSimInsertGalaxies (readout, expCorr, galaxies, config)) ESCAPE (PS_ERR_UNKNOWN, "problem inserting galaxies"); 134 150 } 135 151 … … 137 153 138 154 done: 139 ppSimAddNoise(readout->image, readout->weight, cell, config, rng);140 ppSimSaturate(readout, config);141 142 ppSimBadPixels(readout, config, rng);143 144 ppSimAddOverscan (readout, config, biasCols, biasRows, rng);155 if (!ppSimAddNoise(readout->image, readout->weight, cell, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding noise"); 156 if (!ppSimSaturate(readout, config)) ESCAPE (PS_ERR_UNKNOWN, "problem setting saturation levels"); 157 158 if (!ppSimBadPixels(readout, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding bad pixels"); 159 160 if (!ppSimAddOverscan (readout, config, biasCols, biasRows, rng)) ESCAPE (PS_ERR_UNKNOWN, "problem adding overscan region"); 145 161 psFree(biasRows); 146 162 … … 148 164 readout->parent->data_exists = true; 149 165 readout->parent->parent->data_exists = true; 166 167 // if there is an input image, merge it with the simulated image 168 if (!ppSimMergeReadouts (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image"); 150 169 } 151 170 psFree(biasCols); 152 171 153 ppSimUpdateConceptsCell (cell, config);172 if (!ppSimUpdateConceptsCell (cell, config)) ESCAPE (PS_ERR_UNKNOWN, "problem updating cell concepts"); 154 173 155 174 if (cell->hdu) { 156 ppSimInitHeader(config, NULL, NULL, cell); 175 // XXX only do this if there is no INPUT image? 176 if (!ppSimInitHeader(config, NULL, NULL, cell)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 157 177 } 158 178 … … 166 186 } 167 187 188 // XXX why no UpdateConceptsChip?? 189 168 190 if (chip->hdu) { 169 ppSimInitHeader(config, NULL, chip, NULL); 170 } 191 // XXX only do this if there is no INPUT image 192 if (!ppSimInitHeader(config, NULL, chip, NULL)) ESCAPE (PS_ERR_UNKNOWN, "problem setting output header"); 193 } 194 195 // we perform photometry on the readouts of this chip in the output 196 if (!ppSimPhotom (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem performing photometry"); 171 197 172 198 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { … … 174 200 psFree(rng); 175 201 psFree(view); 176 // return PS_EXIT_SYS_ERROR;177 202 return false; 178 203 } 179 180 204 } 181 205 182 206 psFree(stars); 183 207 psFree(galaxies); 184 185 if (fpa->hdu) {186 ppSimInitHeader(config, fpa, NULL, NULL);187 }188 208 189 209 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { … … 191 211 psFree(rng); 192 212 psFree(view); 193 // return PS_EXIT_SYS_ERROR;194 213 return false; 195 214 }
Note:
See TracChangeset
for help on using the changeset viewer.
