Changeset 5844 for trunk/psModules/src/objects/pmObjects.c
- Timestamp:
- Dec 23, 2005, 3:24:38 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmObjects.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmObjects.c
r5765 r5844 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-12- 12 21:14:38$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-12-24 01:24:32 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 85 85 psVector containing the specified row of data from the psImage. 86 86 87 XXX: Is there a better way to do this? 87 XXX: Is there a better way to do this? 88 88 XXX EAM: does this really need to alloc a new vector??? 89 89 *****************************************************************************/ … … 271 271 tmp->chisq = 0.0; 272 272 tmp->nIter = 0; 273 tmp->radius = 0; 274 tmp->status = PM_MODEL_UNTRIED; 275 273 276 psS32 Nparams = pmModelParameterCount(type); 274 277 if (Nparams == 0) { … … 850 853 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 851 854 for (psS32 col = 0; col < source->pixels->numCols ; col++) { 852 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) 855 if ((source->mask != NULL) && (source->mask->data.U8[row][col])) { 853 856 continue; 857 } 854 858 855 859 psF32 xDiff = col + source->pixels->col0 - xPeak; … … 858 862 // XXX EAM : calculate xDiff, yDiff up front; 859 863 // radius is just a function of (xDiff, yDiff) 860 if (!VALID_RADIUS(xDiff, yDiff, R2)) 864 if (!VALID_RADIUS(xDiff, yDiff, R2)) { 861 865 continue; 866 } 862 867 863 868 psF32 pDiff = source->pixels->data.F32[row][col] - sky; … … 865 870 // XXX EAM : check for valid S/N in pixel 866 871 // XXX EAM : should this limit be user-defined? 867 if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) 872 if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) { 868 873 continue; 874 } 869 875 870 876 Sum += pDiff; … … 970 976 971 977 /****************************************************************************** 972 pmSourcePSFClump(source, metadata): Find the likely PSF clump in the 973 sigma-x, sigma-y plane. return 0,0 clump in case of error. 978 pmSourcePSFClump(source, metadata): Find the likely PSF clump in the 979 sigma-x, sigma-y plane. return 0,0 clump in case of error. 974 980 *****************************************************************************/ 975 981 … … 994 1000 psImage *splane = NULL; 995 1001 int binX, binY; 1002 bool status; 1003 1004 psF32 SX_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SX_MAX"); 1005 if (!status) 1006 SX_MAX = 10.0; 1007 psF32 SY_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SY_MAX"); 1008 if (!status) 1009 SY_MAX = 10.0; 996 1010 997 1011 // construct a sigma-plane image 998 1012 // psImageAlloc does zero the data 999 splane = psImageAlloc ( NPIX/SCALE, NPIX/SCALE, PS_TYPE_F32);1013 splane = psImageAlloc (SX_MAX/SCALE, SY_MAX/SCALE, PS_TYPE_F32); 1000 1014 for (int i = 0; i < splane->numRows; i++) 1001 1015 { … … 1131 1145 XXX: How can this function ever return FALSE? 1132 1146 1133 XXX EAM : add the saturated mask value to metadata 1147 XXX EAM : add the saturated mask value to metadata 1134 1148 *****************************************************************************/ 1135 1149 … … 1146 1160 int Ncr = 0; 1147 1161 int Nsatstar = 0; 1162 psRegion allArray = psRegionSet (0, 0, 0, 0); 1148 1163 1149 1164 psVector *starsn = psVectorAlloc (sources->n, PS_TYPE_F32); … … 1177 1192 1178 1193 // XXX EAM : can we use the value of SATURATE if mask is NULL? 1179 // 1180 // XXX: Must verify this region (the region argument was added to psImageCountPixelMask() 1181 // after EAM wrote this code. 1182 // 1183 psRegion tmpRegion = psRegionSet(0, tmpSrc->mask->numCols, 0, tmpSrc->mask->numRows); 1184 int Nsatpix = psImageCountPixelMask(tmpSrc->mask, tmpRegion, PSPHOT_MASK_SATURATED); 1194 int Nsatpix = psImageCountPixelMask (tmpSrc->mask, allArray, PSPHOT_MASK_SATURATED); 1185 1195 1186 1196 // saturated star (size consistent with PSF or larger) … … 1254 1264 1255 1265 /** pmSourceDefinePixels() 1256 * 1266 * 1257 1267 * Define psImage subarrays for the source located at coordinates x,y on the 1258 1268 * image set defined by readout. The pixels defined by this operation consist of … … 1266 1276 * example). This function should be used to define a region of interest around a 1267 1277 * source, including both source and sky pixels. 1268 * 1278 * 1269 1279 * XXX: must code this. 1270 * 1280 * 1271 1281 */ 1272 1282 bool pmSourceDefinePixels( … … 1360 1370 /****************************************************************************** 1361 1371 pmSourceModelGuess(source, model): This function allocates a new 1362 pmModel structure based on the given modelType specified in the argument list. 1363 The corresponding pmModelGuess function is returned, and used to 1364 supply the values of the params array in the pmModel structure. 1372 pmModel structure based on the given modelType specified in the argument list. 1373 The corresponding pmModelGuess function is returned, and used to 1374 supply the values of the params array in the pmModel structure. 1365 1375 1366 1376 XXX: Many parameters are based on the src->moments structure, which is in … … 1598 1608 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1599 1609 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 1610 model->status = PM_MODEL_BADARGS; 1600 1611 return(false); 1601 1612 } … … 1649 1660 } 1650 1661 1651 // XXX EAM: we need to do something (give an error?) if rc is false 1652 // XXX EAM: psMinimizeLMChi2 does not check convergence 1653 1654 // XXX models can go insane: reject these 1655 onPic &= (params->data.F32[2] >= source->pixels->col0); 1656 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1657 onPic &= (params->data.F32[3] >= source->pixels->row0); 1658 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1659 1660 // XXX EAM: save the resulting chisq, nDOF, nIter 1662 // save the resulting chisq, nDOF, nIter 1661 1663 model->chisq = myMin->value; 1662 1664 model->nIter = myMin->iter; 1663 1665 model->nDOF = y->n - nParams; 1664 1666 1665 // XXX EAMget the Gauss-Newton distance for fixed model parameters1667 // get the Gauss-Newton distance for fixed model parameters 1666 1668 if (paramMask != NULL) { 1667 1669 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64); … … 1673 1675 } 1674 1676 psFree (delta); 1677 } 1678 1679 // set the model success or failure status 1680 if (!fitStatus) { 1681 model->status = PM_MODEL_NONCONVERGE; 1682 } else { 1683 model->status = PM_MODEL_SUCCESS; 1684 } 1685 1686 // models can go insane: reject these 1687 onPic &= (params->data.F32[2] >= source->pixels->col0); 1688 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1689 onPic &= (params->data.F32[3] >= source->pixels->row0); 1690 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1691 if (!onPic) { 1692 model->status = PM_MODEL_OFFIMAGE; 1675 1693 } 1676 1694 … … 1732 1750 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1733 1751 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 1752 model->status = PM_MODEL_BADARGS; 1734 1753 return(false); 1735 1754 } … … 1810 1829 // XXX EAM: psMinimizeLMChi2 does not check convergence 1811 1830 1812 // XXX models can go insane: reject these1813 onPic &= (params->data.F32[2] >= source->pixels->col0);1814 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols);1815 onPic &= (params->data.F32[3] >= source->pixels->row0);1816 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows);1817 1818 1831 // XXX EAM: save the resulting chisq, nDOF, nIter 1819 1832 model->chisq = myMin->value; … … 1832 1845 } 1833 1846 1834 psFree(paramMask); 1847 // set the model success or failure status 1848 if (!fitStatus) { 1849 model->status = PM_MODEL_NONCONVERGE; 1850 } else { 1851 model->status = PM_MODEL_SUCCESS; 1852 } 1853 1854 // XXX models can go insane: reject these 1855 onPic &= (params->data.F32[2] >= source->pixels->col0); 1856 onPic &= (params->data.F32[2] < source->pixels->col0 + source->pixels->numCols); 1857 onPic &= (params->data.F32[3] >= source->pixels->row0); 1858 onPic &= (params->data.F32[3] < source->pixels->row0 + source->pixels->numRows); 1859 if (!onPic) { 1860 model->status = PM_MODEL_OFFIMAGE; 1861 } 1862 1835 1863 psFree(x); 1836 1864 psFree(y); 1865 psFree(yErr); 1837 1866 psFree(myMin); 1867 psFree(covar); 1868 psFree(paramMask); 1838 1869 1839 1870 rc = (onPic && fitStatus); … … 1846 1877 pmModel *model, 1847 1878 bool center, 1848 psS32 flag) 1879 bool sky, 1880 bool add 1881 ) 1849 1882 { 1850 1883 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); … … 1859 1892 psS32 imageCol; 1860 1893 psS32 imageRow; 1894 psF32 skyValue = params->data.F32[0]; 1895 psF32 pixelValue; 1861 1896 1862 1897 for (psS32 i = 0; i < image->numRows; i++) { … … 1864 1899 if ((mask != NULL) && mask->data.U8[i][j]) 1865 1900 continue; 1866 psF32 pixelValue; 1901 1867 1902 // XXX: Should you be adding the pixels for the entire subImage, 1868 1903 // or a radius of pixels around it? … … 1882 1917 x->data.F32[0] = (float) imageCol; 1883 1918 x->data.F32[1] = (float) imageRow; 1884 pixelValue = modelFunc (NULL, params, x); 1885 // fprintf (stderr, "%f %f %d %d %f\n", x->data.F32[0], x->data.F32[1], i, j, pixelValue); 1886 1887 if (flag == 1) { 1888 pixelValue = -pixelValue; 1889 } 1890 1891 // XXX: Must figure out how to calculate the image coordinates and 1892 // how to use the boolean "center" flag. 1893 1894 image->data.F32[i][j]+= pixelValue; 1919 1920 // set the appropriate pixel value for this coordinate 1921 if (sky) { 1922 pixelValue = modelFunc (NULL, params, x); 1923 } else { 1924 pixelValue = modelFunc (NULL, params, x) - skyValue; 1925 } 1926 1927 1928 // add or subtract the value 1929 if (add 1930 ) { 1931 image->data.F32[i][j] += pixelValue; 1932 } 1933 else { 1934 image->data.F32[i][j] -= pixelValue; 1935 } 1895 1936 } 1896 1937 } … … 1907 1948 psImage *mask, 1908 1949 pmModel *model, 1909 bool center) 1910 { 1911 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1912 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 0); 1950 bool center, 1951 bool sky) 1952 { 1953 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1954 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, true); 1913 1955 psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc); 1914 1956 return(rc); … … 1920 1962 psImage *mask, 1921 1963 pmModel *model, 1922 bool center) 1923 { 1924 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1925 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 1); 1964 bool center, 1965 bool sky) 1966 { 1967 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 1968 psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, false); 1926 1969 psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc); 1927 1970 return(rc);
Note:
See TracChangeset
for help on using the changeset viewer.
