IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 27, 2004, 7:43:08 AM (22 years ago)
Author:
eugene
Message:

added rawstars, get_rough_star

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.data/starfuncs.c

    r2826 r2827  
    9292}
    9393
     94/* use a circular aperture */
     95int get_rough_star (float *data, int Nx, int Ny, int x, int y,
     96                       float *xc, float *yc,
     97                       float *sx, float *sy,
     98                       float *zs, float *zp) {
     99
     100  double *sky;
     101  double Raper, Rinner, Router, Ra2, Ri2, Ro2, rad2;
     102  int i, j, Npts, Nsky;
     103  int Xs, Xe, Ys, Ye, off, Xc, Yc;
     104  double peak, fsky, value;
     105  double Sx, Sy, Sx2, Sy2, Sum;
     106 
     107  /* define circular boundaries */
     108  Raper  = 15;  Ra2 = SQ(Raper);
     109  Rinner = 25;  Ri2 = SQ(Rinner);
     110  Router = 35;  Ro2 = SQ(Router);
     111
     112  /* measure the sky level */
     113  ALLOCATE (sky, double, SQ(2*Router + 1));
     114
     115  /* boundaries for the outer sky region */
     116  Xs = MAX (x - Router, 0);
     117  Xe = MIN (x + Router + 1, Nx);
     118  Ys = MAX (y - Router, 0);
     119  Ye = MIN (y + Router + 1, Ny);
     120
     121  Nsky = 0; 
     122  for (j = Ys; j < Ye; j++) {
     123    off = j*Nx;
     124    for (i = Xs; i < Xe; i++) {
     125      rad2 = SQ(i - x) + SQ(j - y);
     126      if (rad2 > Ro2) continue;
     127      if (rad2 < Ri2) continue;
     128      sky[Nsky] = data[i+off];
     129      Nsky ++;
     130    }
     131  }
     132  sort (sky, Nsky);
     133  for (Npts = fsky = 0, i = 0.25*Nsky; i < 0.75*Nsky; i++, Npts += 1.0) {
     134    fsky += sky[i];
     135  }
     136  fsky = fsky / Npts;
     137  free (sky);
     138
     139  /* boundaries for the star region */
     140  Xs = MAX (x - Raper, 0);
     141  Xe = MIN (x + Raper + 1, Nx);
     142  Ys = MAX (y - Raper, 0);
     143  Ye = MIN (y + Raper + 1, Ny);
     144
     145  /** note that this will fail on negative flux objects */
     146  peak = Npts = 0;
     147  Sx = Sy = Sx2 = Sy2 = Sum = 0;
     148  for (j = Ys; j < Ye; j++) {
     149    off = j*Nx;
     150    Yc = j - y;
     151    for (i = Xs; i < Xe; i++) {
     152      Xc = i - x;
     153      rad2 = SQ(Xc) + SQ(Yc);
     154      if (rad2 > Ro2) continue;
     155      value = data[i+off] - fsky;
     156      Sx  += Xc*value;
     157      Sy  += Yc*value;
     158      Sx2 += Xc*Xc*value;
     159      Sy2 += Yc*Yc*value;
     160      Sum += value;
     161      Npts ++;
     162      if (value > peak) peak = value;
     163    }
     164  }
     165
     166  *xc = Sx / Sum;
     167  *yc = Sy / Sum;
     168  *sx = sqrt (fabs (Sx2 / Sum - SQ(*xc)));
     169  *sy = sqrt (fabs (Sy2 / Sum - SQ(*yc)));
     170  *xc += x;
     171  *yc += y;
     172  *zs = Sum;
     173  *zp = peak;
     174  /* note sigma is rough: round-off errors can introduce errors */
     175  /* using values relative to x,y should minimize this effect */
     176
     177  return (Npts);
     178}
     179
Note: See TracChangeset for help on using the changeset viewer.