- Timestamp:
- May 5, 2013, 2:20:46 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoop.c
r35434 r35512 36 36 if (!pswarpSetMaskBits(config)) { 37 37 psError(psErrorCodeLast(), false, "failed to set mask bits"); 38 return NULL;38 return false; 39 39 } 40 40 … … 83 83 // XXX pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.SOURCES"); 84 84 85 // Done with the detector side of things85 // the loops below load the input data 86 86 pswarpFileActivation(config, detectorFiles, true); 87 pswarpFileActivation(config, independentFiles, true); 87 88 // pswarpFileActivation(config, independentFiles, true); 88 89 89 90 pmFPAview *view = pmFPAviewAlloc(0); … … 95 96 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 96 97 psError(psErrorCodeLast(), false, "Unable to read files."); 97 goto DONE;98 goto FAIL; 98 99 } 99 100 … … 107 108 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 108 109 psError(psErrorCodeLast(), false, "Unable to read files."); 109 goto DONE;110 goto FAIL; 110 111 } 111 112 … … 116 117 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 117 118 psError(psErrorCodeLast(), false, "Unable to read files."); 118 goto DONE;119 goto FAIL; 119 120 } 120 121 … … 124 125 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 125 126 psError(psErrorCodeLast(), false, "Unable to read files."); 126 goto DONE;127 goto FAIL; 127 128 } 128 129 if (!readout->data_exists) { … … 145 146 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 146 147 psError(psErrorCodeLast(), false, "Unable to write files."); 147 goto DONE;148 goto FAIL; 148 149 } 149 150 } 150 151 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 151 152 psError(psErrorCodeLast(), false, "Unable to write files."); 152 goto DONE;153 goto FAIL; 153 154 } 154 155 } 155 156 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 156 157 psError(psErrorCodeLast(), false, "Unable to write files."); 157 goto DONE;158 goto FAIL; 158 159 } 159 160 } 160 161 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 161 162 psError(psErrorCodeLast(), false, "Unable to write files."); 162 goto DONE;163 goto FAIL; 163 164 } 164 165 … … 167 168 pswarpFileActivation(config, independentFiles, false); 168 169 169 // XXXX turn these on later .. pswarpUpdateStatistics (output); 170 if (!pswarpUpdateStatistics (output->fpa, stats, input->fpa, astrom->fpa, config)) { 171 psError(psErrorCodeLast(), false, "problem generating statistics."); 172 goto FAIL; 173 } 174 170 175 // XXXX turn these on later .. pswarpMakePSF (output); 171 172 176 // XXX have not yet written the output to disk 173 174 177 psFree(view); 175 176 DONE:177 178 return true; 179 180 FAIL: 181 psFree (view); 182 return false; 178 183 } 179 184 180 # if (0)181 185 // once the output fpa elements have been built, loop over the fpa and generate stats 182 186 // for each readout 183 bool pswarpUpdateStatistics (pmFPA *output, pmFPA *input, pmConfig *config) { 184 185 // output mask bits 186 psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT"); 187 psAssert (status, "MASK.OUTPUT was not defined"); 187 bool pswarpTransformToTarget (pmFPA *output, pmReadout *input, pmConfig *config) { 188 188 189 189 pmFPAview *view = pmFPAviewAlloc(0); … … 195 195 196 196 pmCell *cell; 197 while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) {198 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);199 if (!cell->process || !cell->file_exists) { continue; }200 201 // process each of the readouts202 pmReadout *readout;203 while ((readout = pmFPAviewNextReadout(view, output->fpa, 1)) != NULL) {204 if (!readout->data_exists) {205 psWarning("No overlap between input and skycell.");206 if (stats) {207 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,208 "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP);209 }210 psphotFilesActivate(config, false);211 psFree(cells);212 psFree(view);213 goto DONE;214 }215 216 if (!pswarpPixelsLit(readout, stats, config)) {217 psError(psErrorCodeLast(), false, "Unable to calculate pixel regions.");218 psFree(view);219 goto DONE;220 }221 bool doStats = psMetadataLookupBool(&mdok,recipe,"MASK.STATS");222 if (doStats) {223 if (!pswarpMaskStats(readout, stats, config)) {224 psError(psErrorCodeLast(), false, "Unable to calculate mask stats.");225 psFree(cells);226 psFree(view);227 goto DONE;228 }229 }230 231 // Set covariance matrix for output232 {233 psList *covariances = psMetadataLookupPtr(&mdok, output->analysis,234 PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices235 psAssert(covariances, "Should be there");236 psArray *covars = psListToArray(covariances); // Array of covariance matrices237 psKernel *covar = psImageCovarianceAverage(covars);238 psFree(covars);239 psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES);240 241 // Correct covariance matrix scale for the mean (square root of the) Jacobian242 double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian243 int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels244 jacobian /= goodPixels;245 output->covariance = psImageCovarianceScale(covar, jacobian);246 psFree(covar);247 248 if (output->variance) {249 psImageCovarianceTransfer(output->variance, output->covariance);250 }251 }252 }253 254 // XXX need to get the input Cells for this output cell (save on the analysis somewhere255 // XXX skip this for now256 # if (0)257 psArray *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "something");258 if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) {259 psError(psErrorCodeLast(), false, "Unable to average cell concepts.");260 psFree(view);261 goto DONE;262 }263 # endif264 // XXX Is this too ad-hoc?265 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); ///< Trim section266 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels267 268 }269 270 // Perform statistics on the output image271 if (stats) {272 // XXX this should be done at each level...273 if (!ppStatsFPA(stats, output->parent->parent->parent, view, maskValue, config)) {274 psWarning("Unable to perform statistics on warped image.");275 }276 }277 }278 if (!psMetadataCopy(output->concepts, input->concepts)) {279 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");280 psFree(view);281 goto DONE;282 }283 284 // Update ZP from the astrometry285 {286 psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP");287 item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP");288 }289 290 // need to update the chip and fpa level astrometry appropriate, see291 // code in psastro292 293 # if (0)294 // Add MD5 information for readout295 const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME");296 const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME");297 psString headerName = NULL; ///< Header name for MD5298 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);299 psVector *md5 = psImageMD5(output->image); ///< md5 hash300 psString md5string = psMD5toString(md5); ///< String301 psFree(md5);302 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE,303 "Image MD5", md5string);304 psFree(md5string);305 psFree(headerName);306 # endif307 308 # if (0)309 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {310 psError(psErrorCodeLast(), false, "Unable to generate WCS header.");311 goto DONE;312 }313 # endif314 return true;315 }316 # endif317 318 # if (0)319 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but320 // that's going to be tricky. We have a list of sources, so we use those to redetermine the PSF model.321 bool pswarpMakePSF (pmConfig *config) {322 323 // load the recipe324 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);325 if (!recipe) {326 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);327 return false;328 }329 330 if (psMetadataLookupBool(&mdok, recipe, "PSF")) {331 pswarpFileActivation(config, photFiles, true);332 if (!pswarpIOChecksBefore(config)) {333 psError(psErrorCodeLast(), false, "Unable to read files.");334 goto DONE;335 }336 337 // supply the readout and fpa of interest to psphot338 pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");339 pmFPACopy(photFile->fpa, outFPA);340 341 pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell342 view->chip = view->cell = view->readout = 0;343 344 // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)345 psArray *sources = psphotLoadPSFSources (config, view);346 if (!sources) {347 psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");348 goto DONE;349 }350 351 pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);352 353 // measure the PSF using these sources354 if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {355 // This is likely a data quality issue356 // XXX Split into multiple cases using error codes?357 psErrorStackPrint(stderr, "Unable to determine PSF");358 psWarning("Unable to determine PSF --- suspect bad data quality.");359 if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {360 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,361 "Unable to determine PSF", psErrorCodeLast());362 }363 psErrorClear();364 psphotFilesActivate(config, false);365 }366 367 // Ensure seeing is carried over368 pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); // Chip with seeing369 psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing370 item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING");371 372 // XXX EAM : put this in a visualization function373 #if (TESTING)374 {375 #define PSF_SIZE 20 ///< Half-size of PSF376 #define PSF_FLUX 10000 ///< Central flux for PSF377 pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);378 pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF");379 psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32);380 psImageInit(image, 0);381 pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX);382 pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0);383 psFree(model);384 psFits *fits = psFitsOpen("psf.fits", "w");385 psFitsWriteImage(fits, NULL, image, 0, NULL);386 psFitsClose(fits);387 psFree(image);388 }389 #endif390 391 psFree(view);392 }393 return true;394 }395 # endif396 397 // once the output fpa elements have been built, loop over the fpa and generate stats398 // for each readout399 bool pswarpTransformToTarget (pmFPA *output, pmReadout *input, pmConfig *config) {400 401 pmFPAview *view = pmFPAviewAlloc(0);402 403 pmChip *chip;404 while ((chip = pmFPAviewNextChip (view, output, 1)) != NULL) {405 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);406 if (!chip->process || !chip->file_exists) { continue; }407 408 pmCell *cell;409 197 while ((cell = pmFPAviewNextCell (view, output, 1)) != NULL) { 410 198 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
Note:
See TracChangeset
for help on using the changeset viewer.
