IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2006, 1:58:13 PM (20 years ago)
Author:
Paul Price
Message:

Changed definition of psArrayAlloc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroUtils.c

    r9373 r9732  
    1010
    1111    for (int i = 0; i < rawstars->n; i++) {
    12         pmAstromObj *raw = rawstars->data[i];
    13        
    14         psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip);
    15         psPlaneDistortApply (raw->TP, fpa->toTangentPlane, raw->FP, 0.0, 0.0);
    16         p_psDeproject (raw->sky, raw->TP, fpa->projection);
     12        pmAstromObj *raw = rawstars->data[i];
     13
     14        psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip);
     15        psPlaneDistortApply (raw->TP, fpa->toTangentPlane, raw->FP, 0.0, 0.0);
     16        p_psDeproject (raw->sky, raw->TP, fpa->projection);
    1717    }
    1818
    1919    for (int i = 0; i < refstars->n; i++) {
    20         pmAstromObj *ref = refstars->data[i];
    21         psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP);
     20        pmAstromObj *ref = refstars->data[i];
     21        psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP);
    2222    }
    2323
     
    3535
    3636    for (int i = 0; i < fpa->chips->n; i++) {
    37         pmChip *chip = fpa->chips->data[i];
    38         for (int j = 0; j < chip->cells->n; j++) {
    39             pmCell *cell = chip->cells->data[j];
    40             for (int k = 0; k < cell->readouts->n; k++) {
    41                 pmReadout *readout = cell->readouts->data[k];
    42 
    43                 psArray *stars = psMetadataLookupPtr (&status, readout->analysis, "STARS.FULLSET");
    44                 stars = psArraySort (stars, pmAstromObjSortByMag);
    45 
    46                 int nSubset = PS_MIN (MAX_NSTARS, stars->n);
    47                 psArray *subset = psArrayAlloc (nSubset);
    48 
    49                 for (int i = 0; i < nSubset; i++) {
    50                     subset->data[i] = stars->data[i];
    51                 }
    52                 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "STARS.SUBSET", PS_DATA_ARRAY, "stars from analysis", subset);
    53             }
    54         }
     37        pmChip *chip = fpa->chips->data[i];
     38        for (int j = 0; j < chip->cells->n; j++) {
     39            pmCell *cell = chip->cells->data[j];
     40            for (int k = 0; k < cell->readouts->n; k++) {
     41                pmReadout *readout = cell->readouts->data[k];
     42
     43                psArray *stars = psMetadataLookupPtr (&status, readout->analysis, "STARS.FULLSET");
     44                stars = psArraySort (stars, pmAstromObjSortByMag);
     45
     46                int nSubset = PS_MIN (MAX_NSTARS, stars->n);
     47                psArray *subset = psArrayAlloc (nSubset);
     48
     49                for (int i = 0; i < nSubset; i++) {
     50                    subset->data[i] = stars->data[i];
     51                }
     52                psMetadataAdd (readout->analysis, PS_LIST_TAIL, "STARS.SUBSET", PS_DATA_ARRAY, "stars from analysis", subset);
     53            }
     54        }
    5555    }
    5656    return true;
     
    6464    // first pass: measure the per-chip solutions, modify the chip.toFPA terms
    6565    for (int i = 0; i < fpa->chips->n; i++) {
    66         pmChip *chip = fpa->chips->data[i];
    67         psastroChipAstrom (chip, config);
    68     }
    69 
    70     // second stage: re-normalize the chip terms, passing the 
     66        pmChip *chip = fpa->chips->data[i];
     67        psastroChipAstrom (chip, config);
     68    }
     69
     70    // second stage: re-normalize the chip terms, passing the
    7171    // average rotation and offset values to the fpa.toSky
    7272    if (RENORM) {
    7373
    74         // this code is needed for the mosastro stage, with multiple chip solutions
    75 
    76         double dX, dY, dT, dN;
    77         dX = dY = dT = dN = 0;
    78 
    79         psPlane origin, P1, P2;
    80         origin.x = 0;
    81         origin.y = 0;
    82 
    83         // calculate the average rotation and boresite offset relative to raw
    84         for (int i = 0; i < fpa->chips->n; i++) {
    85             pmChip *iChip = raw->chips->data[i];
    86             pmChip *oChip = fpa->chips->data[i];
    87 
    88             // offset of chip
    89             psCoordChipToFPA (&P1, &origin, iChip);
    90             psCoordChipToFPA (&P2, &origin, oChip);
    91             dX += (P2.x - P1.x);
    92             dY += (P2.y - P1.y);
    93 
    94             // get parity-independent rotations for old and new solutions
    95             double T1 = psPlaneTransformGetRotation (iChip->toFPA);
    96             double T2 = psPlaneTransformGetRotation (oChip->toFPA);
    97             dT += T2 - T1;
    98             dN ++;
    99         }
    100 
    101         dT /= dN;
    102         dX /= dN;
    103         dY /= dN;
    104 
    105         // R(T)
    106         double PC1_1 = fpa->toTPA->x->coeff[1][0][0][0];
    107         double PC1_2 = fpa->toTPA->x->coeff[0][1][0][0];
    108         double PC2_1 = fpa->toTPA->y->coeff[1][0][0][0];
    109         double PC2_2 = fpa->toTPA->y->coeff[0][1][0][0];
    110 
    111         // R(dT)
    112         double dPC1_1 = +cos (dT);
    113         double dPC1_2 = +sin (dT);
    114         double dPC2_1 = -sin (dT);
    115         double dPC2_2 = +cos (dT);
    116 
    117         // R'(T) = R(T) * R(dT)
    118         double pc1_1 = PC1_1*dPC1_1 + PC1_2*dPC2_1;
    119         double pc1_2 = PC1_1*dPC1_2 + PC1_2*dPC2_2;
    120         double pc2_1 = PC2_1*dPC1_1 + PC2_2*dPC2_1;
    121         double pc2_2 = PC2_1*dPC1_2 + PC2_2*dPC2_2;
    122 
    123         double det = 1.0 / (pc1_1*pc2_2 - pc1_2*pc2_1);
    124 
    125         // R'(-T)  (matrix inverse, not just rotation inverse -- keeps parity)
    126         double pi1_1 = +pc2_2 * det;
    127         double pi1_2 = -pc1_2 * det;
    128         double pi2_1 = -pc2_1 * det;
    129         double pi2_2 = +pc1_1 * det;
    130    
    131         // apply the new modifcations in rotation and boresite
    132         for (int i = 0; i < fpa->chips->n; i++) {
    133             pmChip *oChip = fpa->chips->data[i];
    134 
    135             // r(T)
    136             double pr1_1 = oChip->toFPA->x->coeff[1][0];
    137             double pr1_2 = oChip->toFPA->x->coeff[0][1];
    138             double pr2_1 = oChip->toFPA->y->coeff[1][0];
    139             double pr2_2 = oChip->toFPA->y->coeff[0][1];
    140 
    141             // ri'(T) = R(T) r(t)
    142             double ri1_1 = PC1_1*pr1_1 + PC1_2*pr2_1;
    143             double ri1_2 = PC1_1*pr1_2 + PC1_2*pr2_2;
    144             double ri2_1 = PC2_1*pr1_1 + PC2_2*pr2_1;
    145             double ri2_2 = PC2_1*pr1_2 + PC2_2*pr2_2;
    146 
    147             // r'(T) = R'(-T) ri'(T)
    148             oChip->toFPA->x->coeff[1][0] = pi1_1*ri1_1 + pi1_2*ri2_1;
    149             oChip->toFPA->x->coeff[0][1] = pi1_1*ri1_2 + pi1_2*ri2_2;
    150             oChip->toFPA->y->coeff[1][0] = pi2_1*ri1_1 + pi2_2*ri2_1;
    151             oChip->toFPA->y->coeff[0][1] = pi2_1*ri1_2 + pi2_2*ri2_2;
    152 
    153             double dx = PC1_1*oChip->toFPA->x->coeff[0][0] + PC1_2*oChip->toFPA->y->coeff[0][0] + dX;
    154             double dy = PC2_1*oChip->toFPA->x->coeff[0][0] + PC2_2*oChip->toFPA->y->coeff[0][0] + dY;
    155 
    156             oChip->toFPA->x->coeff[0][0] = pi1_1*dx + pi1_2*dy;
    157             oChip->toFPA->y->coeff[0][0] = pi2_1*dx + pi2_2*dy;
    158         }
    159 
    160         fpa->toTPA->x->coeff[0][0][0][0] -= dX;
    161         fpa->toTPA->y->coeff[0][0][0][0] -= dY;
    162 
    163         fpa->toTPA->x->coeff[1][0][0][0] = pc1_1;
    164         fpa->toTPA->x->coeff[0][1][0][0] = pc1_2;
    165         fpa->toTPA->y->coeff[1][0][0][0] = pc2_1;
    166         fpa->toTPA->y->coeff[0][1][0][0] = pc2_2;
    167     }
    168     return true; 
     74        // this code is needed for the mosastro stage, with multiple chip solutions
     75
     76        double dX, dY, dT, dN;
     77        dX = dY = dT = dN = 0;
     78
     79        psPlane origin, P1, P2;
     80        origin.x = 0;
     81        origin.y = 0;
     82
     83        // calculate the average rotation and boresite offset relative to raw
     84        for (int i = 0; i < fpa->chips->n; i++) {
     85            pmChip *iChip = raw->chips->data[i];
     86            pmChip *oChip = fpa->chips->data[i];
     87
     88            // offset of chip
     89            psCoordChipToFPA (&P1, &origin, iChip);
     90            psCoordChipToFPA (&P2, &origin, oChip);
     91            dX += (P2.x - P1.x);
     92            dY += (P2.y - P1.y);
     93
     94            // get parity-independent rotations for old and new solutions
     95            double T1 = psPlaneTransformGetRotation (iChip->toFPA);
     96            double T2 = psPlaneTransformGetRotation (oChip->toFPA);
     97            dT += T2 - T1;
     98            dN ++;
     99        }
     100
     101        dT /= dN;
     102        dX /= dN;
     103        dY /= dN;
     104
     105        // R(T)
     106        double PC1_1 = fpa->toTPA->x->coeff[1][0][0][0];
     107        double PC1_2 = fpa->toTPA->x->coeff[0][1][0][0];
     108        double PC2_1 = fpa->toTPA->y->coeff[1][0][0][0];
     109        double PC2_2 = fpa->toTPA->y->coeff[0][1][0][0];
     110
     111        // R(dT)
     112        double dPC1_1 = +cos (dT);
     113        double dPC1_2 = +sin (dT);
     114        double dPC2_1 = -sin (dT);
     115        double dPC2_2 = +cos (dT);
     116
     117        // R'(T) = R(T) * R(dT)
     118        double pc1_1 = PC1_1*dPC1_1 + PC1_2*dPC2_1;
     119        double pc1_2 = PC1_1*dPC1_2 + PC1_2*dPC2_2;
     120        double pc2_1 = PC2_1*dPC1_1 + PC2_2*dPC2_1;
     121        double pc2_2 = PC2_1*dPC1_2 + PC2_2*dPC2_2;
     122
     123        double det = 1.0 / (pc1_1*pc2_2 - pc1_2*pc2_1);
     124
     125        // R'(-T)  (matrix inverse, not just rotation inverse -- keeps parity)
     126        double pi1_1 = +pc2_2 * det;
     127        double pi1_2 = -pc1_2 * det;
     128        double pi2_1 = -pc2_1 * det;
     129        double pi2_2 = +pc1_1 * det;
     130
     131        // apply the new modifcations in rotation and boresite
     132        for (int i = 0; i < fpa->chips->n; i++) {
     133            pmChip *oChip = fpa->chips->data[i];
     134
     135            // r(T)
     136            double pr1_1 = oChip->toFPA->x->coeff[1][0];
     137            double pr1_2 = oChip->toFPA->x->coeff[0][1];
     138            double pr2_1 = oChip->toFPA->y->coeff[1][0];
     139            double pr2_2 = oChip->toFPA->y->coeff[0][1];
     140
     141            // ri'(T) = R(T) r(t)
     142            double ri1_1 = PC1_1*pr1_1 + PC1_2*pr2_1;
     143            double ri1_2 = PC1_1*pr1_2 + PC1_2*pr2_2;
     144            double ri2_1 = PC2_1*pr1_1 + PC2_2*pr2_1;
     145            double ri2_2 = PC2_1*pr1_2 + PC2_2*pr2_2;
     146
     147            // r'(T) = R'(-T) ri'(T)
     148            oChip->toFPA->x->coeff[1][0] = pi1_1*ri1_1 + pi1_2*ri2_1;
     149            oChip->toFPA->x->coeff[0][1] = pi1_1*ri1_2 + pi1_2*ri2_2;
     150            oChip->toFPA->y->coeff[1][0] = pi2_1*ri1_1 + pi2_2*ri2_1;
     151            oChip->toFPA->y->coeff[0][1] = pi2_1*ri1_2 + pi2_2*ri2_2;
     152
     153            double dx = PC1_1*oChip->toFPA->x->coeff[0][0] + PC1_2*oChip->toFPA->y->coeff[0][0] + dX;
     154            double dy = PC2_1*oChip->toFPA->x->coeff[0][0] + PC2_2*oChip->toFPA->y->coeff[0][0] + dY;
     155
     156            oChip->toFPA->x->coeff[0][0] = pi1_1*dx + pi1_2*dy;
     157            oChip->toFPA->y->coeff[0][0] = pi2_1*dx + pi2_2*dy;
     158        }
     159
     160        fpa->toTPA->x->coeff[0][0][0][0] -= dX;
     161        fpa->toTPA->y->coeff[0][0][0][0] -= dY;
     162
     163        fpa->toTPA->x->coeff[1][0][0][0] = pc1_1;
     164        fpa->toTPA->x->coeff[0][1][0][0] = pc1_2;
     165        fpa->toTPA->y->coeff[1][0][0][0] = pc2_1;
     166        fpa->toTPA->y->coeff[0][1][0][0] = pc2_2;
     167    }
     168    return true;
    169169}
    170170
     
    174174
    175175    for (int i = 0; i < input->nX; i++) {
    176         for (int j = 0; j < input->nY; j++) {
    177             output->mask[i][j]     = input->mask[i][j];
    178             output->coeff[i][j]    = input->coeff[i][j];
    179             output->coeffErr[i][j] = input->coeffErr[i][j];
    180         }
     176        for (int j = 0; j < input->nY; j++) {
     177            output->mask[i][j]     = input->mask[i][j];
     178            output->coeff[i][j]    = input->coeff[i][j];
     179            output->coeffErr[i][j] = input->coeffErr[i][j];
     180        }
    181181    }
    182182    return (output);
     
    188188
    189189    for (int i = 0; i < input->nX; i++) {
    190         for (int j = 0; j < input->nY; j++) {
    191             for (int k = 0; k < input->nZ; k++) {
    192                 for (int m = 0; m < input->nT; m++) {
    193                     output->mask[i][j][k][m]     = input->mask[i][j][k][m];
    194                     output->coeff[i][j][k][m]    = input->coeff[i][j][k][m];
    195                     output->coeffErr[i][j][k][m] = input->coeffErr[i][j][k][m];
    196                 }
    197             }
    198         }
     190        for (int j = 0; j < input->nY; j++) {
     191            for (int k = 0; k < input->nZ; k++) {
     192                for (int m = 0; m < input->nT; m++) {
     193                    output->mask[i][j][k][m]     = input->mask[i][j][k][m];
     194                    output->coeff[i][j][k][m]    = input->coeff[i][j][k][m];
     195                    output->coeffErr[i][j][k][m] = input->coeffErr[i][j][k][m];
     196                }
     197            }
     198        }
    199199    }
    200200    return (output);
     
    206206
    207207    for (int i = 0; i < input->x->nX; i++) {
    208         for (int j = 0; j < input->x->nY; j++) {
    209             for (int k = 0; k < input->x->nZ; k++) {
    210                 for (int m = 0; m < input->x->nT; m++) {
    211                     // x-terms
    212                     output->x->mask[i][j][k][m]     = input->x->mask[i][j][k][m];
    213                     output->x->coeff[i][j][k][m]    = input->x->coeff[i][j][k][m];
    214                     output->x->coeffErr[i][j][k][m] = input->x->coeffErr[i][j][k][m];
    215                     // y-terms
    216                     output->y->mask[i][j][k][m]     = input->y->mask[i][j][k][m];
    217                     output->y->coeff[i][j][k][m]    = input->y->coeff[i][j][k][m];
    218                     output->y->coeffErr[i][j][k][m] = input->y->coeffErr[i][j][k][m];
    219                 }
    220             }
    221         }
     208        for (int j = 0; j < input->x->nY; j++) {
     209            for (int k = 0; k < input->x->nZ; k++) {
     210                for (int m = 0; m < input->x->nT; m++) {
     211                    // x-terms
     212                    output->x->mask[i][j][k][m]     = input->x->mask[i][j][k][m];
     213                    output->x->coeff[i][j][k][m]    = input->x->coeff[i][j][k][m];
     214                    output->x->coeffErr[i][j][k][m] = input->x->coeffErr[i][j][k][m];
     215                    // y-terms
     216                    output->y->mask[i][j][k][m]     = input->y->mask[i][j][k][m];
     217                    output->y->coeff[i][j][k][m]    = input->y->coeff[i][j][k][m];
     218                    output->y->coeffErr[i][j][k][m] = input->y->coeffErr[i][j][k][m];
     219                }
     220            }
     221        }
    222222    }
    223223    return (output);
     
    229229
    230230    for (int i = 0; i < input->x->nX; i++) {
    231         for (int j = 0; j < input->x->nY; j++) {
    232             // x-terms
    233             output->x->mask[i][j]     = input->x->mask[i][j];
    234             output->x->coeff[i][j]    = input->x->coeff[i][j];
    235             output->x->coeffErr[i][j] = input->x->coeffErr[i][j];
    236             // y-terms
    237             output->y->mask[i][j]     = input->y->mask[i][j];
    238             output->y->coeff[i][j]    = input->y->coeff[i][j];
    239             output->y->coeffErr[i][j] = input->y->coeffErr[i][j];
    240         }
     231        for (int j = 0; j < input->x->nY; j++) {
     232            // x-terms
     233            output->x->mask[i][j]     = input->x->mask[i][j];
     234            output->x->coeff[i][j]    = input->x->coeff[i][j];
     235            output->x->coeffErr[i][j] = input->x->coeffErr[i][j];
     236            // y-terms
     237            output->y->mask[i][j]     = input->y->mask[i][j];
     238            output->y->coeff[i][j]    = input->y->coeff[i][j];
     239            output->y->coeffErr[i][j] = input->y->coeffErr[i][j];
     240        }
    241241    }
    242242    return (output);
     
    287287    if (map->y->nX < 1) return 0;
    288288    if (map->y->nY < 1) return 0;
    289    
     289
    290290    double pc1_1 = map->x->coeff[1][0];
    291291    double pc1_2 = map->x->coeff[0][1];
     
    299299    double t1 = -atan2 (px*pc1_2, px*pc1_1);
    300300    double t2 = +atan2 (py*pc2_1, py*pc2_2);
    301    
     301
    302302    // careful near -pi,+pi boundary...
    303303    if (t1 - t2 > M_PI/2) t2 += 2*M_PI;
     
    307307    while (theta < M_PI) theta += 2*M_PI;
    308308    while (theta > M_PI) theta -= 2*M_PI;
    309    
     309
    310310    return (theta);
    311311}
Note: See TracChangeset for help on using the changeset viewer.