IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2004, 12:11:09 PM (22 years ago)
Author:
desonia
Message:

merged psAstrometry and psCCD, which had recursive header dependencies; yuk!
Also added required includes in other files to allow psAstrometry.h to
work without having to know which other include files are needed before
including a particular header file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astronomy/psAstrometry.c

    r1333 r1382  
    1 // This file contains
    2 
    3 #include "psType.h"
    4 #include "psImage.h"
    5 #include "psArray.h"
    6 #include "psList.h"
     1/** @file  psAstrometry.c
     2*
     3*  @brief This file defines the basic types for astronomical coordinate
     4*  transformation
     5*
     6*  @ingroup AstroImage
     7*
     8*  @author George Gusciora, MHPCC
     9*
     10*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-08-04 22:11:09 $
     12*
     13*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     14*/
     15
     16#include<math.h>
     17
    718#include "psFunctions.h"
    8 
    9 psGrommit *psGrommitAlloc(const psExposure *exp)
    10 {
    11     double *slaGrommit = (double *) psAlloc(14 * sizeof(double));
    12     psGrommit *grommit = (psGrommit *) psAlloc(sizeof(psGrommit));
     19#include "psAstrometry.h"
     20#include "psMemory.h"
     21
     22void grommitFree( psGrommit *grommit );
     23int checkValidChipCoords( double x, double y, psChip *tmpChip );
     24int checkValidImageCoords( double x, double y, psImage *tmpImage );
     25
     26psExposure* psExposureAlloc( double ra, double dec, double hourAngle,
     27                             double zenith, double azimuth, double localTime, float date,
     28                             float rotAngle, float temperature, float pressure, float humidity,
     29                             float exposureTime )
     30{
     31    psExposure * exp = psAlloc( sizeof( psExposure ) );
     32   
     33    *( double* ) & exp->ra = ra;
     34    *( double* ) & exp->dec = dec;
     35    *( double* ) & exp->hourAngle = hourAngle;
     36    *( double* ) & exp->zenith = zenith;
     37    *( double* ) & exp->azimuth = azimuth;
     38    *( double* ) & exp->localTime = localTime;
     39    *( float* ) & exp->date = date;
     40    *( float* ) & exp->rotAngle = rotAngle;
     41    *( float* ) & exp->temperature = temperature;
     42    *( float* ) & exp->pressure = pressure;
     43    *( float* ) & exp->humidity = humidity;
     44    *( float* ) & exp->exposureTime = exposureTime;
     45   
     46    return exp;
     47   
     48}
     49
     50psGrommit* psGrommitAlloc( const psExposure *exp )
     51{
     52    double * slaGrommit = ( double * ) psAlloc( 14 * sizeof( double ) );
     53    psGrommit *grommit = ( psGrommit * ) psAlloc( sizeof( psGrommit ) );
    1354    /*
    1455        extern void sla_aoppa(double date,
     
    3071                  tlr);
    3172    */
    32     grommit->latitude = exp->dec;              // XXX Is this correct?
    33     grommit->sinLat = sin(grommit->latitude);
    34     grommit->cosLat = cos(grommit->latitude);
    35     grommit->abberationMag = 0.0;
    36     grommit->height = 0.0;
    37     grommit->temperature = exp->temperature;
    38     grommit->pressure = exp->pressure;
    39     grommit->humidity = exp->humidity;
    40     grommit->wavelength = 0.0;
    41     grommit->lapseRate = 0.0;
    42     grommit->refractA = 0.0;
    43     grommit->refractB = 0.0;
    44     grommit->longitudeOffset = ra;             // XXX Is this correct?
    45     grommit->siderealTime = 0.0;
    46 
    47     psFree(slaGrommit);
    48     return(grommit);
    49 }
    50 
    51 void p_psGrommitFree(psGrommit *grommit)
    52 {
    53     psFree(grommit);
    54 }
    55 
    56 psCell *psCellinFPA(psCell *out,
    57                     const psPlane *coord,
    58                     const psFPA *FPA)
    59 {
    60     psChip *tmpChip = NULL;
     73    *( double* ) & grommit->latitude = exp->dec;              // XXX Is this correct?
     74    *( double* ) & grommit->sinLat = sin( grommit->latitude );
     75    *( double* ) & grommit->cosLat = cos( grommit->latitude );
     76    *( double* ) & grommit->abberationMag = 0.0;
     77    *( double* ) & grommit->height = 0.0;
     78    *( double* ) & grommit->temperature = exp->temperature;
     79    *( double* ) & grommit->pressure = exp->pressure;
     80    *( double* ) & grommit->humidity = exp->humidity;
     81    *( double* ) & grommit->wavelength = 0.0;
     82    *( double* ) & grommit->lapseRate = 0.0;
     83    *( double* ) & grommit->refractA = 0.0;
     84    *( double* ) & grommit->refractB = 0.0;
     85    *( double* ) & grommit->longitudeOffset = exp->ra;             // XXX Is this correct?
     86    *( double* ) & grommit->siderealTime = 0.0;
     87   
     88    psFree( slaGrommit );
     89    return ( grommit );
     90}
     91
     92void p_psGrommitFree( psGrommit *grommit )
     93{
     94    psFree( grommit );
     95}
     96
     97psCell *psCellinFPA( psCell *out,
     98                     const psPlane *coord,
     99                     const psFPA *FPA )
     100{
     101    psChip * tmpChip = NULL;
    61102    psCell *tmpCell = NULL;
    62 
    63     tmpChip = psChipinFPA(tmpChip, coord, FPA);
    64     tmpCell = psCellinChip(tmpCell, coord, tmpChip);
    65     return(tmpCell);
    66 }
    67 
    68 
    69 p_psCheckValidChipCoords(double x, double y, psChil *tmpChip)
    70 {
    71     return(0);
    72 }
    73 
    74 psChip *psChipinFPA(psChip *out,
    75                     const psPlane *coord,
    76                     const psFPA *FPA)
    77 {
    78     psFPA *tmpChip = NULL;
    79 
    80     for (tmpChip = FPA->chips; tmpChip != NULL; tmpChip++) {
    81         tmpCoord = psPlaneTransformApply(out, tmpChip->fromFPA, coord);
    82         if (p_psCheckValidChipCoords(tmpCoord->x, tmpCoord->y,
    83                                      tmpChip)) {
    84             psFree(tmpCoord);
    85             return(tmpChip);
    86         }
    87         psFree(tmpCoord);
    88     }
    89     psFree(tmpCoord);
    90     return(NULL);
    91 }
    92 
    93 p_psCheckValidImageCoords(double x, double y, psImage *tmpImage)
    94 {
    95     if ((x < 0.0) ||
    96             (x > (double) tmpImage->numCols) ||
    97             (y < 0.0) ||
    98             (y > (double) tmpImage->numRows)) {
    99         return(0);
    100     }
    101     return(1);
     103   
     104    tmpChip = psChipinFPA( tmpChip, coord, FPA );
     105    tmpCell = psCellinChip( tmpCell, coord, tmpChip );
     106    return ( tmpCell );
     107}
     108
     109
     110int checkValidChipCoords( double x, double y, psChip *tmpChip )
     111{
     112    return ( 0 );
     113}
     114
     115psChip *psChipinFPA( psChip *out,
     116                     const psPlane *coord,
     117                     const psFPA *FPA )
     118{
     119    psArray * chips = FPA->chips;
     120    int nChips = chips->n;
     121    psPlane* tmpCoord = NULL;
     122   
     123    for ( int i = 0; i < nChips; i++ ) {
     124            psChip* tmpChip = chips->data[ i ];
     125            tmpCoord = psPlaneTransformApply( tmpCoord, tmpChip->fromFPA, coord );
     126            if ( checkValidChipCoords( tmpCoord->x, tmpCoord->y,
     127                                       tmpChip ) ) {
     128                    psFree( tmpCoord );
     129                    // XXX: George, you didn't use the out parameter!
     130                    return ( tmpChip );
     131                }
     132            psFree( tmpCoord );
     133        }
     134    psFree( tmpCoord );
     135    return ( NULL );
     136}
     137
     138int checkValidImageCoords( double x, double y, psImage *tmpImage )
     139{
     140    if ( ( x < 0.0 ) ||
     141            ( x > ( double ) tmpImage->numCols ) ||
     142            ( y < 0.0 ) ||
     143            ( y > ( double ) tmpImage->numRows ) ) {
     144            return ( 0 );
     145        }
     146    return ( 1 );
    102147}
    103148
     
    115160XXX: must deallocate memory.
    116161 *****************************************************************************/
    117 psCell *psCellinChip(psCell *out,
    118                      const psPlane *coord,
    119                      const psChip *chip)
    120 {
    121     psCell *tmpCell = NULL;
    122     psReadout *tmpReadout = NULL;
    123     psPlane *tmpCoord = NULL;
    124 
    125     for (tmpCell = chip->cells; tmpCell != NULL; tmpCell++) {
    126         if (tmpCell->readouts != NULL) {
    127             tmpReadout = tmpCell->readouts;
    128             tmpCoord = psPlaneTransformApply(out, tmpCell->fromChip, coord);
    129             if (p_psCheckValidImageCoords(tmpCoord->x, tmpCoord->y,
    130                                           tmpReadout->image)) {
    131                 return(tmpCell);
    132             }
    133         }
    134     }
    135     return(NULL);
    136 }
    137 
    138 psPlane *psCoordCelltoChip(psPlane *out,
     162psCell *psCellinChip( psCell *out,
     163                      const psPlane *coord,
     164                      const psChip *chip )
     165{
     166    psPlane * tmpCoord = NULL;
     167    psArray* cells;
     168   
     169    if ( chip == NULL ) {
     170            return NULL;
     171        }
     172       
     173    cells = chip->cells;
     174   
     175    if ( cells == NULL ) {
     176            return NULL;
     177        }
     178       
     179    for ( int i = 0; i < cells->n; i++ ) {
     180            psCell* tmpCell = ( psCell* ) cells->data[ i ];
     181            psArray* readouts = tmpCell->readouts;
     182            if ( readouts != NULL ) {
     183                    for ( int j = 0; j < readouts->n; j++ ) {
     184                            psReadout* tmpReadout = readouts->data[ j ];
     185                            tmpCoord = psPlaneTransformApply( tmpCoord, tmpCell->fromChip, coord );
     186                            if ( checkValidImageCoords( tmpCoord->x, tmpCoord->y,
     187                                                        tmpReadout->image ) ) {
     188                                    return ( tmpCell );
     189                                }
     190                        }
     191                }
     192        }
     193    return ( NULL );
     194}
     195
     196psPlane *psCoordCelltoChip( psPlane *out,
     197                            const psPlane *in,
     198                            const psCell *cell )
     199{
     200    return ( psPlaneTransformApply( out, cell->toChip, in ) );
     201}
     202
     203psPlane *psCoordChipToFPA( psPlane *out,
    139204                           const psPlane *in,
    140                            const psCell *cell)
    141 {
    142     return(psPlaneTransformApply(out, cell->toChip, in));
    143 }
    144 
    145 psPlane *psCoordChipToFPA(psPlane *out,
     205                           const psChip *chip )
     206{
     207    return ( psPlaneTransformApply( out, chip->toFPA, in ) );
     208}
     209
     210psPlane *psCoordFPAtoTP( psPlane *out,
     211                         const psPlane *in,
     212                         const psFPA *fpa )
     213{
     214    // XXX: This code doesn't work; fpa->toTangentPlane is of the wrong type.
     215    // return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
     216    return ( NULL );
     217}
     218
     219// XXX: must wrap SLA_QAPQK here.
     220psSphere *psCoordTPtoSky( psSphere *out,
    146221                          const psPlane *in,
    147                           const psChip *chip)
    148 {
    149     return(psPlaneTransformApply(out, chip->toFPA, in));
    150 }
    151 
    152 psPlane *psCoordFPAtoTP(psPlane *out,
    153                         const psPlane *in,
    154                         const psFPA *fpa)
    155 {
    156     return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
    157 }
    158 
    159 // XXX: must wrap SLA_QAPQK here.
    160 psSphere *psCoordTPtoSky(psSphere *out,
    161                          const psPlane *in,
    162                          const psGrommit *grommit)
     222                          const psGrommit *grommit )
    163223{
    164224    /*
     
    169229        sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, &DAP);
    170230    */
    171 
    172     return(out);
    173 }
    174 
    175 
    176 psPlane *psCoordCellToFPA(psPlane *out,
    177                           const psPlane *in,
    178                           const psCell *cell)
    179 {
    180     return(psPlaneTransformApply(out, cell->toFPA, in));
     231   
     232    return ( out );
     233}
     234
     235
     236psPlane *psCoordCellToFPA( psPlane *out,
     237                           const psPlane *in,
     238                           const psCell *cell )
     239{
     240    return ( psPlaneTransformApply( out, cell->toFPA, in ) );
    181241}
    182242
     
    185245// transformation, as well as a few psPlane structs.  Can this be implemented
    186246// better?
    187 psSphere *psCoordCelltoSky(psSphere *out,
     247psSphere *psCoordCelltoSky( psSphere *out,
     248                            const psPlane *in,
     249                            const psCell *cell )
     250{
     251    psPlane * tmp1 = NULL;
     252    psPlane *tmp2 = NULL;
     253    psFPA *parFPA = ( cell->parent ) ->parent;
     254    psGrommit *tmpGrommit = NULL;
     255   
     256    tmp1 = psPlaneTransformApply( tmp1, cell->toFPA, in );
     257    tmp2 = psPlaneTransformApply( tmp2, parFPA->toTangentPlane, tmp1 );
     258    tmpGrommit = psGrommitAlloc( parFPA->exposure );
     259    tmp3 = psCoordTPtoSky( out, tmp2, psGrommit );
     260   
     261    psFree( tmp1 );
     262    psFree( tmp2 );
     263    psFree( tmpGrommit );
     264   
     265    return ( psCoordTPtoSky( out, tmp2, psGrommit ) );
     266   
     267}
     268
     269psSphere *psCoordCelltoSkyQuick( psSphere *out,
     270                                 const psPlane *in,
     271                                 const psCell *cell )
     272{
     273    psPlane * tmp1 = NULL;
     274   
     275    tmp1 = psPlaneTransformApply( tmp1, cell->toSky, in );
     276   
     277    //XXX: Do something to convert the linear coords in tmp1 to spherical
     278    // coords in out.
     279   
     280    psFree( tmp1 );
     281   
     282    return ( out );
     283}
     284
     285// XXX: must wrap SLA_AOPQK here.
     286psPlane *psCoordSkytoTP( psPlane *out,
     287                         const psSphere *in,
     288                         const psGrommit *grommit )
     289{
     290    extern void sla_AOPQK ( RAP, DAP, AOPRMS, AOB, ZOB, HOB, DOB, ROB );
     291    double AOB;
     292    double ZOB;
     293    double HOB;
     294    double DOB;
     295    double ROB;
     296   
     297    if ( out == NULL ) {
     298            out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
     299        }
     300       
     301    sla_AOPQK( psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB );
     302    out->x = XXX;
     303    out->y = XXX;
     304    return ( out );
     305}
     306
     307psPlane *psCoordTPtoFPA( psPlane *out,
     308                         const psPlane *in,
     309                         const psFPA *fpa )
     310{
     311    return ( psPlaneTransformApply( out, fpa->fromTangentPlane, in ) );
     312}
     313
     314psPlane *psCoordFPAtoChip( psPlane *out,
    188315                           const psPlane *in,
    189                            const psCell *cell)
    190 {
    191     psPlane *tmp1 = NULL;
    192     psPlane *tmp2 = NULL;
    193     psFPA *parFPA = (cell->parent)->parent;
    194     psGrommit *tmpGrommit = NULL;
    195 
    196     tmp1 = psPlaneTransformApply(tmp1, cell->toFPA, in)
    197            tmp2 = psPlaneTransformApply(tmp2, parFPA->toTangentPlane, tmp1)
    198                   tmpGrommit = psGrommitAlloc(parFPA->exposure)
    199                                tmp3 = psCoordTPtoSky(out, tmp2, psGrommit);
    200 
    201     psFree(tmp1);
    202     psFree(tmp2);
    203     psFree(tmpGrommit);
    204 
    205     return(psCoordTPtoSky(out, tmp2, psGrommit);
    206        }
    207 
    208        psSphere *psCoordCelltoSkyQuick(psSphere *out,
    209                                        const psPlane *in,
    210                                        const psCell *cell)
    211        {
    212            psPlane *tmp1 = NULL;
    213 
    214            tmp1 = psPlaneTransformApply(tmp1, cell->toSky, in);
    215 
    216            //XXX: Do something to convert the linear coords in tmp1 to spherical
    217            // coords in out.
    218 
    219            free(tmp1)
    220 
    221            return(out);
    222        }
    223 
    224        // XXX: must wrap SLA_AOPQK here.
    225        psPlane *psCoordSkytoTP(psPlane *out,
    226                                const psSphere *in,
    227                                const psGrommit *grommit)
    228        {
    229            extern void sla_AOPQK (RAP, DAP, AOPRMS, AOB, ZOB, HOB, DOB, ROB);
    230            double AOB;
    231            double ZOB;
    232            double HOB;
    233            double DOB;
    234            double ROB;
    235 
    236            if (out == NULL) {
    237                out = (psPlane *) psAlloc(sizeof(psPlane));
    238            }
    239 
    240            sla_AOPQK(psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB);
    241            out->x = XXX;
    242            out->y = XXX;
    243            return(out);
    244        }
    245 
    246        psPlane *psCoordTPtoFPA(psPlane *out,
    247                                const psPlane *in,
    248                                const psFPA *fpa)
    249        {
    250            return(psPlaneTransformApply(out, fpa->fromTangentPlane, in));
    251        }
    252 
    253        psPlane *psCoordFPAtoChip(psPlane *out,
    254                                  const psPlane *in,
    255                                  const psChip *chip)
    256        {
    257            return(psPlaneTransformApply(out, chip->fromFPA, in));
    258        }
    259 
    260 
    261        psPlane *psCoordChiptoCell(psPlane *out,
    262                                   const psPlane *in,
    263                                   const psCell *cell)
    264        {
    265            return(psPlaneTransformApply(out, cell->fromChip, in));
    266        }
    267 
    268        psPlane *psCoordSkytoCell(psPlane *out,
    269                                  const psSphere *in,
    270                                  const psCell *cell)
    271        {
    272            out = psCoordSkytoTP(out, in, tmpGrommit);
    273            out = psCoordTPtoFPA(out, out, whichFPA);
    274            out = psCoordFPAtoChip(out, out, whichChip);
    275            out = psCoordChiptoCell(out, out, whichCell);
    276 
    277            return(out);
    278        }
    279 
    280        psPlane *psCoordSkytoCellQuick(psPlane *out,
    281                                       const psSphere *in,
    282                                       const psCell *cell)
    283        {
    284            if (out == NULL) {
    285                out = (psPlane *) psAlloc(sizeof(psPlane));
    286            }
    287 
    288            return(out);
    289        }
    290 
    291 
     316                           const psChip *chip )
     317{
     318    return ( psPlaneTransformApply( out, chip->fromFPA, in ) );
     319}
     320
     321
     322psPlane *psCoordChiptoCell( psPlane *out,
     323                            const psPlane *in,
     324                            const psCell *cell )
     325{
     326    return ( psPlaneTransformApply( out, cell->fromChip, in ) );
     327}
     328
     329psPlane *psCoordSkytoCell( psPlane *out,
     330                           const psSphere *in,
     331                           const psCell *cell )
     332{
     333    out = psCoordSkytoTP( out, in, tmpGrommit );
     334    out = psCoordTPtoFPA( out, out, whichFPA );
     335    out = psCoordFPAtoChip( out, out, whichChip );
     336    out = psCoordChiptoCell( out, out, whichCell );
     337   
     338    return ( out );
     339}
     340
     341psPlane *psCoordSkytoCellQuick( psPlane *out,
     342                                const psSphere *in,
     343                                const psCell *cell )
     344{
     345    if ( out == NULL ) {
     346            out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
     347        }
     348       
     349    return ( out );
     350}
     351
     352
     353
     354
Note: See TracChangeset for help on using the changeset viewer.