IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 4, 2008, 12:18:13 PM (18 years ago)
Author:
eugene
Message:

substantial work to fix FitChips

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080223/Ohana/src/relastro/src/fitpoly.c

    r16060 r16798  
    128128      matrix[i][j] = fit[0].sum[ix+jx][iy+jy];
    129129    }
     130
     131    // mask the terms not represented by the Coords terms
     132    if (ix + iy > fit[0].Norder) {
     133      for (j = 0; j < fit[0].Nelems; j++) {
     134        matrix[i][j] = 0.0;
     135      }
     136      vector[i][0] = 0.0;
     137      vector[i][1] = 0.0;
     138      matrix[i][i] = 1.0;
     139    }     
    130140  }
    131141
     
    133143    ix = i % fit[0].Nterms;
    134144    iy = i / fit[0].Nterms;
    135     fprintf (stderr, "x2 : x^%dy^%d: %10.4g    y2 : x^%dy^%d: %10.4g \n",
    136             ix, iy, vector[i][0], ix, iy, vector[i][1]);
     145    // fprintf (stderr, "x2 : x^%dy^%d: %10.4g    y2 : x^%dy^%d: %10.4g \n",
     146    // ix, iy, vector[i][0], ix, iy, vector[i][1]);
    137147  }     
    138148
     
    142152    ix = i % fit[0].Nterms;
    143153    iy = i / fit[0].Nterms;
    144     fprintf (stderr, "x2 : x^%dy^%d: %10.4g    y2 : x^%dy^%d: %10.4g \n",
    145             ix, iy, vector[i][0], ix, iy, vector[i][1]);
     154    // fprintf (stderr, "x2 : x^%dy^%d: %10.4g    y2 : x^%dy^%d: %10.4g \n",
     155    // ix, iy, vector[i][0], ix, iy, vector[i][1]);
    146156  }     
    147157
     
    158168}
    159169
     170void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1) {
     171 
     172  int ix, iy;
     173  double xterm, yterm, term;
     174  double x, y;
     175
     176  x = 0.0;
     177  y = 0.0;
     178
     179  xterm = 1;
     180  for (ix = 0; ix < fit[0].Nterms; ix++) {
     181    yterm = 1;
     182    for (iy = 0; iy < fit[0].Nterms; iy++) {
     183      term = xterm*yterm;
     184      x += fit[0].xfit[ix][iy]*term;
     185      y += fit[0].yfit[ix][iy]*term;
     186      yterm *= y1;
     187    }
     188    xterm *= x1;
     189  }
     190  *x2 = x;
     191  *y2 = y;
     192}
     193
    160194// Nx, Ny is the number of terms in x and in y
    161195double **poly2d_dx (double **poly, int Nx, int Ny) {
     
    209243  for (i = 0; i < Nx; i++) {
    210244    for (j = 0; j < Ny; j++) {
    211       out[i][j] = poly[i][j+1];
     245      out[i][j] = poly[i][j];
    212246    }
    213247  }
     
    237271/* this should only apply to the polynomial, not the projection terms */
    238272/* compare with psastro supporting code */
    239 void fit_apply_coords (CoordFit *fit, Coords *coords) {
     273CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords) {
    240274
    241275  double c11, c12;
    242276  double c21, c22;
    243   double Xo, Yo, R;
     277  double Xo, Yo, R1, R2;
    244278  CoordFit *modfit;
    245279
     
    256290  modfit = CoordsSetCenter (fit, Xo, Yo);
    257291
     292  /* we do not modify crval1,2: these are kept at the default values */
     293
     294  // set cdelt1, cdelt2
     295  coords[0].cdelt1 = hypot (modfit[0].xfit[1][0], modfit[0].xfit[0][1]);
     296  coords[0].cdelt2 = hypot (modfit[0].yfit[1][0], modfit[0].yfit[0][1]);
     297  R1 = 1 / coords[0].cdelt1;
     298  R2 = 1 / coords[0].cdelt2;
     299
    258300  // set pc1_1, pc1_2, pc2_1, pc2_2 (cd1,cd2 = 1.0)
    259   coords[0].pc1_1 = modfit[0].xfit[1][0];
    260   coords[0].pc1_2 = modfit[0].xfit[0][1];
    261   coords[0].pc2_1 = modfit[0].yfit[1][0];
    262   coords[0].pc2_2 = modfit[0].yfit[0][1];
     301  coords[0].pc1_1 = modfit[0].xfit[1][0] * R1;
     302  coords[0].pc1_2 = modfit[0].xfit[0][1] * R2;
     303  coords[0].pc2_1 = modfit[0].yfit[1][0] * R1;
     304  coords[0].pc2_2 = modfit[0].yfit[0][1] * R2;
    263305
    264306  // set the polyterm elements
    265307  if (coords->Npolyterms > 1) {
    266     coords[0].polyterms[0][0] = modfit[0].xfit[2][0];
    267     coords[0].polyterms[1][0] = modfit[0].xfit[1][1];
    268     coords[0].polyterms[2][0] = modfit[0].xfit[0][2];
    269 
    270     coords[0].polyterms[0][1] = modfit[0].yfit[2][0];
    271     coords[0].polyterms[1][1] = modfit[0].yfit[1][1];
    272     coords[0].polyterms[2][1] = modfit[0].yfit[0][2];
     308    coords[0].polyterms[0][0] = modfit[0].xfit[2][0]*R1*R1;
     309    coords[0].polyterms[1][0] = modfit[0].xfit[1][1]*R1*R2;
     310    coords[0].polyterms[2][0] = modfit[0].xfit[0][2]*R2*R2;
     311
     312    coords[0].polyterms[0][1] = modfit[0].yfit[2][0]*R1*R1;
     313    coords[0].polyterms[1][1] = modfit[0].yfit[1][1]*R1*R2;
     314    coords[0].polyterms[2][1] = modfit[0].yfit[0][2]*R2*R2;
    273315  }
    274316
    275317  // I need to validate Norder
    276318  if (coords->Npolyterms > 2) {
    277     coords[0].polyterms[3][0] = modfit[0].xfit[3][0];
    278     coords[0].polyterms[4][0] = modfit[0].xfit[2][1];
    279     coords[0].polyterms[5][0] = modfit[0].xfit[1][2];
    280     coords[0].polyterms[6][0] = modfit[0].xfit[0][3];
    281 
    282     coords[0].polyterms[3][1] = modfit[0].yfit[3][0];
    283     coords[0].polyterms[4][1] = modfit[0].yfit[2][1];
    284     coords[0].polyterms[5][1] = modfit[0].yfit[1][2];
    285     coords[0].polyterms[6][1] = modfit[0].yfit[0][3];
    286   }
    287 
    288   /* we do not modify crval1,2: these are kept at the default values */
    289 
    290   /* normalize pc11,etc */
    291   c11 = coords[0].pc1_1;
    292   c21 = coords[0].pc1_1;
    293   c12 = coords[0].pc1_1;
    294   c22 = coords[0].pc1_1;
    295   coords[0].cdelt1 = coords[0].cdelt2 = sqrt(fabs(c11*c22 - c12*c21));
    296   R = 1 / coords[0].cdelt1;
    297 
    298   coords[0].pc1_1  = c11*R;
    299   coords[0].pc2_1  = c21*R;
    300   coords[0].pc1_2  = c12*R;
    301   coords[0].pc2_2  = c22*R;
     319    coords[0].polyterms[3][0] = modfit[0].xfit[3][0]*R1*R1*R1;
     320    coords[0].polyterms[4][0] = modfit[0].xfit[2][1]*R1*R1*R2;
     321    coords[0].polyterms[5][0] = modfit[0].xfit[1][2]*R1*R2*R2;
     322    coords[0].polyterms[6][0] = modfit[0].xfit[0][3]*R2*R2*R2;
     323
     324    coords[0].polyterms[3][1] = modfit[0].yfit[3][0]*R1*R1*R1;
     325    coords[0].polyterms[4][1] = modfit[0].yfit[2][1]*R1*R1*R2;
     326    coords[0].polyterms[5][1] = modfit[0].yfit[1][2]*R1*R2*R2;
     327    coords[0].polyterms[6][1] = modfit[0].yfit[0][3]*R2*R2*R2;
     328  }
    302329
    303330  fit_free (modfit);
Note: See TracChangeset for help on using the changeset viewer.