IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 15, 2005, 3:10:36 PM (21 years ago)
Author:
gusciora
Message:

There are a lot of changes here required by the new SDRS. Most changes
involve the new definitions of the psAstrometry types. Not all tests work
correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmObjects.c

    r4579 r4770  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-07-19 01:44:48 $
     8 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-08-16 01:10:34 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121/******************************************************************************
    22 pmPeakAlloc(): Allocate the psPeak data structure and set appropriate members.
    23 *****************************************************************************/
    24 psPeak *pmPeakAlloc(psS32 x,
     22pmPeakAlloc(): Allocate the pmPeak data structure and set appropriate members.
     23*****************************************************************************/
     24pmPeak *pmPeakAlloc(psS32 x,
    2525                    psS32 y,
    2626                    psF32 counts,
    27                     psPeakType class)
    28 {
    29     psPeak *tmp = (psPeak *) psAlloc(sizeof(psPeak));
     27                    pmPeakType class)
     28{
     29    pmPeak *tmp = (pmPeak *) psAlloc(sizeof(pmPeak));
    3030    tmp->x = x;
    3131    tmp->y = y;
     
    3737
    3838/******************************************************************************
    39 pmMomentsAlloc(): Allocate the psMoments structure and initialize the members
     39pmMomentsAlloc(): Allocate the pmMoments structure and initialize the members
    4040to zero.
    4141*****************************************************************************/
    42 psMoments *pmMomentsAlloc()
    43 {
    44     psMoments *tmp = (psMoments *) psAlloc(sizeof(psMoments));
     42pmMoments *pmMomentsAlloc()
     43{
     44    pmMoments *tmp = (pmMoments *) psAlloc(sizeof(pmMoments));
    4545    tmp->x = 0.0;
    4646    tmp->y = 0.0;
     
    5656}
    5757
    58 static void modelFree(psModel *tmp)
     58static void modelFree(pmModel *tmp)
    5959{
    6060    psFree(tmp->params);
     
    6363
    6464/******************************************************************************
    65 pmModelAlloc(): Allocate the psModel structure, along with its parameters,
     65pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
    6666and initialize the type member.  Initialize the params to 0.0.
    6767XXX EAM: changing params and dparams to psVector
    6868*****************************************************************************/
    69 psModel *pmModelAlloc(psModelType type)
    70 {
    71     psModel *tmp = (psModel *) psAlloc(sizeof(psModel));
     69pmModel *pmModelAlloc(pmModelType type)
     70{
     71    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
    7272
    7373    tmp->type = type;
     
    9999        break;
    100100    default:
    101         psError(PS_ERR_UNKNOWN, true, "Undefined psModelType");
     101        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    102102        return(NULL);
    103103    }
     
    116116We might need to increase the reference counter and decrease it here.
    117117*****************************************************************************/
    118 static void sourceFree(psSource *tmp)
     118static void sourceFree(pmSource *tmp)
    119119{
    120120    psFree(tmp->peak);
     
    122122    //    psFree(tmp->mask);
    123123    psFree(tmp->moments);
    124     psFree(tmp->models);
    125 }
    126 
    127 /******************************************************************************
    128 pmSourceAlloc(): Allocate the psSource structure and initialize its members
     124    psFree(tmp->modelPSF);
     125    psFree(tmp->modelFLT);
     126}
     127
     128/******************************************************************************
     129pmSourceAlloc(): Allocate the pmSource structure and initialize its members
    129130to NULL.
    130131*****************************************************************************/
    131 psSource *pmSourceAlloc()
    132 {
    133     psSource *tmp = (psSource *) psAlloc(sizeof(psSource));
     132pmSource *pmSourceAlloc()
     133{
     134    pmSource *tmp = (pmSource *) psAlloc(sizeof(pmSource));
    134135    tmp->peak = NULL;
    135136    tmp->pixels = NULL;
    136137    tmp->mask = NULL;
    137138    tmp->moments = NULL;
    138     tmp->models = NULL;
     139    tmp->modelPSF = NULL;
     140    tmp->modelFLT = NULL;
    139141    tmp->type = 0;
    140142    psMemSetDeallocator(tmp, (psFreeFunc) sourceFree);
     
    272274                              psS32 col,
    273275                              psF32 counts,
    274                               psPeakType type)
    275 {
    276     psPeak *tmpPeak = pmPeakAlloc(col, row, counts, type);
     276                              pmPeakType type)
     277{
     278    pmPeak *tmpPeak = pmPeakAlloc(col, row, counts, type);
    277279
    278280    if (list == NULL) {
     
    379381        // Step through all local peaks in this row.
    380382        for (psU32 i = 0 ; i < row1->n ; i++ ) {
    381             psPeakType myType = PM_PEAK_UNDEF;
     383            pmPeakType myType = PM_PEAK_UNDEF;
    382384            col = row1->data.U32[i];
    383385
     
    527529    //    printf("pmCullPeaks(): list size is %d\n", peaks->size);
    528530    while (tmpListElem != NULL) {
    529         psPeak *tmpPeak = (psPeak *) tmpListElem->data;
     531        pmPeak *tmpPeak = (pmPeak *) tmpListElem->data;
    530532        if ((tmpPeak->counts > maxValue) ||
    531533                ((valid != NULL) &&
     
    553555
    554556    for (int i = 0; i < peaks->n; i++) {
    555         psPeak *tmpPeak = (psPeak *) peaks->data[i];
     557        pmPeak *tmpPeak = (pmPeak *) peaks->data[i];
    556558        if (tmpPeak->counts > maxValue)
    557559            continue;
     
    566568
    567569/******************************************************************************
    568 psSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): this
    569 routine creates a new psSource data structure and sets the following members:
    570     ->psPeak
    571     ->psMoments->sky
     570pmSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): this
     571routine creates a new pmSource data structure and sets the following members:
     572    ->pmPeak
     573    ->pmMoments->sky
    572574 
    573575The sky value is set from the pixels in the square annulus surrounding the
     
    590592     or they use the image row/column offsets.
    591593 
    592 XXX: Should we simply set psSource->peak = peak?  If so, should we increase
     594XXX: Should we simply set pmSource->peak = peak?  If so, should we increase
    593595the reference counter?  Or, should we copy the data structure?
    594596 
     
    602604     members.
    603605*****************************************************************************/
    604 psSource *pmSourceLocalSky(const psImage *image,
    605                            const psPeak *peak,
     606pmSource *pmSourceLocalSky(const psImage *image,
     607                           const pmPeak *peak,
    606608                           psStatsOptions statsOptions,
    607609                           psF32 innerRadius,
     
    723725    // Create the output mySource, and set appropriate members.
    724726    //
    725     psSource *mySource = pmSourceAlloc();
    726     mySource->peak = (psPeak *) peak;
     727    pmSource *mySource = pmSourceAlloc();
     728    mySource->peak = (pmPeak *) peak;
    727729    mySource->moments = pmMomentsAlloc();
    728730    psF64 tmpF64;
     
    746748XXX: macro this for performance.
    747749*****************************************************************************/
    748 static bool checkRadius(psPeak *peak,
     750static bool checkRadius(pmPeak *peak,
    749751                        psF32 radius,
    750752                        psS32 x,
     
    781783/******************************************************************************
    782784pmSourceMoments(source, radius): this function takes a subImage defined in the
    783 psSource data structure, along with the peak location, and determines the
     785pmSource data structure, along with the peak location, and determines the
    784786various moments associated with that peak.
    785787 
    786788Requires the following to have been created:
    787     psSource
    788     psSource->peak
    789     psSource->pixels
     789    pmSource
     790    pmSource->peak
     791    pmSource->pixels
    790792 
    791793XXX: The peak calculations are done in image coords, not subImage coords.
     
    793795XXX: mask values?
    794796*****************************************************************************/
    795 psSource *pmSourceMoments(psSource *source,
     797pmSource *pmSourceMoments(pmSource *source,
    796798                          psF32 radius)
    797799{
     
    925927int pmComparePeakAscend (const void **a, const void **b)
    926928{
    927     psPeak *A = *(psPeak **)a;
    928     psPeak *B = *(psPeak **)b;
     929    pmPeak *A = *(pmPeak **)a;
     930    pmPeak *B = *(pmPeak **)b;
    929931
    930932    psF32 diff;
     
    940942int pmComparePeakDescend (const void **a, const void **b)
    941943{
    942     psPeak *A = *(psPeak **)a;
    943     psPeak *B = *(psPeak **)b;
     944    pmPeak *A = *(pmPeak **)a;
     945    pmPeak *B = *(pmPeak **)b;
    944946
    945947    psF32 diff;
     
    992994        for (psS32 i = 0 ; i < sources->n ; i++)
    993995        {
    994             psSource *tmpSrc = (psSource *) sources->data[i];
     996            pmSource *tmpSrc = (pmSource *) sources->data[i];
    995997            PS_ASSERT_PTR_NON_NULL(tmpSrc, false); // just skip this one?
    996998            PS_ASSERT_PTR_NON_NULL(tmpSrc->moments, false); // just skip this one?
     
    10271029    // measure statistics on Sx, Sy if Sx, Sy within range of clump
    10281030    {
    1029         psPeak *clump;
     1031        pmPeak *clump;
    10301032        psF32 minSx, maxSx;
    10311033        psF32 minSy, maxSy;
     
    10541056        for (psS32 i = 0 ; i < sources->n ; i++)
    10551057        {
    1056             psSource *tmpSrc = (psSource *) sources->data[i];
     1058            pmSource *tmpSrc = (pmSource *) sources->data[i];
    10571059
    10581060            if (tmpSrc->moments->Sx < minSx)
     
    11031105    for (psS32 i = 0 ; i < sources->n ; i++) {
    11041106
    1105         psSource *tmpSrc = (psSource *) sources->data[i];
     1107        pmSource *tmpSrc = (pmSource *) sources->data[i];
    11061108
    11071109        tmpSrc->peak->class = 0;
     
    11971199     the pmSourceSetLocal() function.
    11981200*****************************************************************************/
    1199 bool pmSourceSetPixelsCircle(psSource *source,
     1201bool pmSourceSetPixelsCircle(pmSource *source,
    12001202                             const psImage *image,
    12011203                             psF32 radius)
     
    12931295/******************************************************************************
    12941296pmSourceModelGuess(source, image, model): This function allocates a new
    1295 psModel structure and stores it in the psSource data structure specified in
     1297pmModel structure and stores it in the pmSource data structure specified in
    12961298the argument list.  The model type is specified in the argument list.  The
    1297 params array in that psModel structure are allocated, and then set to the
     1299params array in that pmModel structure are allocated, and then set to the
    12981300appropriate values.  This function returns true if everything was successful.
    12991301 
     
    13061308image, not subImage coords.  Therefore, the calls to the model evaluation
    13071309functions will be in image, not subImage coords.  Remember this.
    1308 *****************************************************************************/
    1309 bool pmSourceModelGuess(psSource *source,
     1310 
     1311XXX: The source->models member used to be allocated here.  Now I assume
     1312->modelPSF should be allocated
     1313*****************************************************************************/
     1314bool pmSourceModelGuess(pmSource *source,
    13101315                        const psImage *image,
    1311                         psModelType model)
     1316                        pmModelType model)
    13121317{
    13131318    PS_ASSERT_PTR_NON_NULL(source, false);
     
    13161321    PS_ASSERT_IMAGE_NON_NULL(image, false);
    13171322    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false);
    1318     if (source->models != NULL) {
    1319         psLogMsg(__func__, PS_LOG_WARN, "WARNING: source->models was non-NULL; calling psFree(source->models).\n");
    1320         psFree(source->models);
     1323    if (source->modelPSF != NULL) {
     1324        psLogMsg(__func__, PS_LOG_WARN, "WARNING: source->modelPSF was non-NULL; calling psFree(source->modelPSF).\n");
     1325        psFree(source->modelPSF);
    13211326    }
    13221327    if (!((model == PS_MODEL_GAUSS) ||
     
    13301335    }
    13311336
    1332     source->models = pmModelAlloc(model);
    1333 
    1334     psVector *params = source->models->params;
     1337    source->modelPSF = pmModelAlloc(model);
     1338
     1339    psVector *params = source->modelPSF->params;
    13351340
    13361341    switch (model) {
     
    13641369        params->data.F32[6] = source->moments->Sxy;
    13651370        // XXX: What are these?
    1366         // source->models->params[7] = B2;
    1367         // source->models->params[8] = B3;
     1371        // source->modelPSF->params[7] = B2;
     1372        // source->modelPSF->params[8] = B3;
    13681373        return(true);
    13691374
     
    14201425/******************************************************************************
    14211426evalModel(source, level, row): a private function which evaluates the
    1422 source->model function at the specified coords.  The coords are subImage, not
     1427source->modelPSF function at the specified coords.  The coords are subImage, not
    14231428image coords.
    14241429 
     
    14301435the coords is in subImage or image space.
    14311436 
    1432 XXX: This should probably be a public psModules function.
     1437XXX: This should probably be a public pmModules function.
    14331438 
    14341439XXX: Use static vectors for x.
     
    14391444testing.  Try to reproduce that and debug.
    14401445*****************************************************************************/
    1441 static psF32 evalModel(psSource *src,
     1446static psF32 evalModel(pmSource *src,
    14421447                       psU32 row,
    14431448                       psU32 col)
    14441449{
    14451450    PS_ASSERT_PTR_NON_NULL(src, false);
    1446     PS_ASSERT_PTR_NON_NULL(src->models, false);
    1447     PS_ASSERT_PTR_NON_NULL(src->models->params, false);
    1448 
    1449     // XXX: The following step will not be necessary if the models->params
     1451    PS_ASSERT_PTR_NON_NULL(src->modelPSF, false);
     1452    PS_ASSERT_PTR_NON_NULL(src->modelPSF->params, false);
     1453
     1454    // XXX: The following step will not be necessary if the modelPSF->params
    14501455    // member is a psVector.  Suggest to IfA.
    14511456
    1452     // XXX EAM: done: models->params is now a vector
    1453     psVector *params = src->models->params;
     1457    // XXX EAM: done: modelPSF->params is now a vector
     1458    psVector *params = src->modelPSF->params;
    14541459
    14551460    //
     
    14611466    psF32 tmpF;
    14621467
    1463     switch (src->models->type) {
     1468    switch (src->modelPSF->type) {
    14641469    case PS_MODEL_GAUSS:
    14651470        tmpF = pmMinLM_Gauss2D(NULL, params, x);
     
    14811486        break;
    14821487    default:
    1483         psError(PS_ERR_UNKNOWN, true, "Undefined psModelType");
     1488        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    14841489        return(NAN);
    14851490    }
     
    15001505XXX: The result is returned in image coords.
    15011506*****************************************************************************/
    1502 static psF32 findValue(psSource *source,
     1507static psF32 findValue(pmSource *source,
    15031508                       psF32 level,
    15041509                       psU32 row,
     
    15751580XXX: The top, bottom of the contour is not correctly determined.
    15761581*****************************************************************************/
    1577 psArray *pmSourceContour(psSource *source,
     1582psArray *pmSourceContour(pmSource *source,
    15781583                         const psImage *image,
    15791584                         psF32 level,
     
    15851590    PS_ASSERT_PTR_NON_NULL(source->peak, false);
    15861591    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    1587     PS_ASSERT_PTR_NON_NULL(source->models, false);
     1592    PS_ASSERT_PTR_NON_NULL(source->modelPSF, false);
    15881593
    15891594    //
     
    16921697XXX: Probably should remove the "image" argument.
    16931698*****************************************************************************/
    1694 bool pmSourceFitModel(psSource *source,
     1699bool pmSourceFitModel(pmSource *source,
    16951700                      const psImage *image)
    16961701{
     
    16991704    PS_ASSERT_PTR_NON_NULL(source->peak, false);
    17001705    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    1701     PS_ASSERT_PTR_NON_NULL(source->models, false);
     1706    PS_ASSERT_PTR_NON_NULL(source->modelPSF, false);
    17021707    PS_ASSERT_IMAGE_NON_NULL(image, false);
    17031708    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false);
     
    17421747                            PM_SOURCE_FIT_MODEL_TOLERANCE);
    17431748
    1744     psVector *params = source->models->params;
    1745 
    1746     switch (source->models->type) {
     1749    psVector *params = source->modelPSF->params;
     1750
     1751    switch (source->modelPSF->type) {
    17471752    case PS_MODEL_GAUSS:
    17481753        rc = psMinimizeLMChi2(myMin, NULL, params, NULL, x, y, yErr, pmMinLM_Gauss2D);
     
    17641769        break;
    17651770    default:
    1766         psError(PS_ERR_UNKNOWN, true, "Undefined psModelType");
     1771        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    17671772        rc = false;
    17681773    }
    17691774    // XXX EAM: we need to do something (give an error?) if rc is false
    17701775    // XXX EAM: save the resulting chisq, nDOF, nIter
    1771     source->models->chisq = myMin->value;
    1772     source->models->nDOF  = y->n - params->n;
    1773     source->models->nIter = myMin->iter;
     1776    source->modelPSF->chisq = myMin->value;
     1777    source->modelPSF->nDOF  = y->n - params->n;
     1778    source->modelPSF->nIter = myMin->iter;
    17741779
    17751780    psFree(x);
     
    17801785
    17811786static bool sourceAddOrSubModel(psImage *image,
    1782                                 psSource *src,
     1787                                pmSource *src,
    17831788                                bool center,
    17841789                                psS32 flag)
     
    17881793    PS_ASSERT_PTR_NON_NULL(src->peak, false);
    17891794    PS_ASSERT_PTR_NON_NULL(src->pixels, false);
    1790     PS_ASSERT_PTR_NON_NULL(src->models, false);
     1795    PS_ASSERT_PTR_NON_NULL(src->modelPSF, false);
    17911796    PS_ASSERT_IMAGE_NON_NULL(image, false);
    17921797    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false);
    17931798
    17941799    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    1795     psVector *params = src->models->params;
     1800    psVector *params = src->modelPSF->params;
    17961801
    17971802    for (psS32 i = 0; i < src->pixels->numRows; i++) {
     
    18081813            x->data.F32[0] = (float) imageCol;
    18091814            x->data.F32[1] = (float) imageRow;
    1810             switch (src->models->type) {
     1815            switch (src->modelPSF->type) {
    18111816            case PS_MODEL_GAUSS:
    18121817                pixelValue = pmMinLM_Gauss2D(NULL, params, x);
     
    18281833                break;
    18291834            default:
    1830                 psError(PS_ERR_UNKNOWN, true, "Undefined psModelType");
     1835                psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    18311836                psFree(x);
    18321837                return(false);
     
    18511856 *****************************************************************************/
    18521857bool pmSourceAddModel(psImage *image,
    1853                       psSource *src,
     1858                      pmSource *src,
    18541859                      bool center)
    18551860{
     
    18601865 *****************************************************************************/
    18611866bool pmSourceSubModel(psImage *image,
    1862                       psSource *src,
     1867                      pmSource *src,
    18631868                      bool center)
    18641869{
Note: See TracChangeset for help on using the changeset viewer.