IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.