IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 9, 2008, 2:39:01 PM (18 years ago)
Author:
beaumont
Message:

merged mainline into branch. resolved conflicts. added plots.

Location:
branches/cnb_branch_20080830/psastro/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branch_20080830/psastro/src

    • Property svn:ignore
      •  

        old new  
        1515psastroModel
        1616gpcModel
         17psastroModelFit
  • branches/cnb_branch_20080830/psastro/src/psastroModelAnalysis.c

    r15891 r20033  
    11# include "psastroStandAlone.h"
     2# define NONLIN_TOL 0.001
    23
    34bool psastroModelAnalysis (pmConfig *config) {
     
    1213    }
    1314
    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
    1816    char *refChip = psMetadataLookupStr (&status, recipe, "PSASTRO.MODEL.REF.CHIP");
    1917    if (!refChip) {
     
    2119        return false;
    2220    }
     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");
    2340
    2441    /* model analysis:
     
    3552     * T_0 : reference angle for rotator
    3653     * P_0 : orientation of boresite ellipse
     54     *
    3755     */
    3856
     
    5876    output->fpa = NULL;
    5977
     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
    6088    // extract the relevant measured and reported values from the reference chip
    6189    for (int i = 0; i < files->n; i++) {
     
    6391        pmFPAfile *input = file->data.V;
    6492
    65         // reported rotator position angle (this should perhaps be ROT, not POS)
     93        // reported rotator position angle
    6694        double POSANGLE = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.POSANGLE");
    6795        if (!status) psAbort ("missing FPA.POSANGLE");
     
    7199        if (!chip) psAbort ("invalid chip name for reference");
    72100
    73         fprintf (stderr, "input %d : %zx : %zx : %zx\n", i, (size_t) input, (size_t) chip, (size_t) chip->toFPA);
    74101        if (!chip->toFPA) continue;
    75102
     
    80107
    81108        // 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        }
    86122
    87123        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);
    91134        n ++;
    92135    }
     
    100143    psVectorStats (stats, posZero, NULL, NULL, 0);
    101144
    102     fprintf (stderr, "pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
     145    fprintf (outfile, "# pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
    103146    psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POS_ZERO", PS_META_REPLACE, "offset between obs and meas posangle", stats->sampleMedian);
     147    fclose (outfile);
    104148
    105     psVector *params = psastroModelFitBoresite (Xo, Yo, Po);
     149    psVector *params = psastroModelFitBoresite (Xo, Yo, Po, outroot);
    106150    if (params->n != 6) psAbort ("error");
     151
    107152
    108153    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.