Changeset 5844
- Timestamp:
- Dec 23, 2005, 3:24:38 PM (20 years ago)
- Location:
- trunk/psModules
- Files:
-
- 10 edited
-
src/objects/Makefile.am (modified) (1 diff)
-
src/objects/pmModelGroup.c (modified) (10 diffs)
-
src/objects/pmModelGroup.h (modified) (2 diffs)
-
src/objects/pmObjects.c (modified) (26 diffs)
-
src/objects/pmObjects.h (modified) (56 diffs)
-
src/objects/pmPSF.c (modified) (1 diff)
-
src/objects/pmPSFtry.c (modified) (4 diffs)
-
src/objects/pmPSFtry.h (modified) (8 diffs)
-
test/imsubtract/tst_pmSubtractBias.c (modified) (5 diffs)
-
test/objects/verified/tst_pmObjects01.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/Makefile.am
r5765 r5844 15 15 models/pmModel_QGAUSS.c \ 16 16 models/pmModel_SGAUSS.c 17 17 18 18 psmoduleincludedir = $(includedir) 19 19 psmoduleinclude_HEADERS = \ -
trunk/psModules/src/objects/pmModelGroup.c
r5255 r5844 10 10 #include "models/pmModel_SGAUSS.c" 11 11 12 static pmModelGroup models[] = { 13 {"PS_MODEL_GAUSS", 7, pmModelFunc_GAUSS, pmModelFlux_GAUSS, pmModelRadius_GAUSS, pmModelLimits_GAUSS, pmModelGuess_GAUSS, pmModelFromPSF_GAUSS, pmModelFitStatus_GAUSS}, 14 {"PS_MODEL_PGAUSS", 7, pmModelFunc_PGAUSS, pmModelFlux_PGAUSS, pmModelRadius_PGAUSS, pmModelLimits_PGAUSS, pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelFitStatus_PGAUSS}, 15 {"PS_MODEL_QGAUSS", 8, pmModelFunc_QGAUSS, pmModelFlux_QGAUSS, pmModelRadius_QGAUSS, pmModelLimits_QGAUSS, pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelFitStatus_QGAUSS}, 16 {"PS_MODEL_SGAUSS", 9, pmModelFunc_SGAUSS, pmModelFlux_SGAUSS, pmModelRadius_SGAUSS, pmModelLimits_SGAUSS, pmModelGuess_SGAUSS, pmModelFromPSF_SGAUSS, pmModelFitStatus_SGAUSS}, 17 }; 12 static pmModelGroup defaultModels[] = { 13 {"PS_MODEL_GAUSS", 7, pmModelFunc_GAUSS, pmModelFlux_GAUSS, pmModelRadius_GAUSS, pmModelLimits_GAUSS, pmModelGuess_GAUSS, pmModelFromPSF_GAUSS, pmModelFitStatus_GAUSS}, 14 {"PS_MODEL_PGAUSS", 7, pmModelFunc_PGAUSS, pmModelFlux_PGAUSS, pmModelRadius_PGAUSS, pmModelLimits_PGAUSS, pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelFitStatus_PGAUSS}, 15 {"PS_MODEL_QGAUSS", 8, pmModelFunc_QGAUSS, pmModelFlux_QGAUSS, pmModelRadius_QGAUSS, pmModelLimits_QGAUSS, pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelFitStatus_QGAUSS}, 16 {"PS_MODEL_SGAUSS", 9, pmModelFunc_SGAUSS, pmModelFlux_SGAUSS, pmModelRadius_SGAUSS, pmModelLimits_SGAUSS, pmModelGuess_SGAUSS, pmModelFromPSF_SGAUSS, pmModelFitStatus_SGAUSS}, 17 }; 18 19 static pmModelGroup *models = NULL; 20 static int Nmodels = 0; 21 22 static void ModelGroupFree (pmModelGroup *modelGroup) 23 { 24 25 if (modelGroup == NULL) 26 return; 27 psFree (modelGroup); 28 return; 29 } 30 31 pmModelGroup *pmModelGroupAlloc (int nModels) 32 { 33 34 pmModelGroup *modelGroup = (pmModelGroup *) psAlloc (nModels * sizeof(pmModelGroup)); 35 psMemSetDeallocator(modelGroup, (psFreeFunc) ModelGroupFree); 36 return (modelGroup); 37 } 38 39 void pmModelGroupAdd (pmModelGroup *model) 40 { 41 42 if (models == NULL) { 43 pmModelGroupInit (); 44 } 45 46 Nmodels ++; 47 models = (pmModelGroup *) psRealloc (models, Nmodels*sizeof(pmModelGroup)); 48 models[Nmodels-1] = model[0]; 49 return; 50 } 51 52 void pmModelGroupInit (void) 53 { 54 55 int Nnew = sizeof (defaultModels) / sizeof (pmModelGroup); 56 57 models = pmModelGroupAlloc (Nnew); 58 for (int i = 0; i < Nnew; i++) { 59 models[i] = defaultModels[i]; 60 } 61 Nmodels = Nnew; 62 return; 63 } 18 64 19 65 pmModelFunc pmModelFunc_GetFunction (pmModelType type) 20 66 { 21 int Nmodels = sizeof (models) / sizeof (pmModelGroup);22 67 if ((type < 0) || (type >= Nmodels)) { 23 68 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 29 74 pmModelFlux pmModelFlux_GetFunction (pmModelType type) 30 75 { 31 int Nmodels = sizeof (models) / sizeof (pmModelGroup);32 76 if ((type < 0) || (type >= Nmodels)) { 33 77 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 39 83 pmModelRadius pmModelRadius_GetFunction (pmModelType type) 40 84 { 41 int Nmodels = sizeof (models) / sizeof (pmModelGroup);42 85 if ((type < 0) || (type >= Nmodels)) { 43 86 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 49 92 pmModelLimits pmModelLimits_GetFunction (pmModelType type) 50 93 { 51 int Nmodels = sizeof (models) / sizeof (pmModelGroup);52 94 if ((type < 0) || (type >= Nmodels)) { 53 95 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 59 101 pmModelGuessFunc pmModelGuessFunc_GetFunction (pmModelType type) 60 102 { 61 int Nmodels = sizeof (models) / sizeof (pmModelGroup);62 103 if ((type < 0) || (type >= Nmodels)) { 63 104 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 69 110 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type) 70 111 { 71 int Nmodels = sizeof (models) / sizeof (pmModelGroup);72 112 if ((type < 0) || (type >= Nmodels)) { 73 113 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 79 119 pmModelFromPSFFunc pmModelFromPSFFunc_GetFunction (pmModelType type) 80 120 { 81 int Nmodels = sizeof (models) / sizeof (pmModelGroup);82 121 if ((type < 0) || (type >= Nmodels)) { 83 122 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 89 128 psS32 pmModelParameterCount (pmModelType type) 90 129 { 91 int Nmodels = sizeof (models) / sizeof (pmModelGroup);92 130 if ((type < 0) || (type >= Nmodels)) { 93 131 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 99 137 psS32 pmModelSetType (char *name) 100 138 { 101 102 int Nmodels = sizeof (models) / sizeof (pmModelGroup);103 139 for (int i = 0; i < Nmodels; i++) { 104 140 if (!strcmp(models[i].name, name)) { … … 111 147 char *pmModelGetType (pmModelType type) 112 148 { 113 114 int Nmodels = sizeof (models) / sizeof (pmModelGroup);115 149 if ((type < 0) || (type >= Nmodels)) { 116 150 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); -
trunk/psModules/src/objects/pmModelGroup.h
r5255 r5844 9 9 * @author EAM, IfA 10 10 * 11 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-1 0-10 19:53:40$11 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-12-24 01:24:32 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 209 209 pmModelGroup; 210 210 211 // allocate a pmModelGroup to hold nModels entries 212 pmModelGroup *pmModelGroupAlloc (int nModels); 213 214 // initialize the internal (static) model group with the default models 215 void pmModelGroupInit (void); 216 217 // add a new model to the internal (static) model group 218 void pmModelGroupAdd (pmModelGroup *model); 219 211 220 # endif -
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); -
trunk/psModules/src/objects/pmObjects.h
r5765 r5844 4 4 * images is one of the critical tasks of the IPP or any astronomical software 5 5 * system. This file will define structures and functions related to the task 6 * of source detection and measurement. The elements defined in this section 6 * of source detection and measurement. The elements defined in this section 7 7 * are generally low-level components which can be connected together to 8 8 * construct a complete object measurement suite. … … 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-12- 12 21:14:38$12 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-12-24 01:24:32 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 45 45 46 46 /** pmPeakType 47 * 47 * 48 48 * A peak pixel may have several features which may be determined when the 49 49 * peak is found or measured. These are specified by the pmPeakType enum. … … 52 52 * edge. The PM_PEAK_FLAT represents a peak pixel which has more than a specific 53 53 * number of neighbors at the same value, within some tolarence: 54 * 54 * 55 55 */ 56 56 typedef enum { … … 63 63 64 64 /** pmPeak data structure 65 * 65 * 66 66 * A source has the capacity for several types of measurements. The 67 67 * simplest measurement of a source is the location and flux of the peak pixel 68 68 * associated with the source: 69 * 69 * 70 70 */ 71 71 typedef struct … … 80 80 81 81 /** pmMoments data structure 82 * 82 * 83 83 * One of the simplest measurements which can be made quickly for an object 84 84 * are the object moments. We specify a structure to carry the moment information 85 85 * for a specific source: 86 * 86 * 87 87 */ 88 88 typedef struct … … 103 103 104 104 /** pmPSFClump data structure 105 * 105 * 106 106 * A collection of object moment measurements can be used to determine 107 107 * approximate object classes. The key to this analysis is the location and 108 108 * statistics (in the second-moment plane, 109 * 109 * 110 110 */ 111 111 typedef struct … … 118 118 pmPSFClump; 119 119 120 // type of model carried by the pmModel structure 120 121 typedef int pmModelType; 121 #define PS_MODEL_GAUSS 0 122 #define PS_MODEL_PGAUSS 1 123 #define PS_MODEL_QGAUSS 2 124 #define PS_MODEL_SGAUSS 3 125 122 123 typedef enum { 124 PM_MODEL_UNTRIED, ///< model fit not yet attempted 125 PM_MODEL_SUCCESS, ///< model fit succeeded 126 PM_MODEL_NONCONVERGE, ///< model fit did not converge 127 PM_MODEL_OFFIMAGE, ///< model fit drove out of range 128 PM_MODEL_BADARGS ///< model fit called with invalid args 129 } pmModelStatus; 126 130 127 131 /** pmModel data structure 128 * 132 * 129 133 * Every source may have two types of models: a PSF model and a FLT (floating) 130 134 * model. The PSF model represents the best fit of the image PSF to the specific … … 132 136 * object by the PSF, not by the fit. The FLT model represents the best fit of 133 137 * the given model to the object, with all parameters floating in the fit. 134 * 138 * 135 139 */ 136 140 typedef struct … … 142 146 int nDOF; ///< number of degrees of freedom 143 147 int nIter; ///< number of iterations to reach min 148 int status; ///< fit status 144 149 float radius; ///< fit radius actually used 145 150 } … … 147 152 148 153 /** pmSourceType enumeration 149 * 154 * 150 155 * A given source may be identified as most-likely to be one of several source 151 156 * types. The pmSource entry pmSourceType defines the current best-guess for this 152 157 * source. 153 * 158 * 154 159 * XXX: The values given below are currently illustrative and will require 155 160 * some modification as the source classification code is developed. (TBD) 156 * 161 * 157 162 */ 158 163 typedef enum { … … 178 183 179 184 /** pmSource data structure 180 * 185 * 181 186 * This source has the capacity for several types of measurements. The 182 187 * simplest measurement of a source is the location and flux of the peak pixel 183 188 * associated with the source: 184 * 189 * 185 190 */ 186 191 typedef struct … … 194 199 pmModel *modelFLT; ///< FLT (floating) Model fit (parameters and type). 195 200 pmSourceType type; ///< Best identification of object. 201 float apMag; 202 float fitMag; 196 203 } 197 204 pmSource; … … 211 218 212 219 /** pmMomentsAlloc() 213 * 220 * 214 221 */ 215 222 pmMoments *pmMomentsAlloc(); … … 217 224 218 225 /** pmModelAlloc() 219 * 226 * 220 227 */ 221 228 pmModel *pmModelAlloc(pmModelType type); … … 223 230 224 231 /** pmSourceAlloc() 225 * 232 * 226 233 */ 227 234 pmSource *pmSourceAlloc(); … … 229 236 230 237 /** pmFindVectorPeaks() 231 * 238 * 232 239 * Find all local peaks in the given vector above the given threshold. A peak 233 240 * is defined as any element with a value greater than its two neighbors and with … … 243 250 * a vector containing the coordinates (element number) of the detected peaks 244 251 * (type psU32). 245 * 252 * 246 253 */ 247 254 psVector *pmFindVectorPeaks( … … 252 259 253 260 /** pmFindImagePeaks() 254 * 261 * 255 262 * Find all local peaks in the given image above the given threshold. This 256 263 * function should find all row peaks using pmFindVectorPeaks, then test each row … … 263 270 * peaks at the (+x,+y) corner. When selecting the peaks, their type must also be 264 271 * set. The result of this function is an array of pmPeak entries. 265 * 272 * 266 273 */ 267 274 psArray *pmFindImagePeaks( … … 272 279 273 280 /** pmCullPeaks() 274 * 281 * 275 282 * Eliminate peaks from the psList that have a peak value above the given 276 283 * maximum, or fall outside the valid region. 277 * 284 * 278 285 */ 279 286 psList *pmCullPeaks( … … 285 292 286 293 /** pmPeaksSubset() 287 * 294 * 288 295 * Create a new peaks array, removing certain types of peaks from the input 289 296 * array of peaks based on the given criteria. Peaks should be eliminated if they … … 291 298 * the valid region. The result of the function is a new array with a reduced 292 299 * number of peaks. 293 * 300 * 294 301 */ 295 302 psArray *pmPeaksSubset( … … 301 308 302 309 /** pmSourceDefinePixels() 303 * 310 * 304 311 * Define psImage subarrays for the source located at coordinates x,y on the 305 312 * image set defined by readout. The pixels defined by this operation consist of … … 313 320 * example). This function should be used to define a region of interest around a 314 321 * source, including both source and sky pixels. 315 * 322 * 316 323 * XXX: must code this. 317 * 324 * 318 325 */ 319 326 // XXX: Uncommenting the pmReadout causes compile errors. … … 328 335 329 336 /** pmSourceLocalSky() 330 * 337 * 331 338 * Measure the local sky in the vicinity of the given source. The Radius 332 339 * defines the square aperture in which the moments will be measured. This … … 338 345 * This function allocates the pmMoments structure. The resulting sky is used to 339 346 * set the value of the pmMoments.sky element of the provided pmSource structure. 340 * 347 * 341 348 */ 342 349 bool pmSourceLocalSky( … … 348 355 349 356 /** pmSourceMoments() 350 * 357 * 351 358 * Measure source moments for the given source, using the value of 352 359 * source.moments.sky provided as the local background value and the peak … … 355 362 * are measured within the given circular radius of the source.peak coordinates. 356 363 * The return value indicates the success (TRUE) of the operation. 357 * 364 * 358 365 */ 359 366 bool pmSourceMoments( … … 364 371 365 372 /** pmSourcePSFClump() 366 * 373 * 367 374 * We use the source moments to make an initial, approximate source 368 375 * classification, and as part of the information needed to build a PSF model for … … 373 380 * similar. The function returns a pmPSFClump structure, representing the 374 381 * centroid and size of the clump in the sigma_x, sigma_y second-moment plane. 375 * 382 * 376 383 * The goal is to identify and characterize the stellar clump within the 377 384 * sigma_x, sigma_y second-moment plane. To do this, an image is constructed to … … 384 391 * * used to calculate the median and standard deviation of the sigma_x, sigma_y 385 392 * values. These resulting values are returned via the pmPSFClump structure. 386 * 393 * 387 394 * The return value indicates the success (TRUE) of the operation. 388 * 395 * 389 396 * XXX: Limit the S/N of the candidate sources (part of Metadata)? (TBD). 390 397 * XXX: Save the clump parameters on the Metadata (TBD) 391 * 398 * 392 399 */ 393 400 pmPSFClump pmSourcePSFClump( … … 398 405 399 406 /** pmSourceRoughClass() 400 * 407 * 401 408 * Based on the specified data values, make a guess at the source 402 409 * classification. The sources are provides as a psArray of pmSource entries. … … 405 412 * can be extracted from the metadata using the given keywords. Except as noted, 406 413 * the data type for these parameters are psF32. 407 * 414 * 408 415 */ 409 416 bool pmSourceRoughClass( … … 415 422 416 423 /** pmSourceModelGuess() 417 * 424 * 418 425 * Convert available data to an initial guess for the given model. This 419 426 * function allocates a pmModel entry for the pmSource structure based on the … … 421 428 * are specified for each model below. The guess values are placed in the model 422 429 * parameters. The function returns TRUE on success or FALSE on failure. 423 * 430 * 424 431 */ 425 432 pmModel *pmSourceModelGuess( … … 430 437 431 438 /** pmContourType 432 * 439 * 433 440 * Only one type is defined at present. 434 * 441 * 435 442 */ 436 443 typedef enum { … … 442 449 443 450 /** pmSourceContour() 444 * 451 * 445 452 * Find points in a contour for the given source at the given level. If type 446 453 * is PM_CONTOUR_CRUDE, the contour is found by starting at the source peak, … … 452 459 * This function may be used as part of the model guess inputs. Other contour 453 460 * types may be specified in the future for more refined contours (TBD) 454 * 461 * 455 462 */ 456 463 psArray *pmSourceContour( … … 463 470 464 471 /** pmSourceFitModel() 465 * 472 * 466 473 * Fit the requested model to the specified source. The starting guess for the 467 474 * model is given by the input source.model parameter values. The pixels of … … 469 476 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE 470 477 * on success or FALSE on failure. 471 * 478 * 472 479 */ 473 480 bool pmSourceFitModel( … … 479 486 480 487 /** pmModelFitStatus() 481 * 488 * 482 489 * This function wraps the call to the model-specific function returned by 483 490 * pmModelFitStatusFunc_GetFunction. The model-specific function examines the 484 491 * model parameters, parameter errors, Chisq, S/N, and other parameters available 485 492 * from model to decide if the particular fit was successful or not. 486 * 493 * 487 494 * XXX: Must code this. 488 * 495 * 489 496 */ 490 497 bool pmModelFitStatus( … … 494 501 495 502 /** pmSourceAddModel() 496 * 503 * 497 504 * Add the given source model flux to/from the provided image. The boolean 498 505 * option center selects if the source is re-centered to the image center or if … … 501 508 * is at most the pixel range specified by the source.pixels image. The success 502 509 * status is returned. 503 * 510 * 504 511 */ 505 512 bool pmSourceAddModel( … … 507 514 psImage *mask, ///< The image pixel mask (valid == 0) 508 515 pmModel *model, ///< The input pmModel 509 bool center ///< A boolean flag that determines whether pixels are centered 516 bool center, ///< A boolean flag that determines whether pixels are centered 517 bool sky ///< A boolean flag that determines if the sky is subtracted 510 518 ); 511 519 512 520 513 521 /** pmSourceSubModel() 514 * 522 * 515 523 * Subtract the given source model flux to/from the provided image. The 516 524 * boolean option center selects if the source is re-centered to the image center … … 519 527 * image is at most the pixel range specified by the source.pixels image. The 520 528 * success status is returned. 521 * 529 * 522 530 */ 523 531 bool pmSourceSubModel( … … 525 533 psImage *mask, ///< The image pixel mask (valid == 0) 526 534 pmModel *model, ///< The input pmModel 527 bool center ///< A boolean flag that determines whether pixels are centered 535 bool center, ///< A boolean flag that determines whether pixels are centered 536 bool sky ///< A boolean flag that determines if the sky is subtracted 528 537 ); 529 538 530 539 531 540 /** 532 * 541 * 533 542 * The function returns both the magnitude of the fit, defined as -2.5log(flux), 534 543 * where the flux is integrated under the model, theoretically from a radius of 0 … … 537 546 * not excluded by the aperture mask. The model flux is calculated by calling the 538 547 * model-specific function provided by pmModelFlux_GetFunction. 539 * 548 * 540 549 * XXX: must code this. 541 * 550 * 542 551 */ 543 552 bool pmSourcePhotometry( … … 551 560 552 561 /** 553 * 562 * 554 563 * This function converts the source classification into the closest available 555 564 * approximation to the Dophot classification scheme: 556 * 565 * 557 566 * PM_SOURCE_DEFECT: 8 558 567 * PM_SOURCE_SATURATED: 8 … … 569 578 * PM_SOURCE_POOR_FIT_GAL: 2 570 579 * PM_SOURCE_OTHER: ? 571 * 580 * 572 581 */ 573 582 int pmSourceDophotType( … … 577 586 578 587 /** pmSourceSextractType() 579 * 588 * 580 589 * This function converts the source classification into the closest available 581 590 * approximation to the Sextractor classification scheme. the correspondence is 582 591 * not yet defined (TBD) . 583 * 592 * 584 593 * XXX: Must code this. 585 * 594 * 586 595 */ 587 596 int pmSourceSextractType( … … 590 599 591 600 /** pmSourceFitModel_v5() 592 * 601 * 593 602 * Fit the requested model to the specified source. The starting guess for the 594 603 * model is given by the input source.model parameter values. The pixels of … … 596 605 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE 597 606 * on success or FALSE on failure. 598 * 607 * 599 608 */ 600 609 bool pmSourceFitModel_v5( … … 606 615 607 616 /** pmSourceFitModel_v7() 608 * 617 * 609 618 * Fit the requested model to the specified source. The starting guess for the 610 619 * model is given by the input source.model parameter values. The pixels of … … 612 621 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE 613 622 * on success or FALSE on failure. 614 * 623 * 615 624 */ 616 625 bool pmSourceFitModel_v7( … … 622 631 623 632 /** pmSourcePhotometry() 624 * 633 * 625 634 * XXX: Need descriptions 626 * 635 * 627 636 */ 628 637 bool pmSourcePhotometry( -
trunk/psModules/src/objects/pmPSF.c
r5765 r5844 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-12- 12 21:14:38$8 * @version $Revision: 1.4 $ $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 -
trunk/psModules/src/objects/pmPSFtry.c
r5765 r5844 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-12- 12 21:14:38$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-12-24 01:24:32 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 176 176 177 177 // XXX this function wants aperture radius for pmSourcePhotometry 178 pmPSFtryMetric (psfTry, RADIUS);178 pmPSFtryMetric_Alt (psfTry, RADIUS); 179 179 psLogMsg ("psphot.pspsf", 3, "try model %s, ap-fit: %f +/- %f, sky bias: %f\n", 180 180 modelName, … … 288 288 289 289 // linear fit to rfBin, daBin 290 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1); 290 psPolynomial1D *poly = psPolynomial1DAlloc(1, PS_POLYNOMIAL_ORD); 291 psStats *fitstat = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 292 poly = psVectorClipFitPolynomial1D (poly, fitstat, maskB, 1, daBin, NULL, rfBin); 291 293 292 294 // XXX EAM : this is the intended API (cycle 7? cycle 8?) 293 poly = psVectorFitPolynomial1D(poly, maskB, 1, daBin, NULL, rfBin);295 // poly = psVectorFitPolynomial1D(poly, maskB, 1, daBin, NULL, rfBin); 294 296 295 297 // XXX EAM : replace this when the above version is implemented … … 314 316 psFree (poly); 315 317 psFree (stats); 318 psFree (fitstat); 316 319 317 320 return true; 318 321 } 322 323 bool pmPSFtryMetric_Alt (pmPSFtry *try 324 , float RADIUS) 325 { 326 327 // the measured (aperture - fit) magnitudes (dA == try->metric) 328 // depend on both the true ap-fit (dAo) and the bias in the sky measurement: 329 // dA = dAo + dsky/flux 330 // where flux is the flux of the star 331 // we fit this trend to find the infinite flux aperture correction (dAo), 332 // the nominal sky bias (dsky), and the error on dAo 333 // the values of dA are contaminated by stars with close neighbors in the aperture 334 // we use an outlier rejection to avoid this bias 335 336 // rflux = ten(0.4*fitMag); 337 psVector *rflux = psVectorAlloc (try 338 ->sources->n, PS_TYPE_F64); 339 for (int i = 0; i < try 340 ->sources->n; i++) { 341 if (try 342 ->mask->data.U8[i] & PSFTRY_MASK_ALL) continue; 343 rflux->data.F64[i] = pow(10.0, 0.4*try 344 ->fitMag->data.F64[i]); 345 } 346 347 // XXX EAM : try 3hi/1lo sigma clipping on the rflux vs metric fit 348 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 349 350 // XXX EAM 351 stats->min = 1.0; 352 stats->max = 3.0; 353 stats->clipIter = 3; 354 355 // linear clipped fit to rfBin, daBin 356 psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD); 357 poly = psVectorClipFitPolynomial1D (poly, stats, try 358 ->mask, PSFTRY_MASK_ALL, try 359 ->metric, NULL, rflux); 360 fprintf (stderr, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); 361 362 try 363 ->psf->ApResid = poly->coeff[0]; 364 try 365 ->psf->dApResid = stats->sampleStdev; 366 try 367 ->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS)); 368 369 fprintf (stderr, "*******************************************************************************\n"); 370 371 FILE *f; 372 f = fopen ("apresid.dat", "w"); 373 if (f == NULL) 374 psAbort ("pmPSFtry", "can't open output file"); 375 376 for (int i = 0; i < try 377 ->sources->n; i++) { 378 fprintf (f, "%3d %8.4f %12.5e %8.4f %3d\n", i, try 379 ->fitMag->data.F64[i], rflux->data.F64[i], try 380 ->metric->data.F64[i], try 381 ->mask->data.U8[i]); 382 } 383 fclose (f); 384 385 psFree (rflux); 386 psFree (poly); 387 psFree (stats); 388 389 // psFree (daFit); 390 // psFree (daResid); 391 392 return true; 393 } -
trunk/psModules/src/objects/pmPSFtry.h
r5762 r5844 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-12- 12 20:32:44$8 * @version $Revision: 1.3 $ $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 … … 18 18 19 19 /** 20 * 20 * 21 21 * This structure contains a pointer to the collection of sources which will 22 22 * be used to test the PSF model form. It lists the pmModelType type of model … … 38 38 * ultimate metric to intercompare multiple types of PSF models is the value of 39 39 * the aperture correction scatter. 40 * 40 * 41 41 * XXX: There are many more members in the SDRS then in the prototype code. 42 42 * I stuck with the prototype code. 43 * 44 * 43 * 44 * 45 45 */ 46 46 typedef struct … … 58 58 59 59 /** pmPSFtryMaskValues 60 * 60 * 61 61 * The following datatype defines the masks used by the pmPSFtry analysis to 62 62 * identify sources which should or should not be included in the analysis. 63 * 63 * 64 64 */ 65 65 enum { … … 74 74 75 75 /** pmPSFtryAlloc() 76 * 76 * 77 77 * Allocate a pmPSFtry data structure. 78 * 78 * 79 79 */ 80 80 pmPSFtry *pmPSFtryAlloc( … … 85 85 86 86 /** pmPSFtryModel() 87 * 87 * 88 88 * This function takes the input collection of sources and performs a complete 89 89 * analysis to determine a PSF model of the given type (specified by model name). 90 90 * The result is a pmPSFtry with the results of the analysis. 91 * 91 * 92 92 */ 93 93 pmPSFtry *pmPSFtryModel( … … 99 99 100 100 /** pmPSFtryMetric() 101 * 101 * 102 102 * This function is used to measure the PSF model metric for the set of 103 103 * results contained in the pmPSFtry structure. 104 * 104 * 105 105 */ 106 106 bool pmPSFtryMetric( … … 109 109 ); 110 110 111 /** pmPSFtryMetric_Alt() 112 * 113 * This function is used to measure the PSF model metric for the set of 114 * results contained in the pmPSFtry structure (alternative implementation). 115 * 116 */ 117 bool pmPSFtryMetric_Alt( 118 pmPSFtry *try 119 , ///< Add comment. 120 float RADIUS ///< Add comment. 121 ); 122 111 123 # endif -
trunk/psModules/test/imsubtract/tst_pmSubtractBias.c
r5587 r5844 19 19 * test03: Calculate a row overscan vector and subtract it from each 20 20 * row in the input image. 21 * test05: 21 * test05: 22 22 * 23 23 * @author GLG, MHPCC … … 25 25 * XXX: Memory leaks are not being detected. 26 26 * 27 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $28 * @date $Date: 2005-1 1-23 23:54:30$27 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 28 * @date $Date: 2005-12-24 01:24:36 $ 29 29 * 30 30 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 326 326 rc = pmSubtractBias(myReadout, NULL, NULL, PM_OVERSCAN_NONE, stat, 327 327 0, PM_FIT_NONE, myBias); 328 328 329 329 for (i=0;i<numRows;i++) { 330 330 for (j=0;j<numCols;j++) { … … 335 335 testStatus = 1; 336 336 } 337 337 338 338 // Restore myReadout for next test. 339 339 myReadout->image->data.F32[i][j] = (float) (i + j); … … 627 627 // Set overscan axis in the metadata. 628 628 // 629 psBool rc ;629 psBool rc = false; 630 630 if (overscanaxis == PM_OVERSCAN_ROWS) { 631 631 rc = psMetadataAddS32(myReadout->parent->concepts, PS_LIST_HEAD, "CELL.READDIR", 0, NULL, 1); -
trunk/psModules/test/objects/verified/tst_pmObjects01.stdout
r5258 r5844 1 1 Testing pmPeakAlloc()... 2 2 Testing pmMomentsAlloc()... 3 Testing pmModelAlloc(PS_MODEL_GAUSS)...4 Testing pmModelAlloc(PS_MODEL_GAUSS)...5 Testing pmModelAlloc(PS_MODEL_GAUSS)...6 Testing pmModelAlloc(PS_MODEL_GAUSS)...7 3 ---------------------------------------------------------------------------------- 8 4 Calling pmFindVectorPeaks with NULL psVector. Should generate error and return NULL.
Note:
See TracChangeset
for help on using the changeset viewer.
