IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26492


Ignore:
Timestamp:
Dec 29, 2009, 11:06:35 AM (16 years ago)
Author:
bills
Message:

combine toFPA and toTPA transforms and do a single linear fit

File:
1 edited

Legend:

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

    r25876 r26492  
    378378    // XXX make it optional to write out CDi_j terms, or other versions
    379379    // apply CDELT1,2 (degrees / pixel) to yield PCi,j terms of order unity
    380     if (!(wcs->wcsCDkeys)) {
     380    if (!wcs->wcsCDkeys) {
    381381
    382382      double cdelt1 = wcs->cdelt1;
     
    419419        psMetadataRemoveKey(header, "CD2_2");
    420420      }
    421     }
    422     if (wcs->wcsCDkeys) {
     421    } else {
    423422
    424423      psMetadataAddF64 (header, PS_LIST_TAIL, "CD1_1", PS_META_REPLACE, "", wcs->trans->x->coeff[1][0]);
     
    845844    int k=0;
    846845    for (int j=0; j<nSamples; j++) {
    847         double y = j * deltaY / nSamples;
     846        double y = bounds->y0 + (j * deltaY / nSamples);
    848847        for (int i=0; i<nSamples; i++) {
    849848            psPlane *s = psPlaneAlloc();
    850             s->x = i * deltaX / nSamples;
     849            s->x = bounds->x0 + (i * deltaX / nSamples);
    851850            s->y = y;
    852851            psArraySet(src, k, s);
    853852            psPlane *d = psPlaneTransformApply(NULL, trans, s);
    854853            psArraySet(dst, k, d);
    855             psFree(s);
     854            psFree(s);  // drop our refs to s and d
    856855            psFree(d);
    857856            ++k;
     
    869868    // compare the computed coordintes from this transform with the original
    870869    psPlane *new = psPlaneAlloc();
     870    printf("   i     chip_x  fpa_x     fpa_x_fit     dx         chip_y    fpa_y     fpa_y_fit     dy     dx > 0.5 || dy > 0.5\n");
    871871    for (int i=0; i<psArrayLength(dst); i++) {
    872872        psPlane *d = (psPlane *) psArrayGet(dst, i);
     
    875875        new = psPlaneTransformApply(new, newTrans, s);
    876876
    877         printf("%4d %f %f\n", i, 100.*(new->x - d->x)/d->x, 100.*(new->y - d->y)/d->y);
     877        double xerr = new->x - d->x;
     878        double yerr = new->y - d->y;
     879        bool bigerr = (fabs(xerr) > .5) || (fabs(yerr) > .5);
     880        printf("%4d %9.2f %9.2f %9.2f %9.2f     %9.2f %9.2f %9.2f %9.2f   %s\n"
     881        , i, s->x, new->x, d->x, xerr, s->y, new->y, d->y, yerr, bigerr ? "BIGERR" : "");
    878882    }
    879883    psFree(new);
     
    891895    psRegion    *chipBounds = pmChipPixels(chip);
    892896
    893     psPlaneTransform *newToFPA = linearFitToTransform(chip->toFPA, chipBounds);
     897#ifdef TESTING_CAMRUN_14728
     898    chipBounds->y0 = 1874.;
     899    chipBounds->x1 = 2387.;
     900#endif
     901
     902    // First combine the chip to FPA and FPA to TPA into a single transformation
     903    psPlaneTransform *chipToTPA = psPlaneTransformCombine(NULL, chip->toFPA, fpa->toTPA, *chipBounds, 50);
     904    if (!chipToTPA) {
     905        psFree(chipBounds);
     906        psError(PS_ERR_UNKNOWN, false, "failed to create chipToTPA");
     907        return false;
     908    }
     909
     910    // Next do a linear fit
     911    psPlaneTransform *newToFPA = linearFitToTransform(chipToTPA, chipBounds);
     912    psFree(chipToTPA);
    894913    if (!newToFPA) {
    895914        psFree(chipBounds);
    896         psError(PS_ERR_UNKNOWN, false, "linear fit for toFPA failed");
    897         return false;
    898     }
     915        psError(PS_ERR_UNKNOWN, false, "linear fit of chip to TPA transform failed");
     916        return false;
     917    }
     918
     919    psPlaneTransform *newFromFPA = psPlaneTransformInvert(NULL, newToFPA, *chipBounds, 50);
     920    psFree(chipBounds);
     921    if (!newFromFPA) {
     922        psFree(newToFPA);
     923        psError(PS_ERR_UNKNOWN, false, "inversion of fit of chip to TPA transform failed");
     924        return false;
     925    }
     926
     927    // Success. Now set the fpa's toTPA and fromTPA to identity and replace the chip's transforms.
     928
     929    psPlaneTransform *newToTPA   = psPlaneTransformIdentity(1);
     930    psFree(fpa->toTPA);
     931    fpa->toTPA = newToTPA;
     932
     933    psPlaneTransform *newFromTPA = psPlaneTransformIdentity(1);
     934    psFree(fpa->fromTPA);
     935    fpa->fromTPA = newFromTPA;
    899936
    900937    psFree(chip->toFPA);
     
    902939
    903940    psFree(chip->fromFPA);
    904     chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *chipBounds, 50);
    905     if (!chip->fromFPA) {
    906         psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit for toFPA");
    907         return false;
    908     }
    909 
    910     psPlane *chip0 = psPlaneAlloc();
    911     chip0->x = 0;
    912     chip0->y = 0;
    913     psPlane *chip1 = psPlaneAlloc();
    914     chip1->x = chipBounds->x1;
    915     chip1->y = chipBounds->y1;
    916 
    917     // compute bounding region for fpa
    918     psPlane *fpa0 = psPlaneTransformApply(NULL, newToFPA, chip0);
    919     psPlane *fpa1 = psPlaneTransformApply(NULL, newToFPA, chip1);
    920 
    921     psRegion *fpaBounds = psRegionAlloc(fpa0->x, fpa1->x, fpa0->y, fpa1->y);
    922     psFree(chip0);
    923     psFree(chip1);
    924     psFree(fpa0);
    925     psFree(fpa1);
    926 
    927     psPlaneTransform *newToTPA = linearFitToTransform(fpa->toTPA, fpaBounds);
    928     if (!newToTPA) {
    929         psError(PS_ERR_UNKNOWN, false, "failed to perform linear fit to toTPA");
    930         psFree(fpaBounds);
    931         return false;
    932     }
    933     psFree(fpa->toTPA);
    934     fpa->toTPA = newToTPA;
    935 
    936     // XXX: is this region ok?
    937     psFree(fpa->fromTPA);
    938     fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *fpaBounds, 50);
    939     if (!fpa->fromTPA) {
    940         psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit to toTPA");
    941         return false;
    942     }
    943 
     941    chip->fromFPA = newFromFPA;
     942
     943    // Finally change the type for the projection.
    944944    fpa->toSky->type = PS_PROJ_TAN;
    945 
    946     psFree(chipBounds);
    947     psFree(fpaBounds);
    948945
    949946    return true;
Note: See TracChangeset for help on using the changeset viewer.