IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10781


Ignore:
Timestamp:
Dec 16, 2006, 11:46:09 PM (20 years ago)
Author:
magnier
Message:

finished non-linear WCS conversions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryWCS.c

    r10775 r10781  
    77 *  @author EAM, IfA
    88 *
    9  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-12-16 05:34:54 $
     9 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-12-17 09:46:09 $
    1111 *
    1212 *  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    312312// interpret header WCS (only handles traditional WCS for the moment)
    313313// plateScale is nominal physical scale on tangent plane (radians / TPA physical units)
    314 bool pmAstromReadWCS (pmFPA *fpa, pmChip *chip, const psMetadata *header, double plateScale, bool isMosaic)
     314bool pmAstromWCStoFPA (pmFPA *fpa, pmChip *chip, const pmAstromWCS *wcs, double plateScale, bool isMosaic)
    315315{
    316316    psPlaneTransform *toFPA;
    317 
    318     pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
    319     if (!wcs) {
    320         return false;
    321     }
    322317
    323318    /* at this point, we have extracted from the header the WCS terms in the form of a polynomial,
     
    479474             chip->fromFPA->y->coeff[1][0], chip->fromFPA->y->coeff[0][1]);
    480475
    481     psFree (wcs);
    482 
    483476    return true;
    484477}
    485478
    486 // convert toFPA / toSky components to pmAstromWCS, then write to the headers
    487 // plateScale is nominal physical scale on tangent plane (microns / arcsecond)
    488 // this requires toTP to be the identity transformation
    489 bool pmAstromWriteWCS (psMetadata *header, const pmFPA *fpa, const pmChip *chip)
    490 {
    491     // techinically, we can have a plate scale here (fpa->toTPA:dx,dy != 1)
     479// convert toFPA / toSky components to pmAstromWCS
     480// tolerance is in pixels
     481pmAstromWCS *pmAstromWCSfromFPA (const pmFPA *fpa, const pmChip *chip, float tol)
     482{
     483
     484    // technically, we can have a plate scale here (fpa->toTPA:dx,dy != 1)
    492485    if (!psPlaneDistortIsDiagonal (fpa->toTPA))
    493486        psAbort ("psastro", "invalid TPA transformation");
     
    508501    // crpix1,2 = X,Y(crval1,2)
    509502    // start with linear solution for Xo,Yo:
    510     double R  = (chip->toFPA->x->coeff[1][0]*chip->toFPA->y->coeff[0][1] - chip->toFPA->x->coeff[0][1]*chip->toFPA->y->coeff[0][1]);
     503    double R  = (chip->toFPA->x->coeff[1][0]*chip->toFPA->y->coeff[0][1] - chip->toFPA->x->coeff[0][1]*chip->toFPA->y->coeff[1][0]);
    511504    double Xo = (chip->toFPA->y->coeff[0][0]*chip->toFPA->x->coeff[0][1] - chip->toFPA->x->coeff[0][0]*chip->toFPA->y->coeff[0][1])/R;
    512505    double Yo = (chip->toFPA->x->coeff[0][0]*chip->toFPA->y->coeff[1][0] - chip->toFPA->y->coeff[0][0]*chip->toFPA->x->coeff[1][0])/R;
     
    525518        // XXX this loop is rather arbitrary in length...
    526519        // XXX measure the error and use as criterion
    527         for (int i = 0; i < 10; i++) {
     520        /* this is the Newton-Raphson method to solve for Xo,Yo - it needs the high order terms to be small */
     521        // Xo,Yo are in pixels;
     522        float dPos = tol + 1;
     523        for (int i = 0; (dPos > tol) && (i < 10); i++) {
    528524            // NOTE: order is: [y][x]
    529525            Alpha->data.F32[0][0] = psPolynomial2DEval (XdX, Xo, Yo);
     
    537533            psMatrixGJSolveF32 (Alpha, Beta);
    538534
    539             Xo += Beta->data.F32[0];
    540             Yo += Beta->data.F32[1];
     535            Xo -= Beta->data.F32[0];
     536            Yo -= Beta->data.F32[1];
     537            dPos = hypot(Xo,Yo);
    541538        }
    542539        psFree (Alpha);
     
    595592        }
    596593    }
    597 
     594    return wcs;
     595}
     596
     597// interpret header WCS (only handles traditional WCS for the moment)
     598// plateScale is nominal physical scale on tangent plane (radians / TPA physical units)
     599bool pmAstromReadWCS (pmFPA *fpa, pmChip *chip, const psMetadata *header, double plateScale, bool isMosaic)
     600{
     601    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
     602    if (!wcs) {
     603        return false;
     604    }
     605
     606    bool status = pmAstromWCStoFPA (fpa, chip, wcs, plateScale, isMosaic);
     607
     608    psFree (wcs);
     609    return status;
     610}
     611
     612// convert toFPA / toSky components to pmAstromWCS, then write to the headers
     613// tolerance is in pixels
     614bool pmAstromWriteWCS (psMetadata *header, const pmFPA *fpa, const pmChip *chip, float tol)
     615{
     616    // XXX require chip->toFPA->x->nX == chip->toFPA->x->nY
     617    // XXX require chip->toFPA->y->nX == chip->toFPA->y->nY
     618    // XXX require chip->toFPA->x->nX == chip->toFPA->y->nX
     619    // XXX require chip->toFPA->nX == 1,2,3
     620
     621    // technically, we can have a plate scale here (fpa->toTPA:dx,dy != 1)
     622    if (!psPlaneDistortIsDiagonal (fpa->toTPA))
     623        psAbort ("psastro", "invalid TPA transformation");
     624
     625    pmAstromWCS *wcs = pmAstromWCSfromFPA(fpa, chip, tol);
    598626    pmAstromWCStoHeader (header, wcs);
    599627
Note: See TracChangeset for help on using the changeset viewer.