IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30509


Ignore:
Timestamp:
Feb 7, 2011, 4:45:12 PM (15 years ago)
Author:
eugene
Message:

some improvements to the visualization; add user config values for IMFIT_CLIP_NITER, IMFIT_CLIP_NSIGMA, IMFIT_SYS_SIGMA_LIM; calcualte dXpixSys and dYpixSys for images and dRsys (in arcsec) for measures; better tracking of why images are masked; better matching of images to mosaics; do not reset magnitude calibrations in relastro; use the measurement position errors it the fits (use error model from photcode table)

Location:
branches/eam_branches/ipp-20101205/Ohana/src/relastro
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/include/relastro.h

    r29001 r30509  
    9494
    9595double SIGMA_LIM;
    96 int SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored
     96int    SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored
    9797double MIN_ERROR;
     98
     99int    IMFIT_CLIP_NITER; // number of clipping iterations to perform in FitChip
     100double IMFIT_CLIP_NSIGMA; // number of sigma to clip in FitChip
     101double IMFIT_SYS_SIGMA_LIM; // max dMag for objects used to measure systematic scatter
    98102
    99103double RADIUS; // match radius for high-speed objects
     
    325329int UpdateObjectOffsets (SkyList *skylist);
    326330
    327 int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj);
    328 int relastroVisualPlotScatter(double values[], double thresh, int npts);
    329 int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure,
    330                                StatType statsR, StatType statsD, double thresh);
    331 
    332 
     331int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj);
     332// int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj);
     333// int relastroVisualPlotScatter(double values[], double thresh, int npts);
     334// int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, StatType statsR, StatType statsD, double thresh);
     335void relastroSetVisual(int state);
    333336
    334337int FixProblemImages (SkyList *skylist);
     
    352355int createStarMapPoints();
    353356int checkStarMap(int N);
     357
     358int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/ConfigInit.c

    r29001 r30509  
    1919  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
    2020
    21   GetConfig (config, "RELASTRO_SIGMA_LIM",     "%lf", 0, &SIGMA_LIM);
     21  GetConfig (config, "RELASTRO_SIGMA_LIM",         "%lf", 0, &SIGMA_LIM); // exclude measurements on this basis
    2222  GetConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW);
     23
     24  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NITER",    "%d",  0, &IMFIT_CLIP_NITER))    IMFIT_CLIP_NITER  = 3;
     25  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NSIGMA",   "%lf", 0, &IMFIT_CLIP_NSIGMA))   IMFIT_CLIP_NSIGMA = 3.0;
     26  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
    2327
    2428  // XXX these are used in relphot to identify poor stars / images -- define
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/FitChip.c

    r30478 r30509  
    22# include "relastroVisual.h"
    33
    4 // XXX make these user parameters
    5 # define FIT_CHIP_NITER     3
    6 # define FIT_CHIP_NSIGMA    3.0
    7 
    8 // XXX save the fit[0].Npts value in the image table?
    9 
    10 // XXX save measurements of the fit quality (scatter, chisq) in the image table
    11 
    124int FitChip (StarData *raw, StarData *ref, int Nmatch, Image *image) {
    135
    14   int i, Nscatter, Niter, skip;
    15   CoordFit *fit;
    16   double dL, dM, dR, dRmax, *values;
    17 
    18   ALLOCATE (values, double, Nmatch);
    19   for (Niter = 0; Niter < FIT_CHIP_NITER; Niter ++) {
     6  int i, NstatFull, Nstat, Niter, skip;
     7  float dLsig, dMsig, dRsig;
     8  float dLsigFull, dMsigFull, dRsigFull;
     9  float dL, dM, dR, dRmax;
     10
     11  CoordFit *fit = NULL;
     12
     13  for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) {
     14   
     15    // measure the scatter for the unmarked (good) measurements with dM < limit
     16    // SIGMA_LIM here is redundant with ImageOps.c:915
     17    GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, SIGMA_LIM);
     18    dRmax = IMFIT_CLIP_NSIGMA*dRsig;
     19
     20    // (a) skip unfittable points
     21    // (b) mark good and bad points for fit (in and outliers)
    2022
    2123    // measure the scatter distribution (use only the bright end detections)
    22     for (i = Nscatter = 0; i < Nmatch; i++) {
     24    for (i = 0; i < Nmatch; i++) {
    2325      if (raw[i].mask) continue;
    24       if (isnan(raw[i].dMag) || raw[i].dMag > SIGMA_LIM) continue;
     26      if (isnan(raw[i].dMag)) {
     27        raw[i].mask |= 0x0004;
     28        continue;
     29      }
     30      if (raw[i].dMag > SIGMA_LIM) {
     31        raw[i].mask |= 0x0008;
     32        continue;
     33      } // is this redundant with ImageOps.c:915?
    2534
    2635      dL = raw[i].L - ref[i].L;
    2736      dM = raw[i].M - ref[i].M;
    2837      dR = hypot (dL, dM);
    29 
    30       values[Nscatter] = dR;
    31       Nscatter++;
    32     }
    33 
    34     if (Nscatter > 5) {
    35       // for a 2D Gaussian, 40% of the points are within 1 sigma; dRmax is ~ 3 sigma
    36       // XXX this test is not sensible for Nscatter < XXX (5?)
    37       dsort (values, Nscatter);
    38       dRmax = FIT_CHIP_NSIGMA*values[(int)(0.40*Nscatter)];
    39       relastroVisualPlotScatter(values, dRmax, Nscatter);
    40       relastroVisualPlotRawRef(raw, ref, dRmax, Nmatch);
    41     } else {
    42       dRmax = 0;
    43     }
     38      if (dR > dRmax) {
     39        raw[i].mask |= 0x0010;
     40        continue;
     41      }
     42    }
     43
     44    // figures to assess the fitting process:
     45    // x vs dx, x vs dy, y vs dx, y vs dy :
     46    // residual vector field
     47    // dx vs mag, dy vs mag
     48    relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch);
    4449
    4550    // fit the requested order polynomial
     
    4752      image[0].coords.Npolyterms = CHIPORDER;
    4853    }
     54    if (fit) fit_free (fit);
    4955    fit = fit_init (image[0].coords.Npolyterms);
    5056
    5157    // generate the fit matches
    5258    for (i = 0; i < Nmatch; i++) {
    53       if (raw[i].mask) {
    54         continue;
    55       }
    56       if (isnan(raw[i].dMag) || raw[i].dMag > SIGMA_LIM) {
    57         continue;
    58       }
    59 
    60       // only keep objects within dRmax
    61       dL = raw[i].L - ref[i].L;
    62       dM = raw[i].M - ref[i].M;
    63       dR = hypot (dL, dM);
    64 
    65       // fprintf (stderr, "fit %f %f -> %f %f : %f %f (%f vs %f) wt: %f\n", raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].L, raw[i].M, dR, dRmax, raw[i].dPos);
    66 
    67       if ((dRmax > 0.0) && (dR > dRmax)) continue;
    68 
     59      if (raw[i].mask) continue;
    6960      fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
    7061    }
     
    9081      if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms);
    9182      fit_free (fit);
    92       free (values);
    9383      image[0].flags |= ID_IMAGE_ASTROM_FEW;
    9484      return FALSE;
    9585    }
    96 
    97     // fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);
    9886
    9987    // measure the fit, update the coords & object coordinates
     
    11098    }
    11199
    112     fit_free (fit);
    113 
    114100    for (i = 0; i < Nmatch; i++) {
    115101      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords);
     
    118104  }
    119105
    120   free (values);
     106  // count mask classes
     107  int nMask1 = 0;
     108  int nMask2 = 0;
     109  int nMask3 = 0;
     110  int nMask4 = 0;
     111  int nMask5 = 0;
     112  for (i = 0; i < Nmatch; i++) {
     113    if (!raw[i].mask) continue;
     114    if (raw[i].mask & 0x01) nMask1 ++;
     115    if (raw[i].mask & 0x02) nMask2 ++;
     116    if (raw[i].mask & 0x04) nMask3 ++;
     117    if (raw[i].mask & 0x08) nMask4 ++;
     118    if (raw[i].mask & 0x10) nMask5 ++;
     119  }
     120
     121  GetScatterRawRef(&dLsigFull, &dMsigFull, &dRsigFull, &NstatFull, raw, ref, Nmatch, SIGMA_LIM);
     122  GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM);
     123  if (VERBOSE) fprintf (stderr, "fit sigma: %f (%f, %f) : full: %f (%f, %f), scatter limit: %f (%d full, %d bright, %d fit, %d all) (%d %d %d %d %d)\n", dRsig, dLsig, dMsig, dRsigFull, dLsigFull, dMsigFull, dRmax, NstatFull, Nstat, fit[0].Npts, Nmatch, nMask1, nMask2, nMask3, nMask4, nMask5);
     124
     125  image[0].dXpixSys = dLsig;
     126  image[0].dYpixSys = dMsig;
     127  image[0].nFitAstrom = fit[0].Npts;
     128
     129  if (fit) fit_free (fit);
     130
    121131  return TRUE;
     132}
     133
     134// measure the scatter distribution (limit selected objects by dMag)
     135int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit) {
     136
     137  int i, Ns;
     138  float dL, dM, dLsum, dLsum2, dMsum, dMsum2, *dR;
     139
     140  ALLOCATE (dR, float, Nstars);
     141
     142  Ns = 0;
     143  dLsum = dLsum2 = dMsum = dMsum2 = 0.0;
     144  for (i = 0; i < Nstars; i++) {
     145    if (raw[i].mask) continue;
     146    if (isnan(raw[i].dMag)) continue;
     147    if ((SigmaLimit > 0.0) && (raw[i].dMag > SigmaLimit)) continue;
     148   
     149    dL = raw[i].L - ref[i].L;
     150    dM = raw[i].M - ref[i].M;
     151
     152    dLsum  += dL;
     153    dLsum2 += dL*dL;
     154    dMsum  += dM;
     155    dMsum2 += dM*dM;
     156
     157    dR[Ns] = hypot (dL, dM);
     158    Ns++;
     159  }
     160
     161  *dLsig = sqrt((dLsum2 / Ns) - SQ(dLsum/Ns));
     162  *dMsig = sqrt((dMsum2 / Ns) - SQ(dMsum/Ns));
     163  *nKeep = Ns;
     164
     165  if (Ns < 5) {
     166    *dRsig = NAN;
     167    free  (dR);
     168    return (FALSE);
     169  }
     170
     171  // for a 2D Gaussian, 40% of the points are within R = 1 sigma
     172  fsort (dR, Ns);
     173  *dRsig = dR[(int)(0.40*Ns)];
     174 
     175  free  (dR);
     176  return (TRUE);
    122177}
    123178
     
    162217  fclose (f);
    163218*/
     219
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/GetAstromError.c

    r30477 r30509  
    11# include "relastro.h"
    2 # define WEIGHTED_ERRORS 0
     2# define WEIGHTED_ERRORS 1
    33
    44float GetAstromError (Measure *measure, int mode) {
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/ImageOps.c

    r29001 r30509  
    336336  off_t i, m, c, n, nPos;
    337337  double X, Y, L, M, P, Q, R, D, dR, dD;
    338   double dPos, DPOS_MAX_ASEC;
     338  double dPos, dPosSys, DPOS_MAX_ASEC;
    339339
    340340  Mosaic *mosaic;
     
    359359  }
    360360
    361   // accumulate the rms position offsets.  if this value, or any specific entry, is too
    362   // large, we will reset the image to the original coords at the end of the analysis
    363 
     361  // these are used to accumulate the rms position offsets.  if this value, or any
     362  // specific entry, is too large, we will reset the image to the original coords at the
     363  // end of the analysis
    364364  dPos = 0.0;
    365365  nPos = 0;
     366
     367  // convert the image systematic error in pixels to a value in arcsec
     368  {
     369    double dLsig, dMsig;
     370    double Ro, Do, Rx, Dx, dP0, dP1;
     371    Coords *coords;
     372
     373    // these values are in pixels, but we to convert to arcsec
     374    dLsig = image[0].dXpixSys;
     375    dMsig = image[0].dYpixSys;
     376
     377    if (moscoords == NULL) {
     378      coords = imcoords;
     379    } else {
     380      coords = moscoords;
     381    }
     382    XY_to_LM (&Ro, &Do, 0.0, 0.0, coords);
     383    XY_to_LM (&Rx, &Dx, dLsig, 0.0, coords);
     384    dP0 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec
     385    XY_to_LM (&Rx, &Dx, 0.0, dLsig, coords);
     386    dP1 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec
     387    dPosSys = 0.5 * (dP0 + dP1);
     388  }     
    366389
    367390  for (i = 0; i < Nlist[im]; i++) {
     
    418441    catalog[c].measure[m].dR = dR;
    419442    catalog[c].measure[m].dD = dD;
    420 
     443   
    421444    if (catalog[c].measure[m].dR > +180.0*3600.0) {
    422445      // average on high end of boundary, move star up
     
    429452      catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);
    430453    }
     454
     455    // set the systematic error for this image:
     456    catalog[c].measure[m].dRsys = ToShortPixels(dPosSys);
    431457  }
    432458
     
    544570
    545571    // an object with only one detection provides no information about the image calibration
    546     //XXX this is already taken care of in bcatalog
    547     raw[i].mask = FALSE;
    548     int mask = FALSE;
     572    // XXX this is already taken care of in bcatalog
     573    raw[i].mask = 0x0000;
    549574    if (catalog[c].average[n].Nmeasure <= SRC_MEAS_TOOFEW) {
    550       mask = TRUE;
     575      raw[i].mask |= 0x0001;
    551576    }
    552577    if (!finite(catalog[c].measure[m].dR) || !finite(catalog[c].measure[m].dD)) {
    553       mask = TRUE;
    554     }
    555 
    556     raw[i].mask = mask;
    557 
     578      raw[i].mask |= 0x0002;
     579    }
    558580
    559581    switch (mode) {
     
    725747    }
    726748
    727     //examine results
    728     relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset,
    729                                catalog[0].average[j].Nmeasure,
    730                                statsR, statsD, Ns);
     749    // examine results
     750    // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    731751  }
    732752 
     
    852872    }  //done rejecting outliers
    853873
    854     //examine results
    855     relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset,
    856                                catalog[0].average[j].Nmeasure,
    857                                statsR, statsD, Ns);
     874    // examine results
     875    // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    858876   
    859877  } //done looping over objects
     
    917935
    918936  /* select measurements by measurement error */
    919   if ((SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) return FALSE;
     937  if ((SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) {
     938    return FALSE;
     939  }
    920940 
    921941  /* select measurements by mag limit */
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/UpdateChips.c

    r30476 r30509  
    88
    99  /* we can measure new image parameters for each non-mosaic chip independently */
    10   off_t i, Nimage, Nraw, Nref;
     10  off_t i, Nimage, Nraw, Nref, nFitAstr;
    1111  Image *image;
    1212  StarData *raw, *ref;
    1313  Coords *oldCoords;
    14 
     14  float dXpixSys, dYpixSys;
    1515  double *Ro, *Do;
    1616  char *mode;
     
    1919
    2020  image = getimages (&Nimage);
    21   // XXX BuildChipMatch (image, Nimage);
    2221
    2322  // save fit results for summary plot
     
    5453    assert (Nraw == Nref);
    5554
     55    // save these in case of failure
    5656    saveCoords (&image[i].coords, i);
     57    dXpixSys = image[i].dXpixSys;
     58    dYpixSys = image[i].dYpixSys;
     59    nFitAstr = image[i].nFitAstrom;
    5760
    5861    // FitChip does iterative, clipped fitting
     
    6063    if (!FitChip (raw, ref, Nraw, &image[i])) {
    6164      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
     65
     66      // restore status quo ante
    6267      oldCoords = getCoords (i);
    6368      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     69      image[i].dXpixSys = dXpixSys;
     70      image[i].dYpixSys = dYpixSys;
     71      image[i].nFitAstrom = nFitAstr;
     72
    6473      saveCenter (image, &Ro[i], &Do[i], i);
    6574      mode[i] = 1;
     
    7281    if (!checkStarMap (i)) {
    7382      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
     83      // restore status quo ante
    7484      oldCoords = getCoords (i);
    7585      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     86      image[i].dXpixSys = dXpixSys;
     87      image[i].dYpixSys = dYpixSys;
     88      image[i].nFitAstrom = nFitAstr;
     89
    7690      saveCenter (image, &Ro[i], &Do[i], i);
    7791      mode[i] = 2;
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/UpdateObjects.c

    r30475 r30509  
    136136        dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
    137137        dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
     138
     139        // add systematic error in quadrature, if desired
     140        // only do this after the fit has converged (or you will never improve the poor images)
     141        // if (INCLUDE_SYS_ERR) {
     142        // float dRsys = FromShortPixels(catalog[i].measure[m].dRsys);
     143        // dX[N] = hypot(dX[N], dRsys);
     144        // dY[N] = hypot(dY[N], dRsys);
     145        // }
     146
    138147        // dX[N] = 0.1;
    139148        // dY[N] = 0.1;
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/args.c

    r28184 r30509  
    144144    VERBOSE = VERBOSE2 = TRUE;
    145145    remove_argument (N, &argc, argv);
     146  }
     147
     148  if ((N = get_argument (argc, argv, "-visual"))) {
     149    remove_argument (N, &argc, argv);
     150    relastroSetVisual(TRUE);
    146151  }
    147152
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/relastro.c

    r29001 r30509  
    7878        MARKTIME("update chips: %f sec\n", dtime);
    7979      }
     80      // create summary plots of the process
     81      // relastroVisualSummaryChips();
    8082      break;
    8183
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/relastroVisual.c

    r24308 r30509  
    1111#define KAPAY 700
    1212
    13 static int kapa = -1;
     13static int kapa1 = -1;
    1414static int kapa2 = -1;
    1515static int kapa3 = -1;
     16static int kapa4 = -1;
    1617
    1718static int isVisual = FALSE;
    18 static int plotRawRef = FALSE;
    19 static int plotScatter = FALSE;
    20 static int plotResid = FALSE;
    21 static int plotVector = FALSE;
     19static int plotRawRef = TRUE;
     20// static int plotScatter = TRUE;
     21// static int plotResid = TRUE;
     22// static int plotVector = TRUE;
    2223static int plotOutliers = TRUE;
    2324
     
    2930      fprintf(stderr, "Failure to open kapa.\n");
    3031      isVisual = 0;
    31       return 0;
     32      return FALSE;
    3233    }
    33     //    KapaResize (*kapid, KAPAX, KAPAY);
    34   }
    35   return 1;
     34  }
     35  return TRUE;
    3636}
    3737
     
    4949    isVisual = 0;
    5050  }
    51   return 1;
    52 }
     51  return TRUE;
     52}
     53
     54void relastroSetVisual(int state) {
     55  isVisual = state;
     56}
     57
    5358
    5459/** Size graphdata to encompass all points */
     
    7075    graphdata->xmax = xhi;
    7176    graphdata->ymax = yhi;
    72     return 1;
    73 }
    74 
    75 static int residPlot(float x[], float y[],
    76                      float xVec[], float yVec[],
    77                      int npts, int *kapaID) {
    78     if (!isVisual || !plotResid) return TRUE;
     77    return TRUE;
     78}
     79
     80/** 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy **/
     81int relastroVisualRawRef(int *kapaID, float *x, float *y, float *dx, float *dy, float *dPos, int npts) {
     82
    7983    Graphdata graphdata;
    8084    KapaSection section;
     
    8387
    8488    KapaInitGraph(&graphdata);
    85     KapaClearPlots(*kapaID);
     89    KapaClearSections(*kapaID);
    8690    KapaSetFont(*kapaID, "helvetica", 14);
    8791
     
    8993    section.x = 0.0; section.y = 0.0;
    9094    section.dx = .45, section.dy = .45;
     95    section.bg = KapaColorByName("white");
    9196    graphdata.ptype = 7;
    9297    graphdata.style = 2;
     98    graphdata.etype |= 0x01;
    9399
    94100    KapaSetSection(*kapaID, &section);
    95     if(!scaleGraphdata(x, xVec, &graphdata, npts)) return 0;
     101    if(!scaleGraphdata(x, dx, &graphdata, npts)) return 0;
    96102    KapaSetLimits(*kapaID, &graphdata);
    97103    KapaBox(*kapaID, &graphdata);
     
    100106    KapaPrepPlot(*kapaID, npts, &graphdata);
    101107    KapaPlotVector(*kapaID, npts, x, "x");
    102     KapaPlotVector(*kapaID, npts, xVec, "y");
     108    KapaPlotVector(*kapaID, npts, dx, "y");
     109    KapaPlotVector(*kapaID, npts, dPos, "dym");
     110    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    103111
    104112    section.x = .5; section.y = 0; section.name="1";
    105113    KapaSetSection(*kapaID, &section);
    106     if(!scaleGraphdata(x, yVec, &graphdata, npts)) return 0;
     114    if(!scaleGraphdata(x, dy, &graphdata, npts)) return 0;
    107115    KapaSetLimits(*kapaID, &graphdata);
    108116    KapaBox(*kapaID, &graphdata);
     
    111119    KapaPrepPlot(*kapaID, npts, &graphdata);
    112120    KapaPlotVector(*kapaID, npts, x, "x");
    113     KapaPlotVector(*kapaID, npts, yVec, "y");
     121    KapaPlotVector(*kapaID, npts, dy, "y");
     122    KapaPlotVector(*kapaID, npts, dPos, "dym");
     123    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    114124
    115125    section.x = .0; section.y = .5; section.name="2";
    116126    KapaSetSection(*kapaID, &section);
    117     if(!scaleGraphdata(y, xVec, &graphdata, npts)) return 0;;
     127    if(!scaleGraphdata(y, dx, &graphdata, npts)) return 0;;
    118128    KapaSetLimits(*kapaID, &graphdata);
    119129    KapaBox(*kapaID, &graphdata);
     
    122132    KapaPrepPlot(*kapaID, npts, &graphdata);
    123133    KapaPlotVector(*kapaID, npts, y, "x");
    124     KapaPlotVector(*kapaID, npts, xVec, "y");
     134    KapaPlotVector(*kapaID, npts, dx, "y");
     135    KapaPlotVector(*kapaID, npts, dPos, "dym");
     136    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    125137
    126138    section.x = .5; section.y = .5; section.name="3";
    127139    KapaSetSection(*kapaID, &section);
    128     if(!scaleGraphdata(y, yVec, &graphdata, npts)) return 0;
     140    if(!scaleGraphdata(y, dy, &graphdata, npts)) return 0;
    129141    KapaSetLimits(*kapaID, &graphdata);
    130142    KapaBox(*kapaID, &graphdata);
     
    133145    KapaPrepPlot(*kapaID, npts, &graphdata);
    134146    KapaPlotVector(*kapaID, npts, y, "x");
    135     KapaPlotVector(*kapaID, npts, yVec, "y");
    136 
    137     return 1;
    138 }
    139 
    140 
    141 /**Plot a vector field*/
    142 static int plotVectorField(float x[], float y[],
    143                            float xVec[], float yVec[],
    144                            int npts, int *kapaID, double maxVecLength) {
    145 
    146     if(!plotVector) return 1;
     147    KapaPlotVector(*kapaID, npts, dy, "y");
     148    KapaPlotVector(*kapaID, npts, dPos, "dym");
     149    KapaPlotVector(*kapaID, npts, dPos, "dyp");
     150
     151    return TRUE;
     152}
     153
     154
     155/** Plot a vector field (circles at vector origin, scaled lines giving vector directions */
     156int relastroVisualVectorField(int *kapaID, float *x, float *y, float *dx, float *dy, int npts, double maxVecLength) {
    147157
    148158    Graphdata graphdata;
    149     float singleX[2], singleY[2];
     159    float *xVec, *yVec;
    150160    float vecScaleFactor;
    151161    float graphSize;
    152162    int i;
    153163    char plotTitle[50];
    154     sprintf(plotTitle, "Maximum Vector Size = %5.1e", maxVecLength);
    155 
     164
     165    if (!npts) return FALSE;
    156166    if (!initWindow(kapaID)) return 0;
    157167
     168    snprintf(plotTitle, 50, "Maximum Vector Size = %5.1e", maxVecLength);
     169
    158170    KapaInitGraph(&graphdata);
    159     KapaClearPlots(*kapaID);
    160     if(!scaleGraphdata(x, y, &graphdata, npts)) return 0;
     171    KapaClearSections(*kapaID);
     172    KapaSetFont(*kapaID, "helvetica", 14);
     173
     174    if (!scaleGraphdata(x, y, &graphdata, npts)) return 0;
    161175
    162176    graphSize = graphdata.xmax - graphdata.xmin;
     
    164178        graphSize = graphdata.ymax - graphdata.ymin;
    165179    }
    166 
    167180    vecScaleFactor = graphSize * 0.02 / (float)maxVecLength;
    168 #ifdef TESTING
    169     fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n",
    170             graphSize, maxVecLength, vecScaleFactor);
    171 #endif
    172 
     181
     182    // fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n", graphSize, maxVecLength, vecScaleFactor);
    173183
    174184    KapaSetFont (*kapaID, "helvetica", 14);
     
    179189    graphdata.ptype = 7;
    180190    graphdata.style = 2;
     191    graphdata.color = KapaColorByName("black");
    181192    KapaPrepPlot(*kapaID, npts, &graphdata);
    182193    KapaPlotVector(*kapaID, npts, x, "x");
    183194    KapaPlotVector(*kapaID, npts, y, "y");
    184195
    185     //plot each vector individually
    186     graphdata.ptype = 0;
    187     graphdata.style = 0;
     196    ALLOCATE (xVec, float, 2*npts);
     197    ALLOCATE (yVec, float, 2*npts);
     198    for (i = 0; i < npts; i++) {
     199      xVec[2*i + 0] = x[i];
     200      yVec[2*i + 0] = y[i];
     201      xVec[2*i + 1] = x[i] + dx[i] * vecScaleFactor;
     202      yVec[2*i + 1] = y[i] + dy[i] * vecScaleFactor;
     203    }
     204
     205    graphdata.ptype = 100; // line segements by point pair
     206    graphdata.style = 2;
    188207    graphdata.color = KapaColorByName("blue");
    189     for(i = 0; i < npts; i++) {
    190         singleX[0] = x[i];
    191         singleY[0] = y[i];
    192         singleX[1] = x[i] + xVec[i] * vecScaleFactor;
    193         singleY[1] = y[i] + yVec[i] * vecScaleFactor;
    194         KapaPrepPlot(*kapaID, 2, &graphdata);
    195         KapaPlotVector(*kapaID, 2, singleX, "x");
    196         KapaPlotVector(*kapaID, 2, singleY, "y");
    197     }
    198     return 1;
    199 }
    200 
    201 int relastroVisualPlotScatter(double values[], double thresh, int npts) {
    202     float *x, *data;
    203     int i;
    204     float xline[2], yline[2];
    205     if (!isVisual || !plotScatter) return 1;
    206     if (!initWindow(&kapa2)) return 0;
    207 
    208     ALLOCATE(x, float, npts);
    209     ALLOCATE(data, float, npts);
    210 
    211     for(i = 0; i < npts; i++) {
    212         x[i] = i;
    213         data[i] = (float) values[i];
    214     }
     208    KapaPrepPlot  (*kapaID, 2*npts, &graphdata);
     209    KapaPlotVector(*kapaID, 2*npts, xVec, "x");
     210    KapaPlotVector(*kapaID, 2*npts, yVec, "y");
     211
     212    free (xVec);
     213    free (yVec);
     214    return TRUE;
     215}
     216
     217int relastroVisualPlotScatter(int *kapaID, float *dXfit, float *dYfit, float *mag, int npts) {
    215218
    216219    Graphdata graphdata;
    217220    KapaSection section;
    218     section.x = 0; section.y = 0; section.dx = 1; section.dy = 1;
    219     section.name = "junk";
     221
     222    if (!initWindow(kapaID)) return 0;
    220223
    221224    KapaInitGraph(&graphdata);
    222     KapaClearPlots(kapa2);
    223     KapaSetSection(kapa2, &section);
    224 
    225     graphdata.ptype = 0;
    226     graphdata.style = 0;
    227     graphdata.xmin = 0;
    228     graphdata.xmax = npts;
    229     graphdata.ymin = 0;
    230     graphdata.ymax = data[npts-1];
    231 
    232     KapaSetFont(kapa2, "helvetica", 14);
    233     KapaSetLimits(kapa2, &graphdata);
    234     KapaBox(kapa2, &graphdata);
    235     KapaSendLabel( kapa2, "Object", KAPA_LABEL_XM);
    236     KapaSendLabel( kapa2, "Offset(pixels)", KAPA_LABEL_YM);
    237     KapaSendLabel( kapa2, "Astrometric Offset with fit cutoff",
    238                    KAPA_LABEL_XP);
    239     KapaPrepPlot(kapa2, npts, &graphdata);
    240     KapaPlotVector(kapa2, npts, x, "x");
    241     KapaPlotVector(kapa2, npts, data, "y");
    242 
    243     graphdata.color = KapaColorByName("red");
    244     KapaPrepPlot(kapa2, 2, &graphdata);
    245     yline[0] = (float) thresh;
    246     yline[1] = (float) thresh;
    247     xline[0] = graphdata.xmin;
    248     xline[1] = graphdata.xmax;
    249     KapaPlotVector(kapa2, 2, xline, "x");
    250     KapaPlotVector(kapa2, 2, yline, "y");
    251 
    252     askUser(&plotScatter);
    253     return 1;
    254 }
    255 
    256 
     225    KapaClearSections(*kapaID);
     226    KapaSetFont(*kapaID, "helvetica", 14);
     227
     228    section.name = "a";
     229    section.x = 0.0; section.y = 0.0; section.dx = 1.0; section.dy = 0.5;
     230    section.bg = KapaColorByName("white");
     231    KapaSetSection(*kapaID, &section);
     232
     233    graphdata.ptype = 2;
     234    graphdata.style = 2;
     235
     236    if(!scaleGraphdata(mag, dXfit, &graphdata, npts)) return 0;
     237    KapaSetLimits(*kapaID, &graphdata);
     238    KapaBox(*kapaID, &graphdata);
     239    KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM);
     240    KapaSendLabel(*kapaID, "dXfit", KAPA_LABEL_YM);
     241    KapaPrepPlot(*kapaID, npts, &graphdata);
     242    KapaPlotVector(*kapaID, npts, mag, "x");
     243    KapaPlotVector(*kapaID, npts, dXfit, "y");
     244
     245    section.name = "b";
     246    section.x = 0.0; section.y = 0.5; section.dx = 1.0; section.dy = 0.5;
     247    section.bg = KapaColorByName("white");
     248    KapaSetSection(*kapaID, &section);
     249
     250    graphdata.ptype = 2;
     251    graphdata.style = 2;
     252
     253    if(!scaleGraphdata(mag, dYfit, &graphdata, npts)) return 0;
     254    KapaSetLimits(*kapaID, &graphdata);
     255    KapaBox(*kapaID, &graphdata);
     256    KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM);
     257    KapaSendLabel(*kapaID, "dYfit", KAPA_LABEL_YM);
     258    KapaPrepPlot(*kapaID, npts, &graphdata);
     259    KapaPlotVector(*kapaID, npts, mag, "x");
     260    KapaPlotVector(*kapaID, npts, dYfit, "y");
     261
     262    return TRUE;
     263}
    257264
    258265/** plot raw vs ref (L, M). Only those whose distance is < drMax are used in fit*/
    259 int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj) {
    260 
    261   if( !isVisual || !plotRawRef) return 1;
    262   if( !initWindow(&kapa)) return 0;
     266int relastroVisualPlotFittedStars(int *kapaID, float *rawX, float *rawY, float *refX, float *refY, int numNoFit, float *rawXfit, float *rawYfit, float *refXfit, float *refYfit, int numFit) {
     267
     268  Graphdata graphdata;
     269
     270  if (!initWindow(kapaID)) return 0;
     271
     272  KapaInitGraph(&graphdata);
     273  KapaClearPlots(*kapaID);
     274
     275  graphdata.ptype = 7;
     276  graphdata.style = 2;
     277
     278  if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) {
     279      fprintf(stderr, "Not enough finite points for plotting");
     280      return 0;
     281  }
     282
     283  KapaSetFont(*kapaID, "helvetica", 14);
     284  KapaSetLimits(*kapaID, &graphdata);
     285  KapaBox(*kapaID, &graphdata);
     286  KapaSendLabel( *kapaID, "X", KAPA_LABEL_XM);
     287  KapaSendLabel( *kapaID, "Y", KAPA_LABEL_YM);
     288  KapaSendLabel( *kapaID, "orange, red, green, blue: (raw, ref), (nofit, fit)",
     289                 KAPA_LABEL_XP);
     290
     291  graphdata.color = KapaColorByName("orange");
     292  graphdata.size = 1;
     293  KapaPrepPlot(*kapaID, numNoFit, &graphdata);
     294  KapaPlotVector(*kapaID, numNoFit, rawX, "x");
     295  KapaPlotVector(*kapaID, numNoFit, rawY, "y");
     296
     297  graphdata.color = KapaColorByName("red");
     298  graphdata.size = 2;
     299  KapaPrepPlot(*kapaID, numNoFit, &graphdata);
     300  KapaPlotVector(*kapaID, numNoFit, refX, "x");
     301  KapaPlotVector(*kapaID, numNoFit, refY, "y");
     302
     303  graphdata.color = KapaColorByName("green");
     304  graphdata.size = 1;
     305  KapaPrepPlot(*kapaID, numFit,  &graphdata);
     306  KapaPlotVector(*kapaID, numFit, rawXfit, "x");
     307  KapaPlotVector(*kapaID, numFit, rawYfit, "y");
     308
     309  graphdata.color = KapaColorByName("blue");
     310  graphdata.size = 2;
     311  KapaPrepPlot(*kapaID, numFit, &graphdata);
     312  KapaPlotVector(*kapaID, numFit, refXfit, "x");
     313  KapaPlotVector(*kapaID, numFit, refYfit, "y");
     314
     315  return TRUE;
     316}
     317
     318/** create various plots using the data in raw and ref **/
     319int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj) {
    263320
    264321  float *rawX, *rawY,  *refX, *refY;
    265322  float *rawXfit, *rawYfit, *refXfit, *refYfit;
    266323  float *magRaw, *magRef, *magRawfit, *magReffit;
    267   float *xVec, *yVec;
     324  float *dXfit, *dYfit, *dPos;
    268325  int numFit = 0, numNoFit = 0;
    269326  double dL, dM, dR;
     327
     328  if (!isVisual) return TRUE;
    270329
    271330  ALLOCATE(rawX,      float, numObj);
     
    273332  ALLOCATE(refX,      float, numObj);
    274333  ALLOCATE(refY,      float, numObj);
     334  ALLOCATE(magRaw,    float, numObj);
     335  ALLOCATE(magRef,    float, numObj);
     336
    275337  ALLOCATE(rawXfit,   float, numObj);
    276338  ALLOCATE(rawYfit,   float, numObj);
    277339  ALLOCATE(refXfit,   float, numObj);
    278340  ALLOCATE(refYfit,   float, numObj);
    279   ALLOCATE(magRaw,    float, numObj);
    280   ALLOCATE(magRef,    float, numObj);
    281341  ALLOCATE(magRawfit, float, numObj);
    282342  ALLOCATE(magReffit, float, numObj);
     343  ALLOCATE(dXfit,     float, numObj);
     344  ALLOCATE(dYfit,     float, numObj);
     345  ALLOCATE(dPos,      float, numObj);
    283346
    284347  int i;
    285348  for(i = 0; i < numObj; i++) {
    286     if  (raw[i].mask) continue;
     349    if (raw[i].mask) continue; // XXX
    287350
    288351    dL = raw[i].L - ref[i].L;
    289352    dM = raw[i].M - ref[i].M;
    290353    dR = hypot (dL, dM);
     354
     355    // XXX change the selection to a mask-based thing
    291356    if (dR > dRmax) {
     357      // UNFITTED values
    292358      rawX[numNoFit] = raw[i].X;
    293359      rawY[numNoFit] = raw[i].Y;
     
    298364      numNoFit++;
    299365    } else {
    300       rawXfit[numFit] = raw[i].X;
    301       rawYfit[numFit] = raw[i].Y;
    302       refXfit[numFit] = ref[i].X;
    303       refYfit[numFit] = ref[i].Y;
    304       magRaw[numFit] = raw[i].Mag;
    305       magRef[numFit] = ref[i].Mag;
     366      // FITTED values
     367      rawXfit[numFit]   = raw[i].X;
     368      rawYfit[numFit]   = raw[i].Y;
     369      refXfit[numFit]   = ref[i].X;
     370      refYfit[numFit]   = ref[i].Y;
     371      magRawfit[numFit] = raw[i].Mag;
     372      magReffit[numFit] = ref[i].Mag;
     373      dPos[numFit]      = ref[i].dPos;
     374      dXfit[numFit]     = raw[i].X - ref[i].X;
     375      dYfit[numFit]     = raw[i].Y - ref[i].Y;
    306376      numFit++;
    307377    }
     
    310380  if (numFit == 0) return 0;
    311381
    312   Graphdata graphdata;
    313 
    314   KapaInitGraph(&graphdata);
    315   KapaClearPlots(kapa);
    316 
    317   graphdata.ptype = 7;
    318   graphdata.style = 2;
    319 
    320   if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) {
    321       fprintf(stderr, "Not enough finite points for plotting");
    322       return 0;
    323   }
    324 
    325   KapaSetFont(kapa, "helvetica", 14);
    326   KapaSetLimits(kapa, &graphdata);
    327   KapaBox(kapa, &graphdata);
    328   KapaSendLabel( kapa, "X", KAPA_LABEL_XM);
    329   KapaSendLabel( kapa, "Y", KAPA_LABEL_YM);
    330   KapaSendLabel( kapa, "orange, red, green, blue: (raw, ref), (nofit, fit)",
    331                  KAPA_LABEL_XP);
    332 
    333   graphdata.color = KapaColorByName("orange");
    334   graphdata.size = 1;
    335   KapaPrepPlot(kapa, numNoFit, &graphdata);
    336   KapaPlotVector(kapa, numNoFit, rawX, "x");
    337   KapaPlotVector(kapa, numNoFit, rawY, "y");
    338 
    339   graphdata.color = KapaColorByName("red");
    340   graphdata.size = 2;
    341   KapaPrepPlot(kapa, numNoFit, &graphdata);
    342   KapaPlotVector(kapa, numNoFit, refX, "x");
    343   KapaPlotVector(kapa, numNoFit, refY, "y");
    344 
    345   graphdata.color = KapaColorByName("green");
    346   graphdata.size = 1;
    347   KapaPrepPlot(kapa, numFit,  &graphdata);
    348   KapaPlotVector(kapa, numFit, rawXfit, "x");
    349   KapaPlotVector(kapa, numFit, rawYfit, "y");
    350 
    351   graphdata.color = KapaColorByName("blue");
    352   graphdata.size = 2;
    353   KapaPrepPlot(kapa, numFit, &graphdata);
    354   KapaPlotVector(kapa, numFit, refXfit, "x");
    355   KapaPlotVector(kapa, numFit, refYfit, "y");
    356 
    357   ALLOCATE(xVec, float, numFit);
    358   ALLOCATE(yVec, float, numFit);
    359 
    360   //plot the fitted objects as vectors
    361   for(i = 0; i < numFit; i++) {
    362       xVec[i] = rawXfit[i] - refXfit[i];
    363       yVec[i] = rawYfit[i] - refYfit[i];
    364   }
    365 
    366   plotVectorField(rawXfit, rawYfit, xVec, yVec, numFit, &kapa3, dRmax);
    367   if(!residPlot(rawXfit, rawYfit, xVec, yVec, numFit, &kapa2)) {
    368       fprintf(stderr, "Unable to plot residuals");
    369       return 0;
    370   }
    371 
    372   FREE(xVec);
    373   FREE(yVec);
     382  // 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy
     383  relastroVisualRawRef(&kapa1, rawXfit, rawYfit, dXfit, dYfit, dPos, numFit);
     384
     385  // vector line plot for the fit
     386  relastroVisualVectorField(&kapa2, rawXfit, rawYfit, dXfit, dYfit, numFit, dRmax);
     387
     388  // dXfit, dYfit vs mag
     389  relastroVisualPlotScatter(&kapa3, dXfit, dYfit, magRawfit, numFit);
     390
     391  // plot the positions of the fitted stars on the chip
     392  relastroVisualPlotFittedStars(&kapa4, rawX, rawY, refX, refY, numNoFit, rawXfit, rawYfit, refXfit, refYfit, numFit);
    374393
    375394  askUser(&plotRawRef);
    376395
     396  FREE(dXfit);
     397  FREE(dYfit);
     398  FREE(dPos);
    377399  FREE(rawX);
    378400  FREE(rawY);
     
    388410  FREE(magReffit);
    389411
    390   return 1;
     412  return TRUE;
    391413}
    392414
     
    403425  KapaSection section;
    404426 
    405   if (!isVisual || !plotOutliers) return 1;
    406   if (!initWindow(&kapa)) return 0;
     427  if (!isVisual || !plotOutliers) return TRUE;
     428  if (!initWindow(&kapa1)) return 0;
    407429 
    408430  // populate vectors
     
    459481  section.x = 0; section.y = 0; section.dx = 1; section.dy = 1;
    460482  section.name = "junk";
     483  section.bg = KapaColorByName("white");
    461484 
    462485  KapaInitGraph(&graphdata);
    463   KapaClearPlots(kapa);
    464   KapaSetFont(kapa, "helvetica", 14);
     486  KapaClearPlots(kapa1);
     487  KapaSetFont(kapa1, "helvetica", 14);
    465488 
    466489  graphdata.ptype = 7;
     
    472495  graphdata.ymax = ymax;
    473496
    474   KapaSetSection(kapa, &section);
    475   KapaSetLimits(kapa, &graphdata);
    476   KapaBox(kapa, &graphdata);
    477 
    478   KapaSendLabel( kapa, "RA (arcsec)", KAPA_LABEL_XM);
    479   KapaSendLabel( kapa, "Dec (arcsec)", KAPA_LABEL_YM);
    480   KapaSendLabel( kapa, "Points flagged as outliers (red)",
     497  KapaSetSection(kapa1, &section);
     498  KapaSetLimits(kapa1, &graphdata);
     499  KapaBox(kapa1, &graphdata);
     500
     501  KapaSendLabel( kapa1, "RA (arcsec)", KAPA_LABEL_XM);
     502  KapaSendLabel( kapa1, "Dec (arcsec)", KAPA_LABEL_YM);
     503  KapaSendLabel( kapa1, "Points flagged as outliers (red)",
    481504                 KAPA_LABEL_XP);
    482505
    483506  graphdata.color = KapaColorByName("green");
    484   KapaPrepPlot(kapa, Nin, &graphdata);
    485   KapaPlotVector(kapa, Nin, Rin, "x");
    486   KapaPlotVector(kapa, Nin, Din, "y");
     507  KapaPrepPlot(kapa1, Nin, &graphdata);
     508  KapaPlotVector(kapa1, Nin, Rin, "x");
     509  KapaPlotVector(kapa1, Nin, Din, "y");
    487510
    488511  graphdata.color = KapaColorByName("red");
    489   KapaPrepPlot(kapa, Nout, &graphdata);
    490   KapaPlotVector(kapa, Nout, Rout, "x");
    491   KapaPlotVector(kapa, Nout, Dout, "y");
     512  KapaPrepPlot(kapa1, Nout, &graphdata);
     513  KapaPlotVector(kapa1, Nout, Rout, "x");
     514  KapaPlotVector(kapa1, Nout, Dout, "y");
    492515
    493516  graphdata.color = KapaColorByName("black");
    494517  graphdata.ptype = 0;
    495518  graphdata.style = 0;
    496   KapaPrepPlot(kapa, 100, &graphdata);
    497   KapaPlotVector(kapa, 100, xCirc, "x");
    498   KapaPlotVector(kapa, 100, yCirc, "y");
    499 
    500 
    501  
     519  KapaPrepPlot(kapa1, 100, &graphdata);
     520  KapaPlotVector(kapa1, 100, xCirc, "x");
     521  KapaPlotVector(kapa1, 100, yCirc, "y");
     522
    502523  askUser(&plotOutliers);
    503524
     
    510531}
    511532 
    512  
     533# if (0)
     534int relastroVisualSummaryChips() {
     535
     536  // plot the dXsys, dYsys histograms
     537
     538  // plot x vs dx, y vs dy, etc for all mosaics
     539
     540  // plot a map of median star scatter
     541
     542}
     543# endif
     544
  • branches/eam_branches/ipp-20101205/Ohana/src/relastro/src/select_images.c

    r30474 r30509  
    3333  struct timeval start, stop;
    3434 
    35   double RmaxSkyRegion, RminSkyRegion, DminSkyRegion, DmaxSkyRegion;
     35  double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion;
    3636
    3737  double *RmaxSky;
     
    102102    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
    103103  }
     104  RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion);
    104105  MARKTIME("create sky region coords: %f sec\n", dtime);
    105106
     
    169170    double DminImage = +90.0;
    170171    double DmaxImage = -90.0;
     172    int leftside = FALSE;
    171173    for (j = 0; j < 5; j++) {
    172174      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
     175      Ri[j] = ohana_normalize_angle (Ri[j]);
     176      while (Ri[j] < RminSkyRegion) { Ri[j] += 360.0; }
     177      while (Ri[j] > RmaxSkyRegion) { Ri[j] -= 360.0; }
     178      if (j == 0) {
     179        leftside = (Ri[j] < RmidSkyRegion);
     180      } else {
     181        if (  leftside && (Ri[j] > RmidSkyRegion + 90)) { Ri[j] -= 360.0; }
     182        if (! leftside && (Ri[j] < RmidSkyRegion - 90)) { Ri[j] += 360.0; }
     183      }
     184
    173185      RminImage = MIN(RminImage, Ri[j]);
    174186      RmaxImage = MAX(RmaxImage, Ri[j]);
     
    232244      if (RESET) {
    233245        // XXX do we need / want to do this in relastro?
    234         assignMcal (&image[nimage], (double *) NULL, -1);
    235         image[nimage].dMcal = NAN;
     246        // assignMcal (&image[nimage], (double *) NULL, -1);
     247        // image[nimage].Mcal = NAN;
     248        // image[nimage].dMcal = NAN;
    236249        image[nimage].flags &= ~badImage;
    237250      }
Note: See TracChangeset for help on using the changeset viewer.