Changeset 5727
- Timestamp:
- Dec 7, 2005, 10:01:05 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_rel9_b0/psModules/src/objects/pmObjects.c
r5435 r5727 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $9 * @date $Date: 2005-1 0-20 23:06:24$8 * @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-12-07 20:01:05 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 81 81 tmp->chisq = 0.0; 82 82 tmp->nIter = 0; 83 tmp->radius = 0; 84 tmp->status = PM_MODEL_UNTRIED; 85 83 86 psS32 Nparams = pmModelParameterCount(type); 84 87 if (Nparams == 0) { … … 769 772 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 770 773 for (psS32 col = 0; col < source->pixels->numCols ; col++) { 771 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) 774 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) { 772 775 continue; 776 } 773 777 774 778 psF32 xDiff = col + source->pixels->col0 - xPeak; … … 777 781 // XXX EAM : calculate xDiff, yDiff up front; 778 782 // radius is just a function of (xDiff, yDiff) 779 if (!VALID_RADIUS(xDiff, yDiff, R2)) 783 if (!VALID_RADIUS(xDiff, yDiff, R2)) { 780 784 continue; 785 } 781 786 782 787 psF32 pDiff = source->pixels->data.F32[row][col] - sky; … … 784 789 // XXX EAM : check for valid S/N in pixel 785 790 // XXX EAM : should this limit be user-defined? 786 if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) 791 if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) { 787 792 continue; 793 } 788 794 789 795 Sum += pDiff; … … 913 919 psImage *splane = NULL; 914 920 int binX, binY; 921 bool status; 922 923 psF32 SX_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SX_MAX"); 924 if (!status) 925 SX_MAX = 10.0; 926 psF32 SY_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SY_MAX"); 927 if (!status) 928 SY_MAX = 10.0; 915 929 916 930 // construct a sigma-plane image 917 931 // psImageAlloc does zero the data 918 splane = psImageAlloc ( NPIX/SCALE, NPIX/SCALE, PS_TYPE_F32);932 splane = psImageAlloc (SX_MAX/SCALE, SY_MAX/SCALE, PS_TYPE_F32); 919 933 for (int i = 0; i < splane->numRows; i++) 920 934 { … … 1065 1079 int Ncr = 0; 1066 1080 int Nsatstar = 0; 1081 psRegion allArray = psRegionSet (0, 0, 0, 0); 1067 1082 1068 1083 psVector *starsn = psVectorAlloc (sources->n, PS_TYPE_F32); … … 1096 1111 1097 1112 // XXX EAM : can we use the value of SATURATE if mask is NULL? 1098 // 1099 // XXX: Must verify this region (the region argument was added to psImageCountPixelMask() 1100 // after EAM wrote this code. 1101 // 1102 psRegion tmpRegion = psRegionSet(0, tmpSrc->mask->numCols, 0, tmpSrc->mask->numRows); 1103 int Nsatpix = psImageCountPixelMask(tmpSrc->mask, tmpRegion, PSPHOT_MASK_SATURATED); 1113 int Nsatpix = psImageCountPixelMask (tmpSrc->mask, allArray, PSPHOT_MASK_SATURATED); 1104 1114 1105 1115 // saturated star (size consistent with PSF or larger) … … 1107 1117 bool big = (sigX > (clump.X - clump.dX)) && (sigY > (clump.Y - clump.dY)); 1108 1118 if ((Nsatpix > 1) && big) { 1109 tmpSrc->type |= PM_SOURCE_SATSTAR;1119 tmpSrc->type = PM_SOURCE_SATSTAR; 1110 1120 Nsatstar ++; 1111 1121 continue; … … 1114 1124 // saturated object (not a star, eg bleed trails, hot pixels) 1115 1125 if (Nsatpix > 1) { 1116 tmpSrc->type |= PM_SOURCE_SATURATED;1126 tmpSrc->type = PM_SOURCE_SATURATED; 1117 1127 Nsat ++; 1118 1128 continue; … … 1123 1133 // only set candidate defects if 1124 1134 if ((sigX < 0.05) || (sigY < 0.05)) { 1125 tmpSrc->type |= PM_SOURCE_DEFECT;1135 tmpSrc->type = PM_SOURCE_DEFECT; 1126 1136 Ncr ++; 1127 1137 continue; … … 1130 1140 // likely unsaturated galaxy (too large to be stellar) 1131 1141 if ((sigX > (clump.X + 3*clump.dX)) || (sigY > (clump.Y + 3*clump.dY))) { 1132 tmpSrc->type |= PM_SOURCE_GALAXY;1142 tmpSrc->type = PM_SOURCE_GALAXY; 1133 1143 Ngal ++; 1134 1144 continue; … … 1143 1153 psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY); 1144 1154 if ((SN > PSF_SN_LIM) && (radius < 1.5)) { 1145 tmpSrc->type |= PM_SOURCE_PSFSTAR;1155 tmpSrc->type = PM_SOURCE_PSFSTAR; 1146 1156 Npsf ++; 1147 1157 continue; … … 1149 1159 1150 1160 // random type of star 1151 tmpSrc->type |= PM_SOURCE_OTHER;1161 tmpSrc->type = PM_SOURCE_OTHER; 1152 1162 } 1153 1163 … … 1603 1613 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1604 1614 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 1615 model->status = PM_MODEL_BADARGS; 1605 1616 return(false); 1606 1617 } … … 1654 1665 } 1655 1666 1656 // XXX EAM: we need to do something (give an error?) if rc is false 1657 // XXX EAM: psMinimizeLMChi2 does not check convergence 1658 1659 // XXX models can go insane: reject these 1660 onPic &= (params->data.F32[2] >= source->pixels->col0); 1661 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1662 onPic &= (params->data.F32[3] >= source->pixels->row0); 1663 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1664 1665 // XXX EAM: save the resulting chisq, nDOF, nIter 1667 // save the resulting chisq, nDOF, nIter 1666 1668 model->chisq = myMin->value; 1667 1669 model->nIter = myMin->iter; 1668 1670 model->nDOF = y->n - nParams; 1669 1671 1670 // XXX EAMget the Gauss-Newton distance for fixed model parameters1672 // get the Gauss-Newton distance for fixed model parameters 1671 1673 if (paramMask != NULL) { 1672 1674 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64); … … 1678 1680 } 1679 1681 psFree (delta); 1682 } 1683 1684 // set the model success or failure status 1685 if (!fitStatus) { 1686 model->status = PM_MODEL_NONCONVERGE; 1687 } else { 1688 model->status = PM_MODEL_SUCCESS; 1689 } 1690 1691 // models can go insane: reject these 1692 onPic &= (params->data.F32[2] >= source->pixels->col0); 1693 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1694 onPic &= (params->data.F32[3] >= source->pixels->row0); 1695 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1696 if (!onPic) { 1697 model->status = PM_MODEL_OFFIMAGE; 1680 1698 } 1681 1699 … … 1737 1755 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1738 1756 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 1757 model->status = PM_MODEL_BADARGS; 1739 1758 return(false); 1740 1759 } … … 1815 1834 // XXX EAM: psMinimizeLMChi2 does not check convergence 1816 1835 1817 // XXX models can go insane: reject these1818 onPic &= (params->data.F32[2] >= source->pixels->col0);1819 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols);1820 onPic &= (params->data.F32[3] >= source->pixels->row0);1821 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows);1822 1823 1836 // XXX EAM: save the resulting chisq, nDOF, nIter 1824 1837 model->chisq = myMin->value; … … 1837 1850 } 1838 1851 1839 psFree(paramMask); 1852 // set the model success or failure status 1853 if (!fitStatus) { 1854 model->status = PM_MODEL_NONCONVERGE; 1855 } else { 1856 model->status = PM_MODEL_SUCCESS; 1857 } 1858 1859 // XXX models can go insane: reject these 1860 onPic &= (params->data.F32[2] >= source->pixels->col0); 1861 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1862 onPic &= (params->data.F32[3] >= source->pixels->row0); 1863 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1864 if (!onPic) { 1865 model->status = PM_MODEL_OFFIMAGE; 1866 } 1867 1840 1868 psFree(x); 1841 1869 psFree(y); 1870 psFree(yErr); 1842 1871 psFree(myMin); 1872 psFree(covar); 1873 psFree(paramMask); 1843 1874 1844 1875 rc = (onPic && fitStatus); … … 1851 1882 pmModel *model, 1852 1883 bool center, 1853 psS32 flag) 1884 bool sky, 1885 bool add 1886 ) 1854 1887 { 1855 1888 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); … … 1864 1897 psS32 imageCol; 1865 1898 psS32 imageRow; 1899 psF32 skyValue = params->data.F32[0]; 1900 psF32 pixelValue; 1866 1901 1867 1902 for (psS32 i = 0; i < image->numRows; i++) { … … 1869 1904 if ((mask != NULL) && mask->data.U8[i][j]) 1870 1905 continue; 1871 psF32 pixelValue; 1906 1872 1907 // XXX: Should you be adding the pixels for the entire subImage, 1873 1908 // or a radius of pixels around it? … … 1887 1922 x->data.F32[0] = (float) imageCol; 1888 1923 x->data.F32[1] = (float) imageRow; 1889 pixelValue = modelFunc (NULL, params, x); 1890 // fprintf (stderr, "%f %f %d %d %f\n", x->data.F32[0], x->data.F32[1], i, j, pixelValue); 1891 1892 if (flag == 1) { 1893 pixelValue = -pixelValue; 1894 } 1895 1896 // XXX: Must figure out how to calculate the image coordinates and 1897 // how to use the boolean "center" flag. 1898 1899 image->data.F32[i][j]+= pixelValue; 1924 1925 // set the appropriate pixel value for this coordinate 1926 if (sky) { 1927 pixelValue = modelFunc (NULL, params, x); 1928 } else { 1929 pixelValue = modelFunc (NULL, params, x) - skyValue; 1930 } 1931 1932 1933 // add or subtract the value 1934 if (add 1935 ) { 1936 image->data.F32[i][j] += pixelValue; 1937 } 1938 else { 1939 image->data.F32[i][j] -= pixelValue; 1940 } 1900 1941 } 1901 1942 } … … 1912 1953 psImage *mask, 1913 1954 pmModel *model, 1914 bool center) 1915 { 1916 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1917 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 0); 1955 bool center, 1956 bool sky) 1957 { 1958 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1959 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, true); 1918 1960 psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc); 1919 1961 return(rc); … … 1925 1967 psImage *mask, 1926 1968 pmModel *model, 1927 bool center) 1928 { 1929 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1930 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 1); 1969 bool center, 1970 bool sky) 1971 { 1972 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1973 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, false); 1931 1974 psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc); 1932 1975 return(rc);
Note:
See TracChangeset
for help on using the changeset viewer.
