IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5587


Ignore:
Timestamp:
Nov 23, 2005, 1:54:30 PM (21 years ago)
Author:
gusciora
Message:

I added tests for, and a workaround from a possible bug with the psProject()
psDeproject() code, so that the various psAstrometry transforms to and from
the sky work.

Location:
trunk/psModules
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometry.c

    r5553 r5587  
    88*  @author GLG, MHPCC
    99*
    10 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2005-11-19 01:11:03 $
     10*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2005-11-23 23:54:30 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1414*/
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
    1546
    1647/******************************************************************************/
     
    2253#include "psDB.h"
    2354#include "pmAstrometry.h"
    24 
    25 void PS_PRINT_POLY2D(psPolynomial2D *poly)
    26 {
    27     for (psS32 x = 0 ; x < poly->nX+1 ; x++) {
    28         for (psS32 y = 0 ; y < poly->nY+1 ; y++) {
    29             printf("    (%.2f x^%d y^%d)\n", poly->coeff[x][y], x, y);
    30         }
    31     }
    32 }
    33 
    34 void PS_PRINT_PLANE_TRANSFORM(psPlaneTransform *pt)
    35 {
    36     printf("---------------------- Plane Transform ----------------------\n");
    37     printf("x:\n");
    38     PS_PRINT_POLY2D(pt->x);
    39     printf("y:\n");
    40     PS_PRINT_POLY2D(pt->y);
    41 }
    4255
    4356/*****************************************************************************
     
    7083        psFree(readout->mask);
    7184        psFree(readout->weight);
     85        //
     86        // XXX: Not sure if this is the right way to do things.  Currently the psListAdd()
     87        // increase the memory reference counter to the list data.  So, we
     88        // iterate through the list, and decrement the reference counters.
     89        //
     90        if (1) {
     91            if ((readout->bias != NULL) && (readout->bias->head != NULL)) {
     92                psListElem *tmpElem = (psListElem *) readout->bias->head;
     93                while (NULL != tmpElem) {
     94                    psMemDecrRefCounter((psImage *) tmpElem->data);
     95                    tmpElem = tmpElem->next;
     96                }
     97            }
     98        }
    7299        psFree(readout->bias);
    73100        psFree(readout->analysis);
     
    84111        psFree(cell->toSky);
    85112        psFree(cell->concepts);
    86         psFree(cell->camera);
    87113        psFree(cell->analysis);
    88114        //
     
    195221    }
    196222    tmpCell->camera = cameradata;
    197     psMemIncrRefCounter((psMetadata *) cameradata);
    198223    tmpCell->analysis = NULL;
    199224    tmpCell->readouts = psArrayAlloc(0);
     
    247272    tmpFPA->analysis = NULL;
    248273    tmpFPA->camera = camera;
    249     psMemIncrRefCounter((psPtr) camera);
    250274    tmpFPA->chips = psArrayAlloc(0);
    251275    tmpFPA->private = NULL;
     
    338362
    339363    // Convert to those chip coordinates.
    340     pmCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);
     364    psPlane *rc = pmCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);
     365    if (rc == NULL) {
     366        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine Chip coords.\n");
     367        return(NULL);
     368    }
    341369
    342370    // Determine which cell contains those chip coordinates.
    343371    outCell = pmCellInChip(&chipCoord, tmpChip);
     372    if (outCell == NULL) {
     373        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the cell.\n");
     374        return(NULL);
     375    }
    344376
    345377    return (outCell);
     
    379411    }
    380412
    381     // XXX: Print warning here?
     413    psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the chip.\n");
    382414    return (NULL);
    383415}
     
    414446            chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
    415447        } else {
    416             // XXX: Generate warning message.
    417             // XXX: Can we use the following function to derive a transform?
    418             // chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);
    419         }
    420 
    421         PS_ASSERT_PTR_NON_NULL(chipToCell, NULL);
     448            psLogMsg(__func__, PS_LOG_WARN, "WARNING: non-linear cell->chip transforms are not yet implemented.\n");
     449            //chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);
     450            chipToCell = NULL;
     451        }
     452        if (chipToCell == NULL) {
     453            psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not invert the Cell->toChip transform.\n");
     454            return(NULL);
     455        }
    422456        psArray* readouts = tmpCell->readouts;
    423457
     
    442476    }
    443477
     478    psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the cell.\n");
    444479    return (NULL);
    445480}
    446481
     482
     483psPlane* pmCoordCellToFPA(
     484    psPlane* fpaCoord,
     485    const psPlane* cellCoord,
     486    const pmCell* cell)
     487{
     488    PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
     489    PS_ASSERT_PTR_NON_NULL(cell, NULL);
     490
     491    psPlane *rc = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord);
     492    if (rc == NULL) {
     493        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform cell coords to FPA coords.\n");
     494    }
     495    return(rc);
     496}
     497
     498
     499psPlane* pmCoordChipToFPA(
     500    psPlane* outCoord,
     501    const psPlane* inCoord,
     502    const pmChip* chip)
     503{
     504    PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
     505    PS_ASSERT_PTR_NON_NULL(chip, NULL);
     506
     507    psPlane *rc = psPlaneTransformApply(outCoord, chip->toFPA, inCoord);
     508    if (rc == NULL) {
     509        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform chip coords to FPA coords.\n");
     510    }
     511    return(rc);
     512}
     513
     514
     515psPlane* pmCoordFPAToChip(
     516    psPlane* chipCoord,
     517    const psPlane* fpaCoord,
     518    const pmChip* chip)
     519{
     520    PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
     521    PS_ASSERT_PTR_NON_NULL(chip, NULL);
     522    PS_ASSERT_PTR_NON_NULL(chip->fromFPA, NULL);
     523
     524    psPlane *rc = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord);
     525    if (rc == NULL) {
     526        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform FPA coords to Chip coords.\n");
     527    }
     528    return(rc);
     529}
    447530
    448531psPlane* pmCoordCellToChip(
     
    454537    PS_ASSERT_PTR_NON_NULL(cell, NULL);
    455538
    456     return (psPlaneTransformApply(outCoord, cell->toChip, inCoord));
    457 }
    458 
    459 
    460 psPlane* pmCoordChipToFPA(
    461     psPlane* outCoord,
    462     const psPlane* inCoord,
    463     const pmChip* chip)
    464 {
    465     PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
    466     PS_ASSERT_PTR_NON_NULL(chip, NULL);
    467 
    468     return (psPlaneTransformApply(outCoord, chip->toFPA, inCoord));
    469 }
    470 
     539    psPlane *rc = psPlaneTransformApply(outCoord, cell->toChip, inCoord);
     540    if (rc == NULL) {
     541        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform Cell coords to Chip coords.\n");
     542    }
     543    return(rc);
     544}
     545
     546psPlane* pmCoordChipToCell(
     547    psPlane* cellCoord,
     548    const psPlane* chipCoord,
     549    const pmCell* cell)
     550{
     551    PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
     552    PS_ASSERT_PTR_NON_NULL(cell, NULL);
     553    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
     554
     555    pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent);
     556    if (tmpCell == NULL) {
     557        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the proper cell.\n");
     558        return(NULL);
     559    }
     560
     561    psPlaneTransform *tmpChipToCell = NULL;
     562    PS_ASSERT_PTR_NON_NULL(tmpCell->toChip, NULL);
     563    if (true ==  p_psIsProjectionLinear(tmpCell->toChip)) {
     564        tmpChipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
     565    } else {
     566        psLogMsg(__func__, PS_LOG_WARN, "WARNING: non-linear cell->chip transforms are not yet implemented.\n");
     567        // XXX: tmpChipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);
     568        tmpChipToCell = NULL;
     569    }
     570    if (tmpChipToCell == NULL) {
     571        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not invert the Cell->toChip transform.\n");
     572        return(NULL);
     573    }
     574
     575    psPlane *rc = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord);
     576    if (rc == NULL) {
     577        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform Chip coords to Cell coords.\n");
     578    }
     579    psFree(tmpChipToCell);
     580    return(rc);
     581}
    471582
    472583psPlane* pmCoordFPAToTP(
     
    480591    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    481592
    482     return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, color, magnitude));
     593    psPlane *rc = psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, color, magnitude);
     594    if (rc == NULL) {
     595        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform FPA coords to tangent plane coords.\n");
     596    }
     597    return(rc);
     598}
     599
     600psPlane* pmCoordTPToFPA(
     601    psPlane* fpaCoord,
     602    const psPlane* tpCoord,
     603    double color,
     604    double magnitude,
     605    const pmFPA* fpa)
     606{
     607    PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
     608    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
     609    PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL);
     610
     611    psPlane *rc = psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, tpCoord, color, magnitude);
     612    if (rc == NULL) {
     613        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform tangent plane coords to FPA coords.\n");
     614    }
     615    return(rc);
     616}
     617
     618
     619/*****************************************************************************
     620XXXDeproject(outSphere, coord, projection): This private routine is a wrapper
     621for p_psDeproject().  The reason: p_psDeproject() and p_psProject() combined
     622do not seem to produce the original coordinates when they even though they
     623should.  XXXDeproject() simply negates the ->r and ->d members of the output
     624psSphere if the input ->y is larger than 0.0.  I don't know why it works.
     625 
     626I'm guessing the p_psProject() and p_psDeproject() functions have bugs.
     627 *****************************************************************************/
     628psSphere* XXXDeproject(
     629    psSphere *outSphere,
     630    const psPlane* coord,
     631    const psProjection* projection)
     632{
     633    psSphere *rc = p_psDeproject(outSphere, coord, projection);
     634
     635    if (coord->y >= 0.0) {
     636        rc->d = -rc->d;
     637        rc->r = -rc->r;
     638    }
     639
     640    return(rc);
    483641}
    484642
     
    496654    PS_ASSERT_PTR_NON_NULL(projection, NULL);
    497655
    498     return(p_psDeproject(outSphere, tpCoord, projection));
     656    psSphere *rc = XXXDeproject(outSphere, tpCoord, projection);
     657    if (rc == NULL) {
     658        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform tangent plane coords to sky coords.\n");
     659    }
     660    return(rc);
    499661}
    500662/*****************************************************************************
     
    511673    PS_ASSERT_PTR_NON_NULL(projection, NULL);
    512674
    513     return(p_psProject(tpCoord, in, projection));
    514 }
    515 
    516 
    517 psPlane* pmCoordCellToFPA(
    518     psPlane* fpaCoord,
    519     const psPlane* cellCoord,
    520     const pmCell* cell)
    521 {
    522     PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
    523     PS_ASSERT_PTR_NON_NULL(cell, NULL);
    524 
    525     return (psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord));
     675    psPlane *rc = p_psProject(tpCoord, in, projection);
     676    if (rc == NULL) {
     677        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform sky to tangent plane coords.\n");
     678    }
     679    return(rc);
    526680}
    527681
     
    545699    psPlane fpaCoord;
    546700    psPlane tpCoord;
     701    psPlane *rc;
    547702    pmFPA* parFPA = (cell->parent)->parent;
    548703
    549704    // Convert the input cell coordinates to FPA coordinates.
    550     psPlaneTransformApply(&fpaCoord, cell->toFPA, cellCoord);
     705    rc = psPlaneTransformApply(&fpaCoord, cell->toFPA, cellCoord);
     706    if (rc == NULL) {
     707        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform cell coords to FPA coords.\n");
     708        return(NULL);
     709    }
    551710
    552711    // Convert the FPA coordinates to tangent plane Coordinates.
    553     psPlaneDistortApply(&tpCoord, parFPA->toTangentPlane, &fpaCoord, color, magnitude);
     712    rc = psPlaneDistortApply(&tpCoord, parFPA->toTangentPlane, &fpaCoord, color, magnitude);
     713    if (rc == NULL) {
     714        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform FPA coords to tangent plane coords.\n");
     715        return(NULL);
     716    }
    554717
    555718    // Convert the tangent plane Coordinates to sky coordinates.
    556     return(pmCoordTPToSky(NULL, &tpCoord, parFPA->projection));
    557 }
    558 
     719    psSphere *rc2 = pmCoordTPToSky(skyCoord, &tpCoord, parFPA->projection);
     720    if (rc2 == NULL) {
     721        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform cell coords to sky coords.\n");
     722    }
     723
     724    return(rc2);
     725}
     726
     727psPlane* pmCoordSkyToCell(
     728    psPlane* cellCoord,
     729    const psSphere* skyCoord,
     730    float color,
     731    float magnitude,
     732    const pmCell* cell)
     733{
     734    PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
     735    PS_ASSERT_PTR_NON_NULL(cell, NULL);
     736    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
     737    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
     738    pmChip *parChip = cell->parent;
     739    pmFPA *parFPA = parChip->parent;
     740    psPlane tpCoord;
     741    psPlane fpaCoord;
     742    psPlane chipCoord;
     743    psPlane *rc;
     744
     745    // Convert the skyCoords to tangent plane coords.
     746    rc = pmCoordSkyToTP(&tpCoord, skyCoord, parFPA->projection);
     747    if (rc == NULL) {
     748        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine tangent plane coords.\n");
     749        return(NULL);
     750    }
     751
     752    // Convert the tangent plane coords to FPA coords.
     753    rc = pmCoordTPToFPA(&fpaCoord, &tpCoord, color, magnitude, parFPA);
     754    if (rc == NULL) {
     755        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine FPA coords.\n");
     756        return(NULL);
     757    }
     758
     759    // Convert the FPA coords to chip coords.
     760    rc = pmCoordFPAToChip(&chipCoord, &fpaCoord, parChip);
     761    if (rc == NULL) {
     762        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine chip coords.\n");
     763        return(NULL);
     764    }
     765
     766    // Convert the chip coords to cell coords.
     767    rc = pmCoordChipToCell(cellCoord, &chipCoord, cell);
     768    if (rc == NULL) {
     769        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine cell coords.\n");
     770        return(NULL);
     771    }
     772
     773    return (cellCoord);
     774}
    559775
    560776// XXX: This has not been tested.
     
    569785    PS_ASSERT_PTR_NON_NULL(cell->toSky, NULL);
    570786    psPlane outPlane;
    571     psPlaneTransformApply(&outPlane, cell->toSky, cellCoord);
     787    psPlane *rc;
     788    rc = psPlaneTransformApply(&outPlane, cell->toSky, cellCoord);
     789    if (rc == NULL) {
     790        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform cell coords to sky coords.\n");
     791        return(NULL);
     792    }
     793
    572794    psSphere *out = outSphere;
    573795    if (out == NULL) {
     
    577799    out->d = outPlane.x;
    578800
    579     return(NULL);
     801    return(out);
    580802}
    581803
     
    599821    skyPlane.x = skyCoord->d;
    600822
    601     return(psPlaneTransformApply(cellCoord, cell->toSky, &skyPlane));
    602 }
    603 
    604 
    605 psPlane* pmCoordTPToFPA(
    606     psPlane* fpaCoord,
    607     const psPlane* tpCoord,
    608     double color,
    609     double magnitude,
    610     const pmFPA* fpa)
    611 {
    612     PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
    613     PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    614     PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL);
    615 
    616     return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, tpCoord, color, magnitude));
    617 }
    618 
    619 
    620 psPlane* pmCoordFPAToChip(
    621     psPlane* chipCoord,
    622     const psPlane* fpaCoord,
    623     const pmChip* chip)
    624 {
    625     PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
    626     PS_ASSERT_PTR_NON_NULL(chip, NULL);
    627     PS_ASSERT_PTR_NON_NULL(chip->fromFPA, NULL);
    628 
    629     chipCoord = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord);
    630     return(chipCoord);
    631 }
    632 
    633 psPlane* pmCoordChipToCell(
    634     psPlane* cellCoord,
    635     const psPlane* chipCoord,
    636     const pmCell* cell)
    637 {
    638     PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
    639     PS_ASSERT_PTR_NON_NULL(cell, NULL);
    640     PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
    641 
    642     pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent);
    643     PS_ASSERT_PTR_NON_NULL(tmpCell->toChip, NULL);
    644     psPlaneTransform *tmpChipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
    645     PS_ASSERT_PTR_NON_NULL(tmpChipToCell, NULL);
    646     cellCoord = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord);
    647     psFree(tmpChipToCell);
     823    psPlane *rc = psPlaneTransformApply(cellCoord, cell->toSky, &skyPlane);
     824    if (rc == NULL) {
     825        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform sky to cell coords.\n");
     826    }
    648827    return(cellCoord);
    649828}
    650 
    651 
    652 psPlane* pmCoordSkyToCell(
    653     psPlane* cellCoord,
    654     const psSphere* skyCoord,
    655     float color,
    656     float magnitude,
    657     const pmCell* cell)
    658 {
    659     PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
    660     PS_ASSERT_PTR_NON_NULL(cell, NULL);
    661     PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
    662     PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
    663     pmChip *parChip = cell->parent;
    664     pmFPA *parFPA = parChip->parent;
    665 
    666     // Convert the skyCoords to tangent plane coords.
    667     psPlane *tpCoord = pmCoordSkyToTP(NULL, skyCoord, parFPA->projection);
    668 
    669     // Convert the tangent plane coords to FPA coords.
    670     psPlane *fpaCoord = pmCoordTPToFPA(NULL, tpCoord, color, magnitude, parFPA);
    671 
    672     // Convert the FPA coords to chip coords.
    673     psPlane *chipCoord = pmCoordFPAToChip(NULL, fpaCoord, parChip);
    674 
    675     // Convert the chip coords to cell coords.
    676     cellCoord = pmCoordChipToCell(cellCoord, chipCoord, cell);
    677 
    678     psFree(tpCoord);
    679     psFree(fpaCoord);
    680     psFree(chipCoord);
    681 
    682     return (cellCoord);
    683 }
    684 
  • trunk/psModules/src/imsubtract/pmSubtractBias.h

    r5516 r5587  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-11-15 20:09:03 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-11-23 23:54:30 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4848    const pmReadout *dark               ///< A possibly NULL bias pmReadout which is to be subtracted
    4949);
    50 // OLD: remove this
    51 //    const psList *overscans,      ///< A psList of overscan images
    52 //    pmOverscanAxis overScanAxis,  ///< Defines how overscans are applied
    5350
    5451/******************************************************************************
  • trunk/psModules/test/astrom/tst_pmAstrometry.c

    r5543 r5587  
    11/** @file  tst_pmAstrometry.c
    22 *
    3  *  @brief Contains the tests: pmAstrometry.[ch].  Only the pmxxxAlloc()
     3 *  @brief Contains the tests: pmAstrometry.[ch].  The pmxxxAlloc()
    44 *  and psFree() functionality are used here.
    55 *
    6  *  @author George Gusciora, MHPCC
     6 *  @author GLG, MHPCC
    77 *
    8  * XXX: Significant work needed: must test the variout coordinate transformation function.
     8 *  XXX: Untested: pmFPACheckParents()
    99 *
    10  *
    11  *
    12  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-11-18 19:43:14 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-11-23 23:54:30 $
    1412 *
    1513 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3836#define CHIP_ALLOC_NAME "ChipName"
    3937#define CELL_ALLOC_NAME "CellName"
     38#define MISC_NUM 32
     39#define MISC_NAME "META00"
     40#define MISC_NAME2 "META01"
     41#define NUM_BIAS_DATA 10
     42#define TEST_NUM_ROWS 32
     43#define TEST_NUM_COLS 32
     44
     45psPlaneTransform *PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM()
     46{
     47    psPlaneTransform *pt = psPlaneTransformAlloc(1, 1);
     48    pt->x->coeff[1][0] = 1.0;
     49    pt->y->coeff[0][1] = 1.0;
     50    return(pt);
     51}
     52
     53psPlaneDistort *PS_CREATE_4D_IDENTITY_PLANE_DISTORT()
     54{
     55    psPlaneDistort *pd = psPlaneDistortAlloc(1, 1, 1, 1);
     56    pd->x->coeff[1][0][0][0] = 1.0;
     57    pd->y->coeff[0][1][0][0] = 1.0;
     58    return(pd);
     59}
     60
     61/******************************************************************************
     62generateSimpleFPA(): This function generates a pmFPA data structure and then
     63populates its members with real data.  We do this to ensure that the data is
     64later being psFree()'ed correctly.
     65 *****************************************************************************/
     66pmFPA *generateSimpleFPA()
     67{
     68    psBool rc;
     69    pmFPA* fpa = pmFPAAlloc(psMetadataAlloc());
     70
     71    if (fpa == NULL) {
     72        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc() returned a NULL.");
     73        return(NULL);
     74    }
     75
     76    //
     77    // Test and create camera metadata.
     78    //
     79    if (fpa->camera == NULL) {
     80        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: fpa->camera is NULL.");
     81        psFree(fpa);
     82        return(NULL);
     83    } else {
     84        rc = psMetadataAddS32((psMetadata *) fpa->camera, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     85        if (rc == false) {
     86            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to fpa->camera.");
     87            psFree(fpa);
     88            return(NULL);
     89        }
     90        psS32 tmpS32 = psMetadataLookupS32(&rc, fpa->camera, MISC_NAME);
     91        if ((rc == false) || (tmpS32 != MISC_NUM)) {
     92            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from fpa->camera.");
     93            psFree(fpa);
     94            return(NULL);
     95        }
     96    }
     97
     98    //
     99    // Create various transforms and projections.
     100    //
     101    fpa->fromTangentPlane = PS_CREATE_4D_IDENTITY_PLANE_DISTORT();
     102    fpa->toTangentPlane = PS_CREATE_4D_IDENTITY_PLANE_DISTORT();
     103    fpa->projection = psProjectionAlloc(0.0,0.0,10.0,10.0,PS_PROJ_TAN);
     104
     105    //
     106    // Ensure fpa concepts metadata was allocated properly.
     107    //
     108    if (fpa->concepts == NULL) {
     109        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set fpa->concepts.");
     110        psFree(fpa);
     111        return(NULL);
     112    } else {
     113        rc = psMetadataAddS32(fpa->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     114        if (rc == false) {
     115            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add data to fpa->concepts.");
     116            psFree(fpa);
     117            return(NULL);
     118        }
     119        psS32 tmpS32 = psMetadataLookupS32(&rc, fpa->concepts, MISC_NAME);
     120        if ((rc == false) || (tmpS32 != MISC_NUM)) {
     121            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from fpa->concepts.");
     122            psFree(fpa);
     123            return(NULL);
     124        }
     125    }
     126
     127    //
     128    // Create ->analysis metadata.
     129    //
     130    fpa->analysis = psMetadataAlloc();
     131    rc = psMetadataAddS32(fpa->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     132
     133    //
     134    // We test the fpa->chips array later.
     135    //
     136
     137    //
     138    // How to test the p_pmHDU *private member?
     139    //
     140
     141    //
     142    // Create ->phu metadata.
     143    //
     144    fpa->phu = psMetadataAlloc();
     145    rc = psMetadataAddS32(fpa->phu, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     146
     147    return(fpa);
     148}
     149
    40150
    41151psS32 main(psS32 argc, char* argv[])
     
    47157}
    48158
     159/******************************************************************************
     160testFPAAlloc()
     161    1: We ensure that pmFPAAlloc() properly allocates a pmFPA struct.
     162    2: We populate the members with real data to ensure they are being
     163       free'ed correctly.
     164 *****************************************************************************/
    49165static psS32 testFPAAlloc(void)
    50166{
    51     // XXX: Do something more with these arguments.
    52     const psMetadata *camera = psMetadataAlloc();
     167    psMetadata *camera = psMetadataAlloc();
    53168    pmFPA* fpa = pmFPAAlloc(camera);
    54169
    55170    if (fpa == NULL) {
    56         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
     171        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc() returned a NULL.");
    57172        return 1;
    58173    }
     
    96211        return 9;
    97212    }
    98 
    99     psFree(fpa);
    100     psFree(camera);
    101 
    102     return 0;
     213    psFree(fpa);
     214
     215    //
     216    // Populate the pmFPA struct with real data to ensure they were
     217    // psFree()'ed correctly.
     218    //
     219    fpa = generateSimpleFPA();
     220    if (fpa == NULL) {
     221        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: generateSimpleFPA() returned NULL.");
     222        return(15);
     223    }
     224    psFree(fpa);
     225
     226    return(0);
     227}
     228
     229/******************************************************************************
     230generateSimpleChip(): This function generates a pmChip data structure and then
     231populates its members with real data.  We do this to ensure that the data is
     232later being psFree()'ed correctly.
     233 *****************************************************************************/
     234pmChip *generateSimpleChip(pmFPA *fpa)
     235{
     236    psBool rc;
     237    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
     238    if (chip == NULL) {
     239        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.");
     240        return(NULL);
     241    }
     242    chip->toFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM();
     243    chip->fromFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM();
     244    //
     245    // We already ensured that chip->concepts was working properly.
     246    //
     247
     248    //
     249    // Create ->analysis metadata.
     250    //
     251    chip->analysis = psMetadataAlloc();
     252    rc = psMetadataAddS32(chip->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     253
     254    //
     255    // We test the chip->cells array later.
     256    //
     257
     258    //
     259    // How to test the p_pmHDU *private member?
     260    //
     261
     262    return(chip);
    103263}
    104264
    105265static psS32 testChipAlloc(void)
    106266{
    107     const psMetadata *camera = psMetadataAlloc();
    108     pmFPA* fpa = pmFPAAlloc(camera);
    109     if (fpa == NULL) {
    110         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
    111         return 1;
    112     }
    113 
     267    pmFPA* fpa = generateSimpleFPA();
    114268    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
    115269    if (chip == NULL) {
     
    174328        return 25;
    175329    }
    176 
    177     psFree(fpa);
    178     //    psFree(chip);
    179     psFree(camera);
    180 
    181     return 0;
     330    psFree(fpa);
     331
     332    //
     333    // Populate the pmChip struct with real data to ensure they were
     334    // psFree()'ed correctly.
     335    //
     336    fpa = generateSimpleFPA();
     337    chip = generateSimpleChip(fpa);
     338    psFree(fpa);
     339
     340    return(0);
     341}
     342
     343/******************************************************************************
     344generateSimpleCell(): This function generates a pmCell data structure and then
     345populates its members with real data.  We do this to ensure that the data is
     346later being psFree()'ed correctly.
     347 *****************************************************************************/
     348pmCell *generateSimpleCell(pmFPA *fpa, pmChip *chip)
     349{
     350    psBool rc;
     351    pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME);
     352    if (cell == NULL) {
     353        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.");
     354        return(NULL);
     355    }
     356    cell->toChip = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM();
     357    cell->toFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM();
     358    cell->toSky = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM();
     359    //
     360    // We already ensured that cell->concepts was working properly.
     361    //
     362
     363    //
     364    // Test camera metadata.
     365    //
     366    if (cell->camera == NULL) {
     367        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera is NULL.");
     368        psFree(fpa);
     369        return(NULL);
     370    } else {
     371        rc = psMetadataAddS32((psMetadata *) cell->camera, PS_LIST_HEAD, MISC_NAME2, 0, NULL, MISC_NUM);
     372        if (rc == false) {
     373            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to cell->camera.");
     374            psFree(fpa);
     375            return(NULL);
     376        }
     377        psS32 tmpS32 = psMetadataLookupS32(&rc, cell->camera, MISC_NAME2);
     378        if ((rc == false) || (tmpS32 != MISC_NUM)) {
     379            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from cell->camera.");
     380            psFree(fpa);
     381            return(NULL);
     382        }
     383    }
     384
     385    //
     386    // Create ->analysis metadata.
     387    //
     388    cell->analysis = psMetadataAlloc();
     389    rc = psMetadataAddS32(cell->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     390
     391    //
     392    // We test the cell->readouts array later.
     393    //
     394
     395    //
     396    // How to test the p_pmHDU *private member?
     397    //
     398
     399    return(cell);
    182400}
    183401
    184402static psS32 testCellAlloc(void)
    185403{
    186     const psMetadata *camera = psMetadataAlloc();
    187     pmFPA* fpa = pmFPAAlloc(camera);
    188     if (fpa == NULL) {
    189         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.n");
    190         return 1;
    191     }
    192 
     404    pmFPA* fpa = generateSimpleFPA();
    193405    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
    194     if (chip == NULL) {
    195         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.n");
    196         return 2;
    197     }
    198 
    199     pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, CELL_ALLOC_NAME);
     406    pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME);
    200407    if (cell == NULL) {
    201408        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.n");
     
    240447    }
    241448
    242     if (cell->camera != camera) {
     449    if (cell->camera != fpa->camera) {
    243450        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera set improperly.\n");
    244451        return 20;
     
    269476        return 27;
    270477    }
    271 
    272     psFree(fpa);
    273     //    psFree(chip);
    274     //    psFree(cell);
    275     psFree(camera);
    276 
    277     return 0;
    278 }
     478    psFree(fpa);
     479
     480    //
     481    // Populate the pmCell struct with real data to ensure they were
     482    // psFree()'ed correctly.
     483    //
     484    fpa = generateSimpleFPA();
     485    chip = generateSimpleChip(fpa);
     486    cell = generateSimpleCell(fpa, chip);
     487    psFree(fpa);
     488
     489    return(0);
     490}
     491
     492/******************************************************************************
     493generateSimpleReadout(): This function generates a pmReadout data structure and then
     494populates its members with real data.  We do this to ensure that the data is
     495later being psFree()'ed correctly.
     496 *****************************************************************************/
     497pmReadout *generateSimpleReadout(pmFPA *fpa, pmChip *chip, pmCell *cell)
     498{
     499    psBool rc;
     500    pmReadout *readout = pmReadoutAlloc(cell);
     501    if (readout == NULL) {
     502        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmReadoutAlloc returned a NULL.");
     503        return(NULL);
     504    }
     505    readout->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     506    readout->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8);
     507    readout->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     508
     509    //
     510    // Create a psList of bias data.
     511    //
     512    for (psS32 i = 0 ; i < NUM_BIAS_DATA ; i++) {
     513        psImage *tmpImage = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     514        if (readout->bias == NULL) {
     515            readout->bias = psListAlloc(tmpImage);
     516        } else {
     517            psListAdd(readout->bias, PS_LIST_HEAD, tmpImage);
     518        }
     519    }
     520
     521    //
     522    // Test readout->analysis metadata.
     523    //
     524    if (readout->analysis == NULL) {
     525        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: readout->analysis is NULL.");
     526        psFree(fpa);
     527        return(NULL);
     528    } else {
     529        rc = psMetadataAddS32((psMetadata *) readout->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     530        if (rc == false) {
     531            psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to readout->analysis.");
     532            psFree(fpa);
     533            return(NULL);
     534        }
     535    }
     536
     537    return(readout);
     538}
     539
    279540
    280541static psS32 testReadoutAlloc(void)
    281542{
    282     const psMetadata *camera = psMetadataAlloc();
    283     pmFPA* fpa = pmFPAAlloc(camera);
    284 
    285     if (fpa == NULL) {
    286         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.\n");
    287         return 1;
    288     }
    289 
    290     pmChip *chip = pmChipAlloc(fpa, "ChipName");
    291     if (chip == NULL) {
    292         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.\n");
    293         return 2;
    294     }
    295 
    296     pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, "CellName");
    297     if (cell == NULL) {
    298         psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.\n");
    299         return 3;
    300     }
    301 
     543    pmFPA* fpa = generateSimpleFPA();
     544    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
     545    pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME);
    302546    pmReadout *readout = pmReadoutAlloc(cell);
    303547    if (readout == NULL) {
     
    355599        return 20;
    356600    }
    357 
    358     psFree(fpa);
    359     //    psFree(chip);
    360     //    psFree(cell);
    361     //    psFree(readout);
    362     psFree(camera);
    363 
    364     return 0;
    365 }
     601    psFree(fpa);
     602
     603    //
     604    // Populate the pmReadout struct with real data to ensure they were
     605    // psFree()'ed correctly.
     606    //
     607    fpa = generateSimpleFPA();
     608    chip = generateSimpleChip(fpa);
     609    cell = generateSimpleCell(fpa, chip);
     610    readout = generateSimpleReadout(fpa, chip, cell);
     611    psFree(fpa);
     612
     613    return(0);
     614}
  • trunk/psModules/test/imsubtract/tst_pmSubtractBias.c

    r5552 r5587  
    2525 *  XXX: Memory leaks are not being detected.
    2626 *
    27  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    28  *  @date $Date: 2005-11-19 00:55:18 $
     27 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     28 *  @date $Date: 2005-11-23 23:54:30 $
    2929 *
    3030 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5252                          };
    5353
     54psS32 currentId = 0;
     55psS32 memLeaks = 0;             // XXX: remove
    5456
    5557int main(int argc, char* argv[])
     
    6769    psTraceSetLevel("psSpline1DEval", 0);
    6870    psTraceSetLevel("psSpline1DEvalVector", 0);
     71
     72    psS32 currentId = psMemGetId(); // XXX: remove
     73    psS32 memLeaks = 0;             // XXX: remove
     74    if (0) {
     75        PRINT_MEMLEAKS(0);
     76    }
    6977
    7078    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
     
    661669    }
    662670    oAverage/= (psF32) numOverscans;
    663 
    664 
    665     if (fit == PM_FIT_NONE) {
    666         myReadout = pmSubtractBias(myReadout, NULL, PM_FIT_NONE, overscanaxis,
    667                                    stat, nBin, NULL, NULL);
    668     } else if (fit == PM_FIT_POLYNOMIAL) {
    669         myReadout = pmSubtractBias(myReadout, myPoly, PM_FIT_POLYNOMIAL, overscanaxis,
    670                                    stat, nBin, NULL, NULL);
    671     } else if (fit == PM_FIT_SPLINE) {
    672         //        mySpline = psSpline1DAlloc();
    673         myReadout = pmSubtractBias(myReadout, mySpline, PM_FIT_SPLINE, overscanaxis,
    674                                    stat, nBin, NULL, NULL);
    675     }
    676 
    677     for (i=0;i<imageNumRows;i++) {
    678         for (j=0;j<imageNumCols;j++) {
    679             expect = ((float) (i + j)) - oAverage;
    680             actual = myReadout->image->data.F32[i][j];
    681             if (FLT_EPSILON < fabs(expect - actual)) {
    682                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    683                 testStatus = 1;
    684             } else {
    685                 //printf("COOL: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     671    if (0) {
     672        if (fit == PM_FIT_NONE) {
     673            myReadout = pmSubtractBias(myReadout, NULL, PM_FIT_NONE, overscanaxis,
     674                                       stat, nBin, NULL, NULL);
     675        } else if (fit == PM_FIT_POLYNOMIAL) {
     676            myReadout = pmSubtractBias(myReadout, myPoly, PM_FIT_POLYNOMIAL, overscanaxis,
     677                                       stat, nBin, NULL, NULL);
     678        } else if (fit == PM_FIT_SPLINE) {
     679            //        mySpline = psSpline1DAlloc();
     680            myReadout = pmSubtractBias(myReadout, mySpline, PM_FIT_SPLINE, overscanaxis,
     681                                       stat, nBin, NULL, NULL);
     682        }
     683        if (myReadout == NULL ) {
     684            printf("TEST ERROR: pmSubtractBias() returned NULL.\n");
     685            testStatus = 1;
     686        } else {
     687            for (i=0;i<imageNumRows;i++) {
     688                for (j=0;j<imageNumCols;j++) {
     689                    expect = ((float) (i + j)) - oAverage;
     690                    actual = myReadout->image->data.F32[i][j];
     691                    if (FLT_EPSILON < fabs(expect - actual)) {
     692                        printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     693                        testStatus = 1;
     694                    } else {
     695                        //printf("GOOD: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     696                    }
     697                }
    686698            }
    687699        }
    688700    }
    689     // XXX: Figure out memory deallocation
     701
     702    // HEY
    690703    psFree(fpa);
    691     //    psFree(chip);
    692     //    psFree(cell);
    693     /*
    694         psListElem *tmpElem = (psListElem *) myReadout->bias->head;
    695         while (NULL != tmpElem) {
    696             psFree((psImage *) tmpElem->data);
    697             tmpElem = tmpElem->next;
    698         }
    699         psFree(myReadout);
    700     */
    701     psFree(camera);
    702704    psFree(stat);
    703705    psFree(myPoly);
     
    11261128}
    11271129
    1128 
    1129 // This code will
Note: See TracChangeset for help on using the changeset viewer.