Changeset 26898 for trunk/ppStack/src/ppStackMatch.c
- Timestamp:
- Feb 10, 2010, 7:41:23 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackMatch.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackMatch.c
r26454 r26898 144 144 psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad); 145 145 146 psImage *binned = psphot BackgroundModel(ro, config); // Binned background model146 psImage *binned = psphotModelBackgroundReadoutNoFile(ro, config); // Binned background model 147 147 psImageBinning *binning = psMetadataLookupPtr(NULL, ro->analysis, 148 148 "PSPHOT.BACKGROUND.BINNING"); // Binning for model … … 274 274 PM_SUBTRACTION_ANALYSIS_KERNEL); 275 275 276 pmSubtractionAnalysis( readout->analysis, NULL, kernels, region,276 pmSubtractionAnalysis(conv->analysis, NULL, kernels, region, 277 277 readout->image->numCols, readout->image->numRows); 278 278 279 279 psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); // Convolution kernel 280 bool oldThreads = psImageCovarianceSetThreads(true); // Old thread setting 280 281 psKernel *covar = psImageCovarianceCalculate(kernel, readout->covariance); // Covariance matrix 282 psImageCovarianceSetThreads(oldThreads); 281 283 psFree(readout->covariance); 282 284 readout->covariance = covar; … … 298 300 float rej = psMetadataLookupF32(NULL, ppsub, "REJ"); // Rejection threshold 299 301 float kernelError = psMetadataLookupF32(NULL, ppsub, "KERNEL.ERR"); // Relative systematic error in kernel 302 float normFrac = psMetadataLookupF32(NULL, ppsub, "NORM.FRAC"); // Fraction of window for normalisn windw 300 303 float sysError = psMetadataLookupF32(NULL, ppsub, "SYS.ERR"); // Relative systematic error in images 304 float skyErr = psMetadataLookupF32(NULL, ppsub, "SKY.ERR"); // Additional error in sky 305 float covarFrac = psMetadataLookupF32(NULL, ppsub, "COVAR.FRAC"); // Fraction for covariance calculation 306 301 307 const char *typeStr = psMetadataLookupStr(NULL, ppsub, "KERNEL.TYPE"); // Kernel type 302 308 pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Kernel type … … 315 321 float poorFrac = psMetadataLookupF32(&mdok, ppsub, "POOR.FRACTION"); // Fraction for "poor" 316 322 323 bool scale = psMetadataLookupBool(NULL, ppsub, "SCALE"); // Scale kernel parameters? 324 float scaleRef = psMetadataLookupF32(NULL, ppsub, "SCALE.REF"); // Reference for scaling 325 float scaleMin = psMetadataLookupF32(NULL, ppsub, "SCALE.MIN"); // Minimum for scaling 326 float scaleMax = psMetadataLookupF32(NULL, ppsub, "SCALE.MAX"); // Maximum for scaling 327 if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) { 328 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 329 "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in PPSUB recipe.", 330 scaleRef, scaleMin, scaleMax); 331 return false; 332 } 333 334 317 335 // These values are specified specifically for stacking 318 336 const char *stampsName = psMetadataLookupStr(NULL, config->arguments, "STAMPS");// Stamps filename … … 358 376 fake->mask = psImageCopy(NULL, readout->mask, PS_TYPE_IMAGE_MASK); 359 377 378 #if 1 360 379 // Add the background into the target image 361 380 psImage *bgImage = stackBackgroundModel(readout, config); // Image of background 362 381 psBinaryOp(fake->image, fake->image, "+", bgImage); 363 382 psFree(bgImage); 383 #endif 364 384 365 385 #ifdef TESTING … … 395 415 if (kernel) { 396 416 if (!pmSubtractionMatchPrecalc(NULL, conv, fake, readout, readout->analysis, 397 stride, kernelError, maskVal, maskBad, maskPoor,417 stride, kernelError, covarFrac, maskVal, maskBad, maskPoor, 398 418 poorFrac, badFrac)) { 399 419 psError(PS_ERR_UNKNOWN, false, "Unable to convolve images."); … … 408 428 } 409 429 } else { 430 // Scale the input parameters 431 psVector *widthsCopy = psVectorCopy(NULL, widths, PS_TYPE_F32); // Copy of kernel widths 432 if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, 433 options->inputSeeing->data.F32[index], 434 options->targetSeeing, scaleRef, scaleMin, scaleMax)) { 435 psError(PS_ERR_UNKNOWN, false, "Unable to scale kernel parameters"); 436 psFree(fake); 437 psFree(optWidths); 438 psFree(stampSources); 439 psFree(conv); 440 psFree(widthsCopy); 441 if (threads > 0) { 442 pmSubtractionThreadsFinalize(readout, fake); 443 } 444 return false; 445 } 446 410 447 if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing, 411 threshold, stampSources, stampsName, type, size, order, widths ,448 threshold, stampSources, stampsName, type, size, order, widthsCopy, 412 449 orders, inner, ringsOrder, binning, penalty, 413 optimum, optWidths, optOrder, optThresh, iter, rej, sysError,414 kernelError, maskVal, maskBad, maskPoor, poorFrac, badFrac,415 PM_SUBTRACTION_MODE_2)) {450 optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, 451 sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor, 452 poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) { 416 453 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 417 454 psFree(fake); … … 419 456 psFree(stampSources); 420 457 psFree(conv); 458 psFree(widthsCopy); 421 459 if (threads > 0) { 422 460 pmSubtractionThreadsFinalize(readout, fake); … … 424 462 return false; 425 463 } 464 psFree(widthsCopy); 426 465 } 427 466 … … 495 534 while ((item = psMetadataGetAndIncrement(iter))) { 496 535 assert(item->type == PS_DATA_UNKNOWN); 497 // Set the normalisation dimensions, since these will be otherwise unavailable when reading498 // the images by scans.499 536 pmSubtractionKernels *kernel = item->data.V; // Kernel used in subtraction 500 kernel->numCols = readout->image->numCols;501 kernel->numRows = readout->image->numRows;502 503 537 kernels = psArrayAdd(kernels, ARRAY_BUFFER, kernel); 504 538 } … … 526 560 } 527 561 562 // Kernel normalisation 563 { 564 double sum = 0.0; // Sum of chi^2 565 int num = 0; // Number of measurements of chi^2 566 psString regex = NULL; // Regular expression 567 psStringAppend(®ex, "^%s$", PM_SUBTRACTION_ANALYSIS_NORM); 568 psMetadataIterator *iter = psMetadataIteratorAlloc(conv->analysis, PS_LIST_HEAD, regex); 569 psFree(regex); 570 psMetadataItem *item = NULL;// Item from iteration 571 while ((item = psMetadataGetAndIncrement(iter))) { 572 assert(item->type == PS_TYPE_F32); 573 float norm = item->data.F32; // Normalisation 574 sum += norm; 575 num++; 576 } 577 psFree(iter); 578 float conv = sum/num; // Mean normalisation from convolution 579 float stars = powf(10.0, -0.4 * options->norm->data.F32[index]); // Normalisation from stars 580 float renorm = stars / conv; // Renormalisation to apply 581 psLogMsg("ppStack", PS_LOG_INFO, "Renormalising image %d by %f (kernel: %f, stars: %f)\n", 582 index, renorm, conv, stars); 583 psBinaryOp(readout->image, readout->image, "*", psScalarAlloc(renorm, PS_TYPE_F32)); 584 psBinaryOp(readout->variance, readout->variance, "*", psScalarAlloc(PS_SQR(renorm), PS_TYPE_F32)); 585 } 586 528 587 // Reject image completely if the maximum deconvolution fraction exceeds the limit 529 588 float deconv = psMetadataLookupF32(NULL, conv->analysis, 530 589 PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Max deconvolution fraction 531 590 if (deconv > deconvLimit) { 532 psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting \n",533 deconv, deconvLimit );591 psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting image %d\n", 592 deconv, deconvLimit, index); 534 593 psFree(conv); 535 594 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
