IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16792


Ignore:
Timestamp:
Mar 4, 2008, 11:59:26 AM (18 years ago)
Author:
eugene
Message:

iterate, automatic scatter clipping

File:
1 edited

Legend:

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

    r16785 r16792  
    11# include "relastro.h"
     2# define SCATTER_MAX_ERROR 0.05
    23
    34void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {
    45
    5   int i;
     6  int i, Nscatter, Niter;
    67  CoordFit *fit;
     8  double dL, dM, dR, dRmax, *values;
    79
    8   fit = fit_init (coords[0].Npolyterms);
    9   for (i = 0; i < Nmatch; i++) {
    10     if (raw[i].mask) continue;
    11     fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, 1.0);
     10  ALLOCATE (values, double, Nmatch);
     11
     12  for (Niter = 0; Niter < 3; Niter ++) {
     13    // measure the scatter distribution (use only the bright end detections)
     14    for (i = Nscatter = 0; i < Nmatch; i++) {
     15      if (raw[i].mask) continue;
     16      if (raw[i].dMag > SCATTER_MAX_ERROR) continue;
     17
     18      dL = raw[i].L - ref[i].L;
     19      dM = raw[i].M - ref[i].M;
     20      dR = hypot (dL, dM);
     21   
     22      values[Nscatter] = dR;
     23      Nscatter++;
     24    }
     25
     26    // for a 2D Gaussian, 40% of the points are within 1 sigma; dRmax is ~ 3 sigma
     27    dsort (values, Nscatter);
     28    dRmax = 3.0*values[(int)(0.40*Nscatter)];
     29
     30    fit = fit_init (coords[0].Npolyterms);
     31
     32    for (i = 0; i < Nmatch; i++) {
     33      if (raw[i].mask) continue;
     34
     35      // require radius of XXX arcsec
     36      dL = raw[i].L - ref[i].L;
     37      dM = raw[i].M - ref[i].M;
     38      dR = hypot (dL, dM);
     39
     40      if (dR > dRmax) {
     41        continue;
     42        raw[i].mask = TRUE;
     43      }
     44   
     45      fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
     46    }
     47    fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n",
     48             dRmax, Nscatter, fit[0].Npts, Nmatch);
     49
     50    if (fit[0].Npts < 25) {
     51      fit_free (fit);
     52      free (values);
     53      return;
     54    }
     55    fit_eval (fit);
     56    fit_apply_coords (fit, coords);
     57    fit_free (fit);
     58
     59    for (i = 0; i < Nmatch; i++) {
     60      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, coords);
     61    }
    1262  }
    13   fit_eval (fit);
    14   fit_apply_coords (fit, coords);
    15   fit_free (fit);
    1663
    17   // apply new coords to raw (X,Y -> L,M)
    18   for (i = 0; i < Nmatch; i++) {
    19     XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, coords);
    20   }
     64  free (values);
     65  return;
    2166}
    2267
     
    3277*/
    3378
    34 /* XXX I'm not using the errors at all : this could at least be done with the dMag values */
     79/* example using fit_apply() :
     80
     81  f = fopen ("test3.dat", "w");
     82
     83  // apply new coords to raw (X,Y -> L,M)
     84  for (i = 0; i < Nmatch; i++) {
     85    fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
     86    fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
     87    fprintf (f, "%f %f\n", L1, M1);
     88  }
     89  fclose (f);
     90*/
     91
     92/*** XXX this function can be improved in 4 important ways:
     93
     941) the initial value of the clipping radius could be set based on the distribution of the
     95   value (eg, inner 50%) (better to use dL, dM rather than dP, dQ)
     96
     972) multiple clipping passes could be performed
     98
     993) the per-star astrometric errors could be included in the fit (non-systematic terms at
     100   least, or scaled values of the mag error, or simply the mag error itself)
     101
     1024) we could ignore input detections on the basis of the photFlags
     103
     104*/
Note: See TracChangeset for help on using the changeset viewer.