Changeset 21199
- Timestamp:
- Jan 28, 2009, 10:49:50 AM (17 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 4 edited
-
ppStackArguments.c (modified) (2 diffs)
-
ppStackLoop.c (modified) (23 diffs)
-
ppStackMatch.c (modified) (16 diffs)
-
ppStackSources.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackArguments.c
r21183 r21199 152 152 psMetadataAddF32(arguments, PS_LIST_TAIL, "-threshold-mask", 0, "Threshold for mask deconvolution", NAN); 153 153 psMetadataAddF32(arguments, PS_LIST_TAIL, "-poor-frac", 0, "Fraction of weight for poor pixels", NAN); 154 psMetadataAddF32(arguments, PS_LIST_TAIL, "-deconv-limit", 0, "Maximum deconvolution fraction limit", NAN); 154 155 psMetadataAddF32(arguments, PS_LIST_TAIL, "-image-rej", 0, 155 156 "Pixel rejection fraction threshold for rejecting entire image", NAN); … … 236 237 VALUE_ARG_RECIPE_FLOAT("-threshold-mask", "THRESHOLD.MASK", F32); 237 238 VALUE_ARG_RECIPE_FLOAT("-image-rej", "IMAGE.REJ", F32); 239 VALUE_ARG_RECIPE_FLOAT("-deconv-limit", "DECONV.LIMIT", F32); 238 240 VALUE_ARG_RECIPE_INT("-rows", "ROWS", S32, 0); 239 241 VALUE_ARG_RECIPE_FLOAT("-poor-frac", "POOR.FRACTION", F32); -
trunk/ppStack/src/ppStackLoop.c
r21183 r21199 357 357 } 358 358 359 // Generate target PSF 359 360 targetPSF = ppStackPSF(config, numCols, numRows, psfs); 360 361 psFree(psfs); … … 365 366 return false; 366 367 } 368 psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "PSF.TARGET", PS_DATA_UNKNOWN, 369 "Target PSF for stack", targetPSF); 367 370 368 371 pmChip *outChip = pmFPAviewThisChip(view, output->fpa); // Output chip … … 423 426 psFree(inputMask); 424 427 psFree(matchChi2); 428 psFree(fpaList); 429 psFree(cellList); 425 430 return false; 426 431 } … … 440 445 psFree(inputMask); 441 446 psFree(matchChi2); 447 psFree(fpaList); 448 psFree(cellList); 442 449 return false; 443 450 } … … 446 453 psArray *regions = NULL, *kernels = NULL; // Regions and kernels used in subtraction 447 454 psTimerStart("PPSTACK_MATCH"); 455 448 456 if (!ppStackMatch(readout, ®ions, &kernels, &matchChi2->data.F32[i], &weightings->data.F32[i], 449 457 sourceLists->data[i], targetPSF, rng, config)) { … … 476 484 assert(hdu); 477 485 writeImage(imageNames->data[i], hdu->header, readout->image, config); 478 writeImage(maskNames->data[i], hdu->header, readout->mask, config); 486 psMetadata *maskHeader = psMetadataCopy(NULL, hdu->header); // Copy of header, for mask 487 pmConfigMaskWriteHeader(config, maskHeader); 488 writeImage(maskNames->data[i], maskHeader, readout->mask, config); 489 psFree(maskHeader); 479 490 writeImage(weightNames->data[i], hdu->header, readout->weight, config); 480 491 … … 486 497 cells->data[i] = psMemIncrRefCounter(inCell); 487 498 if (!filesIterateUp(config)) { 499 psFree(fpaList); 500 psFree(cellList); 488 501 return false; 489 502 } … … 503 516 psFree(inputMask); 504 517 psFree(matchChi2); 518 psFree(fpaList); 519 psFree(cellList); 505 520 return false; 506 521 } … … 569 584 numGood = 0; // Number of good images 570 585 for (int i = 0; i < num; i++) { 571 if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) {586 if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) { 572 587 continue; 573 588 } … … 612 627 pmFPAview *view = NULL; // View to readout 613 628 psArray *inspect = NULL; // Array of arrays of pixels to inspect 614 psVector *exptimes = psVectorAlloc(num, PS_TYPE_F32); // Exposure times for each input615 629 { 616 630 int row0, col0; // Offset for readout … … 624 638 psFree(inputMask); 625 639 psFree(matchChi2); 626 psFree(exptimes);627 640 psFree(cells); 628 641 return false; … … 638 651 psFree(inputMask); 639 652 psFree(matchChi2); 640 psFree(exptimes);641 653 psFree(cells); 642 654 return false; … … 657 669 psFree(view); 658 670 psFree(outRO); 659 psFree(exptimes);660 671 psFree(cells); 661 672 return false; … … 678 689 psFree(view); 679 690 psFree(outRO); 680 psFree(exptimes);681 691 return false; 682 692 } … … 705 715 psFree(view); 706 716 psFree(outRO); 707 psFree(exptimes);708 717 return false; 709 718 } … … 720 729 psFree(view); 721 730 psFree(outRO); 722 psFree(exptimes);723 731 return false; 724 732 } … … 788 796 psFree(inspect); 789 797 psFree(rejected); 790 psFree(exptimes);791 798 return false; 792 799 } … … 804 811 psFree(inspect); 805 812 psFree(rejected); 806 psFree(exptimes);807 813 return false; 808 814 } … … 899 905 psFree(view); 900 906 psFree(outRO); 901 psFree(exptimes);902 907 return false; 903 908 } … … 928 933 psFree(view); 929 934 psFree(outRO); 930 psFree(exptimes);931 935 return false; 932 936 } … … 950 954 psFree(view); 951 955 psFree(outRO); 952 psFree(exptimes);953 956 return false; 954 957 } … … 963 966 psFree(view); 964 967 psFree(outRO); 965 psFree(exptimes);966 968 return false; 967 969 } … … 1042 1044 psFree(weightNames); 1043 1045 1044 psFree(exptimes);1045 1046 psFree(inputMask); 1046 1047 psFree(stack); -
trunk/ppStack/src/ppStackMatch.c
r21183 r21199 6 6 #include <pslib.h> 7 7 #include <psmodules.h> 8 #include <psphot.h> 8 9 9 10 #include "ppStack.h" … … 47 48 #endif 48 49 50 // Get coordinates from a source 51 static void coordsFromSource(float *x, float *y, const pmSource *source) 52 { 53 assert(x && y); 54 assert(source); 55 56 if (source->modelPSF) { 57 *x = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 58 *y = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 59 } else { 60 *x = source->peak->xf; 61 *y = source->peak->yf; 62 } 63 return; 64 } 65 49 66 static psArray *stackSourcesFilter(psArray *sources, // Source list to filter 50 67 int exclusion // Exclusion zone, pixels … … 64 81 continue; 65 82 } 66 x->data.F32[numGood] = source->peak->xf; 67 y->data.F32[numGood] = source->peak->yf; 83 coordsFromSource(&x->data.F32[numGood], &y->data.F32[numGood], source); 68 84 numGood++; 69 85 } … … 80 96 continue; 81 97 } 82 coords->data.F64[0] = source->peak->xf; 83 coords->data.F64[1] = source->peak->yf; 98 float xSource, ySource; // Coordinates of source 99 coordsFromSource(&xSource, &ySource, source); 100 101 coords->data.F64[0] = xSource; 102 coords->data.F64[1] = ySource; 84 103 85 104 long numWithin = psTreeWithin(tree, coords, exclusion); // Number within exclusion zone … … 101 120 } 102 121 103 #define BG_SIZE 64 // Large box half-size in which to measure background 104 105 // Generate a background model of the readout we're matching 106 psImage *stackBackgroundModel(pmReadout *ro, psImageMaskType maskVal, const psArray *sources, int size) 122 // Add background into the fake image 123 // Based on ppSubBackground() 124 static psImage *stackBackgroundModel(pmReadout *ro, // Readout for which to generate background model 125 const pmConfig *config // Configuration 126 ) 107 127 { 108 psImage *image = ro->image, *mask = ro->mask; // Image and mask of readout 128 psAssert(ro && ro->image, "Need readout image"); 129 psAssert(config, "Need configuration"); 130 131 psImage *image = ro->image; // Image of interest 109 132 int numCols = image->numCols, numRows = image->numRows; // Size of image 110 133 111 psImage *bgImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Background image 112 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for measuring background 113 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator 114 115 for (int i = 0; i < sources->n; i++) { 116 pmSource *source = sources->data[i]; // Source of interest 117 if (!source) { 118 continue; 119 } 120 121 int x = source->peak->xf + 0.5, y = source->peak->yf + 0.5; // Coordinates of source 122 123 int xMin = PS_MAX(x - BG_SIZE, 0), xMax = PS_MIN(x + BG_SIZE, numCols); 124 int yMin = PS_MAX(y - BG_SIZE, 0), yMax = PS_MIN(y + BG_SIZE, numCols); 125 126 psRegion region = psRegionSet(xMin, xMax, yMin, yMax); // Region of interest 127 psImage *subImage = psImageSubset(image, region); // Subimage 128 psImage *subMask = psImageSubset(mask, region); // Subimage mask 129 if (!psImageBackground(stats, NULL, subImage, subMask, maskVal, rng)) { 130 // Can't do anything about it 131 psErrorClear(); 132 continue; 133 } 134 psFree(subImage); 135 psFree(subMask); 136 137 float value = stats->robustMedian; // Value to set background to 138 139 int uMin = PS_MAX(x - size, 0), uMax = PS_MIN(x + size, numCols); 140 int vMin = PS_MAX(y - size, 0), vMax = PS_MIN(y + size, numCols); 141 142 for (int v = vMin; v < vMax; v++) { 143 for (int u = uMin; u < uMax; u++) { 144 bgImage->data.F32[v][u] = value; 145 } 146 } 147 } 148 149 psFree(stats); 150 psFree(rng); 151 152 return bgImage; 134 psMetadata *ppStackRecipe = psMetadataLookupPtr(NULL, config->recipes, PPSTACK_RECIPE); 135 psAssert(ppStackRecipe, "Need PPSTACK recipe"); 136 psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); 137 psAssert(psphotRecipe, "Need PSPHOT recipe"); 138 139 psString maskBadStr = psMetadataLookupStr(NULL, ppStackRecipe, "MASK.BAD");// Name of bits to mask for bad 140 psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 141 142 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 143 psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad); 144 145 psImage *binned = psphotBackgroundModel(ro, config); // Binned background model 146 psImageBinning *binning = psMetadataLookupPtr(NULL, psphotRecipe, 147 "PSPHOT.BACKGROUND.BINNING"); // Binning for model 148 psAssert(binning, "Need binning parameters"); 149 psImage *unbinned = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Unbinned background model 150 if (!psImageUnbin(unbinned, binned, binning)) { 151 psError(PS_ERR_UNKNOWN, false, "Unable to unbin background model"); 152 psFree(unbinned); 153 return NULL; 154 } 155 156 // XXX should these really be here?? (probably not...) 157 // pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL"); 158 // pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV"); 159 160 return unbinned; 153 161 } 162 154 163 155 164 bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels, float *chi2, float *weighting, … … 163 172 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 164 173 psAssert(recipe, "We've thrown an error on this before."); 174 175 float deconvLimit = psMetadataLookupF32(NULL, recipe, "DECONV.LIMIT"); // Limit on deconvolution fraction 165 176 166 177 // Look up appropriate values from the ppSub recipe … … 195 206 assert(outName); 196 207 // Read convolution kernel 197 { 198 psString filename = NULL; // Output filename 199 psStringAppend(&filename, "%s.%d.kernel", outName, numInput); 200 psString resolved = pmConfigConvertFilename(filename, config, false, false); // Resolved filename 201 psFree(filename); 202 psFits *fits = psFitsOpen(resolved, "r"); // FITS file for subtraction kernel 203 psFree(resolved); 204 if (!fits || !pmReadoutReadSubtractionKernels(output, fits)) { 205 psError(PS_ERR_IO, false, "Unable to read previously produced kernel"); 206 psFitsClose(fits); 207 return false; 208 } 208 psString filename = NULL; // Output filename 209 psStringAppend(&filename, "%s.%d.kernel", outName, numInput); 210 psString resolved = pmConfigConvertFilename(filename, config, false, false); // Resolved filename 211 psFree(filename); 212 psFits *fits = psFitsOpen(resolved, "r"); // FITS file for subtraction kernel 213 psFree(resolved); 214 if (!fits || !pmReadoutReadSubtractionKernels(output, fits)) { 215 psError(PS_ERR_IO, false, "Unable to read previously produced kernel"); 209 216 psFitsClose(fits); 210 211 // Add in variance factor 212 pmSubtractionKernels *kernels = psMetadataLookupPtr(NULL, output->analysis, 213 PM_SUBTRACTION_ANALYSIS_KERNEL); // Kernels 214 float vf = pmSubtractionVarianceFactor(kernels, 0.0, 0.0, false); // Variance factor 215 psMetadataItem *vfItem = psMetadataLookup(readout->parent->concepts, "CELL.VARFACTOR"); 216 if (!isfinite(vf)) { 217 vf = 1.0; 218 } 219 if (isfinite(vfItem->data.F32)) { 220 vfItem->data.F32 *= vf; 221 } else { 222 vfItem->data.F32 = vf; 223 } 217 return false; 218 } 219 psFitsClose(fits); 220 221 // Add in variance factor 222 pmSubtractionKernels *kernels = psMetadataLookupPtr(NULL, output->analysis, 223 PM_SUBTRACTION_ANALYSIS_KERNEL); // Kernels 224 float vf = pmSubtractionVarianceFactor(kernels, 0.0, 0.0, false); // Variance factor 225 psMetadataItem *vfItem = psMetadataLookup(readout->parent->concepts, "CELL.VARFACTOR"); 226 if (!isfinite(vf)) { 227 vf = 1.0; 228 } 229 if (isfinite(vfItem->data.F32)) { 230 vfItem->data.F32 *= vf; 231 } else { 232 vfItem->data.F32 = vf; 224 233 } 225 234 … … 244 253 psFree(maskName); 245 254 psFree(weightName); 255 256 psRegion *region = psMetadataLookupPtr(NULL, output->analysis, 257 PM_SUBTRACTION_ANALYSIS_REGION); // Convolution region 258 259 pmSubtractionAnalysis(readout->analysis, kernels, region, 260 readout->image->numCols, readout->image->numRows); 246 261 } else { 247 262 #endif … … 285 300 } 286 301 287 // Generate a fake image to match to288 float minFlux = INFINITY; // Minimum flux for fake image289 {290 psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for bg291 if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal, rng)) {292 psWarning("Can't measure background for image.");293 psErrorClear();294 } else {295 minFlux = bg->robustStdev;296 }297 psFree(bg);298 }299 300 #if 0301 float maxMag = -INFINITY; // Maximum magnitude of sources302 for (int i = 0; i < sources->n; i++) {303 pmSource *source = sources->data[i]; // Source of interest304 if (source->psfMag > maxMag && source->psfMag <= MAG_IGNORE &&305 !(source->mode & SOURCE_MASK)) {306 maxMag = source->psfMag;307 }308 }309 minFlux = PS_MIN(FAINT_SOURCE_FRAC * powf(10.0, -0.4 * maxMag), minFlux);310 #endif311 312 313 302 #if 0 314 303 // Testing the normalisation of the fake image … … 318 307 pmSource *source = pmSourceAlloc(); // Source 319 308 sources->data[0] = source; 320 source->peak = pmPeakAlloc(50 , 50, 10000, PM_PEAK_LONE);309 source->peak = pmPeakAlloc(500, 500, 10000, PM_PEAK_LONE); 321 310 source->psfMag = -13.0; 322 pmReadoutFakeFromSources(test, 100 , 100, sources, NULL, NULL, psf, 0.1, 0, false, true);311 pmReadoutFakeFromSources(test, 1000, 1000, sources, NULL, NULL, psf, 0.1, 0, false, true); 323 312 float sum = 0.0; 324 313 for (int y = 0; y < test->image->numRows; y++) { … … 342 331 343 332 if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, 344 stampSources, NULL, NULL, psf, minFlux, 0, false, true)) { 333 stampSources, NULL, NULL, psf, NAN, footprint + size, 334 false, true)) { 345 335 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF."); 346 336 psFree(fake); … … 351 341 352 342 // Add the background into the target image 353 psImage *bgImage = stackBackgroundModel(readout, maskVal, stampSources, footprint); // Image of background343 psImage *bgImage = stackBackgroundModel(readout, config); // Image of background 354 344 psBinaryOp(fake->image, fake->image, "+", bgImage); 355 345 psFree(bgImage); 356 346 357 358 347 #ifdef TESTING 359 348 { 349 pmHDU *hdu = pmHDUFromCell(readout->parent); 360 350 psString name = NULL; 361 351 psStringAppend(&name, "fake_%03d.fits", numInput); 362 352 psFits *fits = psFitsOpen(name, "w"); 363 353 psFree(name); 364 psFitsWriteImage(fits, NULL, fake->image, 0, NULL);354 psFitsWriteImage(fits, hdu->header, fake->image, 0, NULL); 365 355 psFitsClose(fits); 366 356 } 367 357 { 358 pmHDU *hdu = pmHDUFromCell(readout->parent); 368 359 psString name = NULL; 369 360 psStringAppend(&name, "real_%03d.fits", numInput); 370 361 psFits *fits = psFitsOpen(name, "w"); 371 362 psFree(name); 372 psFitsWriteImage(fits, NULL, readout->image, 0, NULL);363 psFitsWriteImage(fits, hdu->header, readout->image, 0, NULL); 373 364 psFitsClose(fits); 374 365 } … … 410 401 #ifdef TESTING 411 402 { 403 pmHDU *hdu = pmHDUFromCell(readout->parent); 412 404 psString name = NULL; 413 405 psStringAppend(&name, "conv_%03d.fits", numInput); 414 406 psFits *fits = psFitsOpen(name, "w"); 415 407 psFree(name); 416 psFitsWriteImage(fits, NULL, output->image, 0, NULL);408 psFitsWriteImage(fits, hdu->header, output->image, 0, NULL); 417 409 psFitsClose(fits); 418 410 } 419 411 { 412 pmHDU *hdu = pmHDUFromCell(readout->parent); 420 413 psString name = NULL; 421 414 psStringAppend(&name, "diff_%03d.fits", numInput); … … 423 416 psFree(name); 424 417 psBinaryOp(fake->image, output->image, "-", fake->image); 425 psFitsWriteImage(fits, NULL, fake->image, 0, NULL);418 psFitsWriteImage(fits, hdu->header, fake->image, 0, NULL); 426 419 psFitsClose(fits); 427 420 } … … 548 541 } 549 542 543 // Reject image completely if the maximum deconvolution fraction exceeds the limit 544 float deconv = psMetadataLookupF32(NULL, output->analysis, 545 PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Maximum deconvolution fraction 546 if (deconv > deconvLimit) { 547 psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting\n", 548 deconv, deconvLimit); 549 psFree(output); 550 return NULL; 551 } 552 550 553 // Renormalise the variances if desired 551 554 if (renorm) { … … 580 583 psFree(bg); 581 584 585 586 #if 0 587 #define RADIUS 10 // Radius of photometry 588 #define MIN_ERR 0.05 // Minimum photometric error, mag 589 #define MAX_MAG -13 // Maximum magnitude for source 590 591 // Ensure the normalisation is correct 592 // XXX Ideally, would like to do proper PSF-fit photometry, but will settle for aperture photometry 593 int numSources = sources->n; // Number of sources 594 psVector *ratio = psVectorAlloc(numSources, PS_TYPE_F32); // Flux ratios for sources 595 psVector *ratioMask = psVectorAlloc(numSources, PS_TYPE_MASK); // Mask for flux ratios 596 psVectorInit(ratioMask, 0xFF); 597 psImage *image = readout->image; // Image of interest 598 psImage *mask = readout->mask; // Mask of interest 599 int numCols = image->numCols, numRows = image->numRows; // Size of image 600 for (int i = 0; i < numSources; i++) { 601 pmSource *source = sources->data[i]; // Source of interest 602 if (!source || source->mode & SOURCE_MASK || !isfinite(source->psfMag) || !isfinite(source->errMag) || 603 source->errMag > MIN_ERR || source->psfMag > MAX_MAG) { 604 continue; 605 } 606 607 float xSrc, ySrc; // Source coordinates 608 coordsFromSource(&xSrc, &ySrc, source); 609 int xMin = PS_MAX(0, xSrc - RADIUS), xMax = PS_MIN(numCols - 1, xSrc + RADIUS); // Bounds in x 610 int yMin = PS_MAX(0, ySrc - RADIUS), yMax = PS_MIN(numRows - 1, ySrc + RADIUS); // Bounds in y 611 int numPix = 0; // Number of pixels 612 float sum = 0.0; // Sum of pixels 613 for (int y = yMin; y <= yMax; y++) { 614 for (int x = xMin; x <= xMax; x++) { 615 if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) { 616 continue; 617 } 618 sum += image->data.F32[y][x]; 619 numPix++; 620 } 621 } 622 if (sum >= 0 && numPix > 0) { 623 float mag = -2.5 * log10(sum * M_PI * PS_SQR(RADIUS) / numPix); // Instrumental magnitude 624 ratio->data.F32[i] = mag - source->psfMag; 625 ratioMask->data.PS_TYPE_MASK_DATA[i] = 0; 626 } 627 } 628 629 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics 630 if (!psVectorStats(stats, ratio, NULL, ratioMask, 0xFF)) { 631 psWarning("Unable to measure normalisation --- assuming correct."); 632 } else { 633 psLogMsg("ppStack", PS_LOG_INFO, "Renormalising image by %f (+/- %f) mag\n", 634 stats->robustMedian, stats->robustStdev); 635 float norm = powf(10.0, -0.4 * stats->robustMedian); // Normalisation to apply 636 psBinaryOp(image, image, "*", psScalarAlloc(norm, PS_TYPE_F32)); 637 } 638 psFree(stats); 639 psFree(ratio); 640 psFree(ratioMask); 641 #endif 642 643 #ifdef TESTING 644 { 645 pmHDU *hdu = pmHDUFromCell(readout->parent); 646 psString name = NULL; 647 psStringAppend(&name, "convolved_%03d.fits", numInput); 648 psFits *fits = psFitsOpen(name, "w"); 649 psFree(name); 650 psFitsWriteImage(fits, hdu->header, output->image, 0, NULL); 651 psFitsClose(fits); 652 } 653 #endif 654 582 655 psFree(output); 583 656 -
trunk/ppStack/src/ppStackSources.c
r21183 r21199 9 9 //#define TESTING // Enable debugging output 10 10 11 // Size of fake image; set by hand because it's trouble to get it from other places 12 #define FAKE_COLS 4861 13 #define FAKE_ROWS 4913 11 14 12 15 float ppStackSourcesTransparency(const psArray *sourceLists, const pmFPAview *view, const pmConfig *config) … … 60 63 pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest 61 64 65 #ifdef TESTING 66 pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout 67 pmPSF *psf = psMetadataLookupPtr(NULL, config->arguments, "PSF.TARGET"); // PSF for fake image 68 pmReadoutFakeFromSources(fake, FAKE_COLS, FAKE_ROWS, sourceLists->data[i], NULL, NULL, psf, 5, 0, false, true); 69 psString name = NULL; 70 psStringAppend(&name, "start_%03d.fits", i); 71 psFits *fits = psFitsOpen(name, "w"); 72 psFree(name); 73 psFitsWriteImage(fits, NULL, fake->image, 0, NULL); 74 psFitsClose(fits); 75 psFree(fake); 76 #endif 77 78 62 79 float exptime = psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE"); // Exposure time 63 80 float airmass = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.AIRMASS"); // Airmass … … 105 122 FILE *outMatches = fopen("source_match.dat", "w"); // Output matches 106 123 psVector *mag = psVectorAlloc(num, PS_TYPE_F32); // Magnitudes for each star 124 psVector *magErr = psVectorAlloc(num, PS_TYPE_F32); // Errors for each star 107 125 for (int i = 0; i < matches->n; i++) { 108 126 pmSourceMatch *match = matches->data[i]; // Match of interest 109 127 psVectorInit(mag, NAN); 128 psVectorInit(magErr, NAN); 110 129 for (int j = 0; j < match->num; j++) { 111 130 if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) { … … 114 133 int index = match->image->data.U32[j]; // Image index 115 134 mag->data.F32[index] = match->mag->data.F32[j] - zp->data.F32[index] - trans->data.F32[index]; 135 magErr->data.F32[index] = match->magErr->data.F32[j]; 116 136 } 117 137 for (int j = 0; j < num; j++) { 118 fprintf(outMatches, "%f ", mag->data.F32[j]);138 fprintf(outMatches, "%f (%f) ", mag->data.F32[j], magErr->data.F32[j]); 119 139 } 120 140 fprintf(outMatches, "\n"); 121 141 } 122 142 psFree(mag); 143 psFree(magErr); 123 144 fclose(outMatches); 124 145 } … … 162 183 psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej, 163 184 transThresh, starRej, starSys); 185 for (int i = 0; i < num; i++) { 186 fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]); 187 } 164 188 psFree(trans); 165 189 }
Note:
See TracChangeset
for help on using the changeset viewer.
