- Timestamp:
- Oct 9, 2008, 2:39:01 PM (18 years ago)
- Location:
- branches/cnb_branch_20080830/psastro/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psastroModelAnalysis.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branch_20080830/psastro/src
- Property svn:ignore
-
old new 15 15 psastroModel 16 16 gpcModel 17 psastroModelFit
-
- Property svn:ignore
-
branches/cnb_branch_20080830/psastro/src/psastroModelAnalysis.c
r15891 r20033 1 1 # include "psastroStandAlone.h" 2 # define NONLIN_TOL 0.001 2 3 3 4 bool psastroModelAnalysis (pmConfig *config) { … … 12 13 } 13 14 14 pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL"); 15 if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL"); 16 17 // physical pixel scale in microns per pixel 15 // reference chip for boresite parameters 18 16 char *refChip = psMetadataLookupStr (&status, recipe, "PSASTRO.MODEL.REF.CHIP"); 19 17 if (!refChip) { … … 21 19 return false; 22 20 } 21 22 pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL"); 23 if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL"); 24 25 // measure the boresite position from a rotation sequence? 26 bool fitBoresite = psMetadataLookupBool (&status, recipe, "PSASTRO.MODEL.FIT.BORESITE"); 27 if (!fitBoresite) { 28 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", 0.0); 29 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.Y0", PS_META_REPLACE, "boresite parameter", 0.0); 30 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RX", PS_META_REPLACE, "boresite parameter", 0.0); 31 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RY", PS_META_REPLACE, "boresite parameter", 0.0); 32 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.T0", PS_META_REPLACE, "boresite parameter", 0.0); 33 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.P0", PS_META_REPLACE, "boresite parameter", 0.0); 34 psMetadataAddStr (output->fpa->concepts, PS_LIST_TAIL, "FPA.REF.CHIP", PS_META_REPLACE, "boresite parameter", refChip); 35 return true; 36 } 37 38 char *outroot = psMetadataLookupStr (&status, config->arguments, "OUTPUT"); 39 if (!status || !outroot) psAbort ("Can't find outroot on config->arguments"); 23 40 24 41 /* model analysis: … … 35 52 * T_0 : reference angle for rotator 36 53 * P_0 : orientation of boresite ellipse 54 * 37 55 */ 38 56 … … 58 76 output->fpa = NULL; 59 77 78 char filename[256]; 79 snprintf (filename, 256, "%s.bore", outroot); 80 FILE *outfile = fopen (filename, "w"); 81 if (!outfile) { 82 psError(PSASTRO_ERR_ARGUMENTS, true, "cannot open %s for output", filename); 83 return false; 84 } 85 86 float posBoundary = 0.0; 87 60 88 // extract the relevant measured and reported values from the reference chip 61 89 for (int i = 0; i < files->n; i++) { … … 63 91 pmFPAfile *input = file->data.V; 64 92 65 // reported rotator position angle (this should perhaps be ROT, not POS)93 // reported rotator position angle 66 94 double POSANGLE = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.POSANGLE"); 67 95 if (!status) psAbort ("missing FPA.POSANGLE"); … … 71 99 if (!chip) psAbort ("invalid chip name for reference"); 72 100 73 fprintf (stderr, "input %d : %zx : %zx : %zx\n", i, (size_t) input, (size_t) chip, (size_t) chip->toFPA);74 101 if (!chip->toFPA) continue; 75 102 … … 80 107 81 108 // we have two measurements of the posangle (may be parity flipped to different quadrants) 82 float posangle = PM_DEG_RAD * atan2 (chip->toFPA->y->coeff[1][0], chip->toFPA->x->coeff[1][0]); 83 posZero->data.F32[n] = POSANGLE - posangle; 84 while (posZero->data.F32[n] > 360.0) posZero->data.F32[n] -= 360.0; 85 while (posZero->data.F32[n] < 0.0) posZero->data.F32[n] += 360.0; 109 // atan2 returns values in the range 0-2pi 110 // all posZero values should be clustered in some region, but we need to flip over the 0,360 boundary correctly. 111 // push all to one side or the other 112 float chipAngle = PM_DEG_RAD * atan2 (chip->toFPA->y->coeff[1][0], chip->toFPA->x->coeff[1][0]); 113 float fpaAngle = PM_DEG_RAD * atan2 (input->fpa->toTPA->y->coeff[1][0], input->fpa->toTPA->x->coeff[1][0]); 114 115 posZero->data.F32[n] = POSANGLE - chipAngle - fpaAngle; 116 if (n == 0) { 117 posBoundary = posZero->data.F32[n] + 180.0; 118 } else { 119 while (posZero->data.F32[n] > posBoundary) posZero->data.F32[n] -= 360.0; 120 while (posZero->data.F32[n] < posBoundary - 360.0) posZero->data.F32[n] += 360.0; 121 } 86 122 87 123 Po->data.F32[n] = POSANGLE * PM_RAD_DEG; // reported position angle 88 Xo->data.F32[n] = chip->fromFPA->x->coeff[0][0]; // reported boresite x position in ref chip coordinates 89 Yo->data.F32[n] = chip->fromFPA->y->coeff[0][0]; // reported boresite y position in ref chip coordinates 90 fprintf (stderr, "%d : %f %f : %f = %f - %f\n", i, Xo->data.F32[n], Yo->data.F32[n], posZero->data.F32[n], POSANGLE, posangle); 124 float xc = chip->fromFPA->x->coeff[0][0]; // reported boresite x position in ref chip coordinates 125 float yc = chip->fromFPA->y->coeff[0][0]; // reported boresite y position in ref chip coordinates 126 // XXX this can also be derived from toFPA via GetCenter.... 127 128 psPlane *PT = psPlaneTransformGetCenter (chip->toFPA, NONLIN_TOL); 129 Xo->data.F32[n] = PT->x; // reported boresite x position in ref chip coordinates 130 Yo->data.F32[n] = PT->y; // reported boresite y position in ref chip coordinates 131 psFree (PT); 132 133 fprintf (outfile, "%d : %f %f : %f = %f - %f - %f | %f %f\n", i, Xo->data.F32[n], Yo->data.F32[n], posZero->data.F32[n], POSANGLE, chipAngle, fpaAngle, xc, yc); 91 134 n ++; 92 135 } … … 100 143 psVectorStats (stats, posZero, NULL, NULL, 0); 101 144 102 fprintf ( stderr, "pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);145 fprintf (outfile, "# pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); 103 146 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POS_ZERO", PS_META_REPLACE, "offset between obs and meas posangle", stats->sampleMedian); 147 fclose (outfile); 104 148 105 psVector *params = psastroModelFitBoresite (Xo, Yo, Po );149 psVector *params = psastroModelFitBoresite (Xo, Yo, Po, outroot); 106 150 if (params->n != 6) psAbort ("error"); 151 107 152 108 153 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_X0]);
Note:
See TracChangeset
for help on using the changeset viewer.
