Changeset 23924 for trunk/extsrc/gpcsw/gpcsrc/fits/burntool/psfstats.c
- Timestamp:
- Apr 18, 2009, 11:11:15 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/extsrc/gpcsw/gpcsrc/fits/burntool/psfstats.c
r23525 r23924 1 /* psfstats.c - calculate some statistics about a PSF*/1 /* dummy version of psfstats.c - disable use of the psf */ 2 2 #include <stdio.h> 3 3 #include <stdlib.h> … … 12 12 #include "psf/psf.h" 13 13 14 //#define PSFSTATS /* ignore psf stats so we can skip fortan */15 //#define TEST /* Dump all the PSF info? */16 17 static unsigned short int *psfbuf=NULL;18 static int npsfbuf=0;19 #define PHONYSKY 100020 21 14 /****************************************************************/ 22 15 /* psf_stats(): Tell us about this PSF star */ … … 24 17 double *fwhm, double *q) 25 18 { 26 27 #ifdef PSFSTATS 28 29 int i, j, r, r2, err, i0, j0; 30 double d, qxx, qxy, qyy, mx, my, sum; 31 PSF_PARAM psfout; /* Results of fit */ 32 PSF_EXTRA psfextra; /* Extra results from fit */ 33 double pi=4*atan(1.0); 34 35 if(nx*ny > npsfbuf) { 36 if(psfbuf != NULL) free(psfbuf); 37 psfbuf = (ushort *)calloc(nx*ny, sizeof(ushort)); 38 npsfbuf = nx*ny; 39 } 40 for(i=0; i<nx*ny; i++) { 41 j = ((int)data[i]) - bias + PHONYSKY; 42 if(j >= 0 && j < 65535) psfbuf[i] = j; 43 else psfbuf[i] = 0; 44 } 45 46 /* 2D PSF fit */ 47 err = psf(nx, ny, psfbuf, PSF_2DIM, NULL, &psfout, &psfextra); 48 49 #ifdef TEST 50 printf("err = %d\n", err); 51 #endif 52 53 if(!err) { 54 #ifdef TEST 55 printf("err = %d\n", err); 56 printf("bias = %d\n", bias); 57 printf("ix, iy = %d %d\n", psfout.ix, psfout.iy); 58 printf("x0, y0 = %.2f %.2f\n", psfout.x0, psfout.y0); 59 printf("fwhm = %.2f\n", psfout.fwhm); 60 printf("peak, bckgnd = %.1f %.1f\n", psfout.peak, psfout.bkgnd); 61 printf("flux, S/N = %.1f %.2f\n", psfout.flux, psfout.sn); 62 printf("weight = %.2f\n", psfout.weight); 63 printf("FWmaj, FWmin = %.2f %.2f\n", psfextra.majfw, psfextra.minfw); 64 printf("theta = %.1f\n", psfextra.thfw*180/pi); 65 printf("wpeak, wbkgnd = %.1f %.1f\n", psfextra.wpeak, psfextra.wbkgnd); 66 printf("dflux, dbckgnd = %.1f %.1f\n", psfextra.dflux, psfextra.dbkgnd); 67 printf("rmsbkgnd = %.1f\n", psfextra.rmsbkgnd); 68 #endif 69 fwhm[0] = psfextra.majfw; 70 fwhm[1] = psfextra.minfw; 71 fwhm[2] = psfextra.thfw; 72 73 /* Moments */ 74 i0 = MIN(psfout.ix, nx-psfout.ix); 75 j0 = MIN(psfout.iy, ny-psfout.iy); 76 } else { 77 fwhm[0] = fwhm[1] = fwhm[2] = 0.0; 78 i0 = nx/2; 79 j0 = ny/2; 80 } 81 82 r = MIN(i0, j0) - 1; 83 sum = mx = my = qxx = qxy = qyy = 0.0; 84 for(j=j0-r; j<j0+r; j++) { 85 for(i=i0-r; i<i0+r; i++) { 86 r2 = (i-i0)*(i-i0) + (j-j0)*(j-j0); 87 if(r2 > r*r) continue; 88 d = (double)data[i+j*nx] - bias; 89 sum += d; 90 mx += (i+0.5) * d; 91 my += (j+0.5) * d; 92 qxx += (i+0.5) * (i+0.5) * d; 93 qxy += (i+0.5) * (j+0.5) * d; 94 qyy += (j+0.5) * (j+0.5) * d; 95 } 96 } 97 if(sum > 0) { 98 mx /= sum; 99 my /= sum; 100 qxx = qxx / sum - mx*mx; 101 qxy = qxy / sum - mx*my; 102 qyy = qyy / sum - my*my; 103 } else { 104 q[0] = q[1] = q[2] = 0.0; 105 } 106 107 q[0] = (qxx + qyy) / 2; 108 q[1] = qxx - qyy; 109 q[2] = 2 * qxy; 110 111 /* phi is the angular position of the OTA around the center [rad] */ 112 // qtang = (qxx - qyy) * cos(2*phi) + 2 * qxy * sin(2*phi); 113 114 #ifdef TEST 115 printf("Sum= %.1f mx= %.2f my= %.2f qxx= %.4f qxy= %.4f qyy= %.4f\n", 116 sum, mx, my, qxx, qxy, qyy); 117 #endif 118 119 # else 120 printf("psfstats ignored in this build\n"); 121 return (1); 122 #endif /* PSFSTATS */ 123 return(0); 19 return(1); 124 20 }
Note:
See TracChangeset
for help on using the changeset viewer.
