IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 13, 2004, 1:58:20 PM (22 years ago)
Author:
gusciora
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/astronomy/tst_psAstrometry01.c

    r2083 r2096  
    55*  @author GLG, MHPCC
    66*
    7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    8 *  @date $Date: 2004-10-13 21:08:11 $
     7*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     8*  @date $Date: 2004-10-13 23:58:20 $
    99*
    1010*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4040#define HEIGHT  3055.0
    4141#define LAPSERATE 20.0
    42 #define NUM_CHIPS 2
    43 #define NUM_CELLS 4
     42
    4443#define NUM_READOUTS 2
    4544#define READOUT_NUM_ROWS 8
    4645#define READOUT_NUM_COLS 8
     46
     47#define CELL_WIDTH READOUT_NUM_COLS
     48#define CELL_HEIGHT READOUT_NUM_ROWS
     49
     50#define CELL_GAP 2
     51
     52#define NUM_CELLS 4
     53#define CELL_MIN_X 0
     54#define CELL_MAX_X CELL_WIDTH
     55#define CELL_MIN_Y 0
     56#define CELL_MAX_Y CELL_HEIGHT
     57
     58#define NUM_CHIPS 2
     59#define CHIP_MIN_X 0
     60#define CHIP_MAX_X ((NUM_CELLS * CELL_WIDTH) + ((NUM_CELLS) * CELL_GAP))
     61#define CHIP_MIN_Y 0
     62#define CHIP_MAX_Y CELL_HEIGHT
     63
     64#define CHIP_WIDTH CHIP_MAX_X
     65#define CHIP_HEIGHT CHIP_MAX_Y
     66#define CHIP_GAP 2
     67
     68#define FPA_MIN_X 0
     69#define FPA_MAX_X ((NUM_CHIPS * CHIP_WIDTH) + ((NUM_CHIPS) * CHIP_GAP))
     70#define FPA_MIN_Y 0
     71#define FPA_MAX_Y CHIP_HEIGHT
     72
    4773#define ROW0  0
    4874#define COL0  0
    4975
    50 int genSystem()
     76static void psPlaneDistortFree(psPlaneDistort *pd)
     77{
     78    psFree(pd->x);
     79    psFree(pd->y);
     80}
     81
     82static void psPlaneTransformFree(psPlaneTransform *pd)
     83{
     84    psFree(pd->x);
     85    psFree(pd->y);
     86}
     87
     88#define PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(NAME) \
     89{\
     90    NAME = (psPlaneTransform *) psAlloc(sizeof(psPlaneTransform)); \
     91    p_psMemSetDeallocator(NAME, (psFreeFcn) psPlaneTransformFree); \
     92    NAME->x = psDPolynomial2DAlloc(2, 2, PS_POLYNOMIAL_ORD); \
     93    NAME->y = psDPolynomial2DAlloc(2, 2, PS_POLYNOMIAL_ORD); \
     94    NAME->x->coeff[1][0] = 1.0; \
     95    NAME->y->coeff[0][1] = 1.0; \
     96}
     97
     98#define PS_CREATE_4D_IDENTITY_PLANE_DISTORT(NAME) \
     99{\
     100    NAME = (psPlaneDistort *) psAlloc(sizeof(psPlaneDistort)); \
     101    p_psMemSetDeallocator(NAME, (psFreeFcn) psPlaneDistortFree); \
     102    NAME->x = psDPolynomial4DAlloc(2, 2, 2, 2, PS_POLYNOMIAL_ORD); \
     103    NAME->y = psDPolynomial4DAlloc(2, 2, 2, 2, PS_POLYNOMIAL_ORD); \
     104    NAME->x->coeff[1][0][0][0] = 1.0; \
     105    NAME->y->coeff[0][1][0][0] = 1.0; \
     106}
     107
     108/*
     109    This routine will create a system of FPAs/Chips/Cells/Readouts.  For
     110    simplicity, an FPA is defined as a linear array of chips, and a chip is
     111    defined as a linear array of cells, both in the x direction.  The transforms
     112    between the various layers take into account the cell/chip and the boundaries
     113    between each.
     114*/
     115psFPA *genSystem()
    51116{
    52117    int i;
    53118    int j;
    54     psTime* now = psTimeGetTime(PS_TIME_UTC);
    55     psObservatory* obs = psObservatoryAlloc(NAME, LATITUDE, LONGITUDE, HEIGHT, LAPSERATE);
    56     psExposure* exp = psExposureAlloc(RA, DEC, HA, ZD, AZ,
    57                                       now, ROT_ANGLE, TEMPERATURE, PRESSURE, HUMIDITY,
    58                                       EXP_TIME, WAVELENGTH, obs);
     119    int k;
     120    psImage *tmpImage;
     121    //    psTime* now = psTimeGetTime(PS_TIME_UTC);
     122    //    psObservatory* obs = psObservatoryAlloc(NAME, LATITUDE, LONGITUDE, HEIGHT, LAPSERATE);
     123    //    psExposure* exp = psExposureAlloc(RA, DEC, HA, ZD, AZ,
     124    //                                      now, ROT_ANGLE, TEMPERATURE, PRESSURE, HUMIDITY,
     125    //                                      EXP_TIME, WAVELENGTH, obs);
    59126    //    psGrommit *grom = psGrommitAlloc(exp);
    60     psFPA *myFPA = psFPAAlloc(NUM_CHIPS, exp);
     127    psFPA *myFPA = psFPAAlloc(NUM_CHIPS, NULL);
    61128    psChip **chips;
    62129    psCell **cells;
    63 
    64     myFPA->fromTangentPlane = NULL;
    65     myFPA->toTangentPlane = NULL;
     130    psReadout **readouts;
     131
     132    // We create the transforms between the FPA and tangent plane.  The
     133    // transform is a simple identity transform.
     134    PS_CREATE_4D_IDENTITY_PLANE_DISTORT(myFPA->fromTangentPlane);
     135    PS_CREATE_4D_IDENTITY_PLANE_DISTORT(myFPA->toTangentPlane);
    66136
    67137    chips = (psChip **) myFPA->chips->data;
    68138    for (i=0;i<NUM_CHIPS;i++) {
    69139        chips[i] = psChipAlloc(NUM_CELLS, myFPA);
    70         chips[i]->toFPA = NULL;
    71         chips[i]->fromFPA = NULL;
     140        // We create the transforms between the chip and FPA.  The
     141        // transform is a simple identity transform.
     142        PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(chips[i]->toFPA);
     143        chips[i]->toFPA->x->coeff[0][0] = (double) (i * (CHIP_WIDTH + CHIP_GAP));
     144        chips[i]->toFPA->x->coeff[1][1] = 0.0;
     145        PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(chips[i]->fromFPA);
     146        chips[i]->fromFPA->x->coeff[0][0] = (double) (-i * (CHIP_WIDTH + CHIP_GAP));
     147        chips[i]->fromFPA->x->coeff[1][1] = 0.0;
     148
    72149        cells = (psCell **) chips[i]->cells->data;
    73150
    74151        for (j=0;j<NUM_CELLS;j++) {
    75152            cells[j] = psCellAlloc(NUM_READOUTS, chips[i]);
    76             cells[j]->toChip = NULL;
    77             cells[j]->fromChip = NULL;
    78             cells[j]->toFPA = NULL;
    79             cells[j]->toTP = NULL;
    80             /*
    81                         readouts = (psReadout **) cells[j]->readouts->data;
    82                         for (k=0;k<NUM_READOUTS;k++) {
    83                             tmpImage = psImageAlloc(READOUT_NUM_COLS, READOUT_NUM_ROWS, PS_TYPE_F32);
    84                             readouts[k] = psReadoutAlloc(COL0, ROW0, tmpImage);
    85                         }
    86             */
    87         }
    88     }
    89 
    90     psFree(now);
    91     psFree(obs);
    92     psFree(exp);
    93     chips = (psChip **) myFPA->chips->data;
    94     for (i=0;i<NUM_CHIPS;i++) {
    95         cells = (psCell **) chips[i]->cells->data;
    96         for (j=0;j<NUM_CELLS;j++) {
    97             /*
    98                         readouts = (psReadout **) cells[j]->readouts->data;
    99                         for (k=0;k<NUM_READOUTS;k++) {
    100                             psFree(readouts[k]);
    101                         }
    102             */
    103             psFree(cells[j]);
    104         }
    105         psFree(chips[i]);
    106     }
    107     psFree(myFPA);
    108     return(0);
     153            // We create the transforms between the cell and the chip.  The
     154            // transform is a simple identity transform.
     155            PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(cells[j]->toChip);
     156            cells[j]->toChip->x->coeff[0][0] = (double) (j * (CELL_WIDTH + CELL_GAP));
     157            cells[j]->toChip->x->coeff[1][1] = 0.0;
     158            PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(cells[j]->fromChip);
     159            cells[j]->fromChip->x->coeff[0][0] = (double) (-j * (CELL_WIDTH + CELL_GAP));
     160            cells[j]->fromChip->x->coeff[1][1] = 0.0;
     161            PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(cells[j]->toFPA);
     162            cells[j]->toFPA->x->coeff[0][0] = (double) ((i * (CHIP_WIDTH + CHIP_GAP)) +
     163                                              (j * (CELL_WIDTH + CELL_GAP)));
     164            cells[j]->toFPA->x->coeff[1][1] = 0.0;
     165            PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(cells[j]->toTP);
     166            cells[j]->toTP->x->coeff[0][0] = cells[j]->toFPA->x->coeff[0][0];
     167            cells[j]->toTP->x->coeff[1][1] = 0.0;
     168
     169            readouts = (psReadout **) cells[j]->readouts->data;
     170            for (k=0;k<NUM_READOUTS;k++) {
     171                tmpImage = psImageAlloc(READOUT_NUM_COLS, READOUT_NUM_ROWS, PS_TYPE_F32);
     172                for (int row=0;row<READOUT_NUM_ROWS;row++) {
     173                    for(int col=0;col<READOUT_NUM_COLS;col++) {
     174                        tmpImage->data.F32[row][col] = (float) ((i * (CHIP_WIDTH + CHIP_GAP)) +
     175                                                                (j * (CELL_WIDTH + CELL_GAP)));
     176                    }
     177                }
     178                readouts[k] = psReadoutAlloc((j * (CELL_WIDTH + CELL_GAP)), 0, tmpImage);
     179
     180            }
     181        }
     182    }
     183
     184    return(myFPA);
    109185}
    110186
     
    295371}
    296372
     373int test3a( void )
     374{
     375    int x;
     376    int y;
     377    psPlane fpaCoord;
     378    psFPA *myFPA = genSystem();
     379    psCell *myCell = NULL;
     380    psPlane chipCoord;
     381    psPlane cellCoord;
     382    psPlane testCoord;
     383
     384    int xReadout = 0;
     385    int xFPA = 0;
     386    for (int chip=0;chip<NUM_CHIPS;chip++) {
     387        for (int cell=0;cell<NUM_CELLS;cell++) {
     388            for(x=0;x<CELL_WIDTH;x++) {
     389                for (y=0;y<CELL_HEIGHT;y++) {
     390                    fpaCoord.x = (double) xFPA;
     391                    fpaCoord.y = (double) y;
     392                    printf("------------------ (%f, %f) ------------------\n", fpaCoord.x, fpaCoord.y);
     393                }
     394                xFPA++;
     395                xReadout++;
     396            }
     397            // We skip the gaps between cells.
     398            for(x=0;x<CELL_GAP;x++) {
     399                printf("Column %d is CELL GAP\n", xFPA);
     400                xFPA++;
     401                xReadout=0;
     402            }
     403        }
     404        // We skip the gaps between chips.
     405        for (x=0;x<CHIP_GAP;x++) {
     406            printf("Column %d is CHIP GAP\n", xFPA);
     407            xFPA++;
     408            xReadout=0;
     409        }
     410    }
     411
     412    psFree(myFPA);
     413    return(0);
     414}
     415
     416int printCell(psCell *cell)
     417{
     418    psReadout **readouts = (psReadout **) cell->readouts->data;
     419    psReadout *readout = readouts[0];
     420
     421    printf("-------------------------------\n");
     422    for (int i = 0; i < readout->image->numRows ; i++) {
     423        for (int j = 0; j < readout->image->numCols ; j++) {
     424            printf("(%.1f) ", readout->image->data.F32[i][j]);
     425        }
     426        printf("\n");
     427    }
     428    return(0);
     429}
     430
     431
     432/******************************************************************************
     433This routine tests many Astrometry functions:
     434    psChipInFPA()
     435    psCellInFPA()
     436    psCoordFPAToChip()
     437    psCoordChipToCell()
     438This routine loops through all valid cell coordinates and maintains a running
     439set of (x,y) coordinates in the FPA plane.  It calls the first two functions
     440with each FPA coordinate and determines the chip/cell that that coordinate
     441corresponds to.  It then calls the last two functions to determine the actual
     442chip and cell coordinates.  The cell coordinate is verified for correctness.
     443 
     444It then calls
     445    psCoordCellToChip()
     446to determine if the chip coordinates that were generated agree with the chip
     447coords returned above.
     448 
     449Then, it calls
     450    psCellInChip()
     451and flags an ERROR if the cell it returns is different from that of
     452psCellInFPA().
     453 
     454Then, it calls
     455    psCoordChipToFPA
     456to determine if the FPA coordinates are correct.
     457 
     458 
     459 *****************************************************************************/
    297460int test3( void )
    298461{
    299     genSystem();
     462    int x;
     463    int y;
     464    psPlane fpaCoord;
     465    psFPA *myFPA = genSystem();
     466    psCell *myCell = NULL;
     467    psPlane chipCoord;
     468    psPlane cellCoord;
     469    psPlane testCoord;
     470
     471    int xReadout = 0;
     472    int xFPA = 0;
     473    for (int chip=0;chip<NUM_CHIPS;chip++) {
     474        for (int cell=0;cell<NUM_CELLS;cell++) {
     475            for(x=0;x<CELL_WIDTH;x++) {
     476                for (y=0;y<CELL_HEIGHT;y++) {
     477                    fpaCoord.x = (double) xFPA;
     478                    fpaCoord.y = (double) y;
     479                    //printf("------------------ (%f, %f) ------------------\n", fpaCoord.x, fpaCoord.y);
     480                    psChip* tmpChip = psChipInFPA(&fpaCoord, myFPA);
     481                    myCell = psCellInFPA(&fpaCoord, myFPA);
     482
     483                    if ((myCell == NULL) || (tmpChip == NULL)) {
     484                        printf("ERROR: NULL\n");
     485                    } else {
     486                        psCoordFPAToChip(&chipCoord, &fpaCoord, tmpChip);
     487                        psCoordChipToCell(&cellCoord, &chipCoord, myCell);
     488
     489                        if (x != (int) cellCoord.x) {
     490                            printf("ERROR: x coord was %f, should be %d\n", cellCoord.x, x);
     491                        }
     492                        if (y != (int) cellCoord.y) {
     493                            printf("ERROR: y coord was %f, should be %d\n", cellCoord.y, y);
     494                        }
     495
     496                        psCoordCellToChip(&testCoord, &cellCoord, myCell);
     497                        if (testCoord.x != chipCoord.x) {
     498                            printf("ERROR: psCoordCellToChip() x coord was %f, should be %d\n", cellCoord.x, x);
     499                        }
     500                        if (testCoord.y != chipCoord.y) {
     501                            printf("ERROR: psCoordCellToChip() y coord was %f, should be %d\n", cellCoord.y, y);
     502                        }
     503
     504                        psCell *myCell2 = psCellInChip(&chipCoord, tmpChip);
     505                        if (myCell2 != myCell) {
     506                            printf("ERROR: psCellInFPA() != psCellInChip(psChipInFPA()) (%d %d)\n", myCell2, myCell);
     507                            printCell(myCell2);
     508                            printCell(myCell);
     509
     510                        }
     511
     512                        psCoordChipToFPA(&testCoord, &chipCoord, tmpChip);
     513                        if (testCoord.x != xFPA) {
     514                            printf("ERROR: psCoordChipToFPA() x coord was %f, should be %d\n", cellCoord.x, x);
     515                        }
     516                        if (testCoord.y != y) {
     517                            printf("ERROR: psCoordChipToFPA() y coord was %f, should be %d\n", cellCoord.y, y);
     518                        }
     519
     520                        psCoordFPAToTP(&testCoord, &fpaCoord, 0.0, 0.0, myFPA);
     521                        if (testCoord.x != fpaCoord.x) {
     522                            printf("ERROR: psCoordFPAToTP() x coord was %f, should be %d\n", cellCoord.x, x);
     523                        }
     524                        if (testCoord.y != fpaCoord.y) {
     525                            printf("ERROR: psCoordFPAToTP() y coord was %f, should be %d\n", cellCoord.y, y);
     526                        }
     527
     528                        psCoordCellToFPA(&testCoord, &cellCoord, myCell);
     529                        if (testCoord.x != fpaCoord.x) {
     530                            printf("ERROR: psCoordFPAToTP() x coord was %f, should be %d\n", cellCoord.x, x);
     531                        }
     532                        if (testCoord.y != fpaCoord.y) {
     533                            printf("ERROR: psCoordFPAToTP() y coord was %f, should be %d\n", cellCoord.y, y);
     534                        }
     535
     536                        psCoordTPToFPA(&testCoord, &fpaCoord, 0.0, 0.0, myFPA);
     537                        if (testCoord.x != fpaCoord.x) {
     538                            printf("ERROR: psCoordFPAToTP() x coord was %f, should be %d\n", cellCoord.x, x);
     539                        }
     540                        if (testCoord.y != fpaCoord.y) {
     541                            printf("ERROR: psCoordFPAToTP() y coord was %f, should be %d\n", cellCoord.y, y);
     542                        }
     543                    }
     544                }
     545                xFPA++;
     546                xReadout++;
     547            }
     548            // We skip the gaps between cells.
     549            for(x=0;x<CELL_GAP;x++) {
     550                xFPA++;
     551                xReadout=0;
     552            }
     553        }
     554        // We skip the gaps between chips.
     555        for (x=0;x<CHIP_GAP;x++) {
     556            xFPA++;
     557            xReadout=0;
     558        }
     559    }
     560
     561    psFree(myFPA);
    300562    return(0);
    301563}
     564//This code is
Note: See TracChangeset for help on using the changeset viewer.