Changeset 7014 for trunk/psastro/src/psastroUtils.c
- Timestamp:
- Apr 30, 2006, 12:15:03 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroUtils.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroUtils.c
r6176 r7014 1 1 # include "psastro.h" 2 2 # define RENORM 0 3 4 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip, psArray *rawstars, psArray *refstars) { 5 6 // XXX this region needs to be defined more intelligently 7 psRegion region = {0, 0, 2000, 4500}; 8 psFree (chip->fromFPA); 9 chip->fromFPA = psPlaneTransformInvert (NULL, chip->toFPA, region, 20); 10 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); 17 } 18 19 for (int i = 0; i < refstars->n; i++) { 20 pmAstromObj *ref = refstars->data[i]; 21 psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP); 22 } 23 24 return true; 25 } 26 27 # if 0 3 28 4 29 bool psastroSelectBrightStars (pmFPA *fpa, psMetadata *config) { … … 143 168 return true; 144 169 } 170 171 psPolynomial2D *psPolynomial2DCopy (psPolynomial2D *input) { 172 173 psPolynomial2D *output = psPolynomial2DAlloc (input->nX, input->nY, input->type); 174 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 } 181 } 182 return (output); 183 } 184 185 psPolynomial4D *psPolynomial4DCopy (psPolynomial4D *input) { 186 187 psPolynomial4D *output = psPolynomial4DAlloc (input->nX, input->nY, input->nZ, input->nT, input->type); 188 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 } 199 } 200 return (output); 201 } 202 203 psPlaneDistort *psPlaneDistortCopy (psPlaneDistort *input) { 204 205 psPlaneDistort *output = psPlaneDistortAlloc (input->x->nX, input->x->nY, input->x->nZ, input->x->nT); 206 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-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 } 223 return (output); 224 } 225 226 psPlaneTransform *psPlaneTransformCopy (psPlaneTransform *input) { 227 228 psPlaneTransform *output = psPlaneTransformAlloc (input->x->nX, input->x->nY); 229 230 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 } 241 } 242 return (output); 243 } 244 245 psProjection *psProjectionCopy (psProjection *input) { 246 247 psProjection *output = psProjectionAlloc (input->R, input->D, input->Xs, input->Ys, input->type); 248 return (output); 249 } 250 251 // very crude distortion inversion: assumes 0 order in z and t, linear in x and y: 252 psPlaneDistort *psPlaneDistortInvert(psPlaneDistort *distort) { 253 PS_ASSERT_PTR_NON_NULL(distort, 0); 254 PS_ASSERT_PTR_NON_NULL(distort->x, 0); 255 PS_ASSERT_PTR_NON_NULL(distort->y, 0); 256 257 psPlaneDistort *out = psPlaneDistortAlloc(1, 1, 0, 0); 258 259 /* simple matrix inversion code */ 260 261 psF64 r11 = distort->x->coeff[1][0][0][0]; 262 psF64 r12 = distort->x->coeff[0][1][0][0]; 263 psF64 r21 = distort->y->coeff[1][0][0][0]; 264 psF64 r22 = distort->y->coeff[0][1][0][0]; 265 psF64 xo = distort->x->coeff[0][0][0][0]; 266 psF64 yo = distort->y->coeff[0][0][0][0]; 267 268 psF64 invDet = 1.0 / (r11 * r22 - r12 * r21); // Inverse of the determinant 269 270 out->x->coeff[1][0][0][0] = +invDet * r22; 271 out->x->coeff[0][1][0][0] = -invDet * r12; 272 out->y->coeff[1][0][0][0] = -invDet * r21; 273 out->y->coeff[0][1][0][0] = +invDet * r11; 274 275 out->x->coeff[0][0][0][0] = - invDet * (r22 * xo - r12 * yo); 276 out->y->coeff[0][0][0][0] = - invDet * (r11 * yo - r21 * xo); 277 278 return(out); 279 } 280 281 // returns the rotation term, forcing positive parity 282 double psPlaneTransformGetRotation (psPlaneTransform *map) { 283 284 if (map->x->nX < 1) return 0; 285 if (map->x->nY < 1) return 0; 286 287 if (map->y->nX < 1) return 0; 288 if (map->y->nY < 1) return 0; 289 290 double pc1_1 = map->x->coeff[1][0]; 291 double pc1_2 = map->x->coeff[0][1]; 292 double pc2_1 = map->y->coeff[1][0]; 293 double pc2_2 = map->y->coeff[0][1]; 294 295 double px = SIGN (pc1_1); 296 double py = SIGN (pc2_2); 297 298 // both x and y terms imply an angle. take the average 299 double t1 = -atan2 (px*pc1_2, px*pc1_1); 300 double t2 = +atan2 (py*pc2_1, py*pc2_2); 301 302 // careful near -pi,+pi boundary... 303 if (t1 - t2 > M_PI/2) t2 += 2*M_PI; 304 if (t2 - t1 > M_PI/2) t1 += 2*M_PI; 305 306 double theta = 0.5*(t1 + t2); 307 while (theta < M_PI) theta += 2*M_PI; 308 while (theta > M_PI) theta -= 2*M_PI; 309 310 return (theta); 311 } 312 313 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
