IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5765


Ignore:
Timestamp:
Dec 12, 2005, 11:14:38 AM (20 years ago)
Author:
desonia
Message:

removed dependencies on psLibUtils.[ch] and psModuleUtils.[ch].

Location:
trunk/psModules/src/objects
Files:
4 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/Makefile.am

    r5307 r5765  
    88    pmPSFtry.c \
    99    pmModelGroup.c \
    10     psModulesUtils.c \
    11     psLibUtils.c \
    1210    psEllipse.c
    1311
     
    2422    pmPSFtry.h \
    2523    pmModelGroup.h \
    26     psModulesUtils.h \
    27     psLibUtils.h \
    2824    psEllipse.h
  • trunk/psModules/src/objects/pmObjects.c

    r5735 r5765  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6868}
    6969
    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 pmModelParameterCount
    74 *****************************************************************************/
    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 now
    104 *****************************************************************************/
    10570static void sourceFree(pmSource *tmp)
    10671{
     
    11580    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
    11681}
     82
     83/******************************************************************************
     84getRowVectorFromImage(): a private function which simply returns a
     85psVector containing the specified row of data from the psImage.
     86 
     87XXX: Is there a better way to do this? 
     88XXX EAM: does this really need to alloc a new vector???
     89*****************************************************************************/
     90static 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/******************************************************************************
     106myListAddPeak(): A private function which allocates a psArray, if the list
     107argument is NULL, otherwise it adds the peak to that list.
     108XXX EAM : changed the output to psArray
     109XXX EAM : Switched row, col args
     110XXX EAM : NOTE: this was changed in the call, so the new code is consistent
     111*****************************************************************************/
     112static 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/******************************************************************************
     135bool checkRadius2(): private function which simply determines if the (x, y)
     136point is within the radius of the specified peak.
     137 
     138XXX: macro this for performance.
     139XXX: this is rather inefficient - at least compute and compare against radius^2
     140*****************************************************************************/
     141static 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.
     158static 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/******************************************************************************
     175findValue(source, level, row, col, dir): a private function which determines
     176the column coordinate of the model function which has the value "level".  If
     177dir equals 0, then you loop leftwards from the peak pixel, otherwise,
     178rightwards.
     179 
     180XXX: reverse order of row,col args?
     181 
     182XXX: Input row/col are in image coords.
     183 
     184XXX: The result is returned in image coords.
     185*****************************************************************************/
     186static 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/******************************************************************************
     261pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
     262and initialize the type member.  Initialize the params to 0.0.
     263XXX EAM: simplifying code with pmModelParameterCount
     264*****************************************************************************/
     265pmModel *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/******************************************************************************
     293XXX EAM : we can now free these pixels - memory ref is incremented now
     294*****************************************************************************/
    117295
    118296/******************************************************************************
     
    240418}
    241419
    242 /******************************************************************************
    243 getRowVectorFromImage(): a private function which simply returns a
    244 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 list
    266 argument is NULL, otherwise it adds the peak to that list.
    267 XXX EAM : changed the output to psArray
    268 XXX EAM : Switched row, col args
    269 XXX EAM : NOTE: this was changed in the call, so the new code is consistent
    270 *****************************************************************************/
    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 }
    291420
    292421/******************************************************************************
     
    503632}
    504633
    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 
    522634
    523635/******************************************************************************
     
    627739*****************************************************************************/
    628740
    629 
    630 
    631 
    632 
    633 
    634 
    635 
    636 
    637741bool pmSourceLocalSky(
    638742    pmSource *source,
     
    673777    psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
    674778    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^2
    683 *****************************************************************************/
    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 speed
    692     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);
    698779}
    699780
     
    13501431
    13511432/******************************************************************************
    1352 findValue(source, level, row, col, dir): a private function which determines
    1353 the column coordinate of the model function which has the value "level".  If
    1354 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 see
    1389     // XXX EAM   the note below in pmSourceContour
    1390     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 loop
    1398     // 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 /******************************************************************************
    14381433pmSourceContour(src, img, level, mode): For an input subImage, and model, this
    14391434routine returns a psArray of coordinates that evaluate to the specified level.
     
    19331928}
    19341929
    1935 
     1930bool 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  
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-12-12 20:11:07 $
     12 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-12-12 21:14:38 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    620620);
    621621
     622
     623/** pmSourcePhotometry()
     624 *
     625 * XXX: Need descriptions
     626 *
     627 */
     628bool 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 */
     641psF32 pmModelEval(
     642    pmModel *model,
     643    psImage *image,
     644    psS32 col,
     645    psS32 row
     646);
     647
    622648#endif
  • trunk/psModules/src/objects/pmPSF.c

    r5735 r5765  
    66 *  @author EAM, IfA
    77 *
    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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919#include <pslib.h>
    20 #include "psLibUtils.h"
    2120#include "pmObjects.h"
    2221#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
    114# include <pslib.h>
    2 # include "psLibUtils.h"
    315# include "pmObjects.h"
    4 # include "psModulesUtils.h"
    516# include "pmPSF.h"
    617# include "pmPSFtry.h"
     
    4152    type           = pmModelSetType (modelName);
    4253    test->psf      = pmPSFAlloc (type);
    43     test->sources  = psMemCopy(sources);
     54    test->sources  = psMemIncrRefCounter(sources);
    4455    test->modelFLT = psArrayAlloc (sources->n);
    4556    test->modelPSF = psArrayAlloc (sources->n);
Note: See TracChangeset for help on using the changeset viewer.