IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)) { }
Note: See TracChangeset for help on using the changeset viewer.