IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21159


Ignore:
Timestamp:
Jan 23, 2009, 3:08:17 PM (17 years ago)
Author:
bills
Message:

add pmAstromLinearizeTransforms to compute a linear fit to the transforms

Location:
trunk/psModules/src/astrom
Files:
2 edited

Legend:

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

    r21026 r21159  
    77 *  @author EAM, IfA
    88 *
    9  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-12-17 19:49:59 $
     9 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2009-01-24 01:08:17 $
    1111 *
    1212 *  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    782782}
    783783
     784static psPlaneTransform *
     785linearFitToTransform(psPlaneTransform *trans, psRegion *bounds)
     786{
     787    int     nSamples = 10;  // 10 samples in each dimension
     788
     789    double   deltaX = (bounds->x1 - bounds->x0);
     790    double   deltaY = (bounds->y1 - bounds->y0);
     791
     792    psArray *src = psArrayAlloc(nSamples * nSamples);
     793    psArray *dst = psArrayAlloc(nSamples * nSamples);
     794
     795    int k=0;
     796    for (int j=0; j<nSamples; j++) {
     797        double y = j * deltaY / nSamples;
     798        for (int i=0; i<nSamples; i++) {
     799            psPlane *s = psPlaneAlloc();
     800            s->x = i * deltaX / nSamples;
     801            s->y = y;
     802            psArraySet(src, k, s);
     803            psPlane *d = psPlaneTransformApply(NULL, trans, s);
     804            psArraySet(dst, k, d);
     805            ++k;
     806        }
     807    }
     808
     809    psPlaneTransform *newTrans = psPlaneTransformAlloc(1, 1);
     810
     811    if (!psPlaneTransformFit(newTrans, src, dst, 0, 0)) {
     812        psError(PS_ERR_UNKNOWN, false, "linear fit to transform failed");
     813        return NULL;
     814    }
     815
     816#ifdef COMPARE_TRANS
     817    // compare the computed coordintes from this transform with the original
     818    psPlane *new = psPlaneAlloc();
     819    for (int i=0; i<psArrayLength(dst); i++) {
     820        psPlane *d = (psPlane *) psArrayGet(dst, i);
     821        psPlane *s = (psPlane *) psArrayGet(src, i);
     822
     823        new = psPlaneTransformApply(new, newTrans, s);
     824
     825        printf("%4d %f %f\n", i, 100.*(new->x - d->x)/d->x, 100.*(new->y - d->y)/d->y);
     826    }
     827    psFree(new);
     828#endif
     829    psFree(src);
     830    psFree(dst);
     831
     832    return newTrans;
     833}
     834
     835bool pmAstromLinearizeTransforms(pmFPA *fpa, pmChip *chip)
     836{
     837    psRegion    *chipBounds = pmChipPixels(chip);
     838
     839    psPlaneTransform *newToFPA = linearFitToTransform(chip->toFPA, chipBounds);
     840    if (!newToFPA) {
     841        psFree(chipBounds);
     842        psError(PS_ERR_UNKNOWN, false, "linear fit for toFPA failed");
     843        return false;
     844    }
     845
     846    psFree(chip->toFPA);
     847    chip->toFPA = newToFPA;
     848
     849    psFree(chip->fromFPA);
     850    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *chipBounds, 50);
     851    if (!chip->fromFPA) {
     852        psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit for toFPA");
     853        return false;
     854    }
     855
     856    psPlane *chip0 = psPlaneAlloc();
     857    chip0->x = 0;
     858    chip0->y = 0;
     859    psPlane *chip1 = psPlaneAlloc();
     860    chip1->x = chipBounds->x1;
     861    chip1->y = chipBounds->y1;
     862
     863    // compute bounding region for fpa
     864    psPlane *fpa0 = psPlaneTransformApply(NULL, newToFPA, chip0);
     865    psPlane *fpa1 = psPlaneTransformApply(NULL, newToFPA, chip1);
     866
     867    psRegion *fpaBounds = psRegionAlloc(fpa0->x, fpa1->x, fpa0->y, fpa1->y);
     868    psFree(chip0);
     869    psFree(chip1);
     870    psFree(fpa0);
     871    psFree(fpa1);
     872
     873    psPlaneTransform *newToTPA = linearFitToTransform(fpa->toTPA, fpaBounds);
     874    if (!newToTPA) {
     875        psError(PS_ERR_UNKNOWN, false, "failed to perform linear fit to toTPA");
     876        psFree(fpaBounds);
     877        return false;
     878    }
     879    psFree(fpa->toTPA);
     880    fpa->toTPA = newToTPA;
     881
     882    // XXX: is this region ok?
     883    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *fpaBounds, 50);
     884    if (!fpa->fromTPA) {
     885        psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit to toTPA");
     886        return false;
     887    }
     888
     889    fpa->toSky->type = PS_PROJ_TAN;
     890
     891    psFree(chipBounds);
     892    psFree(fpaBounds);
     893
     894    return true;
     895}
     896
    784897static void pmAstromWCSFree (pmAstromWCS *wcs)
    785898{
  • trunk/psModules/src/astrom/pmAstrometryWCS.h

    r12519 r21159  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-03-21 22:00:49 $
     6 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2009-01-24 01:08:17 $
    88 * Copyright 2006 Institute for Astronomy, University of Hawaii
    99 */
     
    6262bool pmAstromWriteBilevelMosaic (psMetadata *header, const pmFPA *fpa, double tol);
    6363
     64bool pmAstromLinearizeTransforms(pmFPA *fpa, pmChip *);
     65
    6466// move to pslib
    6567psPlaneDistort *psPlaneDistortIdentity (int order);
Note: See TracChangeset for help on using the changeset viewer.