IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1475


Ignore:
Timestamp:
Aug 11, 2004, 10:07:44 AM (22 years ago)
Author:
gusciora
Message:

...

Location:
trunk/psLib/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psCoord.c

    r1463 r1475  
    1111*  @author George Gusciora, MHPCC
    1212*
    13 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-08-10 23:59:41 $
     13*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-11 20:07:44 $
    1515*
    1616*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3939    }
    4040    out->x = transform->x->coeff[0][0] +
    41              (transform->x->coeff[1][0] * coords->x) + (transform->x->coeff[0][1] * coords->y);
     41             (transform->x->coeff[1][0] * coords->x) +
     42             (transform->x->coeff[0][1] * coords->y);
    4243
    4344    out->y = transform->y->coeff[0][0] +
    44              (transform->y->coeff[1][0] * coords->x) + (transform->y->coeff[0][1] * coords->y);
     45             (transform->y->coeff[1][0] * coords->x) +
     46             (transform->y->coeff[0][1] * coords->y);
    4547
    4648    return (out);
     
    4850
    4951// This transformation takes into account parameters beyond an objects
    50 // spatial coordinates: term3 and term4.
     52// spatial coordinates: term3 and term4 (magnitude and color).
    5153psPlane* psPlaneDistortApply(psPlane* out,
    5254                             const psPlaneDistort* transform,
  • trunk/psLib/src/astronomy/psAstrometry.c

    r1463 r1475  
    88*  @author George Gusciora, MHPCC
    99*
    10 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-08-10 23:59:41 $
     10*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-08-11 20:07:44 $
    1212*
    1313*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1919#include "psAstrometry.h"
    2020#include "psMemory.h"
    21 
    22 static int checkValidChipCoords(double x, double y, psChip* tmpChip);
    23 static int checkValidImageCoords(double x, double y, psImage* tmpImage);
    2421
    2522psExposure* psExposureAlloc(double ra, double dec, double hourAngle,
     
    4441
    4542    return exp;
    46 
    4743}
    4844
    4945/*
    50     Several members of the psGrommit data structure have no direct counterpart
    51     in the psExposure structure.  How are we to determine them?
     46    XXX: Several members of the psGrommit data structure have no direct
     47    counterpart in the psExposure structure.  How are we to determine them?
    5248*/
    5349psGrommit* psGrommitAlloc(const psExposure* exp)
    5450{
    55     double *slaGrommit = (double *)psAlloc(14 * sizeof(double));
     51    // XXX: is this the correct action?
     52    if (exp == NULL) {
     53        return(NULL);
     54    }
     55
    5656    psGrommit* grommit = (psGrommit* ) psAlloc(sizeof(psGrommit));
    5757
     
    7777    *(double *)&grommit->siderealTime = 0.0;
    7878
    79     psFree(slaGrommit);
    8079    return (grommit);
    8180}
    8281
     82/*
     83 * XXX: The SDRS states this should be a private p_ps() procedure.
     84 */
    8385void psGrommitFree(psGrommit* grommit)
    8486{
     
    8688}
    8789
    88 psCell* psCellinFPA(psCell* out, const psPlane* coord, const psFPA* FPA)
     90psCell* psCellinFPA(psCell* outCell,
     91                    const psPlane* fpaCoord,
     92                    const psFPA* FPA)
    8993{
    9094    psChip* tmpChip = NULL;
    91     psCell* tmpCell = NULL;
    92 
    93     tmpChip = psChipinFPA(tmpChip, coord, FPA);
    94     tmpCell = psCellinChip(tmpCell, coord, tmpChip);
    95     return (tmpCell);
    96 }
    97 
    98 /*
    99     XXX: do this
    100 */
    101 int checkValidChipCoords(double x, double y, psChip* tmpChip)
    102 {
    103     return (0);
    104 }
    105 
    106 psChip* psChipinFPA(psChip* out, const psPlane* coord, const psFPA* FPA)
     95    psPlane* chipCoord = NULL;
     96
     97    if (FPA == NULL) {
     98        return(NULL);
     99    }
     100    if (fpaCoord == NULL) {
     101        return(NULL);
     102    }
     103
     104    // Determine which chip contains the fpaCoords.
     105    tmpChip = psChipinFPA(tmpChip, fpaCoord, FPA);
     106
     107    // Convert to those chip coordinates.
     108    chipCoord = psCoordFPAtoChip(chipCoord, fpaCoord, tmpChip);
     109
     110    // Determine which cell contains those chip coordinates.
     111    outCell = psCellinChip(outCell, chipCoord, tmpChip);
     112
     113    psFree(tmpChip);
     114    psFree(chipCoord);
     115
     116    return (outCell);
     117}
     118
     119int p_psCheckValidImageCoords(double x,
     120                              double y,
     121                              psImage* tmpImage)
     122{
     123    if (tmpImage == NULL) {
     124        return(0);
     125    }
     126
     127    if ((x < 0.0) ||
     128            (x > (double)tmpImage->numCols) ||
     129            (y < 0.0) ||
     130            (y > (double)tmpImage->numRows)) {
     131        return (0);
     132    }
     133
     134    return (1);
     135}
     136
     137/*****************************************************************************
     138    XXX: Return the answer in "out".
     139 *****************************************************************************/
     140psChip* psChipinFPA(psChip* out,
     141                    const psPlane* fpaCoord,
     142                    const psFPA* FPA)
    107143{
    108144    psArray* chips = FPA->chips;
    109145    int nChips = chips->n;
    110     psPlane* tmpCoord = NULL;
    111 
     146    psPlane* chipCoord = NULL;
     147    psCell *tmpCell = NULL;
     148
     149    // Loop through every chip in this FPA.  Convert the original
     150    // FPA coordinates to chip coordinates for that chip.  Then,
     151    // determine if any cells in that chip contain those chip
     152    // coordinates.
    112153    for (int i = 0; i < nChips; i++) {
    113154        psChip* tmpChip = chips->data[i];
    114155
    115         tmpCoord = psPlaneTransformApply(tmpCoord, tmpChip->fromFPA, coord);
    116         if (checkValidChipCoords(tmpCoord->x, tmpCoord->y, tmpChip)) {
    117             psFree(tmpCoord);
    118             // XXX: George, you didn't use the out parameter!
    119             return (tmpChip);
     156        chipCoord = psPlaneTransformApply(chipCoord, tmpChip->fromFPA, fpaCoord);
     157        tmpCell = psCellinChip(tmpCell, chipCoord, tmpChip);
     158        if (tmpCell != NULL) {
     159            psFree(chipCoord);
     160            return(tmpChip);
    120161        }
    121         psFree(tmpCoord);
    122     }
    123     psFree(tmpCoord);
     162        psFree(chipCoord);
     163    }
     164
    124165    return (NULL);
    125166}
    126167
    127 /*
    128     XXX: do this
    129 */
    130 int checkValidImageCoords(double x, double y, psImage* tmpImage)
    131 {
    132     if ((x < 0.0) || (x > (double)tmpImage->numCols) || (y < 0.0) || (y > (double)tmpImage->numRows)) {
    133         return (0);
    134     }
    135     return (1);
    136 }
    137 
    138168/*****************************************************************************
    139169XXX: We assume that readouts have valid coordinates from the range
    140 (0,numRows or numCols) in each dimension, and that they are square with the
    141 x/y axis.
    142  
     170    (0,numRows or numCols) in each dimension, and that they are square with the
     171     x/y axis.
    143172XXX: We assume that if a cell has more than one readout, all readouts have
    144 the same coordinates.
    145  
     173     the same coordinates.
    146174XXX: if we find no cell with has this coordinate, we return NULL.
    147  
    148175XXX: must deallocate memory.
    149  *****************************************************************************/
    150 psCell* psCellinChip(psCell* out, const psPlane* coord, const psChip* chip)
    151 {
    152     int i = 0;
    153     psPlane* tmpCoord = NULL;
     176XXX: must return the cell in the "outCell" parameter.
     177XXX: verify the NULL parameter error handling.
     178 *****************************************************************************/
     179psCell* psCellinChip(psCell* outCell,
     180                     const psPlane* chipCoord,
     181                     const psChip* chip)
     182{
     183    psPlane* cellCoord = NULL;
    154184    psArray* cells;
    155185
     186    // We return NULL if either of the input parameters is NULL.
    156187    if (chip == NULL) {
    157188        return NULL;
    158189    }
    159190
     191    if (chipCoord == NULL) {
     192        return NULL;
     193    }
     194
    160195    cells = chip->cells;
    161 
    162196    if (cells == NULL) {
    163197        return NULL;
    164198    }
    165199
    166     for (i = 0; i < cells->n; i++) {
     200    // We loop over each cell in the chip.  We transform the chipCoord into
     201    // a cellCoord for that cell and determine if that cellCoord is valid.
     202    // If so, then we return that cell.
     203    for (int i = 0; i < cells->n; i++) {
    167204        psCell* tmpCell = (psCell* ) cells->data[i];
    168205        psArray* readouts = tmpCell->readouts;
    169206
     207        // We only check a single readout for this cell since we assume that
     208        // all readouts for a cell have identical parameters.
    170209        if (readouts != NULL) {
    171             for (int j = 0; j < readouts->n; j++) {
    172                 psReadout* tmpReadout = readouts->data[j];
    173 
    174                 tmpCoord = psPlaneTransformApply(tmpCoord, tmpCell->fromChip, coord);
    175                 if (checkValidImageCoords(tmpCoord->x, tmpCoord->y, tmpReadout->image)) {
    176                     return (tmpCell);
    177                 }
     210            psReadout* tmpReadout = readouts->data[0];
     211
     212            cellCoord = psPlaneTransformApply(cellCoord,
     213                                              tmpCell->fromChip,
     214                                              chipCoord);
     215
     216            if (p_psCheckValidImageCoords(cellCoord->x, cellCoord->y, tmpReadout->image)) {
     217                psFree(cellCoord);
     218                return (tmpCell);
    178219            }
    179220        }
    180221    }
     222
     223    psFree(cellCoord);
    181224    return (NULL);
    182225}
    183226
    184 psPlane* psCoordCelltoChip(psPlane* out, const psPlane* in, const psCell* cell)
    185 {
    186     return (psPlaneTransformApply(out, cell->toChip, in));
    187 }
    188 
    189 psPlane* psCoordChipToFPA(psPlane* out, const psPlane* in, const psChip* chip)
    190 {
    191     return (psPlaneTransformApply(out, chip->toFPA, in));
    192 }
    193 
    194 psPlane* psCoordFPAtoTP(psPlane* out, const psPlane* in, const psFPA* fpa)
    195 {
    196     // XXX: This code doesn't work; fpa->toTangentPlane is of the wrong type.
    197     // return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
    198     return (NULL);
     227psPlane* psCoordCelltoChip(psPlane* outCoord,
     228                           const psPlane* inCoord,
     229                           const psCell* cell)
     230{
     231    return (psPlaneTransformApply(outCoord, cell->toChip, inCoord));
     232}
     233
     234psPlane* psCoordChipToFPA(psPlane* outCoord,
     235                          const psPlane* inCoord,
     236                          const psChip* chip)
     237{
     238    return (psPlaneTransformApply(outCoord, chip->toFPA, inCoord));
     239}
     240
     241/*****************************************************************************
     242XXX: must determine the correct values for XXX_Mag and XXX_Col;
     243 *****************************************************************************/
     244psPlane* psCoordFPAtoTP(psPlane* outCoord,
     245                        const psPlane* inCoord,
     246                        const psFPA* fpa)
     247{
     248    float XXX_Mag = 0.0;
     249    float XXX_Col = 0.0;
     250
     251    return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord,
     252                               XXX_Mag, XXX_Col));
    199253}
    200254
    201255// XXX: must wrap SLA_QAPQK here.
    202 psSphere* psCoordTPtoSky(psSphere* out, const psPlane* in, const psGrommit* grommit)
    203 {
     256psSphere* psCoordTPtoSky(psSphere* outSphere,
     257                         const psPlane* tpCoord,
     258                         const psGrommit* grommit)
     259{
     260    if (outSphere == NULL) {
     261        outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
     262    }
     263
    204264    /*
    205265     * double RAP; double DAP;
    206266     *
    207      * extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP); sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP,
    208      * &DAP); */
    209 
    210     return (out);
    211 }
    212 
    213 psPlane* psCoordCellToFPA(psPlane* out, const psPlane* in, const psCell* cell)
    214 {
    215     return (psPlaneTransformApply(out, cell->toFPA, in));
    216 }
    217 
    218 // XXX: This implementation requires a new psGrommit be created for each
    219 // transformation, as well as a few psPlane structs.  Can this be implemented
    220 // better?
    221 psSphere* psCoordCelltoSky(psSphere* out,
    222                            const psPlane* in,
     267     * extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP);
     268     * sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, &DAP);
     269     */
     270
     271    return (outSphere);
     272}
     273
     274psPlane* psCoordCellToFPA(psPlane* fpaCoord,
     275                          const psPlane* cellCoord,
     276                          const psCell* cell)
     277{
     278    return (psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord));
     279}
     280
     281/*****************************************************************************
     282XXX: This implementation requires a new psGrommit be created for each
     283     transformation, as well as a few psPlane structs.  Can this be implemented
     284     better?
     285XXX: must determine the correct values for XXX_Mag and XXX_Col;
     286 *****************************************************************************/
     287psSphere* psCoordCelltoSky(psSphere* skyCoord,
     288                           const psPlane* cellCoord,
    223289                           const psCell* cell)
    224290{
    225     psPlane* tmp1 = NULL;
    226     psPlane* tmp2 = NULL;
     291    psPlane* fpaCoord = NULL;
     292    psPlane* tpCoord = NULL;
    227293    psFPA* parFPA = (cell->parent)->parent;
    228294    psGrommit* tmpGrommit = NULL;
    229     float XXX1 = 0.0;
    230     float XXX2 = 0.0;
    231 
    232 
    233     tmp1 = psPlaneTransformApply(tmp1, cell->toFPA, in);
    234     // XXX:
    235     //
    236     tmp2 = psPlaneDistortApply(tmp2, parFPA->toTangentPlane, tmp1, XXX1, XXX2);
     295    float XXX_Mag = 0.0;
     296    float XXX_Col = 0.0;
     297
     298    // Convert the input cell coordinates to FPA coordinates.
     299    fpaCoord = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord);
     300
     301    // Convert the FPA coordinates to tangent plane Coordinates.
     302    tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane, fpaCoord, XXX_Mag, XXX_Col);
     303
     304    // Generate a grommit for this FPA.
    237305    tmpGrommit = psGrommitAlloc(parFPA->exposure);
     306
     307    // Convert the tangent plane Coordinates to sky coordinates.
     308    skyCoord = psCoordTPtoSky(skyCoord, tpCoord, tmpGrommit);
     309
     310    psFree(fpaCoord);
     311    psFree(tpCoord);
     312    psFree(tmpGrommit);
     313
     314    return(skyCoord);
     315}
     316
     317/*****************************************************************************
     318XXX: not done
     319 *****************************************************************************/
     320psSphere* psCoordCelltoSkyQuick(psSphere* outSphere,
     321                                const psPlane* cellCoord,
     322                                const psCell* cell)
     323{
     324    psPlane* tmp1 = NULL;
     325
     326    if (outSphere == NULL) {
     327        outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
     328    }
     329
     330    tmp1 = psPlaneTransformApply(tmp1, cell->toSky, cellCoord);
     331
     332    // XXX: Do something to convert the linear coords in tmp1 to spherical
     333    // coords in outSphere.
     334
    238335    psFree(tmp1);
    239     psFree(tmp2);
    240     psFree(tmpGrommit);
    241 
    242     return(psCoordTPtoSky(out, tmp2, tmpGrommit));
    243 }
    244 
    245 psSphere* psCoordCelltoSkyQuick(psSphere* out, const psPlane* in, const psCell* cell)
    246 {
    247     psPlane* tmp1 = NULL;
    248 
    249     tmp1 = psPlaneTransformApply(tmp1, cell->toSky, in);
    250 
    251     // XXX: Do something to convert the linear coords in tmp1 to spherical
    252     // coords in out.
    253 
    254     psFree(tmp1);
    255 
    256     return (out);
    257 }
    258 
    259 // XXX: must wrap SLA_AOPQK here.
    260 psPlane* psCoordSkytoTP(psPlane* out, const psSphere* in, const psGrommit* grommit)
     336
     337    return (outSphere);
     338}
     339
     340/*****************************************************************************
     341XXX: must wrap SLA_AOPQK here.
     342 *****************************************************************************/
     343psPlane* psCoordSkytoTP(psPlane* tpCoord,
     344                        const psSphere* in,
     345                        const psGrommit* grommit)
    261346{
    262347    /*
     
    268353        double ROB;
    269354     
    270         if (out == NULL) {
    271             out = (psPlane* ) psAlloc(sizeof(psPlane));
     355        if (tpCoord == NULL) {
     356            tpCoord = (psPlane* ) psAlloc(sizeof(psPlane));
    272357        }
    273358     
    274359        sla_AOPQK(psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB);
    275         out->x = XXX;
    276         out->y = XXX;
    277         return (out);
     360        tpCoord->x = XXX;
     361        tpCoord->y = XXX;
     362        return (tpCoord);
    278363    */
    279364    return(NULL);
     
    281366
    282367
    283 /*
    284     XXX: What are the XXX1 and XXX2 args supposed to be?
    285 */
    286 psPlane* psCoordTPtoFPA(psPlane* out, const psPlane* in, const psFPA* fpa)
    287 {
    288     float XXX1 = 0.0;
    289     float XXX2 = 0.0;
    290 
    291     return (psPlaneDistortApply(out, fpa->fromTangentPlane, in, XXX1, XXX2));
    292 }
    293 
    294 psPlane* psCoordFPAtoChip(psPlane* out, const psPlane* in, const psChip* chip)
    295 {
    296     return (psPlaneTransformApply(out, chip->fromFPA, in));
    297 }
    298 
    299 psPlane* psCoordChiptoCell(psPlane* out, const psPlane* in, const psCell* cell)
    300 {
    301     return (psPlaneTransformApply(out, cell->fromChip, in));
    302 }
    303 
    304 psPlane* psCoordSkytoCell(psPlane* out, const psSphere* in, const psCell* cell)
     368/*****************************************************************************
     369XXX: must determine the correct values for XXX_Mag and XXX_Col;
     370 *****************************************************************************/
     371psPlane* psCoordTPtoFPA(psPlane* fpaCoord,
     372                        const psPlane* tpCoord,
     373                        const psFPA* fpa)
     374{
     375    float XXX_Mag = 0.0;
     376    float XXX_Col = 0.0;
     377
     378    return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane,
     379                                tpCoord, XXX_Mag, XXX_Col));
     380}
     381
     382/*****************************************************************************
     383XXX: must first determine which chip contains this chipcoord.
     384 *****************************************************************************/
     385psPlane* psCoordFPAtoChip(psPlane* chipCoord,
     386                          const psPlane* fpaCoord,
     387                          const psChip* chip)
     388{
     389    return (psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord));
     390}
     391
     392/*****************************************************************************
     393XXX: must first determine which cell contains this chipcoord.
     394 *****************************************************************************/
     395psPlane* psCoordChiptoCell(psPlane* cellCoord,
     396                           const psPlane* chipCoord,
     397                           const psCell* cell)
     398{
     399    return (psPlaneTransformApply(cellCoord, cell->fromChip, chipCoord));
     400}
     401
     402/*****************************************************************************
     403XXX: once this works, get rid of the individual pointers for the various
     404     coords.
     405XXX: How do we determine the grommit for the sky->tp coordinate conversion?
     406XXX: must determine which cell contains this chipcoord.
     407 *****************************************************************************/
     408psPlane* psCoordSkytoCell(psPlane* cellCoord,
     409                          const psSphere* skyCoord,
     410                          const psCell* cell)
    305411{
    306412    psGrommit* XXXGrommit = NULL;
    307     psFPA *whichFPA = NULL;
    308     psChip *whichChip = NULL;
    309     psCell *whichCell = NULL;
    310 
    311     out = psCoordSkytoTP(out, in, XXXGrommit);
    312     out = psCoordTPtoFPA(out, out, whichFPA);
    313     out = psCoordFPAtoChip(out, out, whichChip);
    314     out = psCoordChiptoCell(out, out, whichCell);
    315 
    316     return (out);
    317 }
    318 
    319 psPlane* psCoordSkytoCellQuick(psPlane* out, const psSphere* in, const psCell* cell)
    320 {
    321     if (out == NULL) {
    322         out = (psPlane* ) psAlloc(sizeof(psPlane));
    323     }
    324 
    325     return (out);
    326 }
     413    psChip *whichChip = cell->parent;
     414    psFPA *whichFPA = whichChip->parent;
     415
     416    // Convert the skyCoords to tangent plane coords.
     417    psPlane *tpCoord = psCoordSkytoTP(tpCoord, skyCoord, XXXGrommit);
     418
     419    // Convert the tangent plane coords to FPA coords.
     420    psPlane *fpaCoord = psCoordTPtoFPA(fpaCoord, tpCoord, whichFPA);
     421
     422    // Convert the FPA coords to chip coords.
     423    psPlane *chipCoord = psCoordFPAtoChip(chipCoord, fpaCoord, whichChip);
     424
     425    // Convert the chip coords to cell coords.
     426    cellCoord = psCoordChiptoCell(cellCoord, chipCoord, cell);
     427
     428    psFree(tpCoord);
     429    psFree(fpaCoord);
     430    psFree(chipCoord);
     431
     432    return (cellCoord);
     433}
     434
     435/*****************************************************************************
     436XXX: It is unclear how to perform this transformation.
     437 *****************************************************************************/
     438psPlane* psCoordSkytoCellQuick(psPlane* cellCoord,
     439                               const psSphere* skyCoord,
     440                               const psCell* cell)
     441{
     442    if (cellCoord == NULL) {
     443        cellCoord = (psPlane* ) psAlloc(sizeof(psPlane));
     444    }
     445
     446    return (cellCoord);
     447}
  • trunk/psLib/src/astronomy/psAstrometry.h

    r1463 r1475  
    99*  @author George Gusciora, MHPCC
    1010*
    11 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-08-10 23:59:41 $
     11*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-08-11 20:07:44 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    238238                         );
    239239
     240/// XXX: This is defined as a private p_ps() type of function in the SDRS.
     241/// I changed this to a public function.
    240242void psGrommitFree(psGrommit *grommit);
    241243
Note: See TracChangeset for help on using the changeset viewer.