IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2006, 4:15:35 PM (20 years ago)
Author:
magnier
Message:

finish up the basic astrometry functions

File:
1 edited

Legend:

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

    r7153 r7282  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-05-19 15:49:37 $
     9*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-02 02:15:35 $
    1111*
    1212*  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    5757    // XXX we need to get the chip dimensions from the metadata somewhere
    5858    int Nx = 2;
    59     int Ny = 5;
     59    int Ny = 2;
    6060    int DX = 2080 / Nx;
    6161    int DY = 4600 / Ny;
     
    108108                psVectorExtend (dP, 100, 1);
    109109                psVectorExtend (dQ, 100, 1);
    110             }
     110                Npts++;
     111            }
     112            if (Npts < 5)
     113                continue;
    111114
    112115            // fit the collection of positions and offsets with a local 1st order gradient
     
    114117            psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    115118            psVector *mask = psVectorAlloc (Npts, PS_TYPE_MASK);
     119            mask->n = Npts;
     120            psVectorInit (mask, 0);
    116121
    117122            pmAstromGradient *grad = pmAstromGradientAlloc ();
     
    141146bool pmAstromFitDistortion(pmFPA *fpa, psArray *grads, psMetadata *config)
    142147{
     148
     149    psPolynomial2D *localX = NULL;
     150    psPolynomial2D *localY = NULL;
    143151
    144152    // assign the gradient elements to psVectors for fitting
     
    168176    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    169177    psVector *mask = psVectorAlloc (grads->n, PS_TYPE_MASK);
    170 
    171     // XXX the order of the gradient fits need to be 1 less than the distortion term
    172     // XXX determine the distortion order(s) from the fpa->toTP structure
    173 
    174     psPolynomial2D *localX = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 1, 1);
    175     psPolynomial2D *localY = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 1, 1);
    176     // XXX set masks based on fpa->toTP
    177 
     178    mask->n = grads->n;
     179    psVectorInit (mask, 0);
     180
     181    // the order of the gradient fits need to be 1 less than the distortion term
     182    // determine the gradient order(s) from the fpa->toTP structure
     183    localX = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, fpa->toTangentPlane->x->nX-1, fpa->toTangentPlane->x->nY);
     184    localY = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, fpa->toTangentPlane->x->nX,   fpa->toTangentPlane->x->nY-1);
     185
     186    // set masks based on fpa->toTP
     187    for (int i = 0; i < fpa->toTangentPlane->x->nX; i++) {
     188        for (int j = 0; j < fpa->toTangentPlane->x->nY; j++) {
     189            if (fpa->toTangentPlane->x->mask[i][j][0][0]) {
     190                localX->mask[i-1][j] = 1;
     191                localY->mask[i][j-1] = 1;
     192            }
     193        }
     194    }
     195
     196    // fit the local gradients in each direction
    178197    psVectorClipFitPolynomial2D (localX, stats, mask, 0xff, dPdL, NULL, L, M);
    179198    psVectorClipFitPolynomial2D (localY, stats, mask, 0xff, dPdM, NULL, L, M);
    180199
    181     // XXX update fpa->toTP distortion terms
    182 
     200    // XXX test: generate fit
     201    psVector *dPdLf = psPolynomial2DEvalVector (localX, L, M);
     202    psVector *dPdMf = psPolynomial2DEvalVector (localY, L, M);
     203
     204    // update fpa->toTP distortion terms
     205    fpa->toTangentPlane->x->coeff[0][0][0][0] = 0;
     206    for (int i = 1; i < fpa->toTangentPlane->x->nX; i++) {
     207        if (!fpa->toTangentPlane->x->mask[i][0][0][0]) {
     208            fpa->toTangentPlane->x->coeff[i][0][0][0] = localX->coeff[i-1][0] / i;
     209        }
     210    }
     211    for (int j = 1; j < fpa->toTangentPlane->x->nY; j++) {
     212        if (!fpa->toTangentPlane->x->mask[0][j][0][0]) {
     213            fpa->toTangentPlane->x->coeff[0][j][0][0] = localY->coeff[0][j-1] / j;
     214        }
     215    }
     216    for (int i = 1; i < fpa->toTangentPlane->x->nX; i++) {
     217        for (int j = 1; j < fpa->toTangentPlane->x->nY; j++) {
     218            if (!fpa->toTangentPlane->x->mask[i][j][0][0]) {
     219                fpa->toTangentPlane->x->coeff[i][j][0][0] = 0.5*(localX->coeff[i-1][j] / i + localY->coeff[i][j-1] / j);
     220            }
     221        }
     222    }
     223    psFree (localX);
     224    psFree (localY);
     225
     226    // the order of the gradient fits need to be 1 less than the distortion term
     227    // determine the gradient order(s) from the fpa->toTP structure
     228    localX = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, fpa->toTangentPlane->y->nX-1, fpa->toTangentPlane->y->nY);
     229    localY = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, fpa->toTangentPlane->y->nX,   fpa->toTangentPlane->y->nY-1);
     230
     231    // set masks based on fpa->toTP
     232    for (int i = 0; i < fpa->toTangentPlane->y->nX; i++) {
     233        for (int j = 0; j < fpa->toTangentPlane->y->nY; j++) {
     234            if (fpa->toTangentPlane->y->mask[i][j][0][0]) {
     235                localX->mask[i-1][j] = 1;
     236                localY->mask[i][j-1] = 1;
     237            }
     238        }
     239    }
     240
     241    // fit the local gradients in each direction
    183242    psVectorClipFitPolynomial2D (localX, stats, mask, 0xff, dQdL, NULL, L, M);
    184243    psVectorClipFitPolynomial2D (localY, stats, mask, 0xff, dQdM, NULL, L, M);
    185244
     245    // XXX test: generate fit
     246    psVector *dQdLf = psPolynomial2DEvalVector (localX, L, M);
     247    psVector *dQdMf = psPolynomial2DEvalVector (localY, L, M);
     248
     249    FILE *f = fopen ("grads.dat", "w");
     250    for (int i = 0; i < dPdLf->n; i++) {
     251        fprintf (f, "%f %f  | %f %f  %f %f | %f %f  %f %f\n",
     252                 L->data.F32[i], M->data.F32[i],
     253                 dPdL->data.F32[i], dPdM->data.F32[i],
     254                 dQdL->data.F32[i], dQdM->data.F32[i],
     255                 dPdLf->data.F32[i], dPdMf->data.F32[i],
     256                 dQdLf->data.F32[i], dQdMf->data.F32[i]);
     257    }
     258    fclose (f);
     259
     260    // update fpa->toTP distortion terms
     261    fpa->toTangentPlane->y->coeff[0][0][0][0] = 0;
     262    for (int i = 1; i < fpa->toTangentPlane->y->nX; i++) {
     263        if (!fpa->toTangentPlane->y->mask[i][0][0][0]) {
     264            fpa->toTangentPlane->y->coeff[i][0][0][0] = localX->coeff[i-1][0] / i;
     265        }
     266    }
     267    for (int j = 1; j < fpa->toTangentPlane->y->nY; j++) {
     268        if (!fpa->toTangentPlane->y->mask[0][j][0][0]) {
     269            fpa->toTangentPlane->y->coeff[0][j][0][0] = localY->coeff[0][j-1] / j;
     270        }
     271    }
     272    for (int i = 1; i < fpa->toTangentPlane->y->nX; i++) {
     273        for (int j = 1; j < fpa->toTangentPlane->y->nY; j++) {
     274            if (!fpa->toTangentPlane->y->mask[i][j][0][0]) {
     275                fpa->toTangentPlane->y->coeff[i][j][0][0] = 0.5*(localX->coeff[i-1][j] / i + localY->coeff[i][j-1] / j);
     276            }
     277        }
     278    }
     279    psFree (localX);
     280    psFree (localY);
     281
    186282    // XXX free unneeded structures
     283    psFree (dPdL);
     284    psFree (dPdM);
     285    psFree (dQdL);
     286    psFree (dQdM);
     287    psFree (L);
     288    psFree (M);
     289    psFree (stats);
     290    psFree (mask);
    187291
    188292    return true;
Note: See TracChangeset for help on using the changeset viewer.