IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 9, 2006, 11:11:55 AM (19 years ago)
Author:
eugene
Message:

higher-order terms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroWCS.c

    r10594 r10600  
    284284
    285285        // XXX this loop is rather arbitrary in length...
     286        // XXX measure the error and use as criterion
    286287        for (int i = 0; i < 10; i++) {
    287288            // NOTE: order is: [y][x]
     
    300301        }
    301302    }
     303
    302304    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX1",   PS_META_REPLACE, "", Xo);
    303305    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX2",   PS_META_REPLACE, "", Yo);
    304306
    305     switch (toFPA->x->nX) {
    306 
    307       case 1:
    308         /* the linear solution can be analytically inverted */
    309         pc1_1 = xcoeff[1][0] / cdelt1;
    310         pc1_2 = xcoeff[0][1] / cdelt2;
    311         pc2_1 = ycoeff[1][0] / cdelt1;
    312         pc2_2 = ycoeff[0][1] / cdelt2;
    313 
    314       case 2:
    315         a10 = xcoeff[1][0] + 2.0*xcoeff[2][0]*Xo + xcoeff[1][1]*Yo;
    316         a01 = xcoeff[0][1] + 2.0*xcoeff[0][2]*Yo + xcoeff[1][1]*Xo;
    317         a11 = xcoeff[1][1];
    318         a20 = xcoeff[2][0];
    319         a02 = xcoeff[0][2];
    320 
    321         b10 = ycoeff[1][0] + 2.0*ycoeff[2][0]*Xo + ycoeff[1][1]*Yo;
    322         b01 = ycoeff[0][1] + 2.0*ycoeff[0][2]*Yo + ycoeff[1][1]*Xo;
    323         b20 = ycoeff[2][0];
    324         b11 = ycoeff[1][1];
    325         b02 = ycoeff[0][2];
    326 
    327         coords[0].pc1_1 = a10 / coords[0].cdelt1;
    328         coords[0].pc1_2 = a01 / coords[0].cdelt2;
    329         coords[0].pc2_1 = b10 / coords[0].cdelt1;
    330         coords[0].pc2_2 = b01 / coords[0].cdelt2;
    331 
    332         coords[0].polyterms[0][0] = a20 / SQ(coords[0].cdelt1);
    333         coords[0].polyterms[1][0] = a11 / (coords[0].cdelt1*coords[0].cdelt2);
    334         coords[0].polyterms[2][0] = a02 / SQ(coords[0].cdelt2);
    335 
    336         coords[0].polyterms[0][1] = b20 / SQ(coords[0].cdelt1);
    337         coords[0].polyterms[1][1] = b11 / (coords[0].cdelt1*coords[0].cdelt2);
    338         coords[0].polyterms[2][1] = b02 / SQ(coords[0].cdelt2);
    339         for (i = 3; i < 7; i++) {
    340             coords[0].polyterms[i][0] = coords[0].polyterms[i][1] = 0.0;
    341         }
    342         break;
    343      
    344       case 3:
    345         a10 = xcoeff[1][0] + 2*xcoeff[2][0]*Xo +   xcoeff[1][1]*Yo + 3*xcoeff[3][0]*Xo*Xo + 2*xcoeff[2][1]*Xo*Yo + xcoeff[1][2]*Yo*Yo;
    346         a01 = xcoeff[0][1] + 2*xcoeff[0][2]*Yo +   xcoeff[1][1]*Xo + 3*xcoeff[0][3]*Yo*Yo + 2*xcoeff[1][2]*Xo*Yo + xcoeff[2][1]*Xo*Xo;
    347         a20 = xcoeff[2][0] + 3*xcoeff[3][0]*Xo +   xcoeff[2][1]*Yo;
    348         a11 = xcoeff[1][1] + 2*xcoeff[2][1]*Xo + 2*xcoeff[1][2]*Yo;
    349         a02 = xcoeff[0][2] + 3*xcoeff[0][3]*Yo +   xcoeff[1][2]*Xo;
    350         a30 = xcoeff[3][0];
    351         a21 = xcoeff[2][1];
    352         a12 = xcoeff[1][2];
    353         a03 = xcoeff[0][3];
    354 
    355         b10 = ycoeff[1][0] + 2*ycoeff[2][0]*Xo +   ycoeff[1][1]*Yo + 3*ycoeff[3][0]*Xo*Xo + 2*ycoeff[2][1]*Xo*Yo + ycoeff[1][2]*Yo*Yo;
    356         b01 = ycoeff[0][1] + 2*ycoeff[0][2]*Yo +   ycoeff[1][1]*Xo + 3*ycoeff[0][3]*Yo*Yo + 2*ycoeff[1][2]*Xo*Yo + ycoeff[2][1]*Xo*Xo;
    357         b20 = ycoeff[2][0] + 3*ycoeff[3][0]*Xo +   ycoeff[2][1]*Yo;
    358         b11 = ycoeff[1][1] + 2*ycoeff[2][1]*Xo + 2*ycoeff[1][2]*Yo;
    359         b02 = ycoeff[0][2] + 3*ycoeff[0][3]*Yo +   ycoeff[1][2]*Xo;
    360         b30 = ycoeff[3][0];
    361         b21 = ycoeff[2][1];
    362         b12 = ycoeff[1][2];
    363         b03 = ycoeff[0][3];
    364 
    365         coords[0].pc1_1 = a10 / coords[0].cdelt1;
    366         coords[0].pc1_2 = a01 / coords[0].cdelt2;
    367         coords[0].pc2_1 = b10 / coords[0].cdelt1;
    368         coords[0].pc2_2 = b01 / coords[0].cdelt2;
    369 
    370         coords[0].polyterms[0][0] = a20 / SQ(coords[0].cdelt1);
    371         coords[0].polyterms[1][0] = a11 / (coords[0].cdelt1*coords[0].cdelt2);
    372         coords[0].polyterms[2][0] = a02 / SQ(coords[0].cdelt2);
    373 
    374         coords[0].polyterms[3][0] = a30 / (SQ(coords[0].cdelt1)*coords[0].cdelt1);
    375         coords[0].polyterms[4][0] = a21 / (SQ(coords[0].cdelt1)*coords[0].cdelt2);
    376         coords[0].polyterms[5][0] = a12 / (SQ(coords[0].cdelt2)*coords[0].cdelt1);
    377         coords[0].polyterms[6][0] = a03 / (SQ(coords[0].cdelt2)*coords[0].cdelt2);
    378 
    379         coords[0].polyterms[0][1] = b20 / SQ(coords[0].cdelt1);
    380         coords[0].polyterms[1][1] = b11 / (coords[0].cdelt1*coords[0].cdelt2);
    381         coords[0].polyterms[2][1] = b02 / SQ(coords[0].cdelt2);
    382 
    383         coords[0].polyterms[3][1] = b30 / (SQ(coords[0].cdelt1)*coords[0].cdelt1);
    384         coords[0].polyterms[4][1] = b21 / (SQ(coords[0].cdelt1)*coords[0].cdelt2);
    385         coords[0].polyterms[5][1] = b12 / (SQ(coords[0].cdelt2)*coords[0].cdelt1);
    386         coords[0].polyterms[6][1] = b03 / (SQ(coords[0].cdelt2)*coords[0].cdelt2);
    387         break;
    388 
    389       default:
    390         fprintf (stderr, "error: invalid order %d\n", coords[0].Npolyterms);
    391         exit (2);
     307    psPolynomial2D *xWCS = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, toFPA->x->nX, toFPA->x->nY);
     308    psPolynomial2D *yWCS = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, toFPA->y->nX, toFPA->y->nY);
     309
     310    psPolynomial2D *xPx = psPolynomial2DCopy (toFPA->x);
     311    psPolynomial2D *yPx = psPolynomial2DCopy (toFPA->y);
     312
     313    // skip the zero order terms
     314    // XXX double check that these relationships are correct
     315    for (int i = 0; i < toFPA->x->nX; i++) {
     316        psPolynomial2D *xPy = psPolynomial2DCopy (xPx);
     317        psPolynomial2D *yPy = psPolynomial2DCopy (yPx);
     318        for (int j = 0; j < toFPA->x->nY; j++) {
     319            xWCS->coords[i][j] = psPolynomial2DEval (xPy, Xo, Yo) / (i*j) / pow(cdelt1, i) / pow(cdelt2, j);
     320            yWCS->coords[i][j] = psPolynomial2DEval (yPy, Xo, Yo) / (i*j) / pow(cdelt1, i) / pow(cdelt2, j);
     321            psPolynomial2D_dY(xPy, xPy);
     322            psPolynomial2D_dY(yPy, yPy);
     323        }
     324        psPolynomial2D_dX(xPx, xPx);
     325        psPolynomial2D_dX(yPx, yPx);
    392326    }
    393327
     
    395329    while (coords[0].crval1 > 360.0) coords[0].crval1 -= 360.0;
    396330
    397 
     331    psMetadataAddF32 (header, PS_LIST_TAIL, "CRVAL1",   PS_META_REPLACE, "", toSky->R*DEG_RAD);
     332    psMetadataAddF32 (header, PS_LIST_TAIL, "CRVAL2",   PS_META_REPLACE, "", toSky->D*DEG_RAD);
     333    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX1",   PS_META_REPLACE, "", Xo);
     334    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX2",   PS_META_REPLACE, "", Yo);
     335    psMetadataAddF32 (header, PS_LIST_TAIL, "CDELT1",   PS_META_REPLACE, "", cdelt1);
     336    psMetadataAddF32 (header, PS_LIST_TAIL, "CDELT2",   PS_META_REPLACE, "", cdelt2);
     337
     338    psMetadataAddF32 (header, PS_LIST_TAIL, "PC001001", PS_META_REPLACE, "", xWCS->coeff[1][0]);
     339    psMetadataAddF32 (header, PS_LIST_TAIL, "PC001002", PS_META_REPLACE, "", xWCS->coeff[0][1]);
     340    psMetadataAddF32 (header, PS_LIST_TAIL, "PC002001", PS_META_REPLACE, "", yWCS->coeff[1][0]);
     341    psMetadataAddF32 (header, PS_LIST_TAIL, "PC002002", PS_META_REPLACE, "", yWCS->coeff[0][1]);
     342
     343    // XXX respect the masks
     344    for (int i = 0; i < xWCS->nX; i++) {
     345        for (int j = 0; j < xWCS->nX; j++) {
     346            if (i + j < 2) continue;
     347            sprintf (name, "PCA1dX%1dY%1d", i, j);
     348            psMetadataAddF32 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", xWCS->coeff[i][j]);
     349        }
     350    }
     351    for (int i = 0; i < yWCS->nX; i++) {
     352        for (int j = 0; j < yWCS->nX; j++) {
     353            if (i + j < 2) continue;
     354            sprintf (name, "PCA2dX%1dY%1d", i, j);
     355            psMetadataAddF32 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", yWCS->coeff[i][j]);
     356        }
     357    }
     358           
    398359# else
    399360
Note: See TracChangeset for help on using the changeset viewer.