IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17209


Ignore:
Timestamp:
Mar 28, 2008, 3:40:11 PM (18 years ago)
Author:
eugene
Message:

better clipping, control allowed orders

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/src/FitChip.c

    r17149 r17209  
    11# include "relastro.h"
    2 # define SCATTER_MAX_ERROR 0.05
    3 // XXX make this a user parameters
     2
     3// XXX make these user parameters
     4# define FIT_CHIP_MAX_ERROR 0.05
     5# define FIT_CHIP_NITER     3
     6# define FIT_CHIP_NSIGMA    3.0
     7
     8// XXX we should test if the fit is sufficiently constrained across the chip, or if the
     9// new positions deviate too much from the old positions
     10
     11// XXX add visualization tools: per chip residual plots
     12
     13// XXX save the fit[0].Npts value in the image table?
     14
     15// XXX save measurements of the fit quality (scatter, chisq) in the image table
    416
    517void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {
    618
    7   int i, Nscatter, Niter;
     19  int i, Nscatter, Niter, skip;
    820  CoordFit *fit;
    921  double dL, dM, dR, dRmax, *values;
     
    1123  ALLOCATE (values, double, Nmatch);
    1224
    13   for (Niter = 0; Niter < 3; Niter ++) {
     25  for (Niter = 0; Niter < FIT_CHIP_NITER; Niter ++) {
     26
    1427    // measure the scatter distribution (use only the bright end detections)
    1528    for (i = Nscatter = 0; i < Nmatch; i++) {
    1629      if (raw[i].mask) continue;
    17       if (raw[i].dMag > SCATTER_MAX_ERROR) continue;
     30      if (raw[i].dMag > FIT_CHIP_MAX_ERROR) continue;
    1831
    1932      dL = raw[i].L - ref[i].L;
     
    2740    // for a 2D Gaussian, 40% of the points are within 1 sigma; dRmax is ~ 3 sigma
    2841    dsort (values, Nscatter);
    29     dRmax = 3.0*values[(int)(0.40*Nscatter)];
     42    dRmax = FIT_CHIP_NSIGMA*values[(int)(0.40*Nscatter)];
    3043
     44    // fit the requested order polynomial
    3145    if (CHIPORDER > 0) {
    3246      coords[0].Npolyterms = CHIPORDER;
     
    3448    fit = fit_init (coords[0].Npolyterms);
    3549
     50    // generate the fit matches
    3651    for (i = 0; i < Nmatch; i++) {
    3752      if (raw[i].mask) continue;
    3853
    39       // require radius of XXX arcsec
     54      // only keep objects within dRmax
    4055      dL = raw[i].L - ref[i].L;
    4156      dM = raw[i].M - ref[i].M;
    4257      dR = hypot (dL, dM);
    43 
    44       // XXX ??? why are we not applying the mask?
    45       // the detection is not included in the fit
    46       if (dR > dRmax) {
    47         continue;
    48         raw[i].mask = TRUE;
    49       }
     58      if (dR > dRmax) continue;
    5059   
    5160      fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
    5261    }
    53     fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n",
    54              dRmax, Nscatter, fit[0].Npts, Nmatch);
    5562
    56     // XXX this limit should depend on the order of the fit (see psastro)
    57     if (fit[0].Npts < 25) {
     63    // check if the fit has enough data points for the polynomial order
     64    skip = FALSE;
     65    switch (coords[0].Npolyterms) {
     66      case 0:
     67      case 1:
     68        skip = (fit[0].Npts < 8);
     69        break;
     70      case 2:
     71        skip = (fit[0].Npts < 11);
     72        break;
     73      case 3:
     74        skip = (fit[0].Npts < 15);
     75        break;
     76      default:
     77        fprintf (stderr, "invalid chip order %d\n", coords[0].Npolyterms);
     78        abort ();
     79    }
     80    if (skip) {
     81      fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, coords[0].Npolyterms);
    5882      fit_free (fit);
    5983      free (values);
    6084      return;
    6185    }
     86
     87    fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);
     88
     89    // measure the fit, update the coords & object coordinates
    6290    fit_eval (fit);
    6391    fit_apply_coords (fit, coords);
     
    82110   P,Q -> L,M (polynomial transformation : DIS)
    83111   L,M -> X,Y (polynomial transformation : WRP)
     112
     113Some details about this function:
     114
     115- the initial value of the clipping radius is set based on the distribution of the dR
     116  values for the bright sources.
     117
     118- NITER clipping passes are performed
     119
     120- the per-star astrometric errors are included in the fit.  The photcode table controls
     121  whether only the reported positional errors are used, or if the magnitudes errors are
     122  scaled to determine the error, and if there is a systematic floor for all sources.
     123
     124- input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
     125
     126- outlying detections are clipped in the iterative passes, but the clipped detections are
     127  not recorded
     128
    84129*/
    85130
     
    96141  fclose (f);
    97142*/
    98 
    99 /*** XXX this function can be improved in 4 important ways:
    100 
    101 1) the initial value of the clipping radius could be set based on the distribution of the
    102    value (eg, inner 50%) (better to use dL, dM rather than dP, dQ)
    103 
    104 2) multiple clipping passes could be performed
    105 
    106 3) the per-star astrometric errors could be included in the fit (non-systematic terms at
    107    least, or scaled values of the mag error, or simply the mag error itself)
    108 
    109 4) we could ignore input detections on the basis of the photFlags
    110 
    111 */
Note: See TracChangeset for help on using the changeset viewer.