IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30616


Ignore:
Timestamp:
Feb 13, 2011, 11:30:02 AM (15 years ago)
Author:
eugene
Message:

various fixes to photdbc, relastro and relphot based on analysis of the first reference database

Location:
trunk/Ohana/src
Files:
34 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/photdbc/include/photdbc.h

    r29938 r30616  
    5151double DMGAIN;
    5252double CHISQ_MAX;
     53double SIGMA_MIN_KEEP;
    5354double SIGMA_MAX;
    5455double AVE_SIGMA_LIM;
    5556int    NMEAS_MIN;
     57int    NMEAS_MIN_FILTERED;
     58int    NCODE_MIN;
    5659double ZERO_POINT;
     60
     61int ExcludeByMinSigma;
    5762
    5863int ExcludeByInstMag;
     
    6570SkyRegion REGION;
    6671PhotCodeData photcodes;
     72
     73char          *PHOTCODE_DROP_LIST, *PHOTCODE_SKIP_LIST;
     74int           NphotcodesDrop,      NphotcodesSkip;
     75PhotCode     **photcodesDrop,     **photcodesSkip;
    6776
    6877# define FLAG_AREA            0X0001
  • trunk/Ohana/src/photdbc/src/ConfigInit.c

    r28331 r30616  
    2626  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
    2727
    28   WarnConfig (config, "PHOTDBC_JOIN_RADIUS",       "%lf", 0, &JOIN_RADIUS);
     28  // XXX join_stars (in photdbc.c) is currently disabled
     29  // WarnConfig (config, "PHOTDBC_JOIN_RADIUS",       "%lf", 0, &JOIN_RADIUS);
     30
     31  // XXX unique_measures (in photdbc.c) is currently disabled
    2932  // WarnConfig (config, "UNIQ_RADIUS",            "%lf", 0, &UNIQ_RADIUS);
    3033
     34  // XXX flag_measures (in photdbc.c) is currently disabled
    3135  // WarnConfig (config, "XMIN",                   "%lf", 0, &XMIN);
    3236  // WarnConfig (config, "XMAX",                   "%lf", 0, &XMAX);
     
    3741  // WarnConfig (config, "MMIN",                   "%lf", 0, &tmp);  MMIN      = 1000*tmp;
    3842  // WarnConfig (config, "MMAX",                   "%lf", 0, &tmp);  MMAX      = 1000*tmp;
     43  // WarnConfig (config, "CHISQ_MAX",              "%lf", 0, &CHISQ_MAX);
     44
     45  // XXX get_mags (in photdbc.c) is currently disabled
    3946  // WarnConfig (config, "DMSYS",                  "%lf", 0, &tmp);  DMSYS     = SQ(1000*tmp);
    4047  // WarnConfig (config, "DMGAIN",                 "%lf", 0, &DMGAIN);
    41   // WarnConfig (config, "CHISQ_MAX",              "%lf", 0, &CHISQ_MAX);
    4248
    4349  ScanConfig (config, "SIGMA_MAX",              "%lf", 0, &SIGMA_MAX);
    4450  ScanConfig (config, "AVE_SIGMA_LIM",          "%lf", 0, &AVE_SIGMA_LIM);
    4551  ScanConfig (config, "NMEAS_MIN",              "%d",  0, &NMEAS_MIN);
     52  ScanConfig (config, "NMEAS_MIN_FILTERED",     "%d",  0, &NMEAS_MIN_FILTERED);
    4653
    4754  WarnConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
  • trunk/Ohana/src/photdbc/src/args.c

    r29938 r30616  
    1919  ExcludeByInstMag = FALSE;
    2020  if ((N = get_argument (argc, argv, "-instmag"))) {
    21     remove_argument (N, &argc, argv);
    2221    ExcludeByInstMag = TRUE;
    2322    remove_argument (N, &argc, argv);
     
    2524    remove_argument (N, &argc, argv);
    2625    INST_MAG_MAX = atof(argv[N]);
     26    remove_argument (N, &argc, argv);
     27  }
     28
     29  ExcludeByMinSigma = FALSE;
     30  if ((N = get_argument (argc, argv, "-min-sigma"))) {
     31    ExcludeByMinSigma = TRUE;
     32    remove_argument (N, &argc, argv);
     33    SIGMA_MIN_KEEP = atof(argv[N]);
     34    remove_argument (N, &argc, argv);
    2735  }
    2836
    2937  ExcludeByMaxMinMag = FALSE;
    3038  if ((N = get_argument (argc, argv, "-maxminmag"))) {
    31     remove_argument (N, &argc, argv);
    3239    ExcludeByMaxMinMag = TRUE;
    3340    remove_argument (N, &argc, argv);
    3441    MAX_MIN_MAG = atof(argv[N]);
     42    remove_argument (N, &argc, argv);
    3543  }
    3644
     
    6169  }
    6270
     71  PHOTCODE_DROP_LIST = NULL;
     72  if ((N = get_argument (argc, argv, "-photcode-drop"))) {
     73    remove_argument (N, &argc, argv);
     74    PHOTCODE_DROP_LIST = strcreate(argv[N]);
     75    remove_argument (N, &argc, argv);
     76  }
     77
     78  PHOTCODE_SKIP_LIST = NULL;
     79  if ((N = get_argument (argc, argv, "-photcode-skip"))) {
     80    remove_argument (N, &argc, argv);
     81    PHOTCODE_SKIP_LIST = strcreate(argv[N]);
     82    remove_argument (N, &argc, argv);
     83  }
     84
    6385  if (argc != 2) usage();
    6486
     
    81103  fprintf (stderr, "USAGE: photdbc (output)\n\n");
    82104  fprintf (stderr, " this program takes an existing DVO database and makes a copy, applying a number of optional\n");
    83   fprintf (stderr, " filters in the process.  \n");
    84   fprintf (stderr, "\n");
    85   fprintf (stderr, " photdbc (output)\n");
    86   fprintf (stderr, "\n");
    87   fprintf (stderr, " allowed filters / restrictions include:\n");
    88   fprintf (stderr, "\n");
     105  fprintf (stderr, " filters in the process.  \n\n");
     106
     107  fprintf (stderr, " photdbc (output)\n\n");
     108
     109  fprintf (stderr, " allowed filters / restrictions include:\n\n");
     110
    89111  fprintf (stderr, " -region Rmin Rmax Dmin Dmax : limit operation to the specified region \n");
    90   fprintf (stderr, " -join                 : join measurements between stars using JOIN_RADIUS\n");
    91   fprintf (stderr, " -ccdregion X Y X Y    : only keep detections within the specified detector region\n");
    92   fprintf (stderr, "                         (can this be limited to specific photcodes? cameras? detectors?)\n");
    93   fprintf (stderr, " -photcode_limits code Mmin Mmax : allow multiples of these\n");
    94   fprintf (stderr, "\n");
    95   fprintf (stderr, " SIGMA_MAX\n");
    96   fprintf (stderr, " NMEAS_MIN\n");
    97   fprintf (stderr, " INST_MAG_MAX\n");
    98   fprintf (stderr, " INST_MAG_MIN\n");
     112 
     113  fprintf (stderr, " -photcode-drop   : remove these photcodes from the output (REF or DEP only)\n");
     114  fprintf (stderr, " -photcode-skip  : ignore these photcodes when assessing the validity (keep unless object is dropped)\n");
     115
     116  fprintf (stderr, " -instmag (min) (max) : range of valid instrumental magnitudes (or measurements are dropped)\n");
     117  fprintf (stderr, " -min-sigma (sigma)   : object must have one measurement error less than sigma or object is dropped\n");
     118
     119  fprintf (stderr, " -maxminmag (mag)   : object must have one magnitude less than this or object is dropped\n");
     120
     121  fprintf (stderr, " option options:\n");
     122  fprintf (stderr, " -v : verbose mode\n");
     123  fprintf (stderr, " -params : list the current parameters\n\n");
     124
     125  fprintf (stderr, "ptolemy.rc config values used by this program:\n");
     126  fprintf (stderr, " SIGMA_MAX : drop measurements with errors greater than this\n");
     127  fprintf (stderr, " NMEAS_MIN : drop objects with fewer measurements than this\n");
     128  fprintf (stderr, " NMEAS_MIN_FILTERED : drop objects with fewer measurements than this after filtering above\n");
     129  fprintf (stderr, " AVE_SIGMA_LIM : drop objects if all average mags are greater than this\n");
     130
    99131  exit (2);
    100132}
     133
     134// fprintf (stderr, " -join                 : join measurements between stars using JOIN_RADIUS\n");
     135// fprintf (stderr, " -ccdregion X Y X Y    : only keep detections within the specified detector region\n");
     136// fprintf (stderr, "                         (can this be limited to specific photcodes? cameras? detectors?)\n");
     137// fprintf (stderr, " -photcode_limits code Mmin Mmax : allow multiples of these\n");
  • trunk/Ohana/src/photdbc/src/find_images.c

    r29001 r30616  
    122122     these are measurements from external sources, like USNO */
    123123
    124   assignMcal (&image[nimage], (double *) NULL, -1);
     124  // assignMcal (&image[nimage], (double *) NULL, -1);
     125  image[nimage].Mcal = 0;
    125126  image[nimage].code = ID_IMAGE_NEW;
    126127 
  • trunk/Ohana/src/photdbc/src/initialize.c

    r29938 r30616  
    22
    33void initialize (int argc, char **argv) {
     4
     5  int NPHOTCODES;
     6  char *codename, *ptr, *list;
    47
    58  /* are these set correctly? */
     
    1114  ConfigInit (&argc, argv);
    1215  args (argc, argv);
     16
     17  NphotcodesDrop = 0;
     18  photcodesDrop = NULL;
     19  if (PHOTCODE_DROP_LIST != NULL) {
     20    NPHOTCODES = 10;
     21    ALLOCATE (photcodesDrop, PhotCode *, NPHOTCODES);
     22
     23    /* parse the comma-separated list of photcodesDrop */
     24    list = PHOTCODE_DROP_LIST;
     25    while ((codename = strtok_r (list, ",", &ptr)) != NULL) {
     26      list = NULL; // pass NULL on successive strtok_r calls
     27      fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_DROP_LIST);
     28      fprintf (stderr, "codename: %s\n", codename);
     29      if ((photcodesDrop[NphotcodesDrop] = GetPhotcodebyName (codename)) == NULL) {
     30        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
     31        exit (1);
     32      }
     33      NphotcodesDrop ++;
     34      CHECK_REALLOCATE (photcodesDrop, PhotCode *, NPHOTCODES, NphotcodesDrop, 10);
     35    }
     36  }
     37
     38  NphotcodesSkip = 0;
     39  photcodesSkip = NULL;
     40  if (PHOTCODE_SKIP_LIST != NULL) {
     41    NPHOTCODES = 10;
     42    ALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES);
     43
     44    /* parse the comma-separated list of photcodesSkip */
     45    list = PHOTCODE_SKIP_LIST;
     46    while ((codename = strtok_r (list, ",", &ptr)) != NULL) {
     47      list = NULL; // pass NULL on successive strtok_r calls
     48      fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_SKIP_LIST);
     49      fprintf (stderr, "codename: %s\n", codename);
     50      if ((photcodesSkip[NphotcodesSkip] = GetPhotcodebyName (codename)) == NULL) {
     51        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
     52        exit (1);
     53      }
     54      NphotcodesSkip ++;
     55      CHECK_REALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES, NphotcodesSkip, 10);
     56    }
     57  }
    1358
    1459  if (SHOW_PARAMS) {
  • trunk/Ohana/src/photdbc/src/make_subcatalog.c

    r28331 r30616  
    55int make_subcatalog (Catalog *subcatalog, Catalog *catalog) {
    66 
    7   off_t i, j, offset;
     7  int found;
     8  off_t i, j, k, offset;
    89  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
    9   double mag, minMag;
    10   int keep;
     10  double mag, minMag, minSigma;
     11  int keep, *secSkip;
     12  PhotCode *photcode;
    1113 
    1214  Nsecfilt = GetPhotcodeNsecfilt ();
    1315  assert (catalog[0].Nsecfilt == Nsecfilt);
     16
     17  // set up a list of SEC entries to ignore when evaluating a source
     18  ALLOCATE (secSkip, int, Nsecfilt);
     19  for (i = 0; i < Nsecfilt; i++) {
     20      secSkip[i] = FALSE;
     21      photcode = GetPhotcodebyNsec(i);
     22      for (k = 0; k < NphotcodesSkip; k++) {
     23          if (photcodesSkip[k][0].code != photcode[0].code) continue;
     24          secSkip[i] = TRUE;
     25      }
     26  }
    1427
    1528  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    3851    }
    3952
     53    // exclude stars with too few measurements
     54    if (NCODE_MIN) {
     55      // drop if all of the allowed average photcodes have ncode < NCODE_MIN values
     56      keep = FALSE;
     57      for (j = 0; !keep && (j < Nsecfilt); j++) {
     58          if (secSkip[j]) continue;
     59          if (catalog[0].secfilt[Nsecfilt*i+j].Ncode >= NCODE_MIN) {
     60              keep = TRUE;
     61        }
     62      }
     63      if (!keep) continue;
     64    }
     65
    4066    /* assign average and secfilt values */
    4167    subcatalog[0].average[Naverage] = catalog[0].average[i];
     
    4571    }
    4672
    47     minMag = 32;
     73    minMag   = 32;
     74    minSigma = 32;
    4875    Nm = 0;
    4976    for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
     
    5279
    5380      # if 0
    54       if (DropPhotcode) {
    55         ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode);
    56         if (ecode == photcode[0].code) continue;
    57       }
    5881      if (DropNonStellar && catalog[0].measure[offset].dophot != 1) continue;
    5982      # endif
    6083
    61       /* exclude measurements by measurement error */
     84      // remove certain photcodes from the output measurements
     85      if (NphotcodesDrop > 0) {
     86          found = FALSE;
     87          for (k = 0; (k < NphotcodesSkip) && !found; k++) {
     88              if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     89              if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     90          }
     91          if (found) continue;
     92      } 
     93 
     94      // ignore certain photcodes to assess the measurements
     95      if (NphotcodesSkip > 0) {
     96          found = FALSE;
     97          for (k = 0; (k < NphotcodesSkip) && !found; k++) {
     98              if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     99              if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     100          }
     101          if (found) goto keep;
     102      } 
     103 
     104      // exclude measurements by measurement error -- drop exactly this measurement
    62105      if (SIGMA_MAX && (catalog[0].measure[offset].dM > SIGMA_MAX)) continue;
    63106
    64       /* select measurements by mag limit */
     107      // select measurements by mag limit -- drop exactly this measurement 
    65108      if (ExcludeByInstMag) {
    66109        mag = PhotInst (&catalog[0].measure[offset]);
     
    69112      }
    70113
     114      // check measurements for this object -- drop object if no measurements pass
     115      if (ExcludeByMinSigma) {
     116          minSigma = MIN (minSigma, catalog[0].measure[offset].dM);
     117      }
     118
     119      // check measurements for this object -- drop object if no measurements pass
    71120      if (ExcludeByMaxMinMag) {
    72121        mag = PhotSys (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
    73122        minMag = MIN (minMag, mag);
    74123      }
     124
     125    keep:
    75126
    76127      subcatalog[0].measure[Nmeasure]        = catalog[0].measure[offset];
     
    90141    }
    91142
    92     // after measurement exclusion, exclude stars with too few measurements
    93     if (Nm < NMEAS_MIN) {
     143    // exclude faint objects
     144    if (ExcludeByMinSigma && (minSigma > SIGMA_MIN_KEEP)) {
    94145      Nmeasure -= Nm;
    95146      continue;
    96147    }
     148
     149    // after measurement exclusion, exclude stars with too few measurements
     150    if (NMEAS_MIN_FILTERED && (Nm < NMEAS_MIN_FILTERED)) {
     151      Nmeasure -= Nm;
     152      continue;
     153    }
     154
    97155    subcatalog[0].average[Naverage].Nmissing = 0;
    98156    subcatalog[0].average[Naverage].Nmeasure = Nm;
     
    122180  return (TRUE);
    123181}
     182
     183/**
     184    the purpose of this function is to create a subset database.  there are several ways this could be done:
     185
     186    * reject all measurements from all objects that fail to meet some criteria (objects may lose measurements and/or be dropped)
     187
     188    * only reject an object if all measurements fail to meet some criteria (ie, keep all measurements if any measurement passes)
     189
     190    * only apply the keep / reject criteria to certain photcodes
     191
     192
     193    ***
     194
     195    * options:
     196
     197    minimum value for nmeas : NMEAS_MIN
     198    minimum value for nmeas : NMEAS_MIN_FILTERED
     199    minimum value for ncode : NCODE_MIN (drop if all ncode < NCODE_MIN) (respect photcodes)
     200    reject faint meas       : SIGMA_MAX
     201    reject faint source     : SIGMA_MIN_KEEP (keep source source if its minimum dMag < this limit)
     202
     203    **/
  • trunk/Ohana/src/relastro/include/relastro.h

    r29001 r30616  
    2626  double dPos;
    2727  int mask;
     28  int Nmeas;
    2829} StarData;
    2930
     
    9495
    9596double SIGMA_LIM;
    96 int SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored
     97int    SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored
    9798double MIN_ERROR;
     99
     100int    IMFIT_CLIP_NITER; // number of clipping iterations to perform in FitChip
     101double IMFIT_CLIP_NSIGMA; // number of sigma to clip in FitChip
     102double IMFIT_SYS_SIGMA_LIM; // max dMag for objects used to measure systematic scatter
    98103
    99104double RADIUS; // match radius for high-speed objects
     
    141146int FlagOutlier;
    142147int    CLIP_THRESH;
     148int USE_BASIC_CHECK;
    143149
    144150FitMode FIT_MODE;
     
    296302void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im);
    297303void FlagOutliers(Catalog *catalog);
    298 int MeasFilterTest(Measure *measure);
     304int MeasFilterTest(Measure *measure, int applySigmaLim);
    299305
    300306int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon);
     
    325331int UpdateObjectOffsets (SkyList *skylist);
    326332
    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 
     333int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj);
     334// int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj);
     335// int relastroVisualPlotScatter(double values[], double thresh, int npts);
     336// int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, StatType statsR, StatType statsD, double thresh);
     337void relastroSetVisual(int state);
     338int relastroGetVisual(void);
    333339
    334340int FixProblemImages (SkyList *skylist);
     
    352358int createStarMapPoints();
    353359int checkStarMap(int N);
     360
     361int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
  • trunk/Ohana/src/relastro/src/ConfigInit.c

    r29001 r30616  
    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
  • trunk/Ohana/src/relastro/src/FitChip.c

    r29001 r30616  
    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  dRmax = 0.0;
     14
     15  for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) {
     16   
     17    // measure the scatter for the unmarked (good) measurements with dM < limit
     18    // SIGMA_LIM here is redundant with ImageOps.c:915
     19    GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, SIGMA_LIM);
     20    dRmax = IMFIT_CLIP_NSIGMA*dRsig;
     21
     22    // (a) skip unfittable points
     23    // (b) mark good and bad points for fit (in and outliers)
    2024
    2125    // measure the scatter distribution (use only the bright end detections)
    22     for (i = Nscatter = 0; i < Nmatch; i++) {
     26    for (i = 0; i < Nmatch; i++) {
    2327      if (raw[i].mask) continue;
    24       if (isnan(raw[i].dMag) || raw[i].dMag > SIGMA_LIM) continue;
     28      if (isnan(raw[i].dMag)) {
     29        raw[i].mask |= 0x0004;
     30        continue;
     31      }
     32      if (raw[i].dMag > SIGMA_LIM) {
     33        raw[i].mask |= 0x0008;
     34        continue;
     35      } // is this redundant with ImageOps.c:915?
    2536
    2637      dL = raw[i].L - ref[i].L;
    2738      dM = raw[i].M - ref[i].M;
    2839      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     }
     40      if (dR > dRmax) {
     41        raw[i].mask |= 0x0010;
     42        continue;
     43      }
     44    }
     45
     46    // figures to assess the fitting process:
     47    // x vs dx, x vs dy, y vs dx, y vs dy :
     48    // residual vector field
     49    // dx vs mag, dy vs mag
     50    relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch);
    4451
    4552    // fit the requested order polynomial
     
    4754      image[0].coords.Npolyterms = CHIPORDER;
    4855    }
     56    if (fit) fit_free (fit);
    4957    fit = fit_init (image[0].coords.Npolyterms);
    5058
    5159    // generate the fit matches
    5260    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 
     61      if (raw[i].mask) continue;
    6962      fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
    7063    }
     
    8881    }
    8982    if (skip) {
    90       if (VERBOSE) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms);
     83      if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms);
    9184      fit_free (fit);
    92       free (values);
    9385      image[0].flags |= ID_IMAGE_ASTROM_FEW;
    9486      return FALSE;
    9587    }
    96 
    97     // fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);
    9888
    9989    // measure the fit, update the coords & object coordinates
     
    110100    }
    111101
    112     fit_free (fit);
    113 
    114102    for (i = 0; i < Nmatch; i++) {
    115103      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords);
     
    118106  }
    119107
    120   free (values);
     108  // count mask classes
     109  int nMask1 = 0;
     110  int nMask2 = 0;
     111  int nMask3 = 0;
     112  int nMask4 = 0;
     113  int nMask5 = 0;
     114  for (i = 0; i < Nmatch; i++) {
     115    if (!raw[i].mask) continue;
     116    if (raw[i].mask & 0x01) nMask1 ++;
     117    if (raw[i].mask & 0x02) nMask2 ++;
     118    if (raw[i].mask & 0x04) nMask3 ++;
     119    if (raw[i].mask & 0x08) nMask4 ++;
     120    if (raw[i].mask & 0x10) nMask5 ++;
     121  }
     122
     123  GetScatterRawRef(&dLsigFull, &dMsigFull, &dRsigFull, &NstatFull, raw, ref, Nmatch, SIGMA_LIM);
     124  GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM);
     125
     126  int Nm = 0;
     127  int Ns = 0;
     128  for (i = 0; i < Nmatch; i++) {
     129    if (raw[i].mask) continue;
     130    Nm += raw[i].Nmeas;
     131    Ns++;
     132  }
     133  image[0].nLinkAstrom = (Nm / Ns);
     134
     135  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);
     136
     137  image[0].dXpixSys = dLsig;
     138  image[0].dYpixSys = dMsig;
     139  image[0].nFitAstrom = fit[0].Npts;
     140
     141  if (fit) fit_free (fit);
     142
    121143  return TRUE;
     144}
     145
     146// measure the scatter distribution (limit selected objects by dMag)
     147int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit) {
     148
     149  int i, Ns;
     150  float dL, dM, dLsum, dLsum2, dMsum, dMsum2, *dR;
     151
     152  ALLOCATE (dR, float, Nstars);
     153
     154  Ns = 0;
     155  dLsum = dLsum2 = dMsum = dMsum2 = 0.0;
     156  for (i = 0; i < Nstars; i++) {
     157    if (raw[i].mask) continue;
     158    if (isnan(raw[i].dMag)) continue;
     159    if ((SigmaLimit > 0.0) && (raw[i].dMag > SigmaLimit)) continue;
     160   
     161    dL = raw[i].L - ref[i].L;
     162    dM = raw[i].M - ref[i].M;
     163
     164    dLsum  += dL;
     165    dLsum2 += dL*dL;
     166    dMsum  += dM;
     167    dMsum2 += dM*dM;
     168
     169    dR[Ns] = hypot (dL, dM);
     170    Ns++;
     171  }
     172
     173  *dLsig = sqrt((dLsum2 / Ns) - SQ(dLsum/Ns));
     174  *dMsig = sqrt((dMsum2 / Ns) - SQ(dMsum/Ns));
     175  *nKeep = Ns;
     176
     177  if (Ns < 5) {
     178    *dRsig = NAN;
     179    free  (dR);
     180    return (FALSE);
     181  }
     182
     183  // for a 2D Gaussian, 40% of the points are within R = 1 sigma
     184  fsort (dR, Ns);
     185  *dRsig = dR[(int)(0.40*Ns)];
     186 
     187  free  (dR);
     188  return (TRUE);
    122189}
    123190
     
    162229  fclose (f);
    163230*/
     231
  • trunk/Ohana/src/relastro/src/GetAstromError.c

    r29938 r30616  
    11# include "relastro.h"
     2# define WEIGHTED_ERRORS 1
    23
    34float GetAstromError (Measure *measure, int mode) {
    4   //BIG HACKXXXXXXXX
    5   return 0.1;
     5
    66  PhotCode *code;
    7   float dPobs, dPsys, dPtotal, dM, AS, MS;
     7  float dPobs, dPsys, dPtotal, dM, AS, MS, dX, dY;
     8
     9  if (!WEIGHTED_ERRORS) {
     10    // if we don't understand the errors at all, this at least lets us get things roughly
     11    // right:
     12    return 0.1;
     13  }
     14
    815  switch (mode) {
    916    case ERROR_MODE_RA:
    10       dPobs = measure[0].dXccd / 100.0;  // need to redefine this as RAerr
     17      dPobs = FromShortPixels(measure[0].dXccd);  // dXccd is a value in pixels
    1118      break;
    1219    case ERROR_MODE_DEC:
    13       dPobs = measure[0].dYccd / 100.0;  // need to redefine this as RAerr
     20      dPobs = FromShortPixels(measure[0].dYccd);  // dYccd is a value in pixels
    1421      break;
    1522    case ERROR_MODE_POS:
    16       dPobs = hypot (measure[0].dXccd, measure[0].dYccd) / 100.0;  // need to redefine this as RAerr
     23      dX = FromShortPixels(measure[0].dXccd);  // dXccd is a value in pixels
     24      dY = FromShortPixels(measure[0].dYccd);  // dYccd is a value in pixels
     25      dPobs = hypot (dX, dY);
    1726      break;
    1827    default:
    1928      abort();
    2029  }
    21   /* the astrometric errors are not being carried yet (but should be!) */
    22   /* we use the photometric mag error as a weighting term */
    2330
    2431  code  = GetPhotcodebyCode (measure[0].photcode);
     
    2734  dPsys = code[0].astromErrSys;
    2835  dM    = measure[0].dM;
    29   dPtotal = sqrt(SQ(dPsys) + AS*SQ(dPobs) + MS*SQ(dM));
    30 
    31   //XXX dXccd, dYccd are now working correctly
    32   //dPtotal = AS * dPobs;
     36  dPtotal = sqrt(SQ(dPsys) + SQ(AS*dPobs) + SQ(MS*dM));
    3337
    3438  dPtotal = MAX (dPtotal, MIN_ERROR);
     
    3640}
    3741
     42/* for a long time, psphot was either not reported position errors, or was reporting
     43 * completely wrong astrometry errors.  This function lets us handle, in the
     44 * configuration, different strategies to generating a position error
     45 *
     46 * astrometry systematic error : this is the minimum expected per-position error.  You
     47 * should probably measure this from you data.  watch out for the chicken and egg problem!
     48 *
     49 * astrometry error scale : this field lets you accept position errors in (say) pixels and
     50 * convert them with this term to arcsec.  AS : pixel scale in arcsec
     51 *
     52 * astrometry mag scale : this field lets you define position errors based on the
     53 * photometry error.  the scale factor should be something like a typical seeing number
     54 * (in arcsec) for the given instrument
     55 *
     56 */
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r29001 r30616  
    146146  free (clist);
    147147  free (mlist);
     148  free (Nlist);
     149  free (NLIST);
    148150}
    149151
     
    325327  for (j = 0; j < average[0].Nmeasure; j++) {
    326328    off = average[0].measureOffset + j;
    327     fprintf (stderr, "%f, %f\n", measure[off].dR, measure[off].dD);
     329    fprintf (stderr, "dR, dD, mag, dMag: %f, %f, %f, %f\n", measure[off].dR, measure[off].dD, measure[off].M, measure[off].dM);
    328330  }
    329331  return;
     
    336338  off_t i, m, c, n, nPos;
    337339  double X, Y, L, M, P, Q, R, D, dR, dD;
    338   double dPos, DPOS_MAX_ASEC;
     340  double dPos, dPosSys, DPOS_MAX_ASEC;
    339341
    340342  Mosaic *mosaic;
     
    359361  }
    360362
    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 
     363  // these are used to accumulate the rms position offsets.  if this value, or any
     364  // specific entry, is too large, we will reset the image to the original coords at the
     365  // end of the analysis
    364366  dPos = 0.0;
    365367  nPos = 0;
     368
     369  // convert the image systematic error in pixels to a value in arcsec
     370  {
     371    double dLsig, dMsig;
     372    double Ro, Do, Rx, Dx, dP0, dP1;
     373    Coords *coords;
     374
     375    // these values are in pixels, but we to convert to arcsec
     376    dLsig = image[0].dXpixSys;
     377    dMsig = image[0].dYpixSys;
     378
     379    if (moscoords == NULL) {
     380      coords = imcoords;
     381    } else {
     382      coords = moscoords;
     383    }
     384    XY_to_LM (&Ro, &Do, 0.0, 0.0, coords);
     385    XY_to_LM (&Rx, &Dx, dLsig, 0.0, coords);
     386    dP0 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec
     387    XY_to_LM (&Rx, &Dx, 0.0, dLsig, coords);
     388    dP1 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec
     389    dPosSys = 0.5 * (dP0 + dP1);
     390  }     
    366391
    367392  for (i = 0; i < Nlist[im]; i++) {
     
    390415    // complain if the new location is far from the average location
    391416    // NOTE: This should never happen, or our StarMap tests are not working
    392     if (fabs(dR) > 1.5*ADDSTAR_RADIUS) {
     417    if (fabs(dR) > 3.0*ADDSTAR_RADIUS) {
    393418      fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
    394419      dump_measures (&catalog[c].average[n], catalog[c].measure);
    395420      // abort ();
    396421    }
    397     if (fabs(dD) > 1.5*ADDSTAR_RADIUS) {
     422    if (fabs(dD) > 3.0*ADDSTAR_RADIUS) {
    398423      fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
    399424      dump_measures (&catalog[c].average[n], catalog[c].measure);
     
    418443    catalog[c].measure[m].dR = dR;
    419444    catalog[c].measure[m].dD = dD;
    420 
     445   
    421446    if (catalog[c].measure[m].dR > +180.0*3600.0) {
    422447      // average on high end of boundary, move star up
     
    429454      catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);
    430455    }
     456
     457    // set the systematic error for this image:
     458    catalog[c].measure[m].dRsys = ToShortPixels(dPosSys);
    431459  }
    432460
     
    544572
    545573    // 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;
     574    // XXX this is already taken care of in bcatalog
     575    raw[i].mask = 0x0000;
    549576    if (catalog[c].average[n].Nmeasure <= SRC_MEAS_TOOFEW) {
    550       mask = TRUE;
     577      raw[i].mask |= 0x0001;
    551578    }
    552579    if (!finite(catalog[c].measure[m].dR) || !finite(catalog[c].measure[m].dD)) {
    553       mask = TRUE;
    554     }
    555 
    556     raw[i].mask = mask;
    557 
     580      raw[i].mask |= 0x0002;
     581    }
     582    raw[i].Nmeas = catalog[c].average[n].Nmeasure; // record so we can check how well connected an image is
    558583
    559584    switch (mode) {
     
    685710     
    686711      // skip measurements based on user selected criteria
    687       if (!MeasFilterTest(&catalog[0].measure[m])) continue;
     712      if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue;
    688713      R[N] = catalog[0].measure[m].dR;
    689714      D[N] = catalog[0].measure[m].dD;
     
    711736
    712737      // skip measurements based on user selected criteria
    713       if (!MeasFilterTest(&catalog[0].measure[m])) continue;
     738      if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue;
    714739     
    715740      x = catalog[0].measure[m].dR - statsR.median;
     
    725750    }
    726751
    727     //examine results
    728     relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset,
    729                                catalog[0].average[j].Nmeasure,
    730                                statsR, statsD, Ns);
     752    // examine results
     753    // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    731754  }
    732755 
     
    784807     
    785808      // skip measurements based on user selected criteria
    786       if (!MeasFilterTest(&catalog[0].measure[m])) continue;
     809      if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue;
    787810      R[N] = catalog[0].measure[m].dR;
    788811      D[N] = catalog[0].measure[m].dD;
     
    806829    for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) {
    807830      //skip bad measurements
    808       if (!MeasFilterTest(&catalog[0].measure[m])) continue; 
     831      if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 
    809832      x = catalog[0].measure[m].dR - statsR.median;
    810833      y = catalog[0].measure[m].dD - statsD.median;
     
    838861    for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) {
    839862      //skip bad measurements
    840       if (!MeasFilterTest(&catalog[0].measure[m])) continue; 
     863      if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 
    841864      x = catalog[0].measure[m].dR - statsR.median;
    842865      y = catalog[0].measure[m].dD - statsD.median;
     
    852875    }  //done rejecting outliers
    853876
    854     //examine results
    855     relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset,
    856                                catalog[0].average[j].Nmeasure,
    857                                statsR, statsD, Ns);
     877    // examine results
     878    // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    858879   
    859880  } //done looping over objects
     
    871892
    872893/** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */
    873 int MeasFilterTest(Measure *measure) {
     894// we only optionally apply the sigma limit: for object averages, this should not be used (should it?)
     895int MeasFilterTest(Measure *measure, int applySigmaLim) {
    874896  int found, k;
    875897  long mask;
     
    917939
    918940  /* select measurements by measurement error */
    919   if ((SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) return FALSE;
     941  if (applySigmaLim && (SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) {
     942    return FALSE;
     943  }
    920944 
    921945  /* select measurements by mag limit */
  • trunk/Ohana/src/relastro/src/StarMaps.c

    r29001 r30616  
    7979    starmap[N].stars[ybin*NX_MAP + xbin] ++;
    8080  }
    81   MARKTIME("assign stars to starmap bins: %f sec\n", dtime);
     81  if (VERBOSE2) { MARKTIME("assign stars to starmap bins: %f sec\n", dtime); }
    8282
    8383  return (TRUE);
     
    117117    }
    118118
    119     if (VERBOSE) fprintf (stderr, "starmap: %d points for image %s\n", starmap[i].Npoints, images[i].name);
     119    if (VERBOSE2) fprintf (stderr, "starmap: %d points for image %s\n", starmap[i].Npoints, images[i].name);
    120120  }
    121121
     
    145145  }
    146146
    147   if (VERBOSE) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax);
     147  if (VERBOSE2) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax);
    148148
    149   if (dLmax > DPOS_MAX) return (FALSE);
    150   if (dMmax > DPOS_MAX) return (FALSE);
     149  if (dLmax > DPOS_MAX) {
     150      if (VERBOSE) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax);
     151      return (FALSE);
     152  }
     153  if (dMmax > DPOS_MAX) {
     154      if (VERBOSE) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax);
     155      return (FALSE);
     156  }
    151157  return (TRUE);
    152158}
  • trunk/Ohana/src/relastro/src/UpdateChips.c

    r29001 r30616  
    11# include "relastro.h"
     2int plotChipFits (double *Ro, double *Do, char *mode, int Nimage);
     3int saveCenter (Image *image, double *Ro, double *Do, int im);
    24
    35int UpdateChips (Catalog *catalog, int Ncatalog) {
    46
     7  int Nskip, Nmosaic, NnewFit, NoldFit;
     8
    59  /* we can measure new image parameters for each non-mosaic chip independently */
    6   off_t i, Nimage, Nraw, Nref;
     10  off_t i, Nimage, Nraw, Nref, nFitAstr;
    711  Image *image;
    812  StarData *raw, *ref;
    913  Coords *oldCoords;
     14  float dXpixSys, dYpixSys;
     15  double *Ro, *Do;
     16  char *mode;
     17
     18  Nskip = Nmosaic = NnewFit = NoldFit = 0;
    1019
    1120  image = getimages (&Nimage);
    1221
     22  // save fit results for summary plot
     23  ALLOCATE (Ro, double, Nimage);
     24  ALLOCATE (Do, double, Nimage);
     25  ALLOCATE (mode, char, Nimage);
     26
    1327  for (i = 0; i < Nimage; i++) {
    1428
    1529    /* skip all except WRP images */
    16     if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue;
     30    if (strcmp(&image[i].coords.ctype[4], "-WRP")) {
     31      Nmosaic ++;
     32      mode[i] = 0;
     33      continue;
     34    }
    1735
    1836    /* convert measure coordinates to raw entries */
    1937    raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC);
    20     if (!raw) continue;
     38    if (!raw) {
     39      Nskip ++;
     40      mode[i] = 0;
     41      continue;
     42    }
    2143
    2244    /* convert average coordinates to ref entries */
    2345    ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC);
    24     if (!ref) continue;
     46    if (!ref) {
     47      Nskip ++;
     48      mode[i] = 0;
     49      continue;
     50    }
    2551
    2652    // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions.
    2753    assert (Nraw == Nref);
    2854
     55    // save these in case of failure
    2956    saveCoords (&image[i].coords, i);
     57    dXpixSys = image[i].dXpixSys;
     58    dYpixSys = image[i].dYpixSys;
     59    nFitAstr = image[i].nFitAstrom;
    3060
    3161    // FitChip does iterative, clipped fitting
     
    3363    if (!FitChip (raw, ref, Nraw, &image[i])) {
    3464      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
    3567      oldCoords = getCoords (i);
    3668      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     69      image[i].dXpixSys = dXpixSys;
     70      image[i].dYpixSys = dYpixSys;
     71      image[i].nFitAstrom = nFitAstr;
     72
     73      saveCenter (image, &Ro[i], &Do[i], i);
     74      mode[i] = 1;
     75      NoldFit ++;
    3776      free (raw);
    3877      free (ref);
     
    4281    if (!checkStarMap (i)) {
    4382      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
    4484      oldCoords = getCoords (i);
    4585      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     86      image[i].dXpixSys = dXpixSys;
     87      image[i].dYpixSys = dYpixSys;
     88      image[i].nFitAstrom = nFitAstr;
     89
     90      saveCenter (image, &Ro[i], &Do[i], i);
     91      mode[i] = 2;
    4692      image[i].flags |= ID_IMAGE_ASTROM_POOR;
    47     }
    48 
     93      NoldFit ++;
     94      free (raw);
     95      free (ref);
     96      continue;
     97    }
     98
     99    saveCenter (image, &Ro[i], &Do[i], i);
     100    mode[i] = 3;
     101    NnewFit ++;
    49102    free (raw);
    50103    free (ref);
    51104  }
    52105
     106  plotChipFits (Ro, Do, mode, Nimage);
     107
     108  fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", NnewFit, NoldFit, Nskip, Nmosaic);
    53109  return (TRUE);
    54110}
    55111
     112int saveCenter (Image *image, double *Ro, double *Do, int im) {
     113
     114  Mosaic *mosaic;
     115  Coords *moscoords, *imcoords;
     116  double X, Y, L, M, P, Q, R, D;
     117
     118  moscoords = NULL;
     119  if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
     120    mosaic = getMosaicForImage (im);
     121    if (mosaic == NULL) return FALSE;  // if we cannot find the associated image, skip it
     122    moscoords = &mosaic[0].coords;
     123  }
     124  imcoords = &image[im].coords;
     125 
     126  if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
     127    X = 0.5*image[im].NX;
     128    Y = 0.5*image[im].NY;
     129  } else {
     130    X = 0.0;
     131    Y = 0.0;
     132  }
     133
     134  if (moscoords == NULL) {
     135    // this is a Simple image (not a mosaic)
     136    // note that for a Simple image, L,M = P,Q
     137    XY_to_LM (&L, &M, X, Y, imcoords);
     138    LM_to_RD (&R, &D, L, M, imcoords);
     139  } else {
     140    XY_to_LM (&L, &M, X, Y, imcoords);
     141    XY_to_LM (&P, &Q, L, M, moscoords);
     142    LM_to_RD (&R, &D, P, Q, moscoords);
     143  }
     144
     145  double Rmid;
     146  if (UserCatalog) {
     147      Rmid = UserCatalogRA;
     148  } else {
     149      Rmid = 0.5*(UserPatch.Rmin + UserPatch.Rmax);
     150  }
     151
     152  R = ohana_normalize_angle_to_midpoint (R, Rmid);
     153
     154  *Ro = R;
     155  *Do = D;
     156
     157  return (TRUE);
     158}
     159 
     160int plotChipFits (double *Ro, double *Do, char *mode, int Nimage) {
     161
     162  static int kapa = -1;
     163
     164  int i, N;
     165  double Rmin, Rmax, Dmin, Dmax;
     166  float *xvec, *yvec;
     167  Graphdata graphdata;
     168
     169  if (!relastroGetVisual()) return (TRUE);
     170
     171  if (kapa == -1) {
     172    kapa = KapaOpenNamedSocket("kapa", "relastro");
     173    if (kapa == -1) {
     174      fprintf (stderr, "can't open kapa window\n");
     175      return FALSE;
     176    }
     177  }
     178
     179  Rmin = +720;
     180  Rmax = -720;
     181  Dmin = +90;
     182  Dmax = -90;
     183
     184  // find the R, D range
     185  for (i = 0; i < Nimage; i++) {
     186    if (!mode[i]) continue;
     187
     188    Rmin = MIN(Rmin, Ro[i]);
     189    Rmax = MAX(Rmax, Ro[i]);
     190    Dmin = MIN(Dmin, Do[i]);
     191    Dmax = MAX(Dmax, Do[i]);
     192  }
     193
     194  ALLOCATE (xvec, float, Nimage);
     195  ALLOCATE (yvec, float, Nimage);
     196
     197  bzero (&graphdata, sizeof(Graphdata));
     198  plot_defaults (&graphdata);
     199  graphdata.xmin = Rmin;
     200  graphdata.xmax = Rmax;
     201  graphdata.ymin = Dmin;
     202  graphdata.ymax = Dmax;
     203  graphdata.style = 2;
     204  graphdata.size = 1;
     205
     206  KapaSetFont (kapa, "helvetica", 14);
     207  KapaSetLimits (kapa, &graphdata);
     208  KapaBox (kapa, &graphdata);
     209
     210  // *** good images ***
     211  N = 0;
     212  for (i = 0; i < Nimage; i++) {
     213    if (mode[i] != 3) continue;
     214    xvec[N] = Ro[i];
     215    yvec[N] = Do[i];
     216    N++;
     217  }
     218  graphdata.ptype = 7;
     219  graphdata.color = KapaColorByName("black");
     220  KapaPrepPlot (kapa, N, &graphdata);
     221  KapaPlotVector (kapa, N, xvec, "x");
     222  KapaPlotVector (kapa, N, yvec, "y");
     223 
     224  // *** reject fit ***
     225  N = 0;
     226  for (i = 0; i < Nimage; i++) {
     227    if (mode[i] != 1) continue;
     228    xvec[N] = Ro[i];
     229    yvec[N] = Do[i];
     230    N++;
     231  }
     232  graphdata.ptype = 3;
     233  graphdata.color = KapaColorByName("red");
     234  KapaPrepPlot (kapa, N, &graphdata);
     235  KapaPlotVector (kapa, N, xvec, "x");
     236  KapaPlotVector (kapa, N, yvec, "y");
     237 
     238  // *** divergent fit ***
     239  N = 0;
     240  for (i = 0; i < Nimage; i++) {
     241    if (mode[i] != 2) continue;
     242    xvec[N] = Ro[i];
     243    yvec[N] = Do[i];
     244    N++;
     245  }
     246  graphdata.ptype = 2;
     247  graphdata.color = KapaColorByName("blue");
     248  KapaPrepPlot (kapa, N, &graphdata);
     249  KapaPlotVector (kapa, N, xvec, "x");
     250  KapaPlotVector (kapa, N, yvec, "y");
     251 
     252  free (xvec);
     253  free (yvec);
     254
     255  return (TRUE);
     256}
     257
     258// XXX if (!FindMosaicForImage (image, Nimage, i)) { }
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r27581 r30616  
    4040    UpdateMeasures (&catalog, 1);
    4141
     42    UpdateObjects (&catalog, 1);
     43
    4244    freeImageBins (1);
    4345
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r29938 r30616  
    103103
    104104        //does the measurement pass the supplied filtering constraints?
    105         if (!MeasFilterTest(&catalog[i].measure[m])) {
     105        if (!MeasFilterTest(&catalog[i].measure[m], FALSE)) {
    106106          catalog[i].measure[m].dbFlags &= ~ID_MEAS_USED_OBJ;
    107107          continue;
     
    134134
    135135        // dX, dY : error in arcsec --
    136         // dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
    137         // dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
    138 
    139         dX[N] = 0.1;
    140         dY[N] = 0.1;
     136        dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
     137        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
     147        // dX[N] = 0.1;
     148        // dY[N] = 0.1;
     149
    141150        dT[N] = catalog[i].measure[m].dt;
    142151
  • trunk/Ohana/src/relastro/src/args.c

    r28184 r30616  
    1313    remove_argument (N, &argc, argv);
    1414    FIT_TARGET = TARGET_OBJECTS;
    15 
    16     // check for object fitting modes (not valid for images)
    17     if ((N = get_argument (argc, argv, "-pm"))) {
    18         remove_argument (N, &argc, argv);
    19         FIT_MODE = FIT_PM_ONLY;
    20     }
    21     if ((N = get_argument (argc, argv, "-par"))) {
    22         remove_argument (N, &argc, argv);
    23         FIT_MODE = FIT_PAR_ONLY;
    24     }
    25     if ((N = get_argument (argc, argv, "-pmpar"))) {
    26         remove_argument (N, &argc, argv);
    27         FIT_MODE = FIT_PM_AND_PAR;
    28     }
    29   }
     15  }
     16
     17  // check for object fitting modes
     18  if ((N = get_argument (argc, argv, "-pm"))) {
     19    remove_argument (N, &argc, argv);
     20    FIT_MODE = FIT_PM_ONLY;
     21  }
     22  if ((N = get_argument (argc, argv, "-par"))) {
     23    remove_argument (N, &argc, argv);
     24    FIT_MODE = FIT_PAR_ONLY;
     25  }
     26  if ((N = get_argument (argc, argv, "-pmpar"))) {
     27    remove_argument (N, &argc, argv);
     28    FIT_MODE = FIT_PM_AND_PAR;
     29  }
     30
    3031  if ((N = get_argument (argc, argv, "-high-speed"))) {
    3132    // XXX include a parallax / no-parallax option
     
    9394      usage ();
    9495    }
     96  }
     97
     98  USE_BASIC_CHECK = FALSE;
     99  if ((N = get_argument (argc, argv, "-basic-image-search"))) {
     100    remove_argument (N, &argc, argv);
     101    USE_BASIC_CHECK = TRUE;
    95102  }
    96103
     
    144151    VERBOSE = VERBOSE2 = TRUE;
    145152    remove_argument (N, &argc, argv);
     153  }
     154
     155  if ((N = get_argument (argc, argv, "-visual"))) {
     156    remove_argument (N, &argc, argv);
     157    relastroSetVisual(TRUE);
    146158  }
    147159
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r29001 r30616  
    4545      offset = catalog[0].average[i].measureOffset + j;
    4646     
    47       // filter objects based on user supplied criteria
    48       if (!MeasFilterTest(&catalog[0].measure[offset])) {
     47      // filter objects based on user supplied criteria, including SIGMA_LIM
     48      if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) {
    4949        catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP;
    5050        continue;
     
    7878        subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
    7979      }
    80      
     80
    8181      Nmeasure ++;
    8282      Nm ++;
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r29001 r30616  
    2626    pcatalog[0].Nsecfilt  = GetPhotcodeNsecfilt ();
    2727
    28     if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE, "w")) {
     28    if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE2, "w")) {
    2929      fprintf (stderr, "ERROR: failure reading catalog %s\n", pcatalog[0].filename);
    3030      exit (1);
    3131    }
    32     if (VERBOSE && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
     32    if (VERBOSE2 && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
    3333
    3434    //outlier rejection
  • trunk/Ohana/src/relastro/src/plotstuff.c

    r27588 r30616  
    146146  graphdata[0].ymax = dUNDEF;
    147147   
     148  graphdata[0].ticktextPad = NAN;
     149  graphdata[0].labelPadXm = NAN;
     150  graphdata[0].labelPadXp = NAN;
     151  graphdata[0].labelPadYm = NAN;
     152  graphdata[0].labelPadYp = NAN;
     153  graphdata[0].padXm = NAN;
     154  graphdata[0].padXp = NAN;
     155  graphdata[0].padYm = NAN;
     156  graphdata[0].padYp = NAN;
    148157}
  • trunk/Ohana/src/relastro/src/relastro.c

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

    r24308 r30616  
    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;
     51  return TRUE;
     52}
     53
     54void relastroSetVisual(int state) {
     55  isVisual = state;
     56}
     57
     58int relastroGetVisual(void) {
     59  return isVisual;
    5260}
    5361
     
    7078    graphdata->xmax = xhi;
    7179    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;
     80    return TRUE;
     81}
     82
     83/** 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy **/
     84int relastroVisualRawRef(int *kapaID, float *x, float *y, float *dx, float *dy, float *dPos, int npts) {
     85
    7986    Graphdata graphdata;
    8087    KapaSection section;
     
    8390
    8491    KapaInitGraph(&graphdata);
    85     KapaClearPlots(*kapaID);
     92    KapaClearSections(*kapaID);
    8693    KapaSetFont(*kapaID, "helvetica", 14);
    8794
     
    8996    section.x = 0.0; section.y = 0.0;
    9097    section.dx = .45, section.dy = .45;
     98    section.bg = KapaColorByName("white");
    9199    graphdata.ptype = 7;
    92100    graphdata.style = 2;
     101    graphdata.etype |= 0x01;
    93102
    94103    KapaSetSection(*kapaID, &section);
    95     if(!scaleGraphdata(x, xVec, &graphdata, npts)) return 0;
     104    if(!scaleGraphdata(x, dx, &graphdata, npts)) return 0;
    96105    KapaSetLimits(*kapaID, &graphdata);
    97106    KapaBox(*kapaID, &graphdata);
     
    100109    KapaPrepPlot(*kapaID, npts, &graphdata);
    101110    KapaPlotVector(*kapaID, npts, x, "x");
    102     KapaPlotVector(*kapaID, npts, xVec, "y");
     111    KapaPlotVector(*kapaID, npts, dx, "y");
     112    KapaPlotVector(*kapaID, npts, dPos, "dym");
     113    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    103114
    104115    section.x = .5; section.y = 0; section.name="1";
    105116    KapaSetSection(*kapaID, &section);
    106     if(!scaleGraphdata(x, yVec, &graphdata, npts)) return 0;
     117    if(!scaleGraphdata(x, dy, &graphdata, npts)) return 0;
    107118    KapaSetLimits(*kapaID, &graphdata);
    108119    KapaBox(*kapaID, &graphdata);
     
    111122    KapaPrepPlot(*kapaID, npts, &graphdata);
    112123    KapaPlotVector(*kapaID, npts, x, "x");
    113     KapaPlotVector(*kapaID, npts, yVec, "y");
     124    KapaPlotVector(*kapaID, npts, dy, "y");
     125    KapaPlotVector(*kapaID, npts, dPos, "dym");
     126    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    114127
    115128    section.x = .0; section.y = .5; section.name="2";
    116129    KapaSetSection(*kapaID, &section);
    117     if(!scaleGraphdata(y, xVec, &graphdata, npts)) return 0;;
     130    if(!scaleGraphdata(y, dx, &graphdata, npts)) return 0;;
    118131    KapaSetLimits(*kapaID, &graphdata);
    119132    KapaBox(*kapaID, &graphdata);
     
    122135    KapaPrepPlot(*kapaID, npts, &graphdata);
    123136    KapaPlotVector(*kapaID, npts, y, "x");
    124     KapaPlotVector(*kapaID, npts, xVec, "y");
     137    KapaPlotVector(*kapaID, npts, dx, "y");
     138    KapaPlotVector(*kapaID, npts, dPos, "dym");
     139    KapaPlotVector(*kapaID, npts, dPos, "dyp");
    125140
    126141    section.x = .5; section.y = .5; section.name="3";
    127142    KapaSetSection(*kapaID, &section);
    128     if(!scaleGraphdata(y, yVec, &graphdata, npts)) return 0;
     143    if(!scaleGraphdata(y, dy, &graphdata, npts)) return 0;
    129144    KapaSetLimits(*kapaID, &graphdata);
    130145    KapaBox(*kapaID, &graphdata);
     
    133148    KapaPrepPlot(*kapaID, npts, &graphdata);
    134149    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;
     150    KapaPlotVector(*kapaID, npts, dy, "y");
     151    KapaPlotVector(*kapaID, npts, dPos, "dym");
     152    KapaPlotVector(*kapaID, npts, dPos, "dyp");
     153
     154    return TRUE;
     155}
     156
     157
     158/** Plot a vector field (circles at vector origin, scaled lines giving vector directions */
     159int relastroVisualVectorField(int *kapaID, float *x, float *y, float *dx, float *dy, int npts, double maxVecLength) {
    147160
    148161    Graphdata graphdata;
    149     float singleX[2], singleY[2];
     162    float *xVec, *yVec;
    150163    float vecScaleFactor;
    151164    float graphSize;
    152165    int i;
    153166    char plotTitle[50];
    154     sprintf(plotTitle, "Maximum Vector Size = %5.1e", maxVecLength);
    155 
     167
     168    if (!npts) return FALSE;
    156169    if (!initWindow(kapaID)) return 0;
    157170
     171    snprintf(plotTitle, 50, "Maximum Vector Size = %5.1e", maxVecLength);
     172
    158173    KapaInitGraph(&graphdata);
    159     KapaClearPlots(*kapaID);
    160     if(!scaleGraphdata(x, y, &graphdata, npts)) return 0;
     174    KapaClearSections(*kapaID);
     175    KapaSetFont(*kapaID, "helvetica", 14);
     176
     177    if (!scaleGraphdata(x, y, &graphdata, npts)) return 0;
    161178
    162179    graphSize = graphdata.xmax - graphdata.xmin;
     
    164181        graphSize = graphdata.ymax - graphdata.ymin;
    165182    }
    166 
    167183    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 
     184
     185    // fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n", graphSize, maxVecLength, vecScaleFactor);
    173186
    174187    KapaSetFont (*kapaID, "helvetica", 14);
     
    179192    graphdata.ptype = 7;
    180193    graphdata.style = 2;
     194    graphdata.color = KapaColorByName("black");
    181195    KapaPrepPlot(*kapaID, npts, &graphdata);
    182196    KapaPlotVector(*kapaID, npts, x, "x");
    183197    KapaPlotVector(*kapaID, npts, y, "y");
    184198
    185     //plot each vector individually
    186     graphdata.ptype = 0;
    187     graphdata.style = 0;
     199    ALLOCATE (xVec, float, 2*npts);
     200    ALLOCATE (yVec, float, 2*npts);
     201    for (i = 0; i < npts; i++) {
     202      xVec[2*i + 0] = x[i];
     203      yVec[2*i + 0] = y[i];
     204      xVec[2*i + 1] = x[i] + dx[i] * vecScaleFactor;
     205      yVec[2*i + 1] = y[i] + dy[i] * vecScaleFactor;
     206    }
     207
     208    graphdata.ptype = 100; // line segements by point pair
     209    graphdata.style = 2;
    188210    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     }
     211    KapaPrepPlot  (*kapaID, 2*npts, &graphdata);
     212    KapaPlotVector(*kapaID, 2*npts, xVec, "x");
     213    KapaPlotVector(*kapaID, 2*npts, yVec, "y");
     214
     215    free (xVec);
     216    free (yVec);
     217    return TRUE;
     218}
     219
     220int relastroVisualPlotScatter(int *kapaID, float *dXfit, float *dYfit, float *mag, int npts) {
    215221
    216222    Graphdata graphdata;
    217223    KapaSection section;
    218     section.x = 0; section.y = 0; section.dx = 1; section.dy = 1;
    219     section.name = "junk";
     224
     225    if (!initWindow(kapaID)) return 0;
    220226
    221227    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 
     228    KapaClearSections(*kapaID);
     229    KapaSetFont(*kapaID, "helvetica", 14);
     230
     231    section.name = "a";
     232    section.x = 0.0; section.y = 0.0; section.dx = 1.0; section.dy = 0.5;
     233    section.bg = KapaColorByName("white");
     234    KapaSetSection(*kapaID, &section);
     235
     236    graphdata.ptype = 2;
     237    graphdata.style = 2;
     238
     239    if(!scaleGraphdata(mag, dXfit, &graphdata, npts)) return 0;
     240    KapaSetLimits(*kapaID, &graphdata);
     241    KapaBox(*kapaID, &graphdata);
     242    KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM);
     243    KapaSendLabel(*kapaID, "dXfit", KAPA_LABEL_YM);
     244    KapaPrepPlot(*kapaID, npts, &graphdata);
     245    KapaPlotVector(*kapaID, npts, mag, "x");
     246    KapaPlotVector(*kapaID, npts, dXfit, "y");
     247
     248    section.name = "b";
     249    section.x = 0.0; section.y = 0.5; section.dx = 1.0; section.dy = 0.5;
     250    section.bg = KapaColorByName("white");
     251    KapaSetSection(*kapaID, &section);
     252
     253    graphdata.ptype = 2;
     254    graphdata.style = 2;
     255
     256    if(!scaleGraphdata(mag, dYfit, &graphdata, npts)) return 0;
     257    KapaSetLimits(*kapaID, &graphdata);
     258    KapaBox(*kapaID, &graphdata);
     259    KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM);
     260    KapaSendLabel(*kapaID, "dYfit", KAPA_LABEL_YM);
     261    KapaPrepPlot(*kapaID, npts, &graphdata);
     262    KapaPlotVector(*kapaID, npts, mag, "x");
     263    KapaPlotVector(*kapaID, npts, dYfit, "y");
     264
     265    return TRUE;
     266}
    257267
    258268/** 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;
     269int relastroVisualPlotFittedStars(int *kapaID, float *rawX, float *rawY, float *refX, float *refY, int numNoFit, float *rawXfit, float *rawYfit, float *refXfit, float *refYfit, int numFit) {
     270
     271  Graphdata graphdata;
     272
     273  if (!initWindow(kapaID)) return 0;
     274
     275  KapaInitGraph(&graphdata);
     276  KapaClearPlots(*kapaID);
     277
     278  graphdata.ptype = 7;
     279  graphdata.style = 2;
     280
     281  if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) {
     282      fprintf(stderr, "Not enough finite points for plotting");
     283      return 0;
     284  }
     285
     286  KapaSetFont(*kapaID, "helvetica", 14);
     287  KapaSetLimits(*kapaID, &graphdata);
     288  KapaBox(*kapaID, &graphdata);
     289  KapaSendLabel( *kapaID, "X", KAPA_LABEL_XM);
     290  KapaSendLabel( *kapaID, "Y", KAPA_LABEL_YM);
     291  KapaSendLabel( *kapaID, "orange, red, green, blue: (raw, ref), (nofit, fit)",
     292                 KAPA_LABEL_XP);
     293
     294  graphdata.color = KapaColorByName("orange");
     295  graphdata.size = 1;
     296  KapaPrepPlot(*kapaID, numNoFit, &graphdata);
     297  KapaPlotVector(*kapaID, numNoFit, rawX, "x");
     298  KapaPlotVector(*kapaID, numNoFit, rawY, "y");
     299
     300  graphdata.color = KapaColorByName("red");
     301  graphdata.size = 2;
     302  KapaPrepPlot(*kapaID, numNoFit, &graphdata);
     303  KapaPlotVector(*kapaID, numNoFit, refX, "x");
     304  KapaPlotVector(*kapaID, numNoFit, refY, "y");
     305
     306  graphdata.color = KapaColorByName("green");
     307  graphdata.size = 1;
     308  KapaPrepPlot(*kapaID, numFit,  &graphdata);
     309  KapaPlotVector(*kapaID, numFit, rawXfit, "x");
     310  KapaPlotVector(*kapaID, numFit, rawYfit, "y");
     311
     312  graphdata.color = KapaColorByName("blue");
     313  graphdata.size = 2;
     314  KapaPrepPlot(*kapaID, numFit, &graphdata);
     315  KapaPlotVector(*kapaID, numFit, refXfit, "x");
     316  KapaPlotVector(*kapaID, numFit, refYfit, "y");
     317
     318  return TRUE;
     319}
     320
     321/** create various plots using the data in raw and ref **/
     322int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj) {
    263323
    264324  float *rawX, *rawY,  *refX, *refY;
    265325  float *rawXfit, *rawYfit, *refXfit, *refYfit;
    266326  float *magRaw, *magRef, *magRawfit, *magReffit;
    267   float *xVec, *yVec;
     327  float *dXfit, *dYfit, *dPos;
    268328  int numFit = 0, numNoFit = 0;
    269329  double dL, dM, dR;
     330
     331  if (!isVisual) return TRUE;
    270332
    271333  ALLOCATE(rawX,      float, numObj);
     
    273335  ALLOCATE(refX,      float, numObj);
    274336  ALLOCATE(refY,      float, numObj);
     337  ALLOCATE(magRaw,    float, numObj);
     338  ALLOCATE(magRef,    float, numObj);
     339
    275340  ALLOCATE(rawXfit,   float, numObj);
    276341  ALLOCATE(rawYfit,   float, numObj);
    277342  ALLOCATE(refXfit,   float, numObj);
    278343  ALLOCATE(refYfit,   float, numObj);
    279   ALLOCATE(magRaw,    float, numObj);
    280   ALLOCATE(magRef,    float, numObj);
    281344  ALLOCATE(magRawfit, float, numObj);
    282345  ALLOCATE(magReffit, float, numObj);
     346  ALLOCATE(dXfit,     float, numObj);
     347  ALLOCATE(dYfit,     float, numObj);
     348  ALLOCATE(dPos,      float, numObj);
    283349
    284350  int i;
    285351  for(i = 0; i < numObj; i++) {
    286     if  (raw[i].mask) continue;
     352    if (raw[i].mask) continue; // XXX
    287353
    288354    dL = raw[i].L - ref[i].L;
    289355    dM = raw[i].M - ref[i].M;
    290356    dR = hypot (dL, dM);
     357
     358    // XXX change the selection to a mask-based thing
    291359    if (dR > dRmax) {
     360      // UNFITTED values
    292361      rawX[numNoFit] = raw[i].X;
    293362      rawY[numNoFit] = raw[i].Y;
     
    298367      numNoFit++;
    299368    } 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;
     369      // FITTED values
     370      rawXfit[numFit]   = raw[i].X;
     371      rawYfit[numFit]   = raw[i].Y;
     372      refXfit[numFit]   = ref[i].X;
     373      refYfit[numFit]   = ref[i].Y;
     374      magRawfit[numFit] = raw[i].Mag;
     375      magReffit[numFit] = ref[i].Mag;
     376      dPos[numFit]      = ref[i].dPos;
     377      dXfit[numFit]     = raw[i].X - ref[i].X;
     378      dYfit[numFit]     = raw[i].Y - ref[i].Y;
    306379      numFit++;
    307380    }
     
    310383  if (numFit == 0) return 0;
    311384
    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);
     385  // 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy
     386  relastroVisualRawRef(&kapa1, rawXfit, rawYfit, dXfit, dYfit, dPos, numFit);
     387
     388  // vector line plot for the fit
     389  relastroVisualVectorField(&kapa2, rawXfit, rawYfit, dXfit, dYfit, numFit, dRmax);
     390
     391  // dXfit, dYfit vs mag
     392  relastroVisualPlotScatter(&kapa3, dXfit, dYfit, magRawfit, numFit);
     393
     394  // plot the positions of the fitted stars on the chip
     395  relastroVisualPlotFittedStars(&kapa4, rawX, rawY, refX, refY, numNoFit, rawXfit, rawYfit, refXfit, refYfit, numFit);
    374396
    375397  askUser(&plotRawRef);
    376398
     399  FREE(dXfit);
     400  FREE(dYfit);
     401  FREE(dPos);
    377402  FREE(rawX);
    378403  FREE(rawY);
     
    388413  FREE(magReffit);
    389414
    390   return 1;
     415  return TRUE;
    391416}
    392417
     
    403428  KapaSection section;
    404429 
    405   if (!isVisual || !plotOutliers) return 1;
    406   if (!initWindow(&kapa)) return 0;
     430  if (!isVisual || !plotOutliers) return TRUE;
     431  if (!initWindow(&kapa1)) return 0;
    407432 
    408433  // populate vectors
     
    426451  for(i = 0; i < Nmeasure; i++, m++) {
    427452    meas = catalog[0].measure[m];
    428     if (!MeasFilterTest(&meas)) continue;
     453    if (!MeasFilterTest(&meas, FALSE)) continue;
    429454    xmin = MIN(xmin, meas.dR);
    430455    xmax = MAX(xmax, meas.dR);
     
    459484  section.x = 0; section.y = 0; section.dx = 1; section.dy = 1;
    460485  section.name = "junk";
     486  section.bg = KapaColorByName("white");
    461487 
    462488  KapaInitGraph(&graphdata);
    463   KapaClearPlots(kapa);
    464   KapaSetFont(kapa, "helvetica", 14);
     489  KapaClearPlots(kapa1);
     490  KapaSetFont(kapa1, "helvetica", 14);
    465491 
    466492  graphdata.ptype = 7;
     
    472498  graphdata.ymax = ymax;
    473499
    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)",
     500  KapaSetSection(kapa1, &section);
     501  KapaSetLimits(kapa1, &graphdata);
     502  KapaBox(kapa1, &graphdata);
     503
     504  KapaSendLabel( kapa1, "RA (arcsec)", KAPA_LABEL_XM);
     505  KapaSendLabel( kapa1, "Dec (arcsec)", KAPA_LABEL_YM);
     506  KapaSendLabel( kapa1, "Points flagged as outliers (red)",
    481507                 KAPA_LABEL_XP);
    482508
    483509  graphdata.color = KapaColorByName("green");
    484   KapaPrepPlot(kapa, Nin, &graphdata);
    485   KapaPlotVector(kapa, Nin, Rin, "x");
    486   KapaPlotVector(kapa, Nin, Din, "y");
     510  KapaPrepPlot(kapa1, Nin, &graphdata);
     511  KapaPlotVector(kapa1, Nin, Rin, "x");
     512  KapaPlotVector(kapa1, Nin, Din, "y");
    487513
    488514  graphdata.color = KapaColorByName("red");
    489   KapaPrepPlot(kapa, Nout, &graphdata);
    490   KapaPlotVector(kapa, Nout, Rout, "x");
    491   KapaPlotVector(kapa, Nout, Dout, "y");
     515  KapaPrepPlot(kapa1, Nout, &graphdata);
     516  KapaPlotVector(kapa1, Nout, Rout, "x");
     517  KapaPlotVector(kapa1, Nout, Dout, "y");
    492518
    493519  graphdata.color = KapaColorByName("black");
    494520  graphdata.ptype = 0;
    495521  graphdata.style = 0;
    496   KapaPrepPlot(kapa, 100, &graphdata);
    497   KapaPlotVector(kapa, 100, xCirc, "x");
    498   KapaPlotVector(kapa, 100, yCirc, "y");
    499 
    500 
    501  
     522  KapaPrepPlot(kapa1, 100, &graphdata);
     523  KapaPlotVector(kapa1, 100, xCirc, "x");
     524  KapaPlotVector(kapa1, 100, yCirc, "y");
     525
    502526  askUser(&plotOutliers);
    503527
     
    510534}
    511535 
    512  
     536# if (0)
     537int relastroVisualSummaryChips() {
     538
     539  // plot the dXsys, dYsys histograms
     540
     541  // plot x vs dx, y vs dy, etc for all mosaics
     542
     543  // plot a map of median star scatter
     544
     545}
     546# endif
     547
  • trunk/Ohana/src/relastro/src/select_images.c

    r29001 r30616  
    1515void dsortindex (double *X, off_t *Y, int N);
    1616off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     17
     18# define MARKTIME(MSG,...) { \
     19  float dtime; \
     20  gettimeofday (&stop, (void *) NULL); \
     21  dtime = DTIME (stop, start); \
     22  fprintf (stderr, MSG, __VA_ARGS__); }
    1723
    1824Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
     
    2531  Coords tcoords;
    2632  SkyRegionCoords *skycoords;
    27  
     33  struct timeval start, stop;
     34 
     35  double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion;
     36
    2837  double *RmaxSky;
    2938  off_t *index;
     
    4049    return NULL;
    4150  }
     51
     52  gettimeofday (&start, (void *) NULL);
    4253
    4354  // the comparison is made in the catalog local projection. below we set crval1,2
     
    5263  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
    5364  ALLOCATE (index, off_t, skylist[0].Nregions);
     65
     66  RminSkyRegion = +360.0;
     67  RmaxSkyRegion = -360.0;
     68  DminSkyRegion = +90.0;
     69  DmaxSkyRegion = -90.0;
    5470
    5571  /* compare with each region file */
     
    8096    skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy;
    8197    skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy;
    82   }
     98
     99    RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin);
     100    RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax);
     101    DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
     102    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
     103  }
     104  RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion);
     105  MARKTIME("create sky region coords: %f sec\n", dtime);
    83106
    84107  dsortindex (RmaxSky, index, skylist[0].Nregions);
     108  MARKTIME("sort sky coords: %f sec\n", dtime);
    85109
    86110  if (VERBOSE) fprintf (stderr, "finding images\n");
    87111  BuildChipMatch (timage, Ntimage);
     112  MARKTIME("build chip match: %f sec\n", dtime);
    88113
    89114  nimage = 0;
     
    124149    }
    125150
    126     /* define image corners */
    127     Xi[0] = 0;            Yi[0] = 0;
    128     Xi[1] = timage[i].NX; Yi[1] = 0;
    129     Xi[2] = timage[i].NX; Yi[2] = timage[i].NY;
    130     Xi[3] = 0;            Yi[3] = timage[i].NY;
    131     Xi[4] = 0;            Yi[4] = 0;
     151    /* define image corners - note the DIS images (mosaic phu) are special */
     152    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
     153      Xi[0] = -0.5*timage[i].NX; Yi[0] = -0.5*timage[i].NY;
     154      Xi[1] = +0.5*timage[i].NX; Yi[1] = -0.5*timage[i].NY;
     155      Xi[2] = +0.5*timage[i].NX; Yi[2] = +0.5*timage[i].NY;
     156      Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY;
     157      Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY;
     158    } else {
     159      Xi[0] = 0;            Yi[0] = 0;
     160      Xi[1] = timage[i].NX; Yi[1] = 0;
     161      Xi[2] = timage[i].NX; Yi[2] = timage[i].NY;
     162      Xi[3] = 0;            Yi[3] = timage[i].NY;
     163      Xi[4] = 0;            Yi[4] = 0;
     164    }
    132165    found = FALSE;
    133166
    134167    /* transform corners to ra,dec */
    135168    double RminImage = 360.0;
     169    double RmaxImage =   0.0;
     170    double DminImage = +90.0;
     171    double DmaxImage = -90.0;
     172    // int leftside = FALSE;
    136173    for (j = 0; j < 5; j++) {
    137174      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
     175      Ri[j] = ohana_normalize_angle_to_midpoint (Ri[j], RmidSkyRegion);
     176
    138177      RminImage = MIN(RminImage, Ri[j]);
    139     }
     178      RmaxImage = MAX(RmaxImage, Ri[j]);
     179      DminImage = MIN(DminImage, Di[j]);
     180      DmaxImage = MAX(DmaxImage, Di[j]);
     181    }
     182    if (RmaxImage - RminImage > 180.0) {
     183        double tmp = RminImage;
     184        RmaxImage = RminImage;
     185        RminImage = tmp - 360.0;
     186    }
     187
     188    // check that this image is even in range of the searched region
     189    if (DminImage > DmaxSkyRegion) continue;
     190    if (DmaxImage < DminSkyRegion) continue;
     191   
     192    // the sky region RA is defined to be 0 - 360.0
     193    if (RminImage > RmaxSkyRegion) continue;
     194    if (RmaxImage < RminSkyRegion) continue;
     195
     196    // image overlaps region, keep it
     197    if (USE_BASIC_CHECK) goto found_it;
    140198
    141199    // RA(nStart) is guaranteed to be < RminImage:
     
    161219      for (j = 0; (j < 4) && !found; j++) {
    162220        found = corner_check (&Xi[j], &Yi[j], &skycoords[m].Xc[0], &skycoords[m].Yc[0]);
     221        if (found) goto found_it;
    163222      }
    164223      /* check if catalog corner inside image */
    165224      for (j = 0; (j < 4) && !found; j++) {
    166225        found = corner_check (&skycoords[m].Xc[j], &skycoords[m].Yc[j], &Xi[0], &Yi[0]);
     226        if (found) goto found_it;
    167227      }
    168228      /* check if edges cross */
     
    170230        for (k = 0; (k < 4) && !found; k++) {
    171231          found = edge_check (&Xi[j], &Yi[j], &skycoords[m].Xc[k], &skycoords[m].Yc[k]);
     232          if (found) goto found_it;
    172233        }
    173234      }
    174       if (!found) continue;
    175 
    176       image[nimage] = timage[i];
    177       /* always allow 'few' images to succeed, if possible */
    178       if (image[nimage].flags & ID_IMAGE_ASTROM_FEW) {
    179         image[nimage].flags &= ~ID_IMAGE_ASTROM_FEW;
    180       }
    181       if (RESET) {
    182         // XXX do we need / want to do this in relastro?
    183         assignMcal (&image[nimage], (double *) NULL, -1);
    184         image[nimage].dMcal = NAN;
    185         image[nimage].flags &= ~badImage;
    186       }
    187       line_number[nimage] = i;
    188       nimage ++;
    189       if (nimage == NIMAGE) {
    190         NIMAGE += 100;
    191         REALLOCATE (image, Image, NIMAGE);
    192         REALLOCATE (line_number, off_t, NIMAGE);
    193       }
    194     }
    195   }
    196      
     235    }
     236    if (!found) continue;
     237
     238  found_it:
     239    image[nimage] = timage[i];
     240    /* always allow 'few' images to succeed, if possible */
     241    if (image[nimage].flags & ID_IMAGE_ASTROM_FEW) {
     242      image[nimage].flags &= ~ID_IMAGE_ASTROM_FEW;
     243    }
     244    if (RESET) {
     245      // XXX do we need / want to do this in relastro?
     246      // assignMcal (&image[nimage], (double *) NULL, -1);
     247      // image[nimage].Mcal = NAN;
     248      // image[nimage].dMcal = NAN;
     249      image[nimage].flags &= ~badImage;
     250    }
     251    line_number[nimage] = i;
     252    nimage ++;
     253    if (nimage == NIMAGE) {
     254      NIMAGE += 100;
     255      REALLOCATE (image, Image, NIMAGE);
     256      REALLOCATE (line_number, off_t, NIMAGE);
     257    }
     258  }
     259  MARKTIME("finish image selection: %f sec\n", dtime);
     260   
    197261  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n",  nimage);
    198262
  • trunk/Ohana/src/relphot/Makefile

    r17242 r30616  
    2929$(SRC)/StarOps.$(ARCH).o         \
    3030$(SRC)/args.$(ARCH).o            \
     31$(SRC)/help.$(ARCH).o            \
    3132$(SRC)/bcatalog.$(ARCH).o        \
    3233$(SRC)/global_stats.$(ARCH).o    \
  • trunk/Ohana/src/relphot/include/relphot.h

    r27586 r30616  
    1313  float Mcal;
    1414  float dMcal;
     15  float dMsys;
     16  short nFitPhotom;
    1517  short Xm;
    1618  float secz;
     
    5052double STAR_CHISQ;
    5153double MIN_ERROR;
     54double IMFIT_SYS_SIGMA_LIM;
    5255
    5356int    VERBOSE;
     
    103106SkyRegion UserPatch;
    104107int UserPatchSelect;
     108
     109int USE_BASIC_CHECK;
    105110
    106111# ifdef GRID_V1
     
    215220void          write_coords        PROTO((Header *header, Coords *coords));
    216221int relphot_objects (void);
     222
     223void relphot_usage (void);
     224void relphot_help (int argc, char **argv);
  • trunk/Ohana/src/relphot/src/ConfigInit.c

    r25757 r30616  
    2020  GetConfig (config, "MAG_LIM",                "%lf", 0, &MAG_LIM);
    2121  GetConfig (config, "SIGMA_LIM",              "%lf", 0, &SIGMA_LIM);
     22
     23  if (!ScanConfig (config, "RELPHOT_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
     24
    2225  GetConfig (config, "STAR_SCATTER",           "%lf", 0, &STAR_SCATTER);
    2326  GetConfig (config, "IMAGE_SCATTER",          "%lf", 0, &IMAGE_SCATTER);
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r29001 r30616  
    124124  free (clist);
    125125  free (mlist);
     126  free (Nlist);
     127  free (NLIST);
    126128}
    127129
     
    299301
    300302  off_t i, j, m, c, n, N, Nmax, mark, bad;
    301   int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys;
    302   float Msys, Mrel, Mmos, Mgrid;
     303  int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys, Nbright;
     304  float Msys, Mrel, Mmos, Mgrid, McalBright, McalBright2;
    303305  double *list, *dlist;
    304306  StatType stats;
     
    318320
    319321  Nfew = Nbad = Nmos = Ngrid = Nrel = Nsys = 0;
     322
     323  // counters to measure the bright-end scatter
     324  McalBright = McalBright2 = 0.0;
     325  Nbright = 0;
    320326
    321327  for (i = 0; i < Nimage; i++) {
     
    361367      list[N] = Msys - Mrel - Mmos - Mgrid;
    362368      dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
     369      if (catalog[c].measure[m].dM < IMFIT_SYS_SIGMA_LIM) {
     370        McalBright += list[N];
     371        McalBright2 += SQ(list[N]);
     372        Nbright ++;
     373      }
    363374      N++;
    364375    }
     
    378389    liststats (list, dlist, N, &stats);
    379390    image[i].Mcal  = stats.mean;
    380     image[i].dMcal = stats.sigma;
     391    image[i].dMcal = stats.error;
     392    image[i].dMagSys = stats.sigma;
     393    image[i].nFitPhotom = N;
    381394    image[i].Xm    = 100.0*log10(stats.chisq);
    382395  }
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r29001 r30616  
    7373    mosaic[Nmosaic].Mcal  = 0.0;
    7474    mosaic[Nmosaic].dMcal = 0.0;
     75    mosaic[Nmosaic].dMsys = 0.0;
    7576    mosaic[Nmosaic].Xm    = 0.0;
    7677    mosaic[Nmosaic].flags  = image[i].flags;
     
    189190      image[im].dMcal = mosaic[i].dMcal;
    190191      image[im].Xm = mosaic[i].Xm;
     192      image[im].dMagSys = mosaic[i].dMsys;
     193      image[im].nFitPhotom = mosaic[i].nFitPhotom;
    191194      image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW);
    192195      image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR);
     
    400403      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
    401404      if (mark) {
    402         fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]);
     405        if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]); }
    403406        mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW;
    404407        Nfew ++;
     
    410413    if (PoorImages) fprintf (stderr, "Mmos: %f %f %d "OFF_T_FMT"\n", stats.mean, stats.sigma, stats.Nmeas,  N);
    411414    mosaic[i].Mcal  = stats.mean;
    412     mosaic[i].dMcal = stats.sigma;
     415    mosaic[i].dMcal = stats.error;
     416    mosaic[i].dMsys = stats.sigma;
     417    mosaic[i].nFitPhotom = N;
    413418    mosaic[i].Xm    = 100.0*log10(stats.chisq);
    414419  }
  • trunk/Ohana/src/relphot/src/args.c

    r27586 r30616  
    11# include "relphot.h"
    2 void usage (void);
    32
    43int args (int argc, char **argv) {
     
    5352  }
    5453
     54  USE_BASIC_CHECK = FALSE;
     55  if ((N = get_argument (argc, argv, "-basic-image-search"))) {
     56    remove_argument (N, &argc, argv);
     57    USE_BASIC_CHECK = TRUE;
     58  }
     59
    5560  VERBOSE = VERBOSE2 = FALSE;
    5661  if ((N = get_argument (argc, argv, "-v"))) {
     
    228233  if (UpdateAverages && (argc == 1)) return TRUE;
    229234  if (UserPatchSelect && (argc == 2)) return TRUE;
    230   if (argc != 3) usage ();
     235  if (argc != 3) relphot_usage ();
    231236
    232237  return TRUE;
    233238}
    234 
    235 void usage () {
    236   fprintf (stderr, "ERROR: USAGE: relphot (region) (photcode)\n");
    237   fprintf (stderr, "       or:    relphot (photcode) -region RA RA DEC DEC\n");
    238   fprintf (stderr, "       or:    relphot -averages -region RA RA DEC DEC\n");
    239   fprintf (stderr, "  options: \n");
    240   fprintf (stderr, "  -time (start) (stop)\n");
    241   fprintf (stderr, "  -v : verbose output\n");
    242   fprintf (stderr, "  -vv : more verbose output\n");
    243   fprintf (stderr, "  -outroot (outroot)\n");
    244   fprintf (stderr, "  -plot\n");
    245   fprintf (stderr, "  -plotdelay (seconds)\n");
    246   fprintf (stderr, "  -statmode (mode)\n");
    247   fprintf (stderr, "  -refcode (name) : give extra weight to this photcode\n");
    248   fprintf (stderr, "  -n (nloop)\n");
    249   fprintf (stderr, "  -reset\n");
    250   fprintf (stderr, "  -update\n");
    251   fprintf (stderr, "  -params\n");
    252   fprintf (stderr, "  -mosaic (mosaic)\n");
    253   fprintf (stderr, "  -imfreeze\n");
    254   fprintf (stderr, "  -grid\n");
    255   fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
    256   fprintf (stderr, "  -instmag min max\n");
    257   fprintf (stderr, "  \n");
    258   exit (2);
    259 }
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r28660 r30616  
    119119
    120120  if (VERBOSE) {
    121     fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog\n",
    122               subcatalog[0].Naverage,  subcatalog[0].Nmeasure,  i);
     121    fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog %s\n",
     122             subcatalog[0].Naverage,  subcatalog[0].Nmeasure,  i, catalog[0].filename);
    123123    fprintf (stderr, "rejections: %d code, %d time, %d dophot, %d mag, %d sigma, %d imag, %d few\n",
    124124             Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew);
  • trunk/Ohana/src/relphot/src/initialize.c

    r29001 r30616  
    55  int N;
    66
     7  relphot_help (argc, argv);
    78  ConfigInit (&argc, argv);
    89  args (argc, argv);
  • trunk/Ohana/src/relphot/src/load_catalogs.c

    r29754 r30616  
    66  Catalog *catalog, tcatalog;
    77
    8   if (VERBOSE) fprintf (stderr, "loading catalog data\n");
     8  if (VERBOSE2) fprintf (stderr, "loading catalog data\n");
    99
    1010  ALLOCATE (catalog, Catalog, skylist[0].Nregions);
     
    2222    tcatalog.Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
    2323
    24     if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE, "r")) {
     24    if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE2, "r")) {
    2525      fprintf (stderr, "ERROR: failure reading catalog %s\n", tcatalog.filename);
    2626      exit (1);
    2727    }
    28     if (VERBOSE && !tcatalog.Naves_disk) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename);
     28    if (!tcatalog.Naves_disk) {
     29        if (VERBOSE2) { fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename); }
     30        dvo_catalog_unlock (&tcatalog);
     31        dvo_catalog_free (&tcatalog);
     32        continue;
     33    }
     34
    2935    Nstar_total += tcatalog.Naverage;
    3036    Nmeas_total += tcatalog.Nmeasure;
  • trunk/Ohana/src/relphot/src/load_images.c

    r29001 r30616  
    11# include "relphot.h"
     2
     3# define MARKTIME(MSG,...) { \
     4  float dtime; \
     5  gettimeofday (&stop, (void *) NULL); \
     6  dtime = DTIME (stop, start); \
     7  fprintf (stderr, MSG, __VA_ARGS__); }
    28
    39SkyList *load_images (FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect) {
     
    612  off_t      Nimage, Nsubset, Nchar;
    713  off_t     *LineNumber;
     14  struct timeval start, stop;
    815
    916  SkyTable *sky = NULL;
    1017  SkyList *skylist = NULL;
     18
     19  gettimeofday (&start, (void *) NULL);
    1120
    1221  // load the current sky table (layout of all SkyRegions)
     
    2938      exit (2);
    3039  }
     40  MARKTIME("read image table: %f sec\n", dtime);
    3141
    3242  // select the images which overlap the selected sky regions
    3343  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
     44  MARKTIME("selected images: %f sec\n", dtime);
    3445
    3546  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
     47  MARKTIME("converted ftable to vtable: %f sec\n", dtime);
    3648
    3749  initImages (subset, Nsubset);
     50  MARKTIME("init images: %f sec\n", dtime);
     51
    3852  initMosaics (subset, Nsubset);
     53  MARKTIME("init mosaics: %f sec\n", dtime);
    3954 
    4055  return (skylist);
  • trunk/Ohana/src/relphot/src/relphot.c

    r27480 r30616  
    8585  if (PLOTSTUFF) {
    8686    plot_star_coords (catalog, Ncatalog);
    87     plot_mosaic_fields (catalog);
     87    // plot_mosaic_fields (catalog);
    8888  }
    8989
  • trunk/Ohana/src/relphot/src/select_images.c

    r29001 r30616  
    1515void dsortindex (double *X, off_t *Y, int N);
    1616off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     17
     18# define MARKTIME(MSG,...) { \
     19  float dtime; \
     20  gettimeofday (&stop, (void *) NULL); \
     21  dtime = DTIME (stop, start); \
     22  fprintf (stderr, MSG, __VA_ARGS__); }
    1723
    1824Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
     
    2531  Coords tcoords;
    2632  SkyRegionCoords *skycoords;
    27  
     33  struct timeval start, stop;
     34 
     35  double RmaxSkyRegion, RminSkyRegion, DminSkyRegion, DmaxSkyRegion, RmidSkyRegion;
     36
    2837  double *RmaxSky;
    2938  off_t *index;
     
    3544    return NULL;
    3645  }
     46
     47  gettimeofday (&start, (void *) NULL);
    3748
    3849  // the comparison is made in the catalog local projection. below we set crval1,2
     
    4758  ALLOCATE (RmaxSky, double, skylist[0].Nregions);
    4859  ALLOCATE (index, off_t, skylist[0].Nregions);
     60
     61  RminSkyRegion = +360.0;
     62  RmaxSkyRegion = -360.0;
     63  DminSkyRegion = +90.0;
     64  DmaxSkyRegion = -90.0;
    4965
    5066  /* compare with each region file */
     
    7591    skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy;
    7692    skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy;
    77   }
     93
     94    RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin);
     95    RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax);
     96    DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
     97    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
     98  }
     99  RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion);
     100  MARKTIME("create sky region coords: %f sec\n", dtime);
    78101
    79102  dsortindex (RmaxSky, index, skylist[0].Nregions);
     103  MARKTIME("sort sky coords: %f sec\n", dtime);
    80104
    81105  if (VERBOSE) fprintf (stderr, "finding images\n");
    82106  BuildChipMatch (timage, Ntimage);
     107  MARKTIME("build chip match: %f sec\n", dtime);
    83108
    84109  nimage = 0;
     
    100125    }
    101126   
     127    // this adds 1.3 sec for 3M images
    102128    if (!FindMosaicForImage (timage, Ntimage, i)) {
    103129      fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
     
    113139    found = FALSE;
    114140
    115     /* transform corners to ra,dec */
     141    /* transform corners to ra,dec -- costs ~3sec for 3M images */
    116142    double RminImage = 360.0;
     143    double RmaxImage =   0.0;
     144    double DminImage = +90.0;
     145    double DmaxImage = -90.0;
    117146    for (j = 0; j < 5; j++) {
    118147      XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords);
     148      Ri[j] = ohana_normalize_angle_to_midpoint (Ri[j], RmidSkyRegion);
     149     
    119150      RminImage = MIN(RminImage, Ri[j]);
    120     }
    121 
    122     // RA(nStart) is guaranteed to be < RminImage:
     151      RmaxImage = MAX(RmaxImage, Ri[j]);
     152      DminImage = MIN(DminImage, Di[j]);
     153      DmaxImage = MAX(DmaxImage, Di[j]);
     154    }
     155    if (RmaxImage - RminImage > 180.0) {
     156        double tmp = RminImage;
     157        RmaxImage = RminImage;
     158        RminImage = tmp - 360.0;
     159    }
     160   
     161    // check that this image is even in range of the searched region
     162    if (DminImage > DmaxSkyRegion) continue;
     163    if (DmaxImage < DminSkyRegion) continue;
     164   
     165    // the sky region RA is defined to be 0 - 360.0
     166    if (RminImage > RmaxSkyRegion) continue;
     167    if (RmaxImage < RminSkyRegion) continue;
     168
     169    // image overlaps region, keep it
     170    if (USE_BASIC_CHECK) goto found_it;
     171
     172    // RA(nStart) is guaranteed to be < RminImage: -- costs 0.5sec for 3M images
    123173    nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions);
    124174
    125175    /* compare with each region file */
    126     for (iSky = 0; (iSky < skylist[0].Nregions) && !found; iSky++) {
     176    for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) {
    127177
    128178      m = index[iSky];
     
    142192      for (j = 0; (j < 4) && !found; j++) {
    143193        found = corner_check (&Xi[j], &Yi[j], &skycoords[m].Xc[0], &skycoords[m].Yc[0]);
     194        if (found) goto found_it;
    144195      }
    145196      /* check if catalog corner inside image */
    146197      for (j = 0; (j < 4) && !found; j++) {
    147198        found = corner_check (&skycoords[m].Xc[j], &skycoords[m].Yc[j], &Xi[0], &Yi[0]);
     199        if (found) goto found_it;
    148200      }
    149201      /* check if edges cross */
     
    151203        for (k = 0; (k < 4) && !found; k++) {
    152204          found = edge_check (&Xi[j], &Yi[j], &skycoords[m].Xc[k], &skycoords[m].Yc[k]);
     205          if (found) goto found_it;
    153206        }
    154207      }
    155       if (!found) continue;
    156 
    157       image[nimage] = timage[i];
    158       /* always allow 'few' images to succeed, if possible */
    159       if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) {
    160         image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
    161       }
    162       if (RESET) {
    163         assignMcal (&image[nimage], (double *) NULL, -1);
    164         image[nimage].dMcal = NAN;
    165         image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR;
    166       }
    167       line_number[nimage] = i;
    168       nimage ++;
    169       if (nimage == NIMAGE) {
    170         NIMAGE += 100;
    171         REALLOCATE (image, Image, NIMAGE);
    172         REALLOCATE (line_number, off_t, NIMAGE);
    173       }
    174     }
    175   }
    176      
     208    }
     209    if (!found) continue;
     210
     211  found_it:
     212    image[nimage] = timage[i];
     213    /* always allow 'few' images to succeed, if possible */
     214    if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) {
     215      image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
     216    }
     217    if (RESET) {
     218      // XXX assignMcal (&image[nimage], (double *) NULL, -1);
     219      // XXX this needs to be thought through a bit more
     220      image[nimage].Mcal = 0.0;
     221      image[nimage].dMcal = NAN;
     222      image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR;
     223    }
     224    line_number[nimage] = i;
     225    nimage ++;
     226    if (nimage == NIMAGE) {
     227      NIMAGE += 100;
     228      REALLOCATE (image, Image, NIMAGE);
     229      REALLOCATE (line_number, off_t, NIMAGE);
     230    }
     231  }
     232  MARKTIME("finish image selection: %f sec\n", dtime);
     233
    177234  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage);
    178235
     
    295352  return (Nlo);
    296353}
     354
     355off_t getRegionStopByRA (double R, double *Rref, off_t Nregions) {
     356
     357  // use bisection to find the overlapping mosaic
     358
     359  off_t Nlo, Nhi, N;
     360
     361  // find the last mosaic before start
     362  Nlo = 0; Nhi = Nregions;
     363  while (Nhi - Nlo > 10) {
     364    N = 0.5*(Nlo + Nhi);
     365    if (Rref[N] < R) {
     366      Nlo = MAX(N, 0);
     367    } else {
     368      Nhi = MIN(N, Nregions);
     369    }
     370  }
     371  return (Nlo);
     372}
Note: See TracChangeset for help on using the changeset viewer.