IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38486


Ignore:
Timestamp:
Jun 17, 2015, 5:33:20 AM (11 years ago)
Author:
eugene
Message:

loadgalphot runs and does not crash (but does not yet work)

Location:
branches/eam_branches/ipp-20150616/Ohana/src/addstar
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/loadgalphot.h

    r38483 r38486  
    4848void fit2d_free (Fit2D *fit);
    4949int fit2d (Fit2D *fit, float *xval, float *yval, float *zval, float *zfit, char *mask, int Npts);
     50int fit2d_reset (Fit2D *fit);
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_catalog.c

    r38483 r38486  
    77
    88  // now we have all of the loaded stars in this catalog
     9  dvo_catalog_init (&catalog, TRUE);
    910  catalog.filename = filename;
    1011  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_fit2d.c

    r38483 r38486  
    77
    88  Fit2D *fit;
    9   ALLOCATE (fit, Fit2D, 1);
     9  ALLOCATE_ZERO (fit, Fit2D, 1);
    1010
    1111  // allocate static arrays
     12  fit->order = order;
    1213  fit->nterm = order + 1;
    1314  fit->wterm = fit->nterm*(fit->nterm + 1)/2;
     
    1920  ALLOCATE (fit->c, double *, fit->wterm);
    2021  for (i = 0; i < fit->wterm; i++) {
    21     ALLOCATE (fit->c[i], double, fit->wterm);
    22     ALLOCATE (fit->b[i], double, 1);
     22    ALLOCATE_ZERO (fit->c[i], double, fit->wterm);
     23    ALLOCATE_ZERO (fit->b[i], double, 1);
    2324  }
    2425  for (i = 0; i < fit->mterm; i++) {
    25     ALLOCATE (fit->s[i], double, fit->mterm);
    26   }
     26    ALLOCATE_ZERO (fit->s[i], double, fit->mterm);
     27  }
     28  ALLOCATE_ZERO (fit->Cii, double, fit->wterm);
    2729  return fit;
     30}
     31
     32int fit2d_reset (Fit2D *fit) {
     33
     34  int i;
     35
     36  for (i = 0; i < fit->wterm; i++) {
     37    memset (fit->c[i], 0, fit->wterm*sizeof(double));
     38    memset (fit->b[i], 0, sizeof(double));
     39  }
     40  for (i = 0; i < fit->mterm; i++) {
     41    memset (fit->s[i], 0, fit->mterm*sizeof(double));
     42  }
     43  return TRUE;
    2844}
    2945
     
    4965int fit2d (Fit2D *fit, float *xval, float *yval, float *zval, float *zfit, char *mask, int Npts) {
    5066 
    51   int N, i, j, nx, ny, K, k, n, Npt;
     67  int N, i, j, nx, ny, K, k, n, Npt, status;
    5268
    5369  double mean, sigma, maxsigma;
     
    5975
    6076  for (N = 0; N < ClipNiter; N++) {
    61     /* init registers for current pass */
    62     for (i = 0; i < fit->wterm; i++) {
    63       memset (fit->c[i], 0, fit->wterm*sizeof(double));
    64       memset (fit->b[i], 0, sizeof(double));
    65     }
    66     for (i = 0; i < fit->mterm; i++) {
    67       memset (fit->s[i], 0, fit->mterm*sizeof(double));
    68     }
     77    fit2d_reset (fit);
    6978
    7079    // pointers which loop over datapoints
     
    120129
    121130    // invert the c,b matrix equation
    122     dgaussjordan (fit->c, fit->b, fit->wterm, 1);
     131    status = dgaussjordan (fit->c, fit->b, fit->wterm, 1);
     132    if (!status) return FALSE;
    123133
    124134    /* the b[][0] terms are in the following order:
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c

    r38483 r38486  
    9393  Fit2D *fit = fit2d_init (2);
    9494
     95  int Nbad = 0;
    9596  for (i = 0; i < Nrow; i++) {
    9697
     
    117118    // I need to find the minimum position (interpolated) in this 2D space
    118119
    119     FitChisqMinimum (fit, &stars[i].galphot, &GAL_CHISQ[Nsample*i], &GAL_FLUX[Nsample*i], &GAL_FLUX_ERR[Nsample*i], Nsample, FR_MAJOR_MIN[i], FR_MAJOR_MAX[i], FR_MAJOR_DEL[i], FR_MINOR_MIN[i], FR_MINOR_MAX[i], FR_MINOR_DEL[i]);
     120    if (!FitChisqMinimum (fit, &stars[i].galphot, &GAL_CHISQ[Nsample*i], &GAL_FLUX[Nsample*i], &GAL_FLUX_ERR[Nsample*i], Nsample, FR_MAJOR_MIN[i], FR_MAJOR_MAX[i], FR_MAJOR_DEL[i], FR_MINOR_MIN[i], FR_MINOR_MAX[i], FR_MINOR_DEL[i])) {
     121      Nbad ++;
     122    }
    120123  }
    121124
     
    129132  fit2d_free (fit);
    130133
     134  fprintf (stderr, "Nbad: %d of %d\n", Nbad, (int) Nrow);
     135
    131136  *nstars = Nrow;
    132137  return (stars);
     
    155160  // validate the square dimensions??
    156161
    157   int Nx = (MajorMax - MajorMin) / MajorDel;
    158   int Ny = (MinorMax - MinorMin) / MinorDel;
     162  int Nx = nearbyint((MajorMax - MajorMin) / MajorDel) + 1;
     163  int Ny = nearbyint((MinorMax - MinorMin) / MinorDel) + 1;
    159164  myAssert (Nx*Ny == Npts, "inconsistent grid");
    160165 
     
    193198    galphot->majorAxisErr = MajorDel;
    194199    galphot->minorAxisErr = MinorDel;
    195     return TRUE;
     200    return FALSE;
    196201  }
    197202
     
    217222
    218223  // fit the inner 9 points
    219   fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts);
     224  if (!fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts)) {
     225    // raise a flag?
     226    galphot->majorAxis = Xpt[iMin];
     227    galphot->minorAxis = Ypt[iMin];
     228    galphot->majorAxisErr = MajorDel;
     229    galphot->minorAxisErr = MinorDel;
     230    return FALSE;
     231  }
    220232
    221233  // exclude any extreme outliers
     
    230242 
    231243  // re-fit all except the most extreme set
    232   fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts);
     244  if (!fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts)) {
     245    // raise a flag?
     246    galphot->majorAxis = Xpt[iMin];
     247    galphot->minorAxis = Ypt[iMin];
     248    galphot->majorAxisErr = MajorDel;
     249    galphot->minorAxisErr = MinorDel;
     250    return FALSE;
     251  }
    233252
    234253  // get X,Y for the chisq min from the fit:
     
    269288  galphot->magErr = -2.5*log10(fluxErr[iMin]); // correct for exptime?
    270289  galphot->chisq  = chisqMin;
    271 
    272290 
    273291  return TRUE;
Note: See TracChangeset for help on using the changeset viewer.