IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27581


Ignore:
Timestamp:
Apr 2, 2010, 3:55:04 PM (16 years ago)
Author:
eugene
Message:

various improvements to relastro to calculate the significance of the astrometry model (merged dev work from branches/eam_brances/relastro.20100326)

Location:
trunk/Ohana/src/relastro
Files:
18 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro

  • trunk/Ohana/src/relastro/Makefile

    r24308 r27581  
    5656$(SRC)/save_catalogs.$(ARCH).o       \
    5757$(SRC)/write_coords.$(ARCH).o        \
     58$(SRC)/CoordOps.$(ARCH).o        \
     59$(SRC)/FixProblemImages.$(ARCH).o        \
    5860$(SRC)/relastroVisual.$(ARCH).o
    5961
  • trunk/Ohana/src/relastro/include/relastro.h

    r27435 r27581  
    9191
    9292int    VERBOSE;
     93int    VERBOSE2;
    9394
    9495int    RESET;
     96int    NLOOP;
    9597int    UPDATE;
    9698int    PLOTSTUFF;
     
    103105int    PLOTDELAY;
    104106int    CHIPORDER;
     107
     108int UserCatalog;
     109double UserCatalogRA, UserCatalogDEC;
    105110
    106111char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST;
     
    151156void          dump_grid           PROTO((void));
    152157int           edge_check          PROTO((double *x1, double *y1, double *x2, double *y2));
    153 void          findImages          PROTO((Catalog *catalog, int Ncatalog));
     158void          findImages          PROTO((Catalog *catalog, int Ncatalog, int MATCHCAT));
    154159int           findMosaics         PROTO((Catalog *catalog, int Ncatalog));
    155160Image        *find_images         PROTO((FITS_DB *db, GSCRegion *region, off_t Nregion, off_t *Nimage, off_t **LineNum));
     
    166171void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
    167172int           gcatalog            PROTO((Catalog *catalog, int FINAL));
    168 Coords       *getCoords           PROTO((off_t meas, int cat));
     173// Coords       *getCoords           PROTO((off_t meas, int cat));
    169174float         getMcal             PROTO((off_t meas, int cat));
    170175float         getMgrid            PROTO((off_t meas, int cat));
     
    178183void          initGrid            PROTO((int dX, int dY));
    179184void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
    180 void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
     185void          initImageBins       PROTO((Catalog *catalog, int Ncatalog, int FULLINIT));
    181186void          initImages          PROTO((Image *input, off_t N));
    182187void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
     
    199204int           main                PROTO((int argc, char **argv));
    200205void          mark_images         PROTO((Image *image, off_t Nimage, Image *timage, off_t Ntimage));
    201 void          matchImage          PROTO((Catalog *catalog, off_t meas, int cat));
     206void          matchImage          PROTO((Catalog *catalog, off_t meas, int cat, int MATCHCAT));
    202207void          matchMosaics        PROTO((Catalog *catalog, off_t meas, int cat));
    203208GSCRegion    *name_region         PROTO((char *name, off_t *Nregions));
     
    250255void fit_free (CoordFit *fit);
    251256void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt);
    252 void fit_eval (CoordFit *fit);
     257int fit_eval (CoordFit *fit);
    253258void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1);
    254259double **poly2d_dx (double **poly, int Nx, int Ny);
     
    256261double **poly2d_copy (double **poly, int Nx, int Ny);
    257262double poly2d_eval (double **poly, int Nx, int Ny, double x, double y);
    258 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords);
     263int fit_apply_coords (CoordFit *fit, Coords *coords);
    259264int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo);
    260265CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo);
    261 void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
     266int FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
    262267void FitMosaic (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
    263268void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
     
    273278
    274279int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon);
    275 int ParFactor (double *pR, double *pD, double R, double D, time_t T);
     280int ParFactor (double *pR, double *pD, double R, double D, double T, double Tmean);
    276281int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts);
    277282int FitPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *pR, double *pD, int Npts);
     
    303308                               StatType statsR, StatType statsD, double thresh);
    304309
     310
     311
     312int FixProblemImages (SkyList *skylist);
     313int *getCatlist (int *N, off_t im);
     314
     315void initCoords (void);
     316void getOffsets (double *dPos, off_t *nPos, off_t N);
     317void saveOffsets (double dPos, off_t nPos, off_t N);
     318void setBadCoords (off_t N);
     319int badCoords (off_t N);
     320Coords *getCoords (off_t N);
     321int saveCoords (Coords *coords, off_t N);
     322void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
  • trunk/Ohana/src/relastro/src/FitChip.c

    r24308 r27581  
    1717// XXX save measurements of the fit quality (scatter, chisq) in the image table
    1818
    19 void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {
     19int FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {
    2020
    2121  int i, Nscatter, Niter, skip;
     
    8484      default:
    8585        fprintf (stderr, "invalid chip order %d\n", coords[0].Npolyterms);
    86         abort ();
     86        skip = TRUE;
    8787    }
    8888    if (skip) {
     
    9090      fit_free (fit);
    9191      free (values);
    92       return;
     92      return FALSE;
    9393    }
    9494
    95     fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);
     95    // fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);
    9696
    9797    // measure the fit, update the coords & object coordinates
    98     fit_eval (fit);
    99     fit_apply_coords (fit, coords);
     98    if (!fit_eval (fit)) {
     99      fprintf (stderr, "failed to fit new model\n");
     100      return FALSE;
     101    }
     102
     103    if (!fit_apply_coords (fit, coords)) {
     104      fprintf (stderr, "failed to fit new model\n");
     105      return FALSE;
     106    }
     107
    100108    fit_free (fit);
    101109
     
    107115
    108116  free (values);
    109   return;
     117  return TRUE;
    110118}
    111119
  • trunk/Ohana/src/relastro/src/GetAstromError.c

    r24308 r27581  
    88  switch (mode) {
    99    case ERROR_MODE_RA:
    10       dPobs = measure[0].dXccd;  // need to redefine this as RAerr
     10      dPobs = measure[0].dXccd / 100.0;  // need to redefine this as RAerr
    1111      break;
    1212    case ERROR_MODE_DEC:
    13       dPobs = measure[0].dYccd;  // need to redefine this as RAerr
     13      dPobs = measure[0].dYccd / 100.0;  // need to redefine this as RAerr
    1414      break;
    1515    case ERROR_MODE_POS:
    16       dPobs = hypot (measure[0].dXccd, measure[0].dYccd);  // need to redefine this as RAerr
     16      dPobs = hypot (measure[0].dXccd, measure[0].dYccd) / 100.0;  // need to redefine this as RAerr
    1717      break;
    1818    default:
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r27478 r27581  
    1111static Image        *image;   // list of available images
    1212static off_t        Nimage;   // number of available images
     13
     14static int         *Ncatlist;  // catalogs associated with each image
     15static int         *NCATLIST;  // catalogs associated with each image
     16static int         **catlist;  // catalogs associated with each image
    1317
    1418// if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted
     
    3236}
    3337
     38int *getCatlist (int *N, off_t im) {
     39
     40  *N = Ncatlist[im];
     41  return (catlist[im]);
     42}
     43
    3444void initImages (Image *input, off_t N) {
    3545
     
    8696}
    8797
    88 void initImageBins (Catalog *catalog, int Ncatalog) {
     98// these are really image & catalog indexes
     99void initImageBins (Catalog *catalog, int Ncatalog, int FULLINIT) {
    89100
    90101  off_t i, j;
     
    102113
    103114  for (i = 0; i < Nimage; i++) {
    104     Nlist[i] = 0;
     115    Nlist[i] =   0;
    105116    NLIST[i] = 100;
    106117    ALLOCATE (clist[i], int, NLIST[i]);
    107118    ALLOCATE (mlist[i], off_t, NLIST[i]);
     119  }
     120
     121  if (FULLINIT) {
     122    ALLOCATE (Ncatlist, int,  Nimage);
     123    ALLOCATE (NCATLIST, int,  Nimage);
     124    ALLOCATE (catlist, int *, Nimage);
     125
     126    for (i = 0; i < Nimage; i++) {
     127      Ncatlist[i] =  0;
     128      NCATLIST[i] = 32;
     129      ALLOCATE (catlist[i], int, NCATLIST[i]);
     130    }
    108131  }
    109132}
     
    126149
    127150/* match measurements to images */
    128 void findImages (Catalog *catalog, int Ncatalog) {
     151void findImages (Catalog *catalog, int Ncatalog, int MATCHCAT) {
    129152
    130153  off_t i, j;
     
    136159      // ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
    137160      // if (photcode[0].code != ecode) continue;
    138       matchImage (catalog, j, i);
    139     }
    140   }
    141 
    142   for (i = 0; VERBOSE && (i < Nimage); i++) {
     161      matchImage (catalog, j, i, MATCHCAT);
     162    }
     163  }
     164
     165  for (i = 0; VERBOSE2 && (i < Nimage); i++) {
    143166    name = GetPhotcodeNamebyCode (image[i].photcode);
    144167    fprintf (stderr, "image %lld has %lld measures (%s, %s)\n", (long long) i, (long long) Nlist[i],
     
    149172# if USE_IMAGE_ID
    150173// this is the imageID-based match
    151 void matchImage (Catalog *catalog, off_t meas, int cat) {
     174void matchImage (Catalog *catalog, off_t meas, int cat, int MATCHCAT) {
    152175
    153176  off_t idx, ID;
    154177  Measure *measure;
     178  int i, found;
    155179
    156180  measure = &catalog[cat].measure[meas];
     
    159183  idx = getImageByID (ID);
    160184  if (idx == -1) {
    161     fprintf (stderr, "can't match detection to image?\n");
    162     abort();
     185    if (VERBOSE2) fprintf (stderr, "can't match detection to image?\n");
     186    return;
    163187  }
    164188
     
    178202    REALLOCATE (mlist[idx], off_t, NLIST[idx]);
    179203  }
     204
     205  if (MATCHCAT) {
     206    // index for image -> catalog list
     207    found = FALSE;
     208    for (i = 0; !found && (i < Ncatlist[idx]); i++) {
     209      if (catlist[idx][i] == cat) found = TRUE;
     210    }
     211    if (!found) {
     212      catlist[idx][Ncatlist[idx]] = cat;
     213      Ncatlist[idx] ++;
     214      if (Ncatlist[idx] == NCATLIST[idx]) {
     215        NCATLIST[idx] += 32;
     216        REALLOCATE (catlist[idx], int, NCATLIST[idx]);
     217      }
     218    }
     219  }
     220
    180221  return;
    181222}
     
    183224# else
    184225// this is the time-based match
    185 void matchImage (Catalog *catalog, off_t meas, int cat) {
     226void matchImage (Catalog *catalog, off_t meas, int cat, int MATCHCAT) {
    186227
    187228  off_t i;
     
    216257    return;
    217258  }
    218   fprintf (stderr, "can't match detection to image?\n");
    219   abort();
     259  if (VERBOSE2) fprintf (stderr, "can't match detection to image?\n");
     260  return;
    220261}
    221262# endif
    222263
     264/*
    223265Coords *getCoords (off_t meas, int cat) {
    224266
     
    229271  return (&image[i].coords);
    230272}
     273*/
    231274
    232275void plot_images () {
     
    280323void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
    281324
    282   off_t i, m, c, n;
     325  off_t i, m, c, n, nPos;
    283326  double X, Y, L, M, P, Q, R, D, dR, dD;
     327  double dPos;
    284328
    285329  Mosaic *mosaic;
    286330  Coords *moscoords, *imcoords;
    287331
     332  // check if this image is bad and should be skipped
     333  if (badCoords(im)) return;
     334
     335  // WRP images need to have an associated mosaic
    288336  moscoords = NULL;
    289   mosaic = getMosaicForImage (im);
    290   if (mosaic != NULL) {
     337  if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
     338    mosaic = getMosaicForImage (im);
     339    if (mosaic == NULL) return;  // if we cannot find the associated image, skip it
    291340    moscoords = &mosaic[0].coords;
    292341  }
    293342  imcoords = &image[im].coords;
     343
     344  // accumulate the rms position offsets.  if this value, or any specific entry, is too
     345  // large, we will reset the image to the original coords at the end of the analysis
     346
     347  dPos = 0.0;
     348  nPos = 0;
    294349
    295350  for (i = 0; i < Nlist[im]; i++) {
     
    316371    dD = 3600.0*(catalog[c].average[n].D - D);
    317372
    318     if (fabs(catalog[c].measure[m].dR - dR) > 10.0) {
    319       // XXXXX running into this still for last megacam exposure: wrong mosaic?
    320       // ???? inconsistently hitting this????
     373    // complain if the new location is far from the average location
     374    if (fabs(dR) > 2.0) {
    321375      fprintf (stderr, "!");
    322       // abort ();
    323     }
    324     if (fabs(catalog[c].measure[m].dD - dD) > 10.0) {
     376      setBadCoords (im); // report a failure for this image
     377      return;
     378    }
     379    if (fabs(dD) > 2.0) {
    325380      fprintf (stderr, "*");
    326       // abort ();
    327     }
     381      setBadCoords (im); // report a failure for this image
     382      return;
     383    }
     384
     385    // complain if the new location is far from the old location
     386    if (fabs(catalog[c].measure[m].dR - dR) > 2.0) {
     387      fprintf (stderr, "@");
     388      setBadCoords (im); // report a failure for this image
     389      return;
     390    }
     391    if (fabs(catalog[c].measure[m].dD - dD) > 2.0) {
     392      fprintf (stderr, "#");
     393      setBadCoords (im); // report a failure for this image
     394      return;
     395    }
     396
     397    dPos += SQ(catalog[c].measure[m].dR - dR) + SQ(catalog[c].measure[m].dD - dD);
     398    nPos ++;
    328399
    329400    catalog[c].measure[m].dR = dR;
     
    341412    }
    342413  }
     414
     415  saveOffsets (dPos, nPos, im);
     416
     417  return;
     418}
     419
     420// return StarData values for detections in the specified image, converting coordinates from the
     421// chip positions: X,Y -> L,M -> P,Q -> R,D
     422void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
     423
     424  off_t i, m, c, n;
     425  double X, Y, L, M, P, Q, R, D, dR, dD;
     426
     427  Mosaic *mosaic;
     428  Coords *moscoords, *imcoords, *oldcoords;
     429
     430  // check if this image is bad and should be skipped
     431  if (!badCoords(im)) {
     432    fprintf (stderr, "ERROR: inconsistent result?");
     433    abort();
     434  }
     435
     436  // replace the current coords with the old coords:
     437  oldcoords = getCoords (im);
     438  memcpy (&image[im].coords, oldcoords, sizeof(Coords));
     439
     440  // WRP images need to have an associated mosaic
     441  moscoords = NULL;
     442  if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
     443    mosaic = getMosaicForImage (im);
     444    if (mosaic == NULL) return;  // if we cannot find the associated image, skip it
     445    moscoords = &mosaic[0].coords;
     446  }
     447  imcoords = &image[im].coords;
     448
     449  for (i = 0; i < Nlist[im]; i++) {
     450    m = mlist[im][i];
     451    c = clist[im][i];
     452
     453    X = catalog[c].measure[m].Xccd;
     454    Y = catalog[c].measure[m].Yccd;
     455    n = catalog[c].measure[m].averef;
     456
     457    dR = dD = 0.0;
     458    if (moscoords == NULL) {
     459      // this is a Simple image (not a mosaic)
     460      // note that for a Simple image, L,M = P,Q
     461      XY_to_LM (&L, &M, X, Y, imcoords);
     462      LM_to_RD (&R, &D, L, M, imcoords);
     463    } else {
     464      XY_to_LM (&L, &M, X, Y, imcoords);
     465      XY_to_LM (&P, &Q, L, M, moscoords);
     466      LM_to_RD (&R, &D, P, Q, moscoords);
     467    }
     468
     469    catalog[c].measure[m].dR = dR;
     470    catalog[c].measure[m].dD = dD;
     471
     472    if (catalog[c].measure[m].dR > +180.0*3600.0) {
     473      // average on high end of boundary, move star up
     474      R += 360.0;
     475      catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);
     476    }
     477    if (catalog[c].measure[m].dR < -180.0*3600.0) {
     478      // average on low end of boundary, move star down
     479      R -= 360.0;
     480      catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);
     481    }
     482  }
     483
    343484  return;
    344485}
     
    354495  Coords *moscoords;
    355496  StarData *raw;
    356 
    357   ALLOCATE (raw, StarData, Nlist[im]);
    358497
    359498  mosaic = NULL;
     
    363502    if (mosaic == NULL) {
    364503      fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
    365       exit (1);
     504      return NULL;
    366505    }
    367506    moscoords = &mosaic[0].coords;
    368507  }
     508
     509  ALLOCATE (raw, StarData, Nlist[im]);
    369510
    370511  for (i = 0; i < Nlist[im]; i++) {
     
    430571  StarData *ref;
    431572
    432   ALLOCATE (ref, StarData, Nlist[im]);
    433 
    434573  mosaic = NULL;
    435574  moscoords = NULL;
     
    438577    if (mosaic == NULL) {
    439578      fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
    440       exit (1);
     579      return NULL;
    441580    }
    442581    moscoords = &mosaic[0].coords;
    443582  }
     583
     584  ALLOCATE (ref, StarData, Nlist[im]);
    444585
    445586  for (i = 0; i < Nlist[im]; i++) {
  • trunk/Ohana/src/relastro/src/MosaicOps.c

    r27478 r27581  
    146146
    147147    Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos);
    148     if (Nmos == -1) continue;
     148    if (Nmos == -1) {
     149      fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
     150      continue;
     151    }
    149152
    150153    // mosaic corresponding to this image
     
    185188    // this function does the reverse-lookup for the mosaic corresponding to this image
    186189    new = getImageRaw (catalog, Ncatalog, im, &Nnew, MODE_MOSAIC);
     190    if (!new) {
     191      fprintf (stderr, "inconsistent: missing mosaic for image already associated with a mosaic? (1)\n");
     192      abort();
     193    }
    187194   
    188195    // merge new and raw
     
    217224    // this function does the reverse-lookup for the mosaic corresponding to this image
    218225    new = getImageRef (catalog, Ncatalog, im, &Nnew, MODE_MOSAIC);
     226    if (!new) {
     227      fprintf (stderr, "inconsistent: missing mosaic for image already associated with a mosaic? (2)\n");
     228      abort();
     229    }
    219230   
    220231    // merge new and ref
  • trunk/Ohana/src/relastro/src/ParFactor.c

    r14590 r27581  
    4242
    4343/* given RA, DEC, Time, calculate the parallax factor */
    44 int ParFactor (double *pR, double *pD, double R, double D, time_t T) {
     44int ParFactor (double *pR, double *pD, double R, double D, double T, double Tmean) {
    4545
    4646  double jd;
     
    4949  /* given a time T in UNIX seconds, determine the solar longitude S */
    5050
    51   jd = ohana_sec_to_jd (T);
     51  jd = ohana_sec_to_jd (365.25*86400.0*(T + Tmean));
    5252  sun_ecliptic (jd, &L, &B, &E);
    5353
  • trunk/Ohana/src/relastro/src/UpdateChips.c

    r27435 r27581  
    77  Image *image;
    88  StarData *raw, *ref;
     9  Coords *oldCoords;
    910
    1011  image = getimages (&Nimage);
     
    1718    /* convert measure coordinates to raw entries */
    1819    raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC);
     20    if (!raw) continue;
    1921
    2022    /* convert average coordinates to ref entries */
    2123    ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC);
     24    if (!ref) continue;
    2225
    2326    // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions.
    2427    assert (Nraw == Nref);
    2528
     29    saveCoords (&image[i].coords, i);
     30
    2631    // FitChip does iterative, clipped fitting
    27     fprintf (stderr, "image %lld : Nstars: %lld\n", (long long) i, (long long) Nraw);
    28     FitChip (raw, ref, Nraw, &image[i].coords);
     32    // fprintf (stderr, "image %lld : Nstars: %lld\n", (long long) i, (long long) Nraw);
     33    if (!FitChip (raw, ref, Nraw, &image[i].coords)) {
     34      fprintf (stderr, "reject fit for image %s (%lld) : Nstars: %lld\n", image[i].name, (long long) i, (long long) Nraw);
     35      oldCoords = getCoords (i);
     36      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     37    }
    2938
    3039    free (raw);
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r17243 r27581  
    11# include "relastro.h"
     2
     3// We run through each DVO catalog, updating the measures that come from the modified images
     4// We need to watch for failures:
     5// * in UpdateMeasures, in fixImageRaw, we track the cumulative offset for each image
     6// * after all updates are done, we can check for any bad images and reset them to the
     7//   original coordinates
    28
    39int UpdateObjectOffsets (SkyList *skylist) {
     
    2834
    2935    // match measurements with images
    30     initImageBins (&catalog, 1);
    31     findImages (&catalog, 1);
     36    initImageBins (&catalog, 1, FALSE);
     37    findImages (&catalog, 1, FALSE);
    3238
    3339    // update the detection coordinates using the new image parameters
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r27435 r27581  
    4040int UpdateObjects (Catalog *catalog, int Ncatalog) {
    4141
    42   int i, j, k, m, N, Nsecfilt;
     42  off_t j, k, m;
     43  int i, N, Nsecfilt, mode, result, status, XVERB;
    4344  StatType statsR, statsD;
    4445  Coords coords;
    45   PMFit fit;
    46   time_t To;
    47   int mode, Nave, Npm, Npar, Nskip;
    48   double Tmin, Tmax;
     46  PMFit fitAve, fitPM, fitPAR, fit;
     47  time_t T2000;
     48  off_t Nave, Npm, Npar, Nskip;
     49  off_t NaveSum, NpmSum, NparSum, NskipSum;
     50  double Tmin, Tmax, Tmean, Trange;
    4951
    5052  initObjectData (catalog, Ncatalog);
     
    6163  strcpy (coords.ctype, "RA---SIN");
    6264
     65  XVERB = FALSE;
     66
    6367  // use J2000 as a reference time
    64   To = ohana_date_to_sec ("2000/01/01");
    65   Nave = Npar = Npm = 0;
     68  T2000 = ohana_date_to_sec ("2000/01/01");
    6669
    6770  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
     
    6972  assert (catalog[0].Nsecfilt == Nsecfilt);
    7073
     74  NaveSum = NparSum = NpmSum = NskipSum = 0;
    7175  for (i = 0; i < Ncatalog; i++) {
    7276
    7377    if (VERBOSE) fprintf (stderr, "astrometrize catalog %d : %lld ave, %lld meas\n", i, (long long) catalog[i].Naverage, (long long) catalog[i].Nmeasure);
    7478
    75     Nskip = 0;
     79    Nave = Npar = Npm = Nskip = 0;
    7680    for (j = 0; j < catalog[i].Naverage; j++) {
    7781      /* calculate the average value of R,D for a single star */
     
    7983      // skip objects which are known to be problematic
    8084      // XXX include this code or not?
    81       # if (0)
     85# if (0)
    8286      if (catalog[i].average[j].code & STAR_BAD) {
    8387        Nskip ++;
    8488        continue; 
    8589      }
    86       # endif
     90# endif
    8791
    8892      N = 0;
    8993      m = catalog[i].average[j].measureOffset;
    9094
    91       Tmin = Tmax = (catalog[i].measure[m].t - To) / (86400*365.25);
     95      Tmin = Tmax = (catalog[i].measure[m].t - T2000) / (86400*365.25);
    9296      mode = FIT_MODE;
    9397
     98      // find the basic properties of the detections for this object (Tmin, Tmax, Tmean)
     99      Tmean = 0;
    94100      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    95101
     
    108114        // exclude measurements by previous outlier detection
    109115        // XXX include this code or not?
    110         # if (0)
     116# if (0)
    111117        if (catalog[i].measure[m].dbFlags & MEAS_BAD) {
    112118          catalog[i].measure[m].dbFlags |= ID_MEAS_SKIP_ASTROM;
    113119          continue;
    114120        }
    115         # endif
     121# endif
    116122
    117123        catalog[i].measure[m].dbFlags |= ID_MEAS_USED_OBJ;
     
    119125        R[N] = getMeanR (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    120126        D[N] = getMeanD (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    121         T[N] = (catalog[i].measure[m].t - To) / (86400*365.25) ; // time relative to J2000 in years
     127        T[N] = (catalog[i].measure[m].t - T2000) / (86400*365.25) ; // time relative to J2000 in years
    122128
    123129        Tmin = MIN(Tmin, T[N]);
    124130        Tmax = MAX(Tmax, T[N]);
    125 
    126         dR[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
    127         dD[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
     131        Tmean += T[N];
     132
     133        // dX, dY : error in arcsec --
     134        dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
     135        dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
    128136        dT[N] = catalog[i].measure[m].dt;
     137
     138        // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in
     139        // arcseconds.  dR, dD are the errors in those directions in degrees.  IF we have
     140        // non-circular errors (different values for X and Y), then dR and dD will be
     141        // incorrect: they would need to be rotated to take out the position angle
     142        dR[k] = dX[k] / 3600.0;
     143        dD[k] = dY[k] / 3600.0;
    129144
    130145        N++;
     
    138153
    139154      // XXX add the parallax factor range as a criterion as well
    140       if ((Tmax - Tmin) < PM_DT_MIN) mode = FIT_AVERAGE;
     155      Trange = Tmax - Tmin;
     156      if (Trange < PM_DT_MIN) mode = FIT_AVERAGE;
    141157      if ((mode == FIT_PM_ONLY) && (N < PM_TOOFEW)) mode = FIT_AVERAGE;
    142158
     
    144160      if (N < SRC_MEAS_TOOFEW) {
    145161        // XXX need to define PHOTOM and ASTROM object flags
     162        // XXX reset the average value fields?
    146163        catalog[i].average[j].flags |= ID_STAR_FEW;
     164        catalog[i].average[j].ChiSqAve  = NAN;
     165        catalog[i].average[j].ChiSqPM   = NAN;
     166        catalog[i].average[j].ChiSqPar  = NAN;
    147167        if (N < 2) continue;
    148168      }
     
    151171      coords.crval1 = R[0];
    152172      coords.crval2 = D[0];
     173      Tmean /= (float) N;
    153174     
    154       /* project all of the R,D coordinates to a plane centered on this coordinate */
    155       for (k = 0; k < N; k++) {
    156         RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
    157         dX[k] =  dR[k];
    158         dY[k] =  dD[k];
    159         // fprintf (stderr, "%d %f %f %f  %f %f\n", k, T[k], R[k], D[k], X[k], Y[k]);
     175      XVERB = FALSE && (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
     176
     177      // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
     178
     179      if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
     180        // project all of the R,D coordinates to a plane centered on this coordinate set
     181        // the times to be relative to Tmean (this is required for parallax as well)
     182        for (k = 0; k < N; k++) {
     183          RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
     184          T[k] -= Tmean;
     185          if (XVERB) {
     186            fprintf (stderr, "%lld %f %f %f  %f %f +/- %f %f\n", (long long) k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]);
     187          }
     188        }         
     189
     190        FitPM (&fitPM, X, dX, Y, dY, T, N);
     191        if (XVERB) fprintf (stderr, "fitted:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
     192
     193        // project Ro, Do back to RA,DEC
     194        XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &coords);
     195        if (XVERB) fprintf (stderr, "project: %f %f : %f %f : %f\n", fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.p);
     196
     197        fitPM.p  = fitPM.dp  = 0.0;
     198        catalog[i].average[j].flags |= ID_STAR_FIT_PM;
     199        Npm ++;
     200      }
     201
     202      if (mode == FIT_PM_AND_PAR) {
     203        fprintf (stderr, "parallax fitting is still untested (%s, %d)", __FILE__, __LINE__);
     204        exit (2);
     205
     206        for (k = 0; k < N; k++) {
     207          ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean);
     208        }
     209        FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N);
     210        XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords);
     211        catalog[i].average[j].flags |= ID_STAR_FIT_PAR;
     212        Npar ++;
    160213      }   
    161214
    162       /* fit the model components as needed */
    163       switch (mode) {
     215      // fit the average model
     216      if ((mode == FIT_AVERAGE) || (mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
     217        liststats (R, dR, N, &statsR); // WARNING: this function modifies R (do not use after here)
     218        liststats (D, dD, N, &statsD); // WARNING: this function modifies D (do not use after here)
     219
     220        fitAve.Ro = statsR.mean;
     221        fitAve.dRo = 3600.0*statsR.sigma;
     222
     223        fitAve.Do = statsD.mean;
     224        fitAve.dDo = 3600.0*statsD.sigma;
     225
     226        fitAve.chisq = 0.5*(statsR.chisq + statsD.chisq);
     227        fitAve.Nfit = N;
     228
     229        fitAve.uR = fitAve.duR = 0.0;
     230        fitAve.uD = fitAve.duD = 0.0;
     231        fitAve.p  = fitAve.dp  = 0.0;
     232        catalog[i].average[j].flags |= ID_STAR_FIT_AVE;
     233        Nave ++;
     234      }
     235
     236      /* choose the result based on the chisq values */
     237      // XXXX for now, just use the mode as the result:
     238      result = mode;
     239
     240      switch (result) {
    164241        case FIT_AVERAGE:
    165           liststats (R, dR, N, &statsR);
    166           liststats (D, dD, N, &statsD);
    167 
    168           fit.Ro = statsR.mean;
    169           fit.dRo = 3600.0*statsR.sigma;
    170 
    171           fit.Do = statsD.mean;
    172           fit.dDo = 3600.0*statsD.sigma;
    173 
    174           fit.chisq = 0.5*(statsR.chisq + statsD.chisq);
    175           fit.Nfit = N;
    176 
    177           fit.uR = fit.duR = 0.0;
    178           fit.uD = fit.duD = 0.0;
    179           fit.p  = fit.dp  = 0.0;
    180 
    181           Nave ++;
     242          catalog[i].average[j].flags |= ID_STAR_USE_AVE;
     243          fit = fitAve;
    182244          break;
    183 
    184245        case FIT_PM_ONLY:
    185           FitPM (&fit, X, dX, Y, dY, T, N);
    186           // fprintf (stderr, "fitted:  %f - %f : %f %f : %f %f : %f\n", Tmin, Tmax, fit.Ro, fit.Do, fit.uR, fit.uD, fit.p);
    187           // project Ro, Do back to RA,DEC
    188           XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords);
    189           // fprintf (stderr, "project: %f %f : %f %f : %f\n", fit.Ro, fit.Do, fit.uR, fit.uD, fit.p);
    190           // continue;
    191 
    192           fit.p  = fit.dp  = 0.0;
    193 
    194           Npm ++;
     246          catalog[i].average[j].flags |= ID_STAR_USE_PM;
     247          fit = fitPM;
    195248          break;
    196 
    197         case FIT_PAR_ONLY:
    198           fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__);
    199           exit (2);
    200 
    201           for (k = 0; k < N; k++) {
    202             ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]);
    203           }
    204           FitPar (&fit, X, dX, Y, dY, pX, pY, N);
    205 
    206           // project Ro, Do back to RA,DEC
    207           XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords);
    208 
    209           fit.uR = fit.duR = 0.0;
    210           fit.uD = fit.duD = 0.0;
    211 
    212           Npar ++;
     249        case FIT_PM_AND_PAR:
     250          catalog[i].average[j].flags |= ID_STAR_USE_PAR;
     251          fit = fitPAR;
    213252          break;
    214 
    215         case FIT_PM_AND_PAR:
    216           fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__);
    217           exit (2);
    218 
    219           for (k = 0; k < N; k++) {
    220             ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]);
    221           }
    222           FitPMandPar (&fit, X, dX, Y, dY, T, pX, pY, N);
    223           XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords);
    224           Npar ++;
    225           break;
    226 
    227         default:
    228           fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__);
    229           exit (2);
    230       }   
    231 
    232       if (0 && (j < 100)) {
    233         fprintf (stderr, "%f %f -> %f %f (%f,%f)\n",
    234                  catalog[i].average[j].R,
    235                  catalog[i].average[j].D,
    236                  fit.Ro, fit.Do,
    237                  3600*(catalog[i].average[j].R - fit.Ro),
    238                  3600*(catalog[i].average[j].D - fit.Do));
    239       }
     253      }
     254
     255      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f)\n",
     256                          catalog[i].average[j].R,
     257                          catalog[i].average[j].D,
     258                          fit.Ro, fit.Do,
     259                          3600*(catalog[i].average[j].R - fit.Ro),
     260                          3600*(catalog[i].average[j].D - fit.Do));
    240261
    241262      //make sure that the fit succeeded
    242       assert(finite(fit.Ro) && finite(fit.Do) &&
    243              finite(fit.dRo) && finite(fit.dDo) &&
    244              finite(fit.uR) && finite(fit.uD) &&
    245              finite(fit.duR) && finite(fit.duD) &&
    246              finite(fit.p) && finite(fit.dp));
     263      status  = finite(fit.Ro);
     264      status &= finite(fit.Do);
     265      status &= finite(fit.dRo);
     266      status &= finite(fit.dDo);
     267      status &= finite(fit.uR);
     268      status &= finite(fit.uD);
     269      status &= finite(fit.duR);
     270      status &= finite(fit.duD);
     271      status &= finite(fit.p);
     272      status &= finite(fit.dp);
     273      if (!status) {
     274        Nskip ++;
     275        continue;
     276      }
    247277
    248278      // the measure fields must be updated before the average fields
    249279      m = catalog[i].average[j].measureOffset;
    250280      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    251         // XXX why was this here?? if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
    252281        setMeanR (fit.Ro, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    253282        setMeanD (fit.Do, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     
    267296      catalog[i].average[j].dP  = fit.dp; // parallax error in arcsec
    268297
    269       catalog[i].average[j].Xp  = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NAN_S_SHORT;
     298      // Xp is supposed to be the position scatter, not the chisq : fix this:
     299      // catalog[i].average[j].Xp  = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NAN_S_SHORT;
     300      catalog[i].average[j].ChiSqAve  = fitAve.chisq;
     301      catalog[i].average[j].ChiSqPM   = fitPM.chisq;
     302      catalog[i].average[j].ChiSqPar  = fitPAR.chisq;
     303      catalog[i].average[j].Xp        = 0.0;
     304      catalog[i].average[j].Tmean = (Tmean * 86400 * 365.26) + T2000;
     305      catalog[i].average[j].Trange = (Trange * 86400 * 365.26);
     306      catalog[i].average[j].Npos = fit.Nfit;
    270307    }
    271308
    272     if (VERBOSE) fprintf (stderr, "catalog %d : %d ave, %d pm, %d par : Nskip % d\n", i, Nave, Npm, Npar, Nskip);
     309    NaveSum += Nave;
     310    NpmSum += Npm;
     311    NparSum += Npar;
     312    NskipSum += Nskip;
     313    if (VERBOSE) fprintf (stderr, "catalog %lld : %lld ave, %lld pm, %lld par : Nskip %lld\n", (long long) i, (long long) Nave, (long long) Npm, (long long) Npar, (long long) Nskip);
    273314  }
    274315
    275   if (VERBOSE) fprintf (stderr, "fitted %d objects (%d ave, %d pm, %d par)\n", Nave + Npm + Npar, Nave, Npm, Npar);
     316  fprintf (stderr, "fitted %lld objects (%lld ave, %lld pm, %lld par), skipped %lld\n", (long long) (NaveSum + NpmSum + NparSum), (long long) NaveSum, (long long) NpmSum, (long long) NparSum, (long long) NskipSum);
    276317  return (TRUE);
    277318}
     
    279320/* fitting proper-motion and parallax:
    280321
    281 given a source at position r,d, at a time t, we need to calculate a vector (pr,pd)
    282 
    283 let x,y be the coordinate in the linearized frame with y parallel to DEC lines
    284 
    285 L,B are the ecliptic longitude and latitude of the object,
    286 dL and dB are the offsets in the L and B directions
    287 
    288 dL = sin(t - topp)
    289 dB = cos(t - topp)*sin(B)
    290 
    291 these need to be rotated to the R,D frame to yield pR,pD.  Then, the equation of motion
    292 for the source in the x,y frame is:
    293 
    294 x = Ro + uR * (t - to) + p * pR
    295 y = Do + uD * (t - to) + p * pD
    296 
    297 the unknowns in these equations are Ro, uR, Do, uD, and p
    298 
    299 XXX think through the concepts for the pole a bit better.  all objects near the pole
    300 move the same way with the same phase.  choose a projection center and define dL,dB relative
    301 to that center point coordinate system?
     322   given a source at position r,d, at a time t, we need to calculate a vector (pr,pd)
     323
     324   let x,y be the coordinate in the linearized frame with y parallel to DEC lines
     325
     326   L,B are the ecliptic longitude and latitude of the object,
     327   dL and dB are the offsets in the L and B directions
     328
     329   dL = sin(t - topp)
     330   dB = cos(t - topp)*sin(B)
     331
     332   these need to be rotated to the R,D frame to yield pR,pD.  Then, the equation of motion
     333   for the source in the x,y frame is:
     334
     335   x = Ro + uR * (t - to) + p * pR
     336   y = Do + uD * (t - to) + p * pD
     337
     338   the unknowns in these equations are Ro, uR, Do, uD, and p
     339
     340   XXX think through the concepts for the pole a bit better.  all objects near the pole
     341   move the same way with the same phase.  choose a projection center and define dL,dB relative
     342   to that center point coordinate system?
    302343
    303344*/
  • trunk/Ohana/src/relastro/src/UpdateSimple.c

    r27435 r27581  
    1818    /* convert measure coordinates to raw entries */
    1919    raw = getImageRaw (catalog, Ncatalog, i, &Nstars, MODE_SIMPLE);
     20    if (!raw) continue;
    2021
    2122    /* convert average coordinates to ref entries */
    2223    ref = getImageRef (catalog, Ncatalog, i, &Nstars, MODE_SIMPLE);
     24    if (!ref) continue;
    2325
    2426    FitSimple (raw, ref, Nstars, &image[i].coords);
  • trunk/Ohana/src/relastro/src/args.c

    r24308 r27581  
    5050
    5151  if (FIT_TARGET == TARGET_NONE) usage();
     52
     53  UserCatalog = FALSE;
     54  if ((N = get_argument (argc, argv, "-catalog"))) {
     55    remove_argument (N, &argc, argv);
     56    UserCatalogRA = atof(argv[N]);
     57    remove_argument (N, &argc, argv);
     58    UserCatalogDEC = atof(argv[N]);
     59    remove_argument (N, &argc, argv);
     60    UserCatalog = TRUE;
     61  }
    5262
    5363  /* specify portion of the sky : allow default of all sky? */
     
    6777    remove_argument (N, &argc, argv);
    6878  } else {
    69     usage ();
     79    if (!UserCatalog) {
     80      usage ();
     81    }
    7082  }
    7183
     
    111123  }
    112124
    113   VERBOSE = FALSE;
     125  VERBOSE = VERBOSE2 = FALSE;
    114126  if ((N = get_argument (argc, argv, "-v"))) {
    115127    VERBOSE = TRUE;
     128    remove_argument (N, &argc, argv);
     129  }
     130  if ((N = get_argument (argc, argv, "-vv"))) {
     131    VERBOSE = VERBOSE2 = TRUE;
    116132    remove_argument (N, &argc, argv);
    117133  }
     
    242258  }
    243259
     260  NLOOP = 4;
     261  if ((N = get_argument (argc, argv, "-nloop"))) {
     262    remove_argument (N, &argc, argv);
     263    NLOOP = atof (argv[N]);
     264    remove_argument (N, &argc, argv);
     265  }
     266
    244267  if (argc != 1) usage ();
    245268  return TRUE;
     
    248271void usage () {
    249272  fprintf (stderr, "ERROR: USAGE: relastro -region RA RA DEC DEC\n");
     273  fprintf (stderr, "       OR:    relastro -catalog (ra) (dec)\n");
    250274  fprintf (stderr, "  working options: \n");
    251275  fprintf (stderr, "  -update-objects\n");
     
    263287  fprintf (stderr, "  -statmode (mode)\n");
    264288  fprintf (stderr, "  -reset");
     289  fprintf (stderr, "  -nloop (N) : number of image-fit iterations");
    265290  fprintf (stderr, "  -update : apply new fit to database\n");
    266291  fprintf (stderr, "  -params\n");
  • trunk/Ohana/src/relastro/src/fitpoly.c

    r17419 r27581  
    103103
    104104/* convert the xsum,ysum,sum terms into vector,matrix and solve */
    105 void fit_eval (CoordFit *fit) {
     105int fit_eval (CoordFit *fit) {
    106106
    107107  int i, j, ix, iy, jx, jy;
     
    146146    // ix, iy, vector[i][0], ix, iy, vector[i][1]);
    147147  }     
    148 
    149   dgaussjordan (matrix, vector, fit[0].Nelems, 2);
     148 
     149  if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) {
     150    return (FALSE);
     151  }
    150152
    151153  for (i = 0; i < fit[0].Nelems; i++) {
     
    166168  array_free (matrix, fit[0].Nelems);
    167169  array_free (vector, fit[0].Nelems);
     170  return (TRUE);
    168171}
    169172
     
    271274/* this should only apply to the polynomial, not the projection terms */
    272275/* compare with psastro supporting code */
    273 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords) {
     276int fit_apply_coords (CoordFit *fit, Coords *coords) {
    274277
    275278  double Xo, Yo, R1, R2;
     
    281284  // L = pc1_1*cd1*(x - cp1) + pc1_2*cd2*(y - cp2) + ...
    282285
    283   CoordsGetCenter (fit, 0.001, &Xo, &Yo);
     286  if (!CoordsGetCenter (fit, 0.001, &Xo, &Yo)) {
     287    fprintf (stderr, "failed to modify model\n");
     288    return (FALSE);
     289  }
    284290  coords[0].crpix1 = Xo;
    285291  coords[0].crpix2 = Yo;
     
    329335  /* keep the order and type from initial values */
    330336 
    331   // XXX if desired in the future, return modfit (and free above)
    332   return (NULL);
    333 }
    334 
     337  return (TRUE);
     338}
     339
  • trunk/Ohana/src/relastro/src/load_images.c

    r27435 r27581  
    2424 
    2525  // determine the populated SkyRegions overlapping the requested area
    26   skylist = SkyListByPatch (sky, -1, region);
     26  if (UserCatalog) {
     27    skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC);
     28  } else {
     29    skylist = SkyListByPatch (sky, -1, region);
     30  }
    2731  MARKTIME("  setup sky: %f sec\n", dtime);
    2832
  • trunk/Ohana/src/relastro/src/mkpolyterm.c

    r16810 r27581  
    7373    if (dPos > dPosRef) {
    7474      fprintf (stderr, "*** warning : non-convergence in model conversion (mkpolyterm.c;73) *** \n");
     75      return FALSE;
    7576    }
    7677    array_free (alpha, 2);
  • trunk/Ohana/src/relastro/src/relastro.c

    r27478 r27581  
    99int main (int argc, char **argv) {
    1010
    11   int status, Ncatalog;
     11  int i, status, Ncatalog;
    1212  Catalog *catalog;
    1313  FITS_DB db;
     
    4040  MARKTIME("load images: %f sec\n", dtime);
    4141
     42  initCoords();
     43
    4244  /* load catalog data from region files : subselect high-quality measurements */
    4345  catalog = load_catalogs (skylist, &Ncatalog, TRUE);
     
    4547
    4648  /* match measurements with images */
    47   initImageBins (catalog, Ncatalog);
     49  initImageBins (catalog, Ncatalog, TRUE);
    4850  MARKTIME("make image bins: %f sec\n", dtime);
    4951
    50   findImages (catalog, Ncatalog);
     52  findImages (catalog, Ncatalog, TRUE);
    5153  MARKTIME("set up image indexes: %f sec\n", dtime);
    5254
     
    5961  switch (FIT_TARGET) {
    6062    case TARGET_SIMPLE:
    61       UpdateSimple (catalog, Ncatalog);
     63      for (i = 0; i < NLOOP; i++) {
     64        UpdateObjects (catalog, Ncatalog);
     65        UpdateSimple (catalog, Ncatalog);
     66      }
    6267      break;
    6368
    6469    case TARGET_CHIPS:
    65       UpdateChips (catalog, Ncatalog);
     70      for (i = 0; i < NLOOP; i++) {
     71        UpdateObjects (catalog, Ncatalog);
     72        UpdateChips (catalog, Ncatalog);
     73        MARKTIME("update chips: %f sec\n", dtime);
     74      }
    6675      break;
    6776
    6877    case TARGET_MOSAICS:
    69       UpdateMosaic (catalog, Ncatalog);
     78      for (i = 0; i < NLOOP; i++) {
     79        UpdateObjects (catalog, Ncatalog);
     80        UpdateMosaic (catalog, Ncatalog);
     81      }
    7082      break;
    7183
     
    8395  UpdateObjectOffsets (skylist);
    8496
     97  // iterate over catalogs to make detection coordinates consistant
     98  FixProblemImages (skylist);
     99
    85100  // save the updated image parameters
    86101  dvo_image_update (&db, VERBOSE);
  • trunk/Ohana/src/relastro/src/relastro_objects.c

    r25757 r27581  
    1515 
    1616  // determine the populated SkyRegions overlapping the requested area (default depth)
    17   skylist = SkyListByPatch (sky, -1, &UserPatch);
     17  if (UserCatalog) {
     18    skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC);
     19  } else {
     20    skylist = SkyListByPatch (sky, -1, &UserPatch);
     21  }
    1822
    1923  // load data from each region file, only use bright stars
Note: See TracChangeset for help on using the changeset viewer.