Changeset 9732 for trunk/psastro/src/psastroUtils.c
- Timestamp:
- Oct 24, 2006, 1:58:13 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroUtils.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroUtils.c
r9373 r9732 10 10 11 11 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); 17 17 } 18 18 19 19 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); 22 22 } 23 23 … … 35 35 36 36 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 } 55 55 } 56 56 return true; … … 64 64 // first pass: measure the per-chip solutions, modify the chip.toFPA terms 65 65 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 71 71 // average rotation and offset values to the fpa.toSky 72 72 if (RENORM) { 73 73 74 // this code is needed for the mosastro stage, with multiple chip solutions75 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 raw84 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 chip89 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 solutions95 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 boresite132 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; 169 169 } 170 170 … … 174 174 175 175 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 } 181 181 } 182 182 return (output); … … 188 188 189 189 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 } 199 199 } 200 200 return (output); … … 206 206 207 207 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-terms212 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-terms216 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 } 222 222 } 223 223 return (output); … … 229 229 230 230 for (int i = 0; i < input->x->nX; i++) { 231 for (int j = 0; j < input->x->nY; j++) {232 // x-terms233 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-terms237 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 } 241 241 } 242 242 return (output); … … 287 287 if (map->y->nX < 1) return 0; 288 288 if (map->y->nY < 1) return 0; 289 289 290 290 double pc1_1 = map->x->coeff[1][0]; 291 291 double pc1_2 = map->x->coeff[0][1]; … … 299 299 double t1 = -atan2 (px*pc1_2, px*pc1_1); 300 300 double t2 = +atan2 (py*pc2_1, py*pc2_2); 301 301 302 302 // careful near -pi,+pi boundary... 303 303 if (t1 - t2 > M_PI/2) t2 += 2*M_PI; … … 307 307 while (theta < M_PI) theta += 2*M_PI; 308 308 while (theta > M_PI) theta -= 2*M_PI; 309 309 310 310 return (theta); 311 311 }
Note:
See TracChangeset
for help on using the changeset viewer.
