Changeset 5765
- Timestamp:
- Dec 12, 2005, 11:14:38 AM (20 years ago)
- Location:
- trunk/psModules/src/objects
- Files:
-
- 4 deleted
- 5 edited
-
Makefile.am (modified) (2 diffs)
-
pmObjects.c (modified) (9 diffs)
-
pmObjects.h (modified) (2 diffs)
-
pmPSF.c (modified) (2 diffs)
-
pmPSFtry.c (modified) (2 diffs)
-
psLibUtils.c (deleted)
-
psLibUtils.h (deleted)
-
psModulesUtils.c (deleted)
-
psModulesUtils.h (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/Makefile.am
r5307 r5765 8 8 pmPSFtry.c \ 9 9 pmModelGroup.c \ 10 psModulesUtils.c \11 psLibUtils.c \12 10 psEllipse.c 13 11 … … 24 22 pmPSFtry.h \ 25 23 pmModelGroup.h \ 26 psModulesUtils.h \27 psLibUtils.h \28 24 psEllipse.h -
trunk/psModules/src/objects/pmObjects.c
r5735 r5765 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-12- 07 21:35:35$8 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-12-12 21:14:38 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 68 68 } 69 69 70 /******************************************************************************71 pmModelAlloc(): Allocate the pmModel structure, along with its parameters,72 and initialize the type member. Initialize the params to 0.0.73 XXX EAM: simplifying code with pmModelParameterCount74 *****************************************************************************/75 pmModel *pmModelAlloc(pmModelType type)76 {77 psTrace(__func__, 3, "---- %s() begin ----\n", __func__);78 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));79 80 tmp->type = type;81 tmp->chisq = 0.0;82 tmp->nIter = 0;83 psS32 Nparams = pmModelParameterCount(type);84 if (Nparams == 0) {85 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");86 return(NULL);87 }88 89 tmp->params = psVectorAlloc(Nparams, PS_TYPE_F32);90 tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);91 92 for (psS32 i = 0; i < tmp->params->n; i++) {93 tmp->params->data.F32[i] = 0.0;94 tmp->dparams->data.F32[i] = 0.0;95 }96 97 psMemSetDeallocator(tmp, (psFreeFunc) modelFree);98 psTrace(__func__, 3, "---- %s() end ----\n", __func__);99 return(tmp);100 }101 102 /******************************************************************************103 XXX EAM : we can now free these pixels - memory ref is incremented now104 *****************************************************************************/105 70 static void sourceFree(pmSource *tmp) 106 71 { … … 115 80 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 116 81 } 82 83 /****************************************************************************** 84 getRowVectorFromImage(): a private function which simply returns a 85 psVector containing the specified row of data from the psImage. 86 87 XXX: Is there a better way to do this? 88 XXX EAM: does this really need to alloc a new vector??? 89 *****************************************************************************/ 90 static psVector *getRowVectorFromImage(psImage *image, 91 psU32 row) 92 { 93 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 94 PS_ASSERT_IMAGE_NON_NULL(image, NULL); 95 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL); 96 97 psVector *tmpVector = psVectorAlloc(image->numCols, PS_TYPE_F32); 98 for (psU32 col = 0; col < image->numCols ; col++) { 99 tmpVector->data.F32[col] = image->data.F32[row][col]; 100 } 101 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 102 return(tmpVector); 103 } 104 105 /****************************************************************************** 106 myListAddPeak(): A private function which allocates a psArray, if the list 107 argument is NULL, otherwise it adds the peak to that list. 108 XXX EAM : changed the output to psArray 109 XXX EAM : Switched row, col args 110 XXX EAM : NOTE: this was changed in the call, so the new code is consistent 111 *****************************************************************************/ 112 static psArray *myListAddPeak(psArray *list, 113 psS32 row, 114 psS32 col, 115 psF32 counts, 116 pmPeakType type) 117 { 118 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 119 pmPeak *tmpPeak = pmPeakAlloc(col, row, counts, type); 120 121 if (list == NULL) { 122 list = psArrayAlloc(100); 123 list->n = 0; 124 } 125 psArrayAdd(list, 100, tmpPeak); 126 psFree (tmpPeak); 127 // XXX EAM : is this free appropriate? (does psArrayAdd increment memory counter?) 128 129 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 130 return(list); 131 } 132 133 134 /****************************************************************************** 135 bool checkRadius2(): private function which simply determines if the (x, y) 136 point is within the radius of the specified peak. 137 138 XXX: macro this for performance. 139 XXX: this is rather inefficient - at least compute and compare against radius^2 140 *****************************************************************************/ 141 static bool checkRadius2(psF32 xCenter, 142 psF32 yCenter, 143 psF32 radius, 144 psF32 x, 145 psF32 y) 146 { 147 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 148 /// XXX EAM should compare with hypot (x,y) for speed 149 if ((PS_SQR(x - xCenter) + PS_SQR(y - yCenter)) < PS_SQR(radius)) { 150 return(true); 151 } 152 153 psTrace(__func__, 4, "---- %s(false) end ----\n", __func__); 154 return(false); 155 } 156 157 // XXX: Macro this. 158 static bool isItInThisRegion(const psRegion valid, 159 psS32 x, 160 psS32 y) 161 { 162 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 163 if ((x >= valid.x0) && 164 (x <= valid.x1) && 165 (y >= valid.y0) && 166 (y <= valid.y1)) { 167 psTrace(__func__, 4, "---- %s(true) end ----\n", __func__); 168 return(true); 169 } 170 psTrace(__func__, 4, "---- %s(false) end ----\n", __func__); 171 return(false); 172 } 173 174 /****************************************************************************** 175 findValue(source, level, row, col, dir): a private function which determines 176 the column coordinate of the model function which has the value "level". If 177 dir equals 0, then you loop leftwards from the peak pixel, otherwise, 178 rightwards. 179 180 XXX: reverse order of row,col args? 181 182 XXX: Input row/col are in image coords. 183 184 XXX: The result is returned in image coords. 185 *****************************************************************************/ 186 static psF32 findValue(pmSource *source, 187 psF32 level, 188 psU32 row, 189 psU32 col, 190 psU32 dir) 191 { 192 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 193 // 194 // Convert coords to subImage space. 195 // 196 psU32 subRow = row - source->pixels->row0; 197 psU32 subCol = col - source->pixels->col0; 198 199 // Ensure that the starting column is allowable. 200 if (!((0 <= subCol) && (subCol < source->pixels->numCols))) { 201 psError(PS_ERR_UNKNOWN, true, "Starting column outside subImage range"); 202 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__); 203 return(NAN); 204 } 205 if (!((0 <= subRow) && (subRow < source->pixels->numRows))) { 206 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__); 207 psError(PS_ERR_UNKNOWN, true, "Starting row outside subImage range"); 208 return(NAN); 209 } 210 211 // XXX EAM : i changed this to match pmModelEval above, but see 212 // XXX EAM the note below in pmSourceContour 213 psF32 oldValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow); 214 if (oldValue == level) { 215 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 216 return(((psF32) (subCol + source->pixels->col0))); 217 } 218 219 // 220 // We define variables incr and lastColumn so that we can use the same loop 221 // whether we are stepping leftwards, or rightwards. 222 // 223 psS32 incr; 224 psS32 lastColumn; 225 if (dir == 0) { 226 incr = -1; 227 lastColumn = -1; 228 } else { 229 incr = 1; 230 lastColumn = source->pixels->numCols; 231 } 232 subCol+=incr; 233 234 while (subCol != lastColumn) { 235 psF32 newValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow); 236 if (oldValue == level) { 237 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 238 return((psF32) (subCol + source->pixels->col0)); 239 } 240 241 if ((newValue <= level) && (level <= oldValue)) { 242 // This is simple linear interpolation. 243 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 244 return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - newValue) / (oldValue - newValue)) ); 245 } 246 247 if ((oldValue <= level) && (level <= newValue)) { 248 // This is simple linear interpolation. 249 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 250 return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - oldValue) / (newValue - oldValue)) ); 251 } 252 253 subCol+=incr; 254 } 255 256 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__); 257 return(NAN); 258 } 259 260 /****************************************************************************** 261 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 262 and initialize the type member. Initialize the params to 0.0. 263 XXX EAM: simplifying code with pmModelParameterCount 264 *****************************************************************************/ 265 pmModel *pmModelAlloc(pmModelType type) 266 { 267 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 268 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 269 270 tmp->type = type; 271 tmp->chisq = 0.0; 272 tmp->nIter = 0; 273 psS32 Nparams = pmModelParameterCount(type); 274 if (Nparams == 0) { 275 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 276 return(NULL); 277 } 278 279 tmp->params = psVectorAlloc(Nparams, PS_TYPE_F32); 280 tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32); 281 282 for (psS32 i = 0; i < tmp->params->n; i++) { 283 tmp->params->data.F32[i] = 0.0; 284 tmp->dparams->data.F32[i] = 0.0; 285 } 286 287 psMemSetDeallocator(tmp, (psFreeFunc) modelFree); 288 psTrace(__func__, 3, "---- %s() end ----\n", __func__); 289 return(tmp); 290 } 291 292 /****************************************************************************** 293 XXX EAM : we can now free these pixels - memory ref is incremented now 294 *****************************************************************************/ 117 295 118 296 /****************************************************************************** … … 240 418 } 241 419 242 /******************************************************************************243 getRowVectorFromImage(): a private function which simply returns a244 psVector containing the specified row of data from the psImage.245 246 XXX: Is there a better way to do this?247 XXX EAM: does this really need to alloc a new vector???248 *****************************************************************************/249 static psVector *getRowVectorFromImage(psImage *image,250 psU32 row)251 {252 psTrace(__func__, 4, "---- %s() begin ----\n", __func__);253 PS_ASSERT_IMAGE_NON_NULL(image, NULL);254 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);255 256 psVector *tmpVector = psVectorAlloc(image->numCols, PS_TYPE_F32);257 for (psU32 col = 0; col < image->numCols ; col++) {258 tmpVector->data.F32[col] = image->data.F32[row][col];259 }260 psTrace(__func__, 4, "---- %s() end ----\n", __func__);261 return(tmpVector);262 }263 264 /******************************************************************************265 myListAddPeak(): A private function which allocates a psArray, if the list266 argument is NULL, otherwise it adds the peak to that list.267 XXX EAM : changed the output to psArray268 XXX EAM : Switched row, col args269 XXX EAM : NOTE: this was changed in the call, so the new code is consistent270 *****************************************************************************/271 static psArray *myListAddPeak(psArray *list,272 psS32 row,273 psS32 col,274 psF32 counts,275 pmPeakType type)276 {277 psTrace(__func__, 4, "---- %s() begin ----\n", __func__);278 pmPeak *tmpPeak = pmPeakAlloc(col, row, counts, type);279 280 if (list == NULL) {281 list = psArrayAlloc(100);282 list->n = 0;283 }284 psArrayAdd(list, 100, tmpPeak);285 psFree (tmpPeak);286 // XXX EAM : is this free appropriate? (does psArrayAdd increment memory counter?)287 288 psTrace(__func__, 4, "---- %s() end ----\n", __func__);289 return(list);290 }291 420 292 421 /****************************************************************************** … … 503 632 } 504 633 505 // XXX: Macro this.506 static bool isItInThisRegion(const psRegion valid,507 psS32 x,508 psS32 y)509 {510 psTrace(__func__, 4, "---- %s() begin ----\n", __func__);511 if ((x >= valid.x0) &&512 (x <= valid.x1) &&513 (y >= valid.y0) &&514 (y <= valid.y1)) {515 psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);516 return(true);517 }518 psTrace(__func__, 4, "---- %s(false) end ----\n", __func__);519 return(false);520 }521 522 634 523 635 /****************************************************************************** … … 627 739 *****************************************************************************/ 628 740 629 630 631 632 633 634 635 636 637 741 bool pmSourceLocalSky( 638 742 pmSource *source, … … 673 777 psTrace(__func__, 3, "---- %s(true) end ----\n", __func__); 674 778 return (true); 675 }676 677 /******************************************************************************678 bool checkRadius2(): private function which simply determines if the (x, y)679 point is within the radius of the specified peak.680 681 XXX: macro this for performance.682 XXX: this is rather inefficient - at least compute and compare against radius^2683 *****************************************************************************/684 static bool checkRadius2(psF32 xCenter,685 psF32 yCenter,686 psF32 radius,687 psF32 x,688 psF32 y)689 {690 psTrace(__func__, 4, "---- %s() begin ----\n", __func__);691 /// XXX EAM should compare with hypot (x,y) for speed692 if ((PS_SQR(x - xCenter) + PS_SQR(y - yCenter)) < PS_SQR(radius)) {693 return(true);694 }695 696 psTrace(__func__, 4, "---- %s(false) end ----\n", __func__);697 return(false);698 779 } 699 780 … … 1350 1431 1351 1432 /****************************************************************************** 1352 findValue(source, level, row, col, dir): a private function which determines1353 the column coordinate of the model function which has the value "level". If1354 dir equals 0, then you loop leftwards from the peak pixel, otherwise,1355 rightwards.1356 1357 XXX: reverse order of row,col args?1358 1359 XXX: Input row/col are in image coords.1360 1361 XXX: The result is returned in image coords.1362 *****************************************************************************/1363 static psF32 findValue(pmSource *source,1364 psF32 level,1365 psU32 row,1366 psU32 col,1367 psU32 dir)1368 {1369 psTrace(__func__, 4, "---- %s() begin ----\n", __func__);1370 //1371 // Convert coords to subImage space.1372 //1373 psU32 subRow = row - source->pixels->row0;1374 psU32 subCol = col - source->pixels->col0;1375 1376 // Ensure that the starting column is allowable.1377 if (!((0 <= subCol) && (subCol < source->pixels->numCols))) {1378 psError(PS_ERR_UNKNOWN, true, "Starting column outside subImage range");1379 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__);1380 return(NAN);1381 }1382 if (!((0 <= subRow) && (subRow < source->pixels->numRows))) {1383 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__);1384 psError(PS_ERR_UNKNOWN, true, "Starting row outside subImage range");1385 return(NAN);1386 }1387 1388 // XXX EAM : i changed this to match pmModelEval above, but see1389 // XXX EAM the note below in pmSourceContour1390 psF32 oldValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow);1391 if (oldValue == level) {1392 psTrace(__func__, 4, "---- %s() end ----\n", __func__);1393 return(((psF32) (subCol + source->pixels->col0)));1394 }1395 1396 //1397 // We define variables incr and lastColumn so that we can use the same loop1398 // whether we are stepping leftwards, or rightwards.1399 //1400 psS32 incr;1401 psS32 lastColumn;1402 if (dir == 0) {1403 incr = -1;1404 lastColumn = -1;1405 } else {1406 incr = 1;1407 lastColumn = source->pixels->numCols;1408 }1409 subCol+=incr;1410 1411 while (subCol != lastColumn) {1412 psF32 newValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow);1413 if (oldValue == level) {1414 psTrace(__func__, 4, "---- %s() end ----\n", __func__);1415 return((psF32) (subCol + source->pixels->col0));1416 }1417 1418 if ((newValue <= level) && (level <= oldValue)) {1419 // This is simple linear interpolation.1420 psTrace(__func__, 4, "---- %s() end ----\n", __func__);1421 return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - newValue) / (oldValue - newValue)) );1422 }1423 1424 if ((oldValue <= level) && (level <= newValue)) {1425 // This is simple linear interpolation.1426 psTrace(__func__, 4, "---- %s() end ----\n", __func__);1427 return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - oldValue) / (newValue - oldValue)) );1428 }1429 1430 subCol+=incr;1431 }1432 1433 psTrace(__func__, 4, "---- %s(NAN) end ----\n", __func__);1434 return(NAN);1435 }1436 1437 /******************************************************************************1438 1433 pmSourceContour(src, img, level, mode): For an input subImage, and model, this 1439 1434 routine returns a psArray of coordinates that evaluate to the specified level. … … 1933 1928 } 1934 1929 1935 1930 bool pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask) 1931 { 1932 1933 float obsSum = 0; 1934 float fitSum = 0; 1935 float sky = model->params->data.F32[0]; 1936 1937 pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type); 1938 fitSum = modelFluxFunc (model->params); 1939 1940 for (int ix = 0; ix < image->numCols; ix++) { 1941 for (int iy = 0; iy < image->numRows; iy++) { 1942 if (mask->data.U8[iy][ix]) 1943 continue; 1944 obsSum += image->data.F32[iy][ix] - sky; 1945 } 1946 } 1947 if (obsSum <= 0) 1948 return false; 1949 if (fitSum <= 0) 1950 return false; 1951 1952 *fitMag = -2.5*log10(fitSum); 1953 *obsMag = -2.5*log10(obsSum); 1954 return (true); 1955 } 1956 -
trunk/psModules/src/objects/pmObjects.h
r5760 r5765 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-12-12 2 0:11:07$12 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-12-12 21:14:38 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 620 620 ); 621 621 622 623 /** pmSourcePhotometry() 624 * 625 * XXX: Need descriptions 626 * 627 */ 628 bool pmSourcePhotometry( 629 float *fitMag, 630 float *obsMag, 631 pmModel *model, 632 psImage *image, 633 psImage *mask 634 ); 635 636 /** pmModelEval() 637 * 638 * XXX: Need descriptions 639 * 640 */ 641 psF32 pmModelEval( 642 pmModel *model, 643 psImage *image, 644 psS32 col, 645 psS32 row 646 ); 647 622 648 #endif -
trunk/psModules/src/objects/pmPSF.c
r5735 r5765 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-12- 07 21:35:35$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-12-12 21:14:38 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 19 19 #include <pslib.h> 20 #include "psLibUtils.h"21 20 #include "pmObjects.h" 22 21 #include "pmPSF.h" -
trunk/psModules/src/objects/pmPSFtry.c
r5762 r5765 1 /** @file pmPSFtry.c 2 * 3 * XXX: need description of file purpose 4 * 5 * @author EAM, IfA 6 * 7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-12-12 21:14:38 $ 9 * 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 11 * 12 */ 13 1 14 # include <pslib.h> 2 # include "psLibUtils.h"3 15 # include "pmObjects.h" 4 # include "psModulesUtils.h"5 16 # include "pmPSF.h" 6 17 # include "pmPSFtry.h" … … 41 52 type = pmModelSetType (modelName); 42 53 test->psf = pmPSFAlloc (type); 43 test->sources = psMem Copy(sources);54 test->sources = psMemIncrRefCounter(sources); 44 55 test->modelFLT = psArrayAlloc (sources->n); 45 56 test->modelPSF = psArrayAlloc (sources->n);
Note:
See TracChangeset
for help on using the changeset viewer.
