IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 11, 2021, 11:33:33 AM (5 years ago)
Author:
eugene
Message:

add chebyshev polynomials to 2D fitting; add chebyshev support functions; use chebyshev polynomials for inverse transformation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-dev-20210817/psLib/src/astro/psCoord.c

    r41531 r41831  
    4040#include "psMinimizePolyFit.h"
    4141
     42# define TEST_SAVE_INVERSE_TRANSFORM 0
     43
     44# if (TEST_SAVE_INVERSE_TRANSFORM)
     45# include "psBinaryOp.h"
     46# endif
     47
    4248# define ELIXIR_CODE 1
    4349
     
    8692    }
    8793
    88     psPlaneTransform *out = psPlaneTransformAlloc(1, 1);
     94    // since the output polynomial is 1st order, a Chebyshev is not really useful
     95    psPlaneTransform *out = psPlaneTransformAlloc(1, 1, PS_POLYNOMIAL_ORD);
    8996
    9097    psF64 r12 = 0.0;
     
    191198}
    192199
    193 psPlaneTransform* psPlaneTransformAlloc(int order1, int order2)
     200psPlaneTransform* psPlaneTransformAlloc(int order1, int order2, psPolynomialType type)
    194201{
    195202    PS_ASSERT_INT_NONNEGATIVE(order1, NULL);
     
    198205    psPlaneTransform *pt = psAlloc(sizeof(psPlaneTransform));
    199206
    200     pt->x = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, order1, order2);
    201     pt->y = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, order1, order2);
     207    pt->x = psPolynomial2DAlloc(type, order1, order2);
     208    pt->y = psPolynomial2DAlloc(type, order1, order2);
    202209
    203210    psMemSetDeallocator(pt, (psFreeFunc) planeTransformFree);
     
    797804    }
    798805
     806    // both polynomials in both input transforms must match type -- and for now be ORD
     807    psAssert (trans1->x->type == PS_POLYNOMIAL_ORD, "fix for CHEB");
     808    psAssert (trans1->y->type == PS_POLYNOMIAL_ORD, "fix for CHEB");
     809    psAssert (trans2->x->type == PS_POLYNOMIAL_ORD, "fix for CHEB");
     810    psAssert (trans2->y->type == PS_POLYNOMIAL_ORD, "fix for CHEB");
     811
    799812    //
    800813    // Determine the size of the new psPlaneTransform.
     
    814827    psPlaneTransform *myPT = NULL;
    815828    if (out == NULL) {
    816         myPT = psPlaneTransformAlloc(orderX, orderY);
     829        myPT = psPlaneTransformAlloc(orderX, orderY, PS_POLYNOMIAL_ORD);
    817830    } else {
    818831        if ((out->x->nX == orderX) &&
     
    834847        } else {
    835848            psFree(out);
    836             myPT = psPlaneTransformAlloc(orderX, orderY);
     849            myPT = psPlaneTransformAlloc(orderX, orderY, PS_POLYNOMIAL_ORD);
    837850        }
    838851    }
     
    10371050    psPlaneTransform *myPT = NULL;
    10381051    if (out == NULL) {
    1039         myPT = psPlaneTransformAlloc(order, order);
     1052      myPT = psPlaneTransformAlloc(order, order, PS_POLYNOMIAL_CHEB);
    10401053    } else {
    10411054      // the user has supplied a model with a specific order : fit that order
     
    10711084    result &= psVectorFitPolynomial2D(myPT->x, NULL, 0, xOut, NULL, xIn, yIn);
    10721085    result &= psVectorFitPolynomial2D(myPT->y, NULL, 0, yOut, NULL, xIn, yIn);
     1086
     1087# if (TEST_SAVE_INVERSE_TRANSFORM)
     1088
     1089    psVector *xFit = psPolynomial2DEvalVector (myPT->x, xIn, yIn);
     1090    psVector *xRes = (psVector *) psBinaryOp (NULL, xOut, "-", xFit);
     1091
     1092    psVector *yFit = psPolynomial2DEvalVector (myPT->y, xIn, yIn);
     1093    psVector *yRes = (psVector *) psBinaryOp (NULL, yOut, "-", yFit);
     1094
     1095    static int nOut = 0;
     1096    char filename[1024];
     1097    snprintf (filename, 1024, "test.fit.%03d.ply", nOut);
     1098    FILE *fp = fopen (filename, "w");
     1099   
     1100    fprintf (fp, " ---- xFit ---- \n");
     1101
     1102    for (int ix = 0; ix < myPT->x->nX + 1; ix++) {
     1103      for (int iy = 0; iy < myPT->x->nY + 1; iy++) {
     1104        fprintf (fp, "%18.12e ", myPT->x->coeff[ix][iy]);
     1105      }
     1106      fprintf (fp, "\n");
     1107    }
     1108    fprintf (fp, " ---- yFit ---- \n");
     1109
     1110    for (int ix = 0; ix < myPT->y->nX + 1; ix++) {
     1111      for (int iy = 0; iy < myPT->y->nY + 1; iy++) {
     1112        fprintf (fp, "%18.12e ", myPT->y->coeff[ix][iy]);
     1113      }
     1114      fprintf (fp, "\n");
     1115    }
     1116    fclose (fp);
     1117   
     1118    snprintf (filename, 1024, "test.fit.%03d.dat", nOut); nOut ++;
     1119    FILE *f1 = fopen (filename, "w");
     1120    for (int i = 0; i < xFit->n; i++) {
     1121      fprintf (f1, "%d : %f %f : %f %f : %f %f : %f %f\n", i,
     1122               xIn->data.F64[i], yIn->data.F64[i],
     1123               xOut->data.F64[i], yOut->data.F64[i],
     1124               xFit->data.F64[i], yFit->data.F64[i],
     1125               xRes->data.F64[i], yRes->data.F64[i]);
     1126    }
     1127    fclose (f1);
     1128
     1129    psStats *myStats = psStatsAlloc (PS_STAT_SAMPLE_STDEV);
     1130    psVectorStats (myStats, xRes, NULL, NULL, 0); float dX = myStats->sampleStdev;
     1131    psVectorStats (myStats, yRes, NULL, NULL, 0); float dY = myStats->sampleStdev;
     1132    fprintf (stderr, "xRes Sigma: %f  --  yRes Sigma %f\n", dX, dY);
     1133
     1134    psFree (myStats);
     1135    psFree (xFit);
     1136    psFree (yFit);
     1137    psFree (xRes);
     1138    psFree (yRes);
     1139
     1140# endif
    10731141
    10741142    psFree(inCoord);
Note: See TracChangeset for help on using the changeset viewer.