Changeset 5048
- Timestamp:
- Sep 13, 2005, 3:35:20 PM (21 years ago)
- Location:
- trunk/psphot
- Files:
-
- 15 edited
-
doc/notes.txt (modified) (1 diff)
-
src/pmObjects_EAM.c (modified) (21 diffs)
-
src/pmObjects_EAM.h (modified) (3 diffs)
-
src/psLibUtils.c (modified) (2 diffs)
-
src/psLibUtils.h (modified) (2 diffs)
-
src/psMinimize.c (modified) (1 diff)
-
src/psModulesUtils.c (modified) (2 diffs)
-
src/psModulesUtils.h (modified) (1 diff)
-
src/psphotApplyPSF.c (modified) (3 diffs)
-
src/psphotChoosePSF.c (modified) (1 diff)
-
src/psphotFitGalaxies.c (modified) (4 diffs)
-
src/psphotMarkPSF.c (modified) (7 diffs)
-
src/psphotOutput.c (modified) (7 diffs)
-
src/psphotSourceStats.c (modified) (2 diffs)
-
src/psphotSubtractPSF.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/doc/notes.txt
r4983 r5048 50 50 - fixed 'center' option in pmSourceAdd/Sub 51 51 52 - pmPSF params should be F64 53 52 54 lingering concerns: 53 55 - Polynomials and related functions are STILL messed up. this is a -
trunk/psphot/src/pmObjects_EAM.c
r4977 r5048 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-09- 08 04:32:40 $8 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-09-14 01:35:20 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 603 603 members. 604 604 *****************************************************************************/ 605 pmSource *pmSourceLocalSky(const psImage *image, 606 const pmPeak *peak, 607 psStatsOptions statsOptions, 608 psF32 innerRadius, 609 psF32 outerRadius) 610 { 611 PS_ASSERT_IMAGE_NON_NULL(image, NULL); 612 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL); 613 PS_ASSERT_PTR_NON_NULL(peak, NULL); 614 PS_FLOAT_COMPARE(0.0, innerRadius, NULL); 615 PS_FLOAT_COMPARE(innerRadius, outerRadius, NULL); 616 psS32 innerRadiusS32 = (psS32) innerRadius; 617 psS32 outerRadiusS32 = (psS32) outerRadius; 618 619 // 620 // We define variables for code readability. 621 // 622 // XXX: Since the peak->xy coords are in image, not subImage coords, 623 // these variables should be renamed for clarity (imageCenterRow, etc). 624 // 625 // peak->x,y is guaranteed to be on image 626 psS32 SubImageCenterRow = peak->y; 627 psS32 SubImageCenterCol = peak->x; 628 629 // XXX EAM : I added this code to stay on the image. So did George 630 // XXX EAM : EndRow is *exclusive* of pixel region (ie, last pixel + 1) 631 // XXX EAM : dropped the Annulus width (not needed) 632 // XXX EAM : dropped off-boundary tests (not needed) 633 psS32 SubImageStartRow = PS_MAX (0, SubImageCenterRow - outerRadiusS32); 634 psS32 SubImageEndRow = PS_MIN (image->numRows, SubImageCenterRow + outerRadiusS32 + 1); 635 psS32 SubImageStartCol = PS_MAX (0, SubImageCenterCol - outerRadiusS32); 636 psS32 SubImageEndCol = PS_MIN (image->numCols, SubImageCenterCol + outerRadiusS32 + 1); 637 // 638 // Grab a subimage of the original image of size (2 * outerRadius). 639 // 640 // XXX EAM : merged psImageSubset & psRegionSet 641 // XXX EAM : cast for image is needed because of const (above) 642 psImage *subImage = psImageSubset((psImage *) image, psRegionSet(SubImageStartCol, 643 SubImageEndCol, 644 SubImageStartRow, 645 SubImageEndRow)); 646 647 psImage *subImageMask = psImageAlloc(subImage->numCols, 648 subImage->numRows, 649 PS_TYPE_U8); 650 // XXX EAM : for consistency, mask needs col0,row0 set to match image 651 // XXX EAM : CONFLICT between psLib and code requirement. FIX PSLIB!!! 652 // subImageMask->col0 = subImage->col0; 653 // subImageMask->row0 = subImage->row0; 654 psAbort ("pmObjects", "must fix this error before psphot will work!!!\n"); 655 656 // 657 // Loop through the subimage mask & initialize PSPHOT_MASK_INVALID 658 // 659 for (psS32 row = 0 ; row < subImageMask->numRows; row++) { 660 for (psS32 col = 0 ; col < subImageMask->numCols; col++) { 661 subImageMask->data.U8[row][col] = PSPHOT_MASK_INVALID; 662 } 663 } 664 665 // 666 // Loop through the subimage, mask off pixels in the inner square. 667 // XXX this uses a static mask value of 0 668 // XXX EAM : this was wrong: it masked the wrong pixels at the edge of the image 669 // XXX EAM : this masks the pixels in the center region 670 // XXX EAM : should we be using psImageMaskRegion ??? 671 psS32 StartRow = PS_MAX (0, SubImageCenterRow - subImageMask->row0 - innerRadiusS32); 672 psS32 EndRow = PS_MIN (subImageMask->numRows, SubImageCenterRow - subImageMask->row0 + innerRadiusS32 + 1); 673 psS32 StartCol = PS_MAX (0, SubImageCenterCol - subImageMask->col0 - innerRadiusS32); 674 psS32 EndCol = PS_MIN (subImageMask->numCols, SubImageCenterCol - subImageMask->col0 + innerRadiusS32 + 1); 675 for (psS32 row = StartRow; row < EndRow; row++) { 676 for (psS32 col = StartCol; col < EndCol; col++) { 677 subImageMask->data.U8[row][col] = PSPHOT_MASK_CLEAR; 678 } 679 } 680 681 // XXX EAM : make this trace information?? 682 // for (psS32 row = 0 ; row < subImage->numRows; row++) { 683 // for (psS32 col = 0 ; col < subImage->numCols; col++) { 684 // printf("(%d) ", subImageMask->data.U8[row][col]); 685 // } 686 // printf("\n"); 687 // } 688 689 // 690 // Allocate the myStats structure, then call psImageStats(), which will 691 // calculate the specified statistic. 692 // 605 bool pmSourceLocalSky (pmSource *source, 606 psStatsOptions statsOptions, 607 psF32 Radius) 608 { 609 610 psImage *image = source->pixels; 611 psImage *mask = source->mask; 612 pmPeak *peak = source->peak; 613 psRegion srcRegion; 614 615 // XXX EAM : psRegionXXX funcs should take value not ptr 616 srcRegion = psRegionForSquare (peak->x, peak->y, Radius); 617 srcRegion = psRegionForImage (mask, &srcRegion); 618 619 psImageMaskRegion (mask, &srcRegion, "OR", PSPHOT_MASK_MARKED); 693 620 psStats *myStats = psStatsAlloc(statsOptions); 694 myStats = psImageStats(myStats, subImage, subImageMask, 1); 695 696 // 697 // Create the output mySource, and set appropriate members. 698 // 699 pmSource *mySource = pmSourceAlloc(); 700 mySource->peak = (pmPeak *) peak; 701 mySource->moments = pmMomentsAlloc(); 621 myStats = psImageStats(myStats, image, mask, 0xff); 622 psImageMaskRegion (mask, &srcRegion, "AND", ~PSPHOT_MASK_MARKED); 623 702 624 psF64 tmpF64; 703 625 p_psGetStatValue(myStats, &tmpF64); 704 mySource->moments->Sky = (psF32) tmpF64; 705 mySource->pixels = subImage; 706 mySource->mask = subImageMask; 707 708 // 709 // Free things. XXX: This should be static memory. 710 // 711 psFree(myStats); 712 713 return(mySource); 714 } 715 716 /****************************************************************************** 717 bool checkRadius(*peak, radius, x, y): private function which simply 718 determines if the (x, y) point is within the radius of the specified peak. 719 720 XXX: macro this for performance. 721 *****************************************************************************/ 722 static bool checkRadius(pmPeak *peak, 723 psF32 radius, 724 psS32 x, 725 psS32 y) 726 { 727 if (PS_SQR(radius) >= (psF32) (PS_SQR(x - peak->x) + PS_SQR(y - peak->y))) { 728 return(true); 729 } 730 731 return(false); 626 psFree (myStats); 627 628 if (isnan(tmpF64)) return (false); 629 source->moments = pmMomentsAlloc(); 630 source->moments->Sky = (psF32) tmpF64; 631 return (true); 732 632 } 733 633 … … 762 662 pmSource->peak 763 663 pmSource->pixels 664 pmSource->noise 665 pmSource->mask 764 666 765 667 XXX: The peak calculations are done in image coords, not subImage coords. 766 668 767 XXX: mask values? 768 *****************************************************************************/ 669 XXX EAM : this version clips input pixels on S/N 670 XXX EAM : this version returns false for several reasons 671 *****************************************************************************/ 672 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0) 673 769 674 bool pmSourceMoments(pmSource *source, 770 675 psF32 radius) 771 676 { 772 PS_ASSERT_PTR_NON_NULL(source, NULL); 773 PS_ASSERT_PTR_NON_NULL(source->peak, NULL); 774 PS_ASSERT_PTR_NON_NULL(source->pixels, NULL); 677 // PS_PTR_CHECK_NULL(source, NULL); 678 // PS_PTR_CHECK_NULL(source->peak, NULL); 679 // PS_PTR_CHECK_NULL(source->pixels, NULL); 680 // PS_PTR_CHECK_NULL(source->noise, NULL); 775 681 PS_FLOAT_COMPARE(0.0, radius, NULL); 776 682 … … 791 697 // XY = SUM (x - xc)*(y - yc)*(z - sky) 792 698 // 793 psF32 Sum = 0.0;794 699 psF32 peakPixel = -PS_MAX_F32; 795 700 psS32 numPixels = 0; 701 psF32 Sum = 0.0; 796 702 psF32 X1 = 0.0; 797 703 psF32 Y1 = 0.0; … … 799 705 psF32 Y2 = 0.0; 800 706 psF32 XY = 0.0; 801 psF32 x = 0; 802 psF32 y = 0; 803 // 707 psF32 x = 0; 708 psF32 y = 0; 709 psF32 R2 = PS_SQR(radius); 710 711 psF32 xPeak = source->peak->x; 712 psF32 yPeak = source->peak->y; 713 804 714 // XXX why do I get different results for these two methods of finding Sx? 805 715 // XXX Sx, Sy would be better measured if we clip pixels close to sky … … 809 719 // proceed with the moments calculation. need to do two loops for a 810 720 // numerically stable result. first loop: get the sums. 811 // 721 // XXX EAM : mask == 0 is valid 722 812 723 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 813 724 for (psS32 col = 0; col < source->pixels->numCols ; col++) { 814 // XXX EAM : mask == 0 is valid815 725 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) continue; 816 psS32 imgColCoord = col + source->pixels->col0; 817 psS32 imgRowCoord = row + source->pixels->row0; 818 if (checkRadius(source->peak, 819 radius, 820 imgColCoord, 821 imgRowCoord)) { 822 psF32 xDiff = (psF32) (imgColCoord - source->peak->x); 823 psF32 yDiff = (psF32) (imgRowCoord - source->peak->y); 824 psF32 pDiff = source->pixels->data.F32[row][col] - sky; 825 826 Sum+= pDiff; 827 X1+= xDiff * pDiff; 828 Y1+= yDiff * pDiff; 829 XY+= xDiff * yDiff * pDiff; 830 831 X2+= PS_SQR(xDiff) * pDiff; 832 Y2+= PS_SQR(yDiff) * pDiff; 833 834 if (source->pixels->data.F32[row][col] > peakPixel) { 835 peakPixel = source->pixels->data.F32[row][col]; 836 } 837 numPixels++; 838 } 726 727 psF32 xDiff = col + source->pixels->col0 - xPeak; 728 psF32 yDiff = row + source->pixels->row0 - yPeak; 729 730 // XXX EAM : calculate xDiff, yDiff up front; 731 // radius is just a function of (xDiff, yDiff) 732 if (!VALID_RADIUS(xDiff, yDiff, R2)) continue; 733 734 psF32 pDiff = source->pixels->data.F32[row][col] - sky; 735 736 // XXX EAM : check for valid S/N in pixel 737 // XXX EAM : should this limit be user-defined? 738 if (pDiff / sqrt(source->noise->data.F32[row][col]) < 1) continue; 739 740 Sum += pDiff; 741 X1 += xDiff * pDiff; 742 Y1 += yDiff * pDiff; 743 XY += xDiff * yDiff * pDiff; 744 745 X2 += PS_SQR(xDiff) * pDiff; 746 Y2 += PS_SQR(yDiff) * pDiff; 747 748 peakPixel = PS_MAX (source->pixels->data.F32[row][col], peakPixel); 749 numPixels++; 839 750 } 840 751 } 841 752 // XXX EAM - the limit is a bit arbitrary. make it user defined? 842 753 if ((numPixels < 3) || (Sum <= 0)) { 843 psTrace (".psModules.pmSourceMoments", 5, "no valid pixels for source\n");844 return (false);754 psTrace (".psModules.pmSourceMoments", 5, "no valid pixels for source\n"); 755 return (false); 845 756 } 846 757 … … 857 768 y = Y1/Sum; 858 769 if ((fabs(x) > radius) || (fabs(y) > radius)) { 859 psTrace (".psModules.pmSourceMoments", 5, 860 "large centroid swing; invalid peak %d, %d\n", 861 source->peak->x, source->peak->y); 862 return (false); 863 } 864 865 source->moments->x = x + ((psF32) source->peak->x); 866 source->moments->y = y + ((psF32) source->peak->y); 867 770 psTrace (".psModules.pmSourceMoments", 5, 771 "large centroid swing; invalid peak %d, %d\n", 772 source->peak->x, source->peak->y); 773 return (false); 774 } 775 776 source->moments->x = x + xPeak; 777 source->moments->y = y + yPeak; 778 779 // XXX EAM : Sxy needs to have x*y subtracted 868 780 source->moments->Sxy = XY/Sum - x*y; 869 781 source->moments->Sum = Sum; … … 919 831 *****************************************************************************/ 920 832 833 // XXX EAM include a S/N cutoff in selecting the sources? 921 834 pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *metadata) 922 835 { … … 1123 1036 bool big = (sigX > (clump.X - clump.dX)) && (sigY > (clump.Y - clump.dY)); 1124 1037 if ((Nsatpix > 1) && big) { 1125 tmpSrc->type |= P S_SOURCE_SATSTAR;1038 tmpSrc->type |= PM_SOURCE_SATSTAR; 1126 1039 Nsatstar ++; 1127 1040 continue; … … 1130 1043 // saturated object (not a star, eg bleed trails, hot pixels) 1131 1044 if (Nsatpix > 1) { 1132 tmpSrc->type |= P S_SOURCE_SATURATED;1045 tmpSrc->type |= PM_SOURCE_SATURATED; 1133 1046 Nsat ++; 1134 1047 continue; … … 1139 1052 // only set candidate defects if 1140 1053 if ((sigX < 0.05) || (sigY < 0.05)) { 1141 tmpSrc->type |= P S_SOURCE_DEFECT;1054 tmpSrc->type |= PM_SOURCE_DEFECT; 1142 1055 Ncr ++; 1143 1056 continue; … … 1146 1059 // likely unsaturated galaxy (too large to be stellar) 1147 1060 if ((sigX > (clump.X + 3*clump.dX)) || (sigY > (clump.Y + 3*clump.dY))) { 1148 tmpSrc->type |= P S_SOURCE_GALAXY;1061 tmpSrc->type |= PM_SOURCE_GALAXY; 1149 1062 Ngal ++; 1150 1063 continue; … … 1159 1072 psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY); 1160 1073 if ((SN > PSF_SN_LIM) && (radius < 1.5)) { 1161 tmpSrc->type |= P S_SOURCE_PSFSTAR;1074 tmpSrc->type |= PM_SOURCE_PSFSTAR; 1162 1075 Npsf ++; 1163 1076 continue; … … 1165 1078 1166 1079 // random type of star 1167 tmpSrc->type |= P S_SOURCE_OTHER;1080 tmpSrc->type |= PM_SOURCE_OTHER; 1168 1081 } 1169 1082 … … 1197 1110 XXX: The circle will have a diameter of (1+radius). This is different from 1198 1111 the pmSourceSetLocal() function. 1112 1113 XXX: this should probably use the psImageMaskCircle Function for consistency 1199 1114 *****************************************************************************/ 1200 1115 bool pmSourceSetPixelsCircle(pmSource *source, … … 1537 1452 XXX EAM : fit the specified model (not necessarily the one in source) 1538 1453 *****************************************************************************/ 1539 bool pmSourceFitModel (pmSource *source,1540 pmModel *model,1541 const bool PSF)1454 bool pmSourceFitModel_v5(pmSource *source, 1455 pmModel *model, 1456 const bool PSF) 1542 1457 { 1543 1458 PS_ASSERT_PTR_NON_NULL(source, false); … … 1554 1469 // tests below could be conditions (!NULL) 1555 1470 1556 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);1557 1558 1471 psVector *params = model->params; 1559 1472 psVector *dparams = model->dparams; 1560 1473 psVector *paramMask = NULL; 1474 1475 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 1561 1476 1562 1477 int nParams = PSF ? params->n - 4 : params->n; … … 1615 1530 } 1616 1531 1617 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 1532 // XXX EAM : covar must be F64? 1533 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F64); 1618 1534 1619 1535 psTrace (".pmObjects.pmSourceFitModel", 5, "fitting function\n"); … … 1621 1537 for (int i = 0; i < dparams->n; i++) { 1622 1538 if ((paramMask != NULL) && paramMask->data.U8[i]) continue; 1623 dparams->data.F32[i] = sqrt(covar->data.F 32[i][i]);1539 dparams->data.F32[i] = sqrt(covar->data.F64[i][i]); 1624 1540 } 1625 1541 … … 1640 1556 // XXX EAM get the Gauss-Newton distance for fixed model parameters 1641 1557 if (paramMask != NULL) { 1642 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F 32);1558 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64); 1643 1559 psMinimizeGaussNewtonDelta (delta, params, NULL, x, y, yErr, modelFunc); 1644 1560 for (int i = 0; i < dparams->n; i++) { 1645 1561 if (!paramMask->data.U8[i]) continue; 1646 dparams->data.F32[i] = delta->data.F 32[i];1562 dparams->data.F32[i] = delta->data.F64[i]; 1647 1563 } 1648 1564 psFree (delta); … … 1655 1571 psFree(covar); 1656 1572 psFree(paramMask); 1573 1574 rc = (onPic && fitStatus); 1575 return(rc); 1576 } 1577 1578 // XXX EAM : new version with parameter range limits and noise enhancement 1579 bool pmSourceFitModel (pmSource *source, 1580 pmModel *model, 1581 const bool PSF) 1582 { 1583 PS_ASSERT_PTR_NON_NULL(source, false); 1584 PS_ASSERT_PTR_NON_NULL(source->moments, false); 1585 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1586 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 1587 PS_ASSERT_PTR_NON_NULL(source->mask, false); 1588 PS_ASSERT_PTR_NON_NULL(source->noise, false); 1589 1590 // XXX EAM : is it necessary for the mask & noise to exist? the 1591 // tests below could be conditions (!NULL) 1592 1593 psBool fitStatus = true; 1594 psBool onPic = true; 1595 psBool rc = true; 1596 psF32 Ro, ymodel; 1597 1598 psVector *params = model->params; 1599 psVector *dparams = model->dparams; 1600 psVector *paramMask = NULL; 1601 1602 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 1603 1604 // XXX EAM : I need to use the sky value to constrain the noise model 1605 int nParams = PSF ? params->n - 4 : params->n; 1606 psF32 So = params->data.F32[0]; 1607 1608 // find the number of valid pixels 1609 // XXX EAM : this loop and the loop below could just be one pass 1610 // using the psArrayAdd and psVectorExtend functions 1611 psS32 count = 0; 1612 for (psS32 i = 0; i < source->pixels->numRows; i++) { 1613 for (psS32 j = 0; j < source->pixels->numCols; j++) { 1614 if (source->mask->data.U8[i][j] == 0) { 1615 count++; 1616 } 1617 } 1618 } 1619 if (count < nParams + 1) { 1620 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1621 return(false); 1622 } 1623 1624 // construct the coordinate and value entries 1625 psArray *x = psArrayAlloc(count); 1626 psVector *y = psVectorAlloc(count, PS_TYPE_F32); 1627 psVector *yErr = psVectorAlloc(count, PS_TYPE_F32); 1628 psS32 tmpCnt = 0; 1629 for (psS32 i = 0; i < source->pixels->numRows; i++) { 1630 for (psS32 j = 0; j < source->pixels->numCols; j++) { 1631 if (source->mask->data.U8[i][j] == 0) { 1632 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 1633 // XXX: Convert i/j to image space: 1634 // XXX EAM: coord order is (x,y) == (col,row) 1635 coord->data.F32[0] = (psF32) (j + source->pixels->col0); 1636 coord->data.F32[1] = (psF32) (i + source->pixels->row0); 1637 x->data[tmpCnt] = (psPtr *) coord; 1638 y->data.F32[tmpCnt] = source->pixels->data.F32[i][j]; 1639 1640 // compare observed flux to model flux to adjust weight 1641 ymodel = modelFunc (NULL, model->params, coord); 1642 1643 // this test enhances the noise based on deviation from the model flux 1644 Ro = 1.0 + fabs (y->data.F32[tmpCnt] - ymodel) / sqrt(PS_SQR(ymodel - So) + PS_SQR(So)); 1645 1646 // XXX EAM : note the wasted effort: we carry dY^2, take sqrt(), then 1647 // the minimization function calculates sq(). 1648 // should psMinimizeLMChi2 take dY^2? 1649 yErr->data.F32[tmpCnt] = sqrt (source->noise->data.F32[i][j] * Ro); 1650 tmpCnt++; 1651 } 1652 } 1653 } 1654 1655 psMinimization *myMin = psMinimizationAlloc(PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, 1656 PM_SOURCE_FIT_MODEL_TOLERANCE); 1657 1658 // PSF model only fits first 4 parameters, FLT model fits all 1659 if (PSF) { 1660 paramMask = psVectorAlloc (params->n, PS_TYPE_U8); 1661 for (int i = 0; i < 4; i++) { 1662 paramMask->data.U8[i] = 0; 1663 } 1664 for (int i = 4; i < paramMask->n; i++) { 1665 paramMask->data.U8[i] = 1; 1666 } 1667 } 1668 1669 // XXX EAM : I've added three types of parameter range checks 1670 // XXX EAM : this requires my new psMinimization functions 1671 pmModelLimits modelLimits = pmModelLimits_GetFunction (model->type); 1672 psVector *beta_lim = NULL; 1673 psVector *params_min = NULL; 1674 psVector *params_max = NULL; 1675 1676 // XXX EAM : in this implementation, I pass in the limits with the covar matrix. 1677 // in the SDRS, I define a new psMinimization which will take these in 1678 psImage *covar = psImageAlloc (params->n, 3, PS_TYPE_F64); 1679 modelLimits (&beta_lim, ¶ms_min, ¶ms_max); 1680 for (int i = 0; i < params->n; i++) { 1681 covar->data.F64[0][i] = beta_lim->data.F32[i]; 1682 covar->data.F64[1][i] = params_min->data.F32[i]; 1683 covar->data.F64[2][i] = params_max->data.F32[i]; 1684 } 1685 1686 psTrace (".pmObjects.pmSourceFitModel", 5, "fitting function\n"); 1687 fitStatus = psMinimizeLMChi2_EAM(myMin, covar, params, paramMask, x, y, yErr, modelFunc); 1688 for (int i = 0; i < dparams->n; i++) { 1689 if ((paramMask != NULL) && paramMask->data.U8[i]) continue; 1690 dparams->data.F32[i] = sqrt(covar->data.F64[i][i]); 1691 } 1692 1693 // XXX EAM: we need to do something (give an error?) if rc is false 1694 // XXX EAM: psMinimizeLMChi2 does not check convergence 1695 1696 // XXX models can go insane: reject these 1697 onPic &= (params->data.F32[2] >= source->pixels->col0); 1698 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1699 onPic &= (params->data.F32[3] >= source->pixels->row0); 1700 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1701 1702 // XXX EAM: save the resulting chisq, nDOF, nIter 1703 model->chisq = myMin->value; 1704 model->nIter = myMin->iter; 1705 model->nDOF = y->n - nParams; 1706 1707 // XXX EAM get the Gauss-Newton distance for fixed model parameters 1708 if (paramMask != NULL) { 1709 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64); 1710 psMinimizeGaussNewtonDelta (delta, params, NULL, x, y, yErr, modelFunc); 1711 for (int i = 0; i < dparams->n; i++) { 1712 if (!paramMask->data.U8[i]) continue; 1713 dparams->data.F32[i] = delta->data.F64[i]; 1714 } 1715 } 1716 1717 psFree(paramMask); 1718 psFree(x); 1719 psFree(y); 1720 psFree(myMin); 1657 1721 1658 1722 rc = (onPic && fitStatus); -
trunk/psphot/src/pmObjects_EAM.h
r4983 r5048 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-09- 09 18:31:29$7 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-09-14 01:35:20 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 210 210 211 211 *****************************************************************************/ 212 pmSource *pmSourceLocalSky( 213 const psImage *image, ///< The input image (float) 214 const pmPeak *peak, ///< The peak for which the pmSource struct is created. 212 bool pmSourceLocalSky( 213 pmSource *source, ///< The input image (float) 215 214 psStatsOptions statsOptions, ///< The statistic used in calculating the background sky 216 float innerRadius, ///< The inner radius of the suqare annulus for calculating sky 217 float outerRadius ///< The outer radius of the suqare annulus for calculating sky 218 ); 215 float Radius ///< The inner radius of the square annulus to exclude 216 ); 219 217 220 218 /****************************************************************************** … … 298 296 ); 299 297 298 bool pmSourceFitModel_v5( 299 pmSource *source, ///< The input pmSource 300 pmModel *model, ///< model to be fitted 301 const bool PSF ///< Treat model as PSF or FLT? 302 ); 303 304 bool pmSourceFitModel_v7( 305 pmSource *source, ///< The input pmSource 306 pmModel *model, ///< model to be fitted 307 const bool PSF ///< Treat model as PSF or FLT? 308 ); 309 300 310 #endif -
trunk/psphot/src/psLibUtils.c
r4977 r5048 147 147 } 148 148 149 # if (0) 149 150 // alternate implementation of this function from pmObjects.c 150 // XXX EAM : move this to pmObjects_EAM.c151 // now defined in psLib SDRS as psImageRow 151 152 psVector *psGetRowVectorFromImage(psImage *image, 152 153 psU32 row) … … 159 160 return(tmpVector); 160 161 } 162 # endif 161 163 162 164 // XXX EAM : this is now in psLib -
trunk/psphot/src/psLibUtils.h
r4983 r5048 39 39 int psArgumentRemove (int N, int *argc, char **argv); // added to SDRS 40 40 psVector *psVectorCreate (double lower, double upper, double delta, psElemType type); // added to SDRS 41 psVector *psGetRowVectorFromImage(psImage *image, psU32 row); // added to SDRS (as psImageRow)41 // psVector *psGetRowVectorFromImage(psImage *image, psU32 row); // added to SDRS (as psImageRow) 42 42 int psImageCountPixelMask (psImage *mask, psU8 value); // added to SDRS 43 43 … … 56 56 57 57 // polynomial functions -- all in SDRS, not done for v.15 58 // XXX the pslib 0.7.0 polynomials are *still* nTerm, not nOrder!!! 58 59 psPolynomial1D *Polynomial1DAlloc_EAM(psPolynomialType type, psS32 nOrder); 59 60 void Polynomial1DDump_EAM(psPolynomial1D *poly); -
trunk/psphot/src/psMinimize.c
r4977 r5048 95 95 96 96 // iterate until the tolerance is reached, or give up 97 while ((min-> lastDelta > min->tol) && (min->iter < min->maxIter)) {97 while ((min->iter < min->maxIter) && ((min->lastDelta > min->tol) || !isfinite(min->lastDelta))) { 98 98 99 99 // set a new guess for Alpha, Beta, Params -
trunk/psphot/src/psModulesUtils.c
r4977 r5048 2 2 3 3 // extract config informatin from config data or from image header, if specified 4 // XXX EAM : this function should be replaced with Paul's image/header/metadata load scheme 4 5 psF32 pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name) { 5 6 … … 48 49 } 49 50 50 // XXX EAM : these are my alternate implementations of psModule functions51 52 // this sets and clears bit 0x8053 bool pmSourceLocalSky_EAM (pmSource *source,54 psStatsOptions statsOptions,55 psF32 Radius)56 {57 58 psImage *image = source->pixels;59 psImage *mask = source->mask;60 pmPeak *peak = source->peak;61 psRegion srcRegion;62 63 // XXX EAM : psRegionXXX funcs need value not ptr64 65 srcRegion = psRegionForSquare (peak->x, peak->y, Radius);66 srcRegion = psRegionForImage (mask, &srcRegion);67 68 psImageMaskRegion (mask, &srcRegion, "OR", PSPHOT_MASK_MARKED);69 psStats *myStats = psStatsAlloc(statsOptions);70 myStats = psImageStats(myStats, image, mask, 0xff);71 psImageMaskRegion (mask, &srcRegion, "AND", ~PSPHOT_MASK_MARKED);72 73 psF64 tmpF64;74 p_psGetStatValue(myStats, &tmpF64);75 psFree (myStats);76 77 if (isnan(tmpF64)) return (false);78 source->moments = pmMomentsAlloc();79 source->moments->Sky = (psF32) tmpF64;80 return (true);81 }82 83 # define PM_SOURCE_FIT_MODEL_NUM_ITERATIONS 1584 # define PM_SOURCE_FIT_MODEL_TOLERANCE 0.185 bool pmSourceFitModel_EAM (pmSource *source,86 pmModel *model,87 const bool PSF)88 {89 // PS_PTR_CHECK_NULL(source, false);90 // PS_PTR_CHECK_NULL(source->moments, false);91 // PS_PTR_CHECK_NULL(source->peak, false);92 // PS_PTR_CHECK_NULL(source->pixels, false);93 // PS_PTR_CHECK_NULL(source->mask, false);94 // PS_PTR_CHECK_NULL(source->noise, false);95 psBool fitStatus = true;96 psBool onPic = true;97 psBool rc = true;98 psF32 Ro, ymodel;99 100 101 // XXX EAM : is it necessary for the mask & noise to exist? the102 // tests below could be conditions (!NULL)103 104 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);105 pmModelLimits modelLimits = pmModelLimits_GetFunction (model->type);106 107 psVector *params = model->params;108 psVector *dparams = model->dparams;109 psVector *paramMask = NULL;110 111 psVector *beta_lim = NULL;112 psVector *params_min = NULL;113 psVector *params_max = NULL;114 115 int nParams = PSF ? params->n - 4 : params->n;116 psF32 So = params->data.F32[0];117 118 // find the number of valid pixels119 // XXX EAM : this loop and the loop below could just be one pass120 // using the psArrayAdd and psVectorExtend functions121 psS32 count = 0;122 for (psS32 i = 0; i < source->pixels->numRows; i++) {123 for (psS32 j = 0; j < source->pixels->numCols; j++) {124 if (source->mask->data.U8[i][j] == 0) {125 count++;126 }127 }128 }129 if (count < nParams + 1) {130 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n");131 return(false);132 }133 134 // construct the coordinate and value entries135 psArray *x = psArrayAlloc(count);136 psVector *y = psVectorAlloc(count, PS_TYPE_F32);137 psVector *yErr = psVectorAlloc(count, PS_TYPE_F32);138 psS32 tmpCnt = 0;139 for (psS32 i = 0; i < source->pixels->numRows; i++) {140 for (psS32 j = 0; j < source->pixels->numCols; j++) {141 if (source->mask->data.U8[i][j] == 0) {142 psVector *coord = psVectorAlloc(2, PS_TYPE_F32);143 // XXX: Convert i/j to image space:144 // XXX EAM: coord order is (x,y) == (col,row)145 coord->data.F32[0] = (psF32) (j + source->pixels->col0);146 coord->data.F32[1] = (psF32) (i + source->pixels->row0);147 x->data[tmpCnt] = (psPtr *) coord;148 y->data.F32[tmpCnt] = source->pixels->data.F32[i][j];149 150 ymodel = modelFunc (NULL, model->params, coord);151 152 // this test enhances the noise based on deviation from the model flux153 Ro = 1.0 + fabs (y->data.F32[tmpCnt] - ymodel) / sqrt(PS_SQR(ymodel - So) + PS_SQR(So));154 yErr->data.F32[tmpCnt] = sqrt (source->noise->data.F32[i][j] * Ro);155 // XXX EAM : note the wasted effort: we carry dY^2, take sqrt(), then156 // the minimization function calculates sq()157 tmpCnt++;158 }159 }160 }161 162 psMinimization *myMin = psMinimizationAlloc(PM_SOURCE_FIT_MODEL_NUM_ITERATIONS,163 PM_SOURCE_FIT_MODEL_TOLERANCE);164 165 // PSF model only fits first 4 parameters, FLT model fits all166 if (PSF) {167 paramMask = psVectorAlloc (params->n, PS_TYPE_U8);168 for (int i = 0; i < 4; i++) {169 paramMask->data.U8[i] = 0;170 }171 for (int i = 4; i < paramMask->n; i++) {172 paramMask->data.U8[i] = 1;173 }174 }175 176 psImage *covar = psImageAlloc (params->n, 3, PS_TYPE_F64);177 modelLimits (&beta_lim, ¶ms_min, ¶ms_max);178 for (int i = 0; i < params->n; i++) {179 covar->data.F64[0][i] = beta_lim->data.F32[i];180 covar->data.F64[1][i] = params_min->data.F32[i];181 covar->data.F64[2][i] = params_max->data.F32[i];182 }183 184 psTrace (".pmObjects.pmSourceFitModel", 5, "fitting function\n");185 fitStatus = psMinimizeLMChi2_EAM(myMin, covar, params, paramMask, x, y, yErr, modelFunc);186 for (int i = 0; i < dparams->n; i++) {187 if ((paramMask != NULL) && paramMask->data.U8[i]) continue;188 dparams->data.F32[i] = sqrt(covar->data.F64[i][i]);189 }190 191 // XXX EAM: we need to do something (give an error?) if rc is false192 // XXX EAM: psMinimizeLMChi2 does not check convergence193 194 // XXX models can go insane: reject these195 onPic &= (params->data.F32[2] >= source->pixels->col0);196 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols);197 onPic &= (params->data.F32[3] >= source->pixels->row0);198 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows);199 200 // XXX EAM: save the resulting chisq, nDOF, nIter201 model->chisq = myMin->value;202 model->nIter = myMin->iter;203 model->nDOF = y->n - nParams;204 205 // XXX EAM get the Gauss-Newton distance for fixed model parameters206 if (paramMask != NULL) {207 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64);208 psMinimizeGaussNewtonDelta (delta, params, NULL, x, y, yErr, modelFunc);209 for (int i = 0; i < dparams->n; i++) {210 if (!paramMask->data.U8[i]) continue;211 dparams->data.F32[i] = delta->data.F64[i];212 }213 }214 215 psFree(paramMask);216 psFree(x);217 psFree(y);218 psFree(myMin);219 220 rc = (onPic && fitStatus);221 return(rc);222 }223 224 /******************************************************************************225 pmSourceMoments(source, radius): this function takes a subImage defined in the226 pmSource data structure, along with the peak location, and determines the227 various moments associated with that peak.228 229 Requires the following to have been created:230 pmSource231 pmSource->peak232 pmSource->pixels233 234 XXX: The peak calculations are done in image coords, not subImage coords.235 236 XXX: mask values?237 238 XXX EAM : this version clips input pixels on S/N239 *****************************************************************************/240 # define VALID_RADIUS(X,Y) (((R2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0)241 242 bool pmSourceMoments_EAM(pmSource *source,243 psF32 radius)244 {245 // PS_PTR_CHECK_NULL(source, NULL);246 // PS_PTR_CHECK_NULL(source->peak, NULL);247 // PS_PTR_CHECK_NULL(source->pixels, NULL);248 // PS_PTR_CHECK_NULL(source->noise, NULL);249 PS_FLOAT_COMPARE(0.0, radius, NULL);250 251 //252 // XXX: Verify the setting for sky if source->moments == NULL.253 //254 psF32 sky = 0.0;255 if (source->moments == NULL) {256 source->moments = pmMomentsAlloc();257 } else {258 sky = source->moments->Sky;259 }260 261 //262 // Sum = SUM (z - sky)263 // X1 = SUM (x - xc)*(z - sky)264 // X2 = SUM (x - xc)^2 * (z - sky)265 // XY = SUM (x - xc)*(y - yc)*(z - sky)266 //267 psF32 peakPixel = -PS_MAX_F32;268 psS32 numPixels = 0;269 psF32 Sum = 0.0;270 psF32 X1 = 0.0;271 psF32 Y1 = 0.0;272 psF32 X2 = 0.0;273 psF32 Y2 = 0.0;274 psF32 XY = 0.0;275 psF32 x = 0;276 psF32 y = 0;277 psF32 R2 = PS_SQR(radius);278 279 psF32 xPeak = source->peak->x;280 psF32 yPeak = source->peak->y;281 282 // XXX why do I get different results for these two methods of finding Sx?283 // XXX Sx, Sy would be better measured if we clip pixels close to sky284 // XXX Sx, Sy can still be imaginary, so we probably need to keep Sx^2?285 // We loop through all pixels in this subimage (source->pixels), and for each286 // pixel that is not masked, AND within the radius of the peak pixel, we287 // proceed with the moments calculation. need to do two loops for a288 // numerically stable result. first loop: get the sums.289 // XXX EAM : mask == 0 is valid290 291 for (psS32 row = 0; row < source->pixels->numRows ; row++) {292 for (psS32 col = 0; col < source->pixels->numCols ; col++) {293 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) continue;294 295 psF32 xDiff = col + source->pixels->col0 - xPeak;296 psF32 yDiff = row + source->pixels->row0 - yPeak;297 298 if (!VALID_RADIUS(xDiff, yDiff)) continue;299 300 psF32 pDiff = source->pixels->data.F32[row][col] - sky;301 302 // XXX EAM : check for valid S/N in pixel303 if (pDiff / sqrt(source->noise->data.F32[row][col]) < 1) continue;304 305 Sum += pDiff;306 X1 += xDiff * pDiff;307 Y1 += yDiff * pDiff;308 XY += xDiff * yDiff * pDiff;309 310 X2 += PS_SQR(xDiff) * pDiff;311 Y2 += PS_SQR(yDiff) * pDiff;312 313 peakPixel = PS_MAX (source->pixels->data.F32[row][col], peakPixel);314 numPixels++;315 }316 }317 // XXX EAM - the limit is a bit arbitrary. make it user defined?318 if ((numPixels < 3) || (Sum <= 0)) {319 psTrace (".psModules.pmSourceMoments", 5, "no valid pixels for source\n");320 return (false);321 }322 323 psTrace (".psModules.pmSourceMoments", 5,324 "sky: %f Sum: %f X1: %f Y1: %f X2: %f Y2: %f XY: %f Npix: %d\n",325 sky, Sum, X1, Y1, X2, Y2, XY, numPixels);326 327 //328 // first moment X = X1/Sum + xc329 // second moment X = sqrt (X2/Sum - (X1/Sum)^2)330 // Sxy = XY / Sum331 //332 x = X1/Sum;333 y = Y1/Sum;334 if ((fabs(x) > radius) || (fabs(y) > radius)) {335 psTrace (".psModules.pmSourceMoments", 5,336 "large centroid swing; invalid peak %d, %d\n",337 source->peak->x, source->peak->y);338 return (false);339 }340 341 source->moments->x = x + xPeak;342 source->moments->y = y + yPeak;343 344 source->moments->Sxy = XY/Sum - x*y;345 source->moments->Sum = Sum;346 source->moments->Peak = peakPixel;347 source->moments->nPixels = numPixels;348 349 // XXX EAM : these values can be negative, so we need to limit the range350 source->moments->Sx = sqrt(PS_MAX(X2/Sum - PS_SQR(x), 0));351 source->moments->Sy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0));352 353 psTrace (".psModules.pmSourceMoments", 4,354 "sky: %f Sum: %f x: %f y: %f Sx: %f Sy: %f Sxy: %f\n",355 sky, Sum, source->moments->x, source->moments->y,356 source->moments->Sx, source->moments->Sy, source->moments->Sxy);357 358 return(true);359 }360 361 51 bool pmModelFitStatus (pmModel *model) { 362 52 -
trunk/psphot/src/psModulesUtils.h
r4983 r5048 10 10 11 11 // psModule extra utilities 12 bool pmSourceLocalSky_EAM (pmSource *source, psStatsOptions statsOptions, psF32 Radius); 13 bool pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF); 14 bool pmSourceMoments_EAM(pmSource *source, psF32 radius); 12 // bool pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF); 15 13 bool pmModelFitStatus (pmModel *model); 16 14 int pmSourceDophotType (pmSource *source); -
trunk/psphot/src/psphotApplyPSF.c
r4977 r5048 39 39 // skip non-astronomical objects (very likely defects) 40 40 // XXX EAM : should we try these anyway? 41 if (source->type == P S_SOURCE_DEFECT) continue;42 if (source->type == P S_SOURCE_SATURATED) continue;41 if (source->type == PM_SOURCE_DEFECT) continue; 42 if (source->type == PM_SOURCE_SATURATED) continue; 43 43 44 44 // use the source moments, etc to guess basic model parameters … … 65 65 } 66 66 67 if (i > 66) psTraceSetLevel (".psLib.dataManip.psMinimizeLMChi2", 5);67 // if (i > 66) psTraceSetLevel (".psLib.dataManip.psMinimizeLMChi2", 5); 68 68 69 69 // fit PSF model (set/unset the pixel mask) … … 73 73 if (!status || (model->params->data.F32[1] < 0)) { 74 74 psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter); 75 source->type = P S_SOURCE_FAIL_FIT_PSF; // better choice?75 source->type = PM_SOURCE_FAIL_FIT_PSF; // better choice? 76 76 psFree (model); 77 77 continue; -
trunk/psphot/src/psphotChoosePSF.c
r4977 r5048 18 18 for (int i = 0; i < sources->n; i++) { 19 19 pmSource *source = sources->data[i]; 20 if (source->type != P S_SOURCE_PSFSTAR) continue;20 if (source->type != PM_SOURCE_PSFSTAR) continue; 21 21 psArrayAdd (stars, 200, source); 22 22 } -
trunk/psphot/src/psphotFitGalaxies.c
r4977 r5048 31 31 // sources which should not be fitted 32 32 // skip all valid stars 33 if (source->type == P S_SOURCE_PSFSTAR) continue;34 if (source->type == P S_SOURCE_SATSTAR) continue;35 if (source->type == P S_SOURCE_GOODSTAR) continue;33 if (source->type == PM_SOURCE_PSFSTAR) continue; 34 if (source->type == PM_SOURCE_SATSTAR) continue; 35 if (source->type == PM_SOURCE_GOODSTAR) continue; 36 36 37 37 // skip all likely defects 38 if (source->type == P S_SOURCE_DEFECT) continue;39 if (source->type == P S_SOURCE_SATURATED) continue;38 if (source->type == PM_SOURCE_DEFECT) continue; 39 if (source->type == PM_SOURCE_SATURATED) continue; 40 40 41 41 // skip poorly fitted stars 42 if (source->type == P S_SOURCE_FAINTSTAR) continue;43 if (source->type == P S_SOURCE_POOR_FIT_PSF) continue;42 if (source->type == PM_SOURCE_FAINTSTAR) continue; 43 if (source->type == PM_SOURCE_POOR_FIT_PSF) continue; 44 44 45 45 // XXX EAM when do we pick these up again? 46 46 if (source->moments->SN < GAL_MIN_SN) { 47 source->type = P S_SOURCE_FAINT_GALAXY; // better choice?47 source->type = PM_SOURCE_FAINT_GALAXY; // better choice? 48 48 continue; 49 49 } 50 50 51 51 // recalculate the source moments using the larger galaxy moments radius 52 // XXX EAM : 0.5.0 code used _EAM version 53 // status = pmSourceMoments (source, GAL_MOMENTS_RAD); 54 status = pmSourceMoments_EAM (source, GAL_MOMENTS_RAD); 52 status = pmSourceMoments (source, GAL_MOMENTS_RAD); 55 53 if (!status) { 56 source->type = P S_SOURCE_DROP_GALAXY; // better choice?54 source->type = PM_SOURCE_DROP_GALAXY; // better choice? 57 55 continue; 58 56 } … … 84 82 // if the fit fails, we need to change the classification 85 83 psLogMsg ("psphot", 3, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius); 86 source->type = P S_SOURCE_FAIL_FIT_GAL; // better choice?84 source->type = PM_SOURCE_FAIL_FIT_GAL; // better choice? 87 85 source->modelFLT = model; 88 86 Nfail ++; … … 95 93 // if the fit fails, we need to change the classification 96 94 psLogMsg ("psphot", 3, "GAL fit poor for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius); 97 source->type = P S_SOURCE_POOR_FIT_GAL; // better choice?95 source->type = PM_SOURCE_POOR_FIT_GAL; // better choice? 98 96 source->modelFLT = model; 99 97 Nfail ++; … … 102 100 103 101 // accept the model 104 source->type = P S_SOURCE_GALAXY;102 source->type = PM_SOURCE_GALAXY; 105 103 source->modelFLT = model; 106 104 Niter += model[0].nIter; -
trunk/psphot/src/psphotMarkPSF.c
r4949 r5048 18 18 // we also reject objects with S/N too low or ChiSquare to high 19 19 20 // any object which meets the criterion is marked as P S_SOURCE_BRIGHTSTAR20 // any object which meets the criterion is marked as PM_SOURCE_BRIGHTSTAR 21 21 22 22 // floor for DS value … … 35 35 // remember: fit does not use saturated pixels (masked) 36 36 if (source->modelPSF->params->data.F32[1] >= SATURATE) { 37 if (source->type == P S_SOURCE_PSFSTAR) {37 if (source->type == PM_SOURCE_PSFSTAR) { 38 38 psLogMsg ("psphot", 3, "PSFSTAR marked SATSTAR\n"); 39 39 } 40 source->type = P S_SOURCE_SATSTAR;40 source->type = PM_SOURCE_SATSTAR; 41 41 return (true); 42 42 } 43 if (source->type == P S_SOURCE_SATSTAR) {43 if (source->type == PM_SOURCE_SATSTAR) { 44 44 psLogMsg ("psphot", 4, "SATSTAR marked GOODSTAR (fitted peak below saturation)\n"); 45 source->type = P S_SOURCE_GOODSTAR;45 source->type = PM_SOURCE_GOODSTAR; 46 46 } 47 47 … … 57 57 nSy = dSY / hypot (MIN_DS, 1 / (SY * SN)); 58 58 59 // assign P S_SOURCE_GOODSTAR to bright objects within PSF region of dparams[]59 // assign PM_SOURCE_GOODSTAR to bright objects within PSF region of dparams[] 60 60 keep = TRUE; 61 61 keep &= (fabs(nSx) < shapeNsigma); … … 64 64 keep &= (Chi < maxChi); 65 65 if (keep) { 66 if (source->type == P S_SOURCE_PSFSTAR) return (true);67 source->type = P S_SOURCE_GOODSTAR;66 if (source->type == PM_SOURCE_PSFSTAR) return (true); 67 source->type = PM_SOURCE_GOODSTAR; 68 68 return (true); 69 69 } 70 70 71 if (source->type == P S_SOURCE_PSFSTAR) {71 if (source->type == PM_SOURCE_PSFSTAR) { 72 72 psLogMsg ("psphot", 3, "PSFSTAR demoted based on fit quality\n"); 73 73 } … … 75 75 // object appears to be small, suspected defect 76 76 if ((nSx <= -shapeNsigma) || (nSy <= -shapeNsigma)) { 77 source->type = P S_SOURCE_DEFECT;77 source->type = PM_SOURCE_DEFECT; 78 78 return (false); 79 79 } … … 81 81 // object appears to be large, suspected galaxy 82 82 if ((nSx >= shapeNsigma) || (nSy >= shapeNsigma)) { 83 source->type = P S_SOURCE_GALAXY;83 source->type = PM_SOURCE_GALAXY; 84 84 return (false); 85 85 } … … 87 87 // object appears to be extremely faint: what is this? 88 88 if (SN < minSN) { 89 source->type = P S_SOURCE_FAINTSTAR;89 source->type = PM_SOURCE_FAINTSTAR; 90 90 return (false); 91 91 } 92 92 93 93 // these are pooly fitted, probable stars near other stars? 94 source->type = P S_SOURCE_POOR_FIT_PSF;94 source->type = PM_SOURCE_POOR_FIT_PSF; 95 95 return (false); 96 96 } -
trunk/psphot/src/psphotOutput.c
r4954 r5048 91 91 92 92 // use PSF model with stars 93 case P S_SOURCE_PSFSTAR:94 case P S_SOURCE_SATSTAR:95 case P S_SOURCE_GOODSTAR:93 case PM_SOURCE_PSFSTAR: 94 case PM_SOURCE_SATSTAR: 95 case PM_SOURCE_GOODSTAR: 96 96 model = source->modelPSF; 97 97 break; 98 98 99 99 // use FLT model with galaxies 100 case P S_SOURCE_GALAXY:100 case PM_SOURCE_GALAXY: 101 101 model = source->modelFLT; 102 102 break; 103 103 104 104 // skip defects and poorly fitted stars or galaxies 105 case P S_SOURCE_DEFECT:106 case P S_SOURCE_SATURATED:107 case P S_SOURCE_FAINTSTAR:108 case P S_SOURCE_POOR_FIT_PSF:109 case P S_SOURCE_POOR_FIT_GAL:110 case P S_SOURCE_FAIL_FIT_GAL:105 case PM_SOURCE_DEFECT: 106 case PM_SOURCE_SATURATED: 107 case PM_SOURCE_FAINTSTAR: 108 case PM_SOURCE_POOR_FIT_PSF: 109 case PM_SOURCE_POOR_FIT_GAL: 110 case PM_SOURCE_FAIL_FIT_GAL: 111 111 default: 112 112 model = NULL; … … 183 183 184 184 // use PSF model with stars 185 case P S_SOURCE_SATSTAR:185 case PM_SOURCE_SATSTAR: 186 186 flags = 4; 187 187 model = source->modelPSF; 188 188 break; 189 189 190 case P S_SOURCE_PSFSTAR:191 case P S_SOURCE_GOODSTAR:190 case PM_SOURCE_PSFSTAR: 191 case PM_SOURCE_GOODSTAR: 192 192 model = source->modelPSF; 193 193 break; 194 194 195 195 // use FLT model with galaxies 196 case P S_SOURCE_GALAXY:196 case PM_SOURCE_GALAXY: 197 197 model = source->modelFLT; 198 198 break; 199 199 200 200 // skip defects and poorly fitted stars or galaxies 201 case P S_SOURCE_DEFECT:202 case P S_SOURCE_SATURATED:203 case P S_SOURCE_FAINTSTAR:204 case P S_SOURCE_POOR_FIT_PSF:205 case P S_SOURCE_POOR_FIT_GAL:206 case P S_SOURCE_FAIL_FIT_GAL:201 case PM_SOURCE_DEFECT: 202 case PM_SOURCE_SATURATED: 203 case PM_SOURCE_FAINTSTAR: 204 case PM_SOURCE_POOR_FIT_PSF: 205 case PM_SOURCE_POOR_FIT_GAL: 206 case PM_SOURCE_FAIL_FIT_GAL: 207 207 default: 208 208 model = NULL; … … 288 288 289 289 // use PSF model with stars 290 case P S_SOURCE_PSFSTAR:291 case P S_SOURCE_SATSTAR:292 case P S_SOURCE_GOODSTAR:290 case PM_SOURCE_PSFSTAR: 291 case PM_SOURCE_SATSTAR: 292 case PM_SOURCE_GOODSTAR: 293 293 model = source->modelPSF; 294 294 break; 295 295 296 296 // use FLT model with galaxies 297 case P S_SOURCE_GALAXY:297 case PM_SOURCE_GALAXY: 298 298 model = source->modelFLT; 299 299 break; 300 300 301 301 // skip defects and poorly fitted stars or galaxies 302 case P S_SOURCE_DEFECT:303 case P S_SOURCE_SATURATED:304 case P S_SOURCE_FAINTSTAR:305 case P S_SOURCE_POOR_FIT_PSF:306 case P S_SOURCE_POOR_FIT_GAL:307 case P S_SOURCE_FAIL_FIT_GAL:302 case PM_SOURCE_DEFECT: 303 case PM_SOURCE_SATURATED: 304 case PM_SOURCE_FAINTSTAR: 305 case PM_SOURCE_POOR_FIT_PSF: 306 case PM_SOURCE_POOR_FIT_GAL: 307 case PM_SOURCE_FAIL_FIT_GAL: 308 308 default: 309 309 model = NULL; … … 445 445 446 446 // valid source types for this function 447 if (source->type == P S_SOURCE_SATSTAR) goto valid;448 if (source->type == P S_SOURCE_PSFSTAR) goto valid;449 if (source->type == P S_SOURCE_GOODSTAR) goto valid;447 if (source->type == PM_SOURCE_SATSTAR) goto valid; 448 if (source->type == PM_SOURCE_PSFSTAR) goto valid; 449 if (source->type == PM_SOURCE_GOODSTAR) goto valid; 450 450 continue; 451 451 … … 509 509 model = (pmModel *) source->modelFLT; 510 510 if (model == NULL) continue; 511 if (source->type == P S_SOURCE_GALAXY) goto valid;511 if (source->type == PM_SOURCE_GALAXY) goto valid; 512 512 continue; 513 513 … … 570 570 571 571 // skip these sources (in PSF or FLT) 572 if (source->type == P S_SOURCE_GALAXY) continue;573 if (source->type == P S_SOURCE_PSFSTAR) continue;574 if (source->type == P S_SOURCE_SATSTAR) continue;575 if (source->type == P S_SOURCE_GOODSTAR) continue;572 if (source->type == PM_SOURCE_GALAXY) continue; 573 if (source->type == PM_SOURCE_PSFSTAR) continue; 574 if (source->type == PM_SOURCE_SATSTAR) continue; 575 if (source->type == PM_SOURCE_GOODSTAR) continue; 576 576 577 577 if (source->moments == NULL) { … … 602 602 switch (source->type) { 603 603 604 case P S_SOURCE_DEFECT:605 case P S_SOURCE_SATURATED:604 case PM_SOURCE_DEFECT: 605 case PM_SOURCE_SATURATED: 606 606 return (8); 607 607 608 case P S_SOURCE_SATSTAR:608 case PM_SOURCE_SATSTAR: 609 609 return (10); 610 610 611 case P S_SOURCE_PSFSTAR:612 case P S_SOURCE_GOODSTAR:611 case PM_SOURCE_PSFSTAR: 612 case PM_SOURCE_GOODSTAR: 613 613 return (1); 614 614 615 case P S_SOURCE_POOR_FIT_PSF:615 case PM_SOURCE_POOR_FIT_PSF: 616 616 return (7); 617 617 618 case P S_SOURCE_FAIL_FIT_PSF:619 case P S_SOURCE_FAINTSTAR:618 case PM_SOURCE_FAIL_FIT_PSF: 619 case PM_SOURCE_FAINTSTAR: 620 620 return (4); 621 621 622 case P S_SOURCE_GALAXY:623 case P S_SOURCE_FAINT_GALAXY:624 case P S_SOURCE_DROP_GALAXY:625 case P S_SOURCE_FAIL_FIT_GAL:626 case P S_SOURCE_POOR_FIT_GAL:622 case PM_SOURCE_GALAXY: 623 case PM_SOURCE_FAINT_GALAXY: 624 case PM_SOURCE_DROP_GALAXY: 625 case PM_SOURCE_FAIL_FIT_GAL: 626 case PM_SOURCE_POOR_FIT_GAL: 627 627 return (2); 628 628 629 case P S_SOURCE_OTHER:629 case PM_SOURCE_OTHER: 630 630 default: 631 631 return (0); -
trunk/psphot/src/psphotSourceStats.c
r4977 r5048 28 28 // measure a local sky value 29 29 // XXX EAM : this should use ROBUST not SAMPLE median, but it is broken 30 status = pmSourceLocalSky _EAM(source, PS_STAT_SAMPLE_MEDIAN, INNER);30 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER); 31 31 if (!status) { 32 32 psFree (source); … … 36 36 // measure basic source moments 37 37 // XXX EAM : choose between these two versions 38 status = pmSourceMoments _EAM(source, RADIUS);38 status = pmSourceMoments (source, RADIUS); 39 39 if (!status) { 40 40 psFree (source); -
trunk/psphot/src/psphotSubtractPSF.c
r4949 r5048 11 11 12 12 // only subtract successful fits 13 if (source->type == P S_SOURCE_SATSTAR) goto valid;14 if (source->type == P S_SOURCE_PSFSTAR) goto valid;15 if (source->type == P S_SOURCE_GOODSTAR) goto valid;13 if (source->type == PM_SOURCE_SATSTAR) goto valid; 14 if (source->type == PM_SOURCE_PSFSTAR) goto valid; 15 if (source->type == PM_SOURCE_GOODSTAR) goto valid; 16 16 return (false); 17 17
Note:
See TracChangeset
for help on using the changeset viewer.
