Changeset 27838 for branches/tap_branches/ppStack/src/ppStackConvolve.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ppStack/src (modified) (1 prop)
-
ppStack/src/ppStackConvolve.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_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/tap_branches/ppStack/src/ppStackConvolve.c
r23602 r27838 9 9 #include "ppStack.h" 10 10 #include "ppStackLoop.h" 11 12 //#define TESTING 13 11 14 12 15 // Update the value of a concept … … 39 42 options->weightings = psVectorAlloc(num, PS_TYPE_F32); // Combination weightings for images (1/noise^2) 40 43 psVectorInit(options->weightings, 0.0); 41 options->covariances = psArrayAlloc(num); // Covariance matrices 44 options->origCovars = psArrayAlloc(num); 45 options->convCovars = psArrayAlloc(num); // Covariance matrices 46 47 psVector *renorms = psVectorAlloc(num, PS_TYPE_F32); // Renormalisation values for variances 48 psVectorInit(renorms, NAN); 42 49 43 50 psList *fpaList = psListAlloc(NULL); // List of input FPAs, for concept averaging … … 52 59 pmFPAfileActivate(config->files, false, NULL); 53 60 ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, i); 61 if (options->convolve) { 62 // XXX PPSTACK.CONV.KERNEL not defined unless convolve 63 // pmFPAfileActivate(config->files, true, "PPSTACK.CONV.KERNEL"); 64 pmFPAfileActivateSingle(config->files, true, "PPSTACK.CONV.KERNEL", i); // Activated file 65 } 66 54 67 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File of interest 55 68 pmFPAview *view = ppStackFilesIterateDown(config); … … 69 82 } else if (options->numCols != readout->image->numCols || 70 83 options->numRows != readout->image->numRows) { 71 psError(P S_ERR_UNKNOWN, true, "Sizes of input images don't match: %dx%d vs %dx%d",84 psError(PPSTACK_ERR_ARGUMENTS, true, "Sizes of input images don't match: %dx%d vs %dx%d", 72 85 readout->image->numCols, readout->image->numRows, options->numCols, options->numRows); 73 86 psFree(rng); … … 79 92 // Background subtraction, scaling and normalisation is performed automatically by the image matching 80 93 psTimerStart("PPSTACK_MATCH"); 94 options->origCovars->data[i] = psMemIncrRefCounter(readout->covariance); 81 95 if (!ppStackMatch(readout, options, i, config)) { 82 psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i); 83 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_MATCH; 84 psErrorClear(); 85 continue; 86 } 87 options->covariances->data[i] = psMemIncrRefCounter(readout->covariance); 96 // XXX many things can cause a failure of ppStackMatch -- should some be handled differently? 97 psErrorCode error = psErrorCodeLast(); // Error code 98 switch (error) { 99 // Fatal errors 100 case PM_ERR_CONFIG: 101 case PPSTACK_ERR_CONFIG: 102 case PPSTACK_ERR_IO: 103 psError(error, false, "Unable to match image %d due to fatal error.", i); 104 return false; 105 // Non-fatal errors 106 case PM_ERR_STAMPS: 107 case PM_ERR_SMALL_AREA: 108 case PPSTACK_ERR_DATA: 109 default: 110 psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i); 111 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_MATCH; 112 psErrorClear(); 113 continue; 114 } 115 } 116 options->convCovars->data[i] = psMemIncrRefCounter(readout->covariance); 117 118 float renorm = psMetadataLookupF32(NULL, readout->analysis, PM_READOUT_ANALYSIS_RENORM); 119 if (!isfinite(renorm)) { 120 renorm = 1.0; 121 } 122 renorms->data.F32[i] = renorm; 88 123 89 124 if (options->stats) { … … 114 149 pmHDU *hdu = readout->parent->parent->parent->hdu; // HDU for convolved image 115 150 assert(hdu); 116 ppStackWriteImage(options->imageNames->data[i], hdu->header, readout->image, config); 151 if (!ppStackWriteImage(options->convImages->data[i], hdu->header, readout->image, config)) { 152 psError(PPSTACK_ERR_IO, false, "Unable to write convolved image %d", i); 153 psFree(fpaList); 154 psFree(cellList); 155 psFree(rng); 156 return false; 157 } 117 158 psMetadata *maskHeader = psMetadataCopy(NULL, hdu->header); // Copy of header, for mask 118 159 pmConfigMaskWriteHeader(config, maskHeader); 119 ppStackWriteImage(options->maskNames->data[i], maskHeader, readout->mask, config); 160 if (!ppStackWriteImage(options->convMasks->data[i], maskHeader, readout->mask, config)) { 161 psError(PPSTACK_ERR_IO, false, "Unable to write convolved mask %d", i); 162 psFree(fpaList); 163 psFree(cellList); 164 psFree(rng); 165 psFree(maskHeader); 166 return false; 167 } 120 168 psFree(maskHeader); 121 psImageCovarianceTransfer(readout->variance, readout->covariance); 122 ppStackWriteImage(options->varianceNames->data[i], hdu->header, readout->variance, config); 169 if (!ppStackWriteImage(options->convVariances->data[i], hdu->header, readout->variance, config)) { 170 psError(PPSTACK_ERR_IO, false, "Unable to write convolved variance %d", i); 171 psFree(fpaList); 172 psFree(cellList); 173 psFree(rng); 174 return false; 175 } 123 176 #ifdef TESTING 124 177 { … … 129 182 psFree(name); 130 183 } 184 { 185 int numCols = readout->image->numCols, numRows = readout->image->numRows; 186 psImage *sn = psImageAlloc(numCols, numRows, PS_TYPE_F32); 187 for (int y = 0; y < numRows; y++) { 188 for (int x = 0; x < numCols; x++) { 189 sn->data.F32[y][x] = readout->image->data.F32[y][x] / 190 sqrtf(readout->variance->data.F32[y][x]); 191 } 192 } 193 psString name = NULL; 194 psStringAppend(&name, "signoise_%d.fits", i); 195 ppStackWriteImage(name, hdu->header, sn, config); 196 psFree(name); 197 psFree(sn); 198 } 131 199 #endif 132 200 … … 136 204 psListAdd(fpaList, PS_LIST_TAIL, inCell->parent->parent); 137 205 206 // Correct ZP 207 if (options->matchZPs) { 208 // I think I need to take off the exposure time because we're going to set the new exposure time 209 psMetadataItem *zpItem = psMetadataLookup(inCell->parent->parent->concepts, "FPA.ZP"); 210 zpItem->data.F32 += options->norm->data.F32[i] + 2.5*log10(options->sumExposure); 211 212 psMetadataItem *expItem = psMetadataLookup(inCell->parent->parent->concepts, "FPA.EXPOSURE"); 213 expItem->data.F32 = options->sumExposure; 214 215 expItem = psMetadataLookup(inCell->concepts, "CELL.EXPOSURE"); 216 expItem->data.F32 = options->sumExposure; 217 } 218 138 219 options->cells->data[i] = psMemIncrRefCounter(inCell); 139 220 if (!ppStackFilesIterateUp(config)) { … … 149 230 psFree(rng); 150 231 151 psFree(options->norm); options->norm = NULL;152 232 psFree(options->sourceLists); options->sourceLists = NULL; 153 233 psFree(options->psf); options->psf = NULL; … … 155 235 156 236 if (numGood == 0) { 157 psError(P S_ERR_UNKNOWN, false, "No good images to combine.");237 psError(PPSTACK_ERR_REJECTED, false, "No good images to combine."); 158 238 psFree(fpaList); 159 239 psFree(cellList); … … 167 247 pmFPAview view; // View for output 168 248 view.chip = view.cell = view.readout = 0; 249 169 250 pmCell *outCell = pmFPAfileThisCell(config->files, &view, "PPSTACK.OUTPUT"); // Output cell 170 251 pmFPA *outFPA = outCell->parent->parent; // Output FPA 252 253 pmCell *unconvCell = pmFPAfileThisCell(config->files, &view, "PPSTACK.UNCONV"); // Unconvolved cell 254 pmFPA *unconvFPA = unconvCell->parent->parent; // Unconvolved FPA 255 171 256 pmConceptsAverageFPAs(outFPA, fpaList); 172 257 pmConceptsAverageCells(outCell, cellList, NULL, NULL, true); 258 259 pmConceptsAverageFPAs(unconvFPA, fpaList); 260 pmConceptsAverageCells(unconvCell, cellList, NULL, NULL, true); 261 173 262 psFree(fpaList); 174 263 psFree(cellList); … … 177 266 UPDATE_CONCEPT(outCell, "CELL.EXPOSURE", options->sumExposure); 178 267 UPDATE_CONCEPT(outCell, "CELL.DARKTIME", NAN); 268 UPDATE_CONCEPT(outFPA, "FPA.ZP", options->zp); 269 270 UPDATE_CONCEPT(unconvFPA, "FPA.EXPOSURE", options->sumExposure); 271 UPDATE_CONCEPT(unconvCell, "CELL.EXPOSURE", options->sumExposure); 272 UPDATE_CONCEPT(unconvCell, "CELL.DARKTIME", NAN); 273 UPDATE_CONCEPT(unconvFPA, "FPA.ZP", options->zp); 179 274 } 180 275 … … 191 286 assert(values->n == numGood); 192 287 if (!psVectorSortInPlace(values)) { 193 psError(P S_ERR_UNKNOWN, false, "Unable to sort vector.");288 psError(PPSTACK_ERR_PROG, false, "Unable to sort vector."); 194 289 psFree(values); 195 290 return false; … … 211 306 numGood = 0; // Number of good images 212 307 for (int i = 0; i < num; i++) { 213 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) {308 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) { 214 309 continue; 215 310 } … … 229 324 230 325 if (numGood == 0) { 231 psError(P S_ERR_UNKNOWN, false, "No good images to combine.");326 psError(PPSTACK_ERR_REJECTED, false, "No good images to combine."); 232 327 return false; 233 328 } 329 330 // Correct chi^2 for renormalisation 331 psBinaryOp(options->matchChi2, options->matchChi2, "/", renorms); 332 for (int i = 0; i < num; i++) { 333 psLogMsg("ppStack", PS_LOG_INFO, "Additional variance for image %d: %f\n", 334 i, options->matchChi2->data.F32[i]); 335 } 336 psFree(renorms); 234 337 235 338 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
