Changeset 23839
- Timestamp:
- Apr 13, 2009, 4:05:58 PM (17 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 4 edited
-
pmSubtraction.c (modified) (3 diffs)
-
pmSubtractionEquation.c (modified) (4 diffs)
-
pmSubtractionStamps.c (modified) (9 diffs)
-
pmSubtractionStamps.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r23740 r23839 850 850 psTrace("psModules.imcombine", 1, "Deviation limit: %f\n", limit); 851 851 852 853 psString ds9name = NULL; // Filename for ds9 region file 854 static int ds9num = 0; // File number for ds9 region file 855 psStringAppend(&ds9name, "stamps_reject_%d.ds9", ds9num); 856 FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "rejected stamps"); 857 psFree(ds9name); 858 ds9num++; 859 852 860 int numRejected = 0; // Number of stamps rejected 853 861 int numGood = 0; // Number of good stamps … … 872 880 } 873 881 } 882 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red"); 874 883 875 884 // Set stamp for replacement … … 897 906 numGood++; 898 907 newMean += deviations->data.F32[i]; 908 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green"); 899 909 } 900 910 } 901 911 } 902 912 newMean /= numGood; 913 914 if (ds9) { 915 fclose(ds9); 916 } 903 917 904 918 if (numRejected > 0) { -
trunk/psModules/src/imcombine/pmSubtractionEquation.c
r21422 r23839 749 749 } 750 750 751 psString ds9name = NULL; // Filename for ds9 region file 752 static int ds9num = 0; // File number for ds9 region file 753 psStringAppend(&ds9name, "stamps_solution_%d.ds9", ds9num); 754 FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "solution stamps"); 755 psFree(ds9name); 756 ds9num++; 757 751 758 if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) { 752 759 // Accumulate the least-squares matricies and vectors … … 761 768 (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix1); 762 769 (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector1); 770 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green"); 763 771 numStamps++; 772 } else if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED) { 773 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red"); 764 774 } 765 775 } … … 830 840 (void)psBinaryOp(sumVector1, sumVector1, "+", stamp->vector1); 831 841 (void)psBinaryOp(sumVector2, sumVector2, "+", stamp->vector2); 842 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green"); 832 843 numStamps++; 833 844 } … … 990 1001 // XXXXX Free temporary matrices and vectors 991 1002 1003 } 1004 1005 if (ds9) { 1006 fclose(ds9); 992 1007 } 993 1008 -
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r23837 r23839 149 149 return clean; 150 150 } 151 152 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 153 // Functions for generating ds9 region files 154 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 155 156 static bool ds9regions = false; // Save ds9 region files? 157 158 void pmSubtractionRegions(bool state) 159 { 160 ds9regions = state; 161 } 162 163 FILE *pmSubtractionStampsFile(const pmSubtractionStampList *stamps, const char *filename, 164 const char *description) 165 { 166 if (!ds9regions || !stamps || !filename) { 167 return NULL; 168 } 169 170 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Writing %s to ds9 region file: %s", 171 description, filename); 172 173 FILE *file = fopen(filename, "w"); 174 175 // Outline the stamps 176 for (int i = 0; i < stamps->num; i++) { 177 psRegion *region = stamps->regions->data[i]; // Region of interest 178 float xCentre = 0.5 * (region->x0 + region->x1), yCentre = 0.5 * (region->y0 + region->y1); 179 fprintf(file, "image;box(%f,%f,%f,%f,0) # color=blue\nimage;text(%f,%f,{%d}) # color=blue\n", 180 xCentre, yCentre, region->x1 - region->x0, region->y1 - region->y0, 181 xCentre, yCentre, i); 182 } 183 184 return file; 185 } 186 187 void pmSubtractionStampPrint(FILE *ds9, float x, float y, float size, const char *color) 188 { 189 if (!ds9regions || !ds9) { 190 return; 191 } 192 fprintf(ds9, "image;circle(%f,%f,%f)", x, y, size); 193 if (color && strlen(color) > 0) { 194 fprintf(ds9, " # color=%s", color); 195 } 196 fprintf(ds9, "\n"); 197 return; 198 } 199 151 200 152 201 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 366 415 } 367 416 368 bool pmSubtractionStampsRegions(pmSubtractionStampList *stamps, const char *filename) 369 { 370 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); 371 PS_ASSERT_STRING_NON_EMPTY(filename, false); 372 373 FILE *outFile = fopen(filename, "w"); // File to write 374 if (!outFile) { 375 psError(PS_ERR_IO, false, "Unable to open %s for writing", filename); 376 return false; 377 } 378 379 for (int i = 0; i < stamps->num; i++) { 380 // Outline the stamp 381 psRegion *region = stamps->regions->data[i]; // Region of interest 382 fprintf(outFile, "image;box(%f,%f,%f,%f,0)\n", 383 0.5 * (region->x0 + region->x1), 0.5 * (region->y0 + region->y1), 384 region->x1 - region->x0, region->y1 - region->y0); 385 386 psVector *xList = stamps->x->data[i], *yList = stamps->y->data[i]; // Coordinate lists 387 388 for (int j = 0; j < xList->n; j++) { 389 fprintf(outFile, "image;circle(%f,%f,%d)\n", 390 xList->data.F32[j], yList->data.F32[j], stamps->footprint); 391 } 392 } 393 394 fclose(outFile); 395 396 return true; 397 } 417 398 418 399 419 pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, const psVector *y, … … 424 444 int numStamps = stamps->num; // Number of stamps 425 445 446 psString ds9name = NULL; // Filename for ds9 region file 447 static int ds9num = 0; // File number for ds9 region file 448 psStringAppend(&ds9name, "stamps_all_%d.ds9", ds9num); 449 FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "all stamps"); // ds9 region file 450 ds9num++; 451 426 452 // Initialise the lists 427 453 stamps->x = psArrayAlloc(numStamps); … … 442 468 psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because outside region", 443 469 xPix, yPix); 470 pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "magenta"); 444 471 continue; 445 472 } … … 448 475 psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because bad mask", 449 476 xPix, yPix); 477 pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "red"); 450 478 continue; 451 479 } … … 471 499 psTrace("psModules.imcombine", 9, "Putting input stamp (%d,%d) into subregion %d", 472 500 xPix, yPix, j); 501 pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "green"); 473 502 } 474 503 } … … 477 506 psTrace("psModules.imcombine", 9, "Unable to find subregion for stamp (%d,%d)", 478 507 xPix, yPix); 479 } 508 pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "yellow"); 509 } 510 } 511 512 if (ds9) { 513 fclose(ds9); 480 514 } 481 515 … … 508 542 } 509 543 510 if (psTraceGetLevel("psModules.imcombine") >= 9) {511 pmSubtractionStampsRegions(stamps, "stamps_all.ds9");512 }513 514 544 return stamps; 515 545 } … … 581 611 } 582 612 583 #if 0584 bool pmSubtractionStampsGenerate(pmSubtractionStampList *stamps, float fwhm, int kernelSize)585 {586 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);587 PS_ASSERT_FLOAT_LARGER_THAN(fwhm, 0.0, false);588 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false);589 590 int size = kernelSize + stamps->footprint; // Size of postage stamps591 int num = stamps->num; // Number of stamps592 float sigma = fwhm / (2.0 * sqrtf(2.0 * log(2.0))); // Gaussian sigma593 594 for (int i = 0; i < num; i++) {595 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest596 if (!(stamp->status & PM_SUBTRACTION_STAMP_CALCULATE)) {597 continue;598 }599 600 float x = stamp->x, y = stamp->y; // Coordinates of stamp601 float flux = stamp->flux; // Flux of star602 if (!isfinite(flux)) {603 psWarning("Unable to generate PSF for stamp %d --- bad flux.", i);604 stamp->status = PM_SUBTRACTION_STAMP_REJECTED;605 continue;606 }607 608 float xStamp = x - (int)(x + 0.5); // x coordinate of star in stamp frame609 float yStamp = y - (int)(y + 0.5); // y coordinate of star in stamp frame610 611 psFree(stamp->image2);612 stamp->image2 = psKernelAlloc(-size, size, -size, size);613 psKernel *target = stamp->image2; // Target stamp614 615 // Put in a Waussian, just for fun!616 for (int v = -size; v <= size; v++) {617 for (int u = -size; u <= size; u++) {618 float z = (PS_SQR(u + xStamp) + PS_SQR(v + yStamp)) / (2.0 * PS_SQR(sigma));619 target->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 / (1.0 + z + PS_SQR(z));620 }621 }622 623 }624 625 return true;626 }627 #endif628 629 613 pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *image, 630 614 const psImage *subMask, const psRegion *region, -
trunk/psModules/src/imcombine/pmSubtractionStamps.h
r23789 r23839 125 125 126 126 127 /// Write a ds9 region file with stamp positions127 /// Turn on/off generation of ds9 region files 128 128 /// 129 129 /// Intended for debugging 130 bool pmSubtractionStampsRegions(pmSubtractionStampList *stamps, ///< Stamps 131 const char *filename ///< Filename to which to write regions 130 void pmSubtractionRegions(bool state ///< Generate ds9 region files? 132 131 ); 133 132 133 /// Open a file for ds9 regions 134 /// 135 /// Intended for debugging 136 FILE *pmSubtractionStampsFile(const pmSubtractionStampList *stamps, ///< List of stamps, for outlines 137 const char *filename, ///< Filename to write 138 const char *description ///< Description of file 139 ); 140 141 /// Print a stamp position to ds9 region file 142 /// 143 /// Intended for debugging 144 void pmSubtractionStampPrint(FILE *ds9, ///< ds9 region file 145 float x, float y, ///< Position of stamp 146 float size,///< Size of circle 147 const char *color ///< Colour 148 ); 134 149 135 150 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
