IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5510


Ignore:
Timestamp:
Nov 13, 2005, 1:16:22 PM (21 years ago)
Author:
eugene
Message:

development work

Location:
trunk/psastro
Files:
2 added
6 edited

Legend:

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

    r5495 r5510  
    5454}
    5555
    56 pmAstromMatchedListFit (pmFPA *fpa, psArray *st1, psArray *st2, psArray *match, psMetadata *config) {
     56// take two matched star lists and fit a psPlaneTransform between them
     57//
     58psPlaneTransform *pmAstromMatchedListFit (psPlaneTransform *map, psArray *st1, psArray *st2, psArray *match, psMetadata *config) {
     59
     60    if (map == NULL) {
     61        // int nX = psMetadataLookupS32 (&status, myHeader, "CHIP.NX");
     62        // int nY = psMetadataLookupS32 (&status, myHeader, "CHIP.NY");
     63        map = psPlaneTransform (2, 2);
     64    }
     65
     66    psStats *stats = psStatsAlloc (CLIPPED_MEAN);
     67    stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NITER");
     68    stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NSIGMA");
    5769
    5870    psVector *X = psVectorAlloc (match->n);
     
    6274 
    6375    // take the matched stars, first fit
    64     for (i = 0; i < match->n; i++) {
     76    for (int i = 0; i < match->n; i++) {
    6577
    6678        pair = match->data[i];
     
    6880        ob2 = st2->data[pair->i2];
    6981
    70         X->data.F64[i] = ob1->P;
    71         Y->data.F64[i] = ob1->Q;
     82        X->data.F64[i] = ob1->chip.x;
     83        Y->data.F64[i] = ob1->chip.y;
    7284
    73         x->data.F64[i] = ob2->P;
    74         y->data.F64[i] = ob2->Q;
    75 
    76         // use one or the other...
    77         psPolynomial2D *xt = psVectorFitPolynomial2D (NULL, stats, NULL, 0, X, NULL, x, y);
    78         psPolynomial2D *xt = psVectorClipFitPolynomial2D (NULL, stats, NULL, 0, X, NULL, x, y);
    79 
    80         psPolynomial2D *yt = psVectorFitPolynomial2D (NULL, stats, NULL, 0, Y, NULL, x, y);
    81         psPolynomial2D *yt = psVectorClipFitPolynomial2D (NULL, stats, NULL, 0, Y, NULL, x, y);
     85        x->data.F64[i] = ob2->FP.x;
     86        y->data.F64[i] = ob2->FP.y;
    8287    }
    8388
    84     // apply fitted polynomials to fpa
     89    // no masking, no errors
     90    psVectorClipFitPolynomial2D (map->x, stats, NULL, 0, X, NULL, x, y);
     91    psVectorClipFitPolynomial2D (map->y, stats, NULL, 0, Y, NULL, x, y);
     92    psFree (x);
     93    psFree (y);
     94    psFree (X);
     95    psFree (Y);
     96    psFree (stats);
     97
     98    return (map);
    8599}
    86100
     
    103117        newObj = pmAstromObjCopy (oldObj);
    104118
    105         P = oldObj->FP.x - xCenter;
    106         Q = oldObj->FP.y - yCenter;
     119        X = oldObj->FP.x - xCenter;
     120        Y = oldObj->FP.y - yCenter;
    107121       
    108         newObj->FP.x = P*cs + Q*sn;
    109         newObj->FP.y = Q*cs - P*sn;
     122        newObj->FP.x = X*cs + Y*sn;
     123        newObj->FP.y = Y*cs - X*sn;
    110124       
    111125        new->data[i] = newObj;
  • trunk/psastro/src/pmAstrom.h

    r5360 r5510  
    77
    88typedef struct {
    9     double X, Y;
    10     double P, Q;
    11     double L, M;
    12     double R, D;
     9    psPlane pix;
     10    psPlane cell;
     11    psPlane chip;
     12    psPlane FP;
     13    psPlane TP;
     14    psSphere sky;
    1315    double Mag, dMag;
    1416} pmAstromObj;
     
    2628
    2729typedef struct {
     30    psPlane center;
     31    psPlane offset;
    2832    double angle;
    29     double dP;
    30     double dQ;
    3133    double minMetric;
    3234    double minVar;
  • trunk/psastro/src/pmAstromGrid.c

    r5495 r5510  
    4747        st2r = pmAstromRotateObj (st2, center, angle);
    4848        newStat = pmAstromGridMatchAngle (st1, st2r, config);
    49         newStat.angle = angle;
     49        newStat.angle  = angle;
     50        newStat.center = center;
    5051        if (newStat.minMetric < minStat.minMetric) {
    5152            minStat = newStat;
     
    147148                    minMetric = metric;
    148149                    minVar    = var;
    149                     minP      = i;
    150                     minQ      = j;
     150                    minX      = i;
     151                    minY      = j;
    151152                }
    152153            }
     
    154155
    155156        // convert the bin to delta-delta
    156         matchStats.dX        = DP[minY][minX] / NP[minY][minX];
    157         matchStats.dY        = DQ[minY][minX] / NP[minY][minX];
     157        matchStats.offset.x  = DP[minY][minX] / NP[minY][minX];
     158        matchStats.offset.y  = DQ[minY][minX] / NP[minY][minX];
    158159        matchStats.minMetric = minMetric;
    159160        matchStats.minVar    = minVar;
     
    164165
    165166// apply the measured FPA offset and rotation (stat) to the fpa astrom structures
    166 psFPA *pmAstromApplyGridMatch (psFPA *fpa, pmAstromGridMatchStat stat) {
     167psFPA *pmAstromGridApply (psPlaneTransform *map, pmAstromGridMatchStat stat) {
    167168
    168     // stat.angle modifies fpa.toTangentPlane (effective angle)
    169     // stat.dP, stat.dQ modifies fpa.projection (Ro, Do)
     169    // stat.angle, stat.center, stat.offse
     170    // I think i need to know the center reference....
    170171
    171172    return (fpa);
  • trunk/psastro/src/psastro.c

    r5509 r5510  
    2222    psastroProjectRawstars (subset);
    2323
    24     // load the corresponding reference data (DVO command)
    25     psArray *refstars = psastroLoadReference (argv[3]);
    26 
    27     // use the header & config info to project refstars on the focal plane
    28     psastroProjectRefstars (refstars, subset);
    29 
    3024    // fpa and subset point to the same astrometry terms
    31     psastroChipAstrom (refstars, subset);
     25    psastroChipAstrom (subset, config);
    3226
    3327    // write out data (cmp file)
  • trunk/psastro/src/psastroBuildFPA.c

    r5509 r5510  
    136136    // set toChip to identity as default
    137137    // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581)
     138    // XXX EAM : define these in the config?
     139    // int nX = psMetadataLookupS32 (&status, myHeader, "CHIP.NX");
     140    // int nY = psMetadataLookupS32 (&status, myHeader, "CHIP.NY");
    138141    cell->toChip   = psPlaneTransformAlloc (2, 2);
    139142    cell->toChip->x->coeff[1][0] = 1;
  • trunk/psastro/src/psastroUtils.c

    r5509 r5510  
    197197}
    198198
    199 bool psastroProjectRawstars (pmFPA *fpa) {
     199bool psastroProjectFPA (pmFPA *fpa, bool toSky) {
    200200
    201201    for (int i = 0; i < fpa->chips->n; i++) {
     
    205205            for (int k = 0; k < cell->readouts->n; k++) {
    206206                pmReadout *readout = cell->readouts->data[k];
    207                 for (int m = 0; m < readout->stars->n; m++) {
    208                     pmAstromObj *star = readout->data[m];
    209                     // apply readout offsets
    210                     // apply cell PlaneTransform
    211                     // apply chip PlaneTransform
    212                     psPlaneTransformApply (star->
    213 
    214             }
    215             chip->cells->data[j] = cell;
    216         }
    217         fpa->chips->data[i] = chip;
    218     }
    219     return (fpa);
     207                if (toSky) {
     208                    psastroProjectRawstars (readout->stars, readout);
     209                } else {
     210                    psastroProjectRefstars (readout->stars, readout);
     211                }
     212            }
     213        }
     214    }
     215    return true;
    220216}
    221217 
    222 bool psastroChipAstrom (psArray *refstars, pmFPA *subset) {
    223 
    224     // do this loop over the readouts
    225 
    226     // find initial offset / rotation
    227     stat = pmAstromGridMatch (subset, refstars, config);
    228 
    229     pmAstromModifyFPA (fpa, stat);
    230 
    231     // use fit result to re-project rawstars
    232     psastroProjectRawstars (fpa, subset);
    233     psastroProjectRefstars (fpa, refstars);
     218bool psastroProjectRawstars (psArray *stars, pmReadout *readout) {
     219
     220    pmCell *cell = readout->cell;
     221    pmChip *chip = cell->chip;
     222    pmFPA  *fpa  = chip->cell;
     223
     224    for (int i = 0; i < readout->stars->n; i++) {
     225        pmAstromObj *star = readout->stars->data[i];
     226        psCoordReadoutToCell (&star->cell, &star->pix, readout);
     227        psCoordCellToChip (&star->chip, &star->cell, cell);
     228        psCoordChipToFP (&star->FP, &star->chip, chip);
     229        psCoordFPtoTP (&star->TP, &star->FP, fpa);
     230        psCoordTPtoSky (&star->sky, &star->TP, fpa);
     231    }
     232    return true;
     233}
     234 
     235bool psastroProjectRefstars (psArray *stars, pmReadout *readout) {
     236
     237    pmCell *cell = readout->cell;
     238    pmChip *chip = cell->chip;
     239    pmFPA  *fpa  = chip->cell;
     240
     241    for (int i = 0; i < stars->n; i++) {
     242        pmAstromObj *star = stars->data[i];
     243
     244        psCoordSkytoTP (&star->TP, &star->sky, fpa);
     245        psCoordTPtoFP (&star->FP, &star->TP, fpa);
     246        psCoordFPtoChip (&star->chip, &star->FP, chip);
     247        psCoordChipToCell (&star->cell, &star->chip, cell);
     248        psCoordReadoutToCell (&star->pix, &star->cell, readout);
     249    }
     250    return true;
     251}
     252 
     253// measure per-chip astrometry terms
     254bool psastroChipAstrom (pmFPA *fpa, psMetadata *config) {
     255
     256    pmFPA *raw = pmFPACopy (fpa);
     257
     258    // first pass: measure the per-chip solutions, modify the chip.toFPA terms
     259    for (int i = 0; i < fpa->chips->n; i++) {
     260        pmChip *chip = fpa->chips->data[i];
     261
     262        // cells->n > 1 is not yet well-defined
     263        if (chip->cells->n > 1) {
     264            psLogMsg ("pmSourcesReadCMP", 3, "undefined behavior for nCells > 1");
     265            return false;
     266        }
     267
     268        for (int j = 0; j < chip->cells->n; j++) {
     269            pmCell *cell = chip->cells->data[j];
     270
     271            // readouts->n > 1 is not yet well-defined
     272            if (cell->readouts->n > 1) {
     273                psLogMsg ("pmSourcesReadCMP", 3, "undefined behavior for nReadouts > 1");
     274                return false;
     275            }
     276
     277            // load the corresponding reference data (DVO command)
     278            psArray *refstars = psastroLoadReference (cell->header, config);
     279
     280            for (int k = 0; k < cell->readouts->n; k++) {
     281
     282                pmReadout *readout = cell->readouts->data[k];
     283
     284                // use the header & config info to project refstars on the focal plane
     285                psastroProjectRefstars (refstars, readout);
     286
     287                // find initial offset / rotation
     288                stat = pmAstromGridMatch (readout->stars, refstars, config);
     289
     290                // adjust the chip.toFPA terms only
     291                pmAstromGridApply (chip->toFPA, stat);
     292
     293                // use fit result to re-project rawstars
     294                psastroProjectRawstars (readout->stars, readout);
     295                psastroProjectRefstars (refstars,       readout);
    234296   
    235     // use small radius to match stars
    236     match = pmAstromRadiusMatch (rawstars, refstars, options);
    237 
    238     // fit astrometric terms
    239     output = pmAstromMatchedListFit (fpa, subset, refstars, match, options);
    240 }
    241 
     297                // use small radius to match stars
     298                match = pmAstromRadiusMatch (rawstars, refstars, options);
     299
     300                // fit astrometric terms
     301                pmAstromMatchedListFit (chip->toFPA, readout->stars, refstars, match, options);
     302            }
     303        }
     304    }
     305
     306    // second stage: re-normalize the chip terms, passing the
     307    // average rotation and offset values to the fpa.toSky
     308           
     309# if (0)
     310    // code disabled for now
     311    // this is not as trivial as it seems at first:
     312    // applying a new rotation to the FPA implies changes to the
     313    // (x,y) reference coordinates for the chips as well as a rotation
     314    // I need to calculate both the x,y offset effect and the rotation
     315    // in one step.  what about the effect of higher order terms in either
     316    // the chip.toFPA or the fpa.toTPA?
     317    // this calculation also needs to account for scale effects between the
     318    // fpa and the chips.
     319
     320    // calculate the average rotation and boresite offset relative to raw
     321    for (int i = 0; i < fpa->chips->n; i++) {
     322        pmChip *iChip = raw->chips->data[i];
     323        pmChip *oChip = fpa->chips->data[i];
     324
     325        T1 = psPlaneTransformGetRotation (iChip->toFPA);
     326        T2 = psPlaneTransformGetRotation (oChip->toFPA);
     327        dT += T1 - T2;
     328        dN ++;
     329
     330       
     331    }
     332
     333    dT /= dN;
     334
     335    psPlaneTransformSetRotation (fpa->toTPA, dT);
     336       
     337    // apply the new modifcations in rotation and boresite
     338    for (int i = 0; i < fpa->chips->n; i++) {
     339        pmChip *iChip = raw->chips->data[i];
     340        pmChip *oChip = fpa->chips->data[i];
     341
     342        psPlaneTransformSetRotation (oChip->toFPA, -dT);
     343    }
     344# endif
     345}
Note: See TracChangeset for help on using the changeset viewer.