- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ppStack/src (modified) (1 prop)
-
ppStack/src/ppStackPrepare.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ppStack/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppStackVersionDefinitions.h 12 ppStackErrorCodes.c 13 ppStackErrorCodes.h
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ppStack/src/ppStackPrepare.c
r23573 r27840 26 26 float zpRadius = psMetadataLookupS32(&mdok, recipe, "PHOT.RADIUS"); // Radius for PHOT measurement 27 27 if (!mdok) { 28 psError(P S_ERR_UNKNOWN, true, "Unable to find PHOT.RADIUS in recipe");28 psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.RADIUS in recipe"); 29 29 return false; 30 30 } 31 31 float zpSigma = psMetadataLookupF32(&mdok, recipe, "PHOT.SIGMA"); // Gaussian sigma for photometry 32 32 if (!mdok) { 33 psError(P S_ERR_UNKNOWN, true, "Unable to find PHOT.SIGMA in recipe");33 psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.SIGMA in recipe"); 34 34 return false; 35 35 } 36 36 float zpFrac = psMetadataLookupF32(&mdok, recipe, "PHOT.FRAC"); // Fraction of good pixels for photometry 37 37 if (!mdok) { 38 psError(P S_ERR_UNKNOWN, true, "Unable to find PHOT.FRAC in recipe");38 psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.FRAC in recipe"); 39 39 return false; 40 40 } … … 42 42 psString maskValStr = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask going in 43 43 if (!mdok || !maskValStr) { 44 psError(P S_ERR_UNKNOWN, false, "Unable to find MASK.VAL in recipe");44 psError(PPSTACK_ERR_CONFIG, false, "Unable to find MASK.VAL in recipe"); 45 45 return false; 46 46 } … … 53 53 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics 54 54 if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) { 55 psError(P S_ERR_UNKNOWN, false, "Unable to measure background for image");55 psError(PPSTACK_ERR_DATA, false, "Unable to measure background for image"); 56 56 psFree(stats); 57 57 psFree(rng); … … 126 126 options->inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs 127 127 psVectorInit(options->inputMask, 0); 128 options->exposures = psVectorAlloc(options->num, PS_TYPE_F32); 129 psVectorInit(options->exposures, NAN); 128 130 129 131 pmFPAfileActivate(config->files, false, NULL); … … 134 136 } 135 137 136 psMetadataIterator *fileIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, "^PPSTACK.INPUT$");137 psMetadataItem *fileItem; // Item from iteration138 138 psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope 139 139 int numCols = 0, numRows = 0; // Size of image 140 int index = 0; // Index for file 141 while ((fileItem = psMetadataGetAndIncrement(fileIter))) { 142 assert(fileItem->type == PS_DATA_UNKNOWN); 143 pmFPAfile *inputFile = fileItem->data.V; // An input file 140 options->sumExposure = 0.0; 141 for (int i = 0; i < num; i++) { 142 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File of interest 143 pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest 144 145 options->exposures->data.F32[i] = psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE"); 146 options->sumExposure += options->exposures->data.F32[i]; 144 147 145 148 // Get list of PSFs, to determine target PSF 146 149 if (options->convolve) { 147 pmChip *chip = pmFPAviewThisChip(view, inputFile->fpa); // The chip: holds the PSF150 pmChip *chip = pmFPAviewThisChip(view, file->fpa); // The chip: holds the PSF 148 151 pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF 149 152 if (!psf) { 150 psError(PS_ERR_UNKNOWN, false, "Unable to find PSF."); 151 psFree(view); 152 psFree(fileIter); 153 psError(PPSTACK_ERR_PROG, false, "Unable to find PSF."); 154 psFree(view); 153 155 psFree(psfs); 154 156 return false; 155 157 } 156 psfs->data[i ndex] = psMemIncrRefCounter(psf);158 psfs->data[i] = psMemIncrRefCounter(psf); 157 159 psMetadataRemoveKey(chip->analysis, "PSPHOT.PSF"); 158 160 159 pmCell *cell = pmFPAviewThisCell(view, inputFile->fpa); // Cell of interest161 pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest 160 162 pmHDU *hdu = pmHDUFromCell(cell); 161 163 assert(hdu && hdu->header); … … 163 165 int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows 164 166 if (naxis1 <= 0 || naxis2 <= 0) { 165 psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF."); 166 psFree(view); 167 psFree(fileIter); 167 psError(PPSTACK_ERR_PROG, false, "Unable to determine size of image from PSF."); 168 psFree(view); 168 169 psFree(psfs); 169 170 return false; … … 176 177 177 178 178 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources 179 psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources 180 if (!sources) { 181 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout."); 182 return NULL; 183 } 184 options->sourceLists->data[index] = psMemIncrRefCounter(sources); 179 bool redoPhot = psMetadataLookupBool(NULL, recipe, "PHOT"); 180 181 pmDetections *detections = NULL; 182 if (options->convolve || options->matchZPs || options->photometry || redoPhot) { 183 pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout with sources 184 detections = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.DETECTIONS"); // Sources 185 if (!detections || !detections->allSources) { 186 psWarning("No detections found for image %d --- rejecting.", i); 187 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_CAL; 188 continue; 189 } 190 psAssert (detections->allSources, "missing sources?"); 191 192 options->sourceLists->data[i] = psMemIncrRefCounter(detections->allSources); 193 } 185 194 186 195 // Re-do photometry if we don't trust the source lists 187 if ( psMetadataLookupBool(NULL, recipe, "PHOT")) {188 psTrace("ppStack", 2, "Photometering input %d of %d....\n", i ndex, num);196 if (redoPhot) { 197 psTrace("ppStack", 2, "Photometering input %d of %d....\n", i, num); 189 198 pmFPAfileActivate(config->files, false, NULL); 190 ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, index); 191 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", index); // File 199 ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, i); 200 if (options->convolve) { 201 pmFPAfileActivate(config->files, true, "PPSTACK.CONV.KERNEL"); 202 } 203 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File 192 204 pmFPAview *photView = ppStackFilesIterateDown(config); 193 205 if (!photView) { … … 198 210 pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest 199 211 200 if (!ppStackInputPhotometer(ro, sources, config)) {201 psError( PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources");212 if (!ppStackInputPhotometer(ro, detections->allSources, config)) { 213 psError(psErrorCodeLast(), false, "Unable to do photometry on input sources"); 202 214 psFree(view); 203 215 psFree(photView); … … 213 225 ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true); 214 226 } 215 216 index++; 217 } 218 psFree(fileIter); 227 } 228 229 psString log = psStringCopy("Input seeing FWHMs:\n"); // Log message 230 bool havePSFs = false; // Do we have any PSFs? 231 options->inputSeeing = psVectorAlloc(num, PS_TYPE_F32); 232 psVectorInit(options->inputSeeing, NAN); 233 for (int i = 0; i < num; i++) { 234 pmPSF *psf = psfs->data[i]; // PSF for image 235 if (!psf) { 236 continue; 237 } 238 havePSFs = true; 239 240 int xNum = PS_MAX(psf->trendNx, 1), yNum = PS_MAX(psf->trendNy, 1); // Number of realisations 241 double sumFWHM = 0.0; // FWHM for image 242 int numFWHM = 0; // Number of FWHM measurements 243 for (int y = 0; y < yNum; y++) { 244 float yPos = ((float)y + 0.5) / (float)yNum * numRows; 245 for (int x = 0; x < xNum; x++) { 246 float xPos = ((float)x + 0.5) / (float)xNum * numCols; 247 float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image 248 if (isfinite(fwhm)) { 249 sumFWHM += fwhm; 250 numFWHM++; 251 } 252 } 253 } 254 if (numFWHM == 0) { 255 options->inputSeeing->data.F32[i] = NAN; 256 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_PSF; 257 psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", i); 258 } else { 259 options->inputSeeing->data.F32[i] = sumFWHM / (float)numFWHM; 260 } 261 262 psStringAppend(&log, "Input %d: %f\n", i, options->inputSeeing->data.F32[i]); 263 } 264 if (havePSFs) { 265 psLogMsg("ppStack", PS_LOG_INFO, "%s", log); 266 } 267 psFree(log); 219 268 220 269 // Generate target PSF … … 223 272 psFree(psfs); 224 273 if (!options->psf) { 225 psError( PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");274 psError(psErrorCodeLast(), false, "Unable to determine output PSF."); 226 275 psFree(view); 227 276 return false; … … 229 278 psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "PSF.TARGET", PS_DATA_UNKNOWN, 230 279 "Target PSF for stack", options->psf); 231 232 pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.OUTPUT"); // Output chip 280 options->targetSeeing = pmPSFtoFWHM(options->psf, 0.5 * numCols, 0.5 * numRows); // FWHM for target 281 psLogMsg("ppStack", PS_LOG_INFO, "Target seeing FWHM: %f\n", options->targetSeeing); 282 283 pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.TARGET.PSF"); // Output chip 233 284 psMetadataAddPtr(outChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, 234 285 "Target PSF", options->psf); … … 238 289 // Zero point calibration 239 290 if (!ppStackSourcesTransparency(options, view, config)) { 240 psError(P S_ERR_UNKNOWN, false, "Unable to calculate transparency differences");291 psError(PPSTACK_ERR_DATA, false, "Unable to calculate transparency differences"); 241 292 psFree(view); 242 293 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
