IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24391


Ignore:
Timestamp:
Jun 12, 2009, 3:53:07 PM (17 years ago)
Author:
eugene
Message:

updates to burntool-and-related from camera svn

Location:
trunk/extsrc/gpcsw/gpcsrc
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/extsrc/gpcsw/gpcsrc/analysis/libpscoords/pscoords.c

    r23490 r24391  
    2424rcsid[] = "$Id: pscoords.c,v 1.2 2008/09/06 03:26:48 jt Exp jt $";
    2525
     26#define MRAD2 (0.001)   /* Convert from mrad to rad, used for PSC_OFFROT_T */
     27
    2628/* Overall focal plane offset and rotation (um, rad) */
    27 const PSC_OFFROT_T psc_psc_fpoff={0.,0.,0.};
     29PSC_OFFROT_T psc_psc_fpoff={0.,0.,0.};
    2830
    2931/* Offsets and rotations of each OTA (um, millirad) */
    30 const PSC_OFFROT_T psc_otaoff[PSC_NX*PSC_NY]={  /* Offsets and rotations derived o4885 090228 */
     32PSC_OFFROT_T psc_otaoff[PSC_NX*PSC_NY]={        /* Offsets and rotations derived o4885 090516 */
     33   {   0.0,   0.0,  0.00}, {  -6.8, -32.4, -1.30},  /* OTA00 , OTA10 */
     34   {  15.7,-130.7,  0.07}, {  -9.4, -43.5, -1.34},  /* OTA20 , OTA30 */
     35   {  17.8,  71.7, -0.48}, {   7.2,  41.3, -0.82},  /* OTA40 , OTA50 */
     36   {  22.1, -48.3, -1.74}, {   0.0,   0.0,  0.00},  /* OTA60 , OTA70 */
     37   { -23.0, -12.9,  0.68}, { -52.0, -52.2,  0.88},  /* OTA01 , OTA11 */
     38   {  28.8, -10.9, -0.73}, { -22.9,  18.1, -0.89},  /* OTA21 , OTA31 */
     39   { -13.8,  45.9,  0.90}, { -12.2,  49.7, -0.32},  /* OTA41 , OTA51 */
     40   { -31.9,  -9.8, -1.60}, {   1.9,   8.0,  0.53},  /* OTA61 , OTA71 */
     41   { -27.2,  42.6,  2.73}, {   6.5, -52.6,  0.48},  /* OTA02 , OTA12 */
     42   {  10.1, -37.9, -1.53}, {   3.1,-139.0,  1.75},  /* OTA22 , OTA32 */
     43   { -21.4,  25.6, -1.12}, { -13.8,   0.9,  0.02},  /* OTA42 , OTA52 */
     44   {  -1.8, -16.1, -2.06}, {  76.0,  31.7,  1.70},  /* OTA62 , OTA72 */
     45   { -15.7,  24.1,  0.14}, {-104.2, -76.8,  1.97},  /* OTA03 , OTA13 */
     46   {  75.4,  31.8,  1.04}, { -18.7,  14.6,  0.51},  /* OTA23 , OTA33 */
     47   { -30.6,  53.4, -0.78}, {  12.6,  24.4,  0.43},  /* OTA43 , OTA53 */
     48   {   8.0, -34.9,  1.44}, {   6.4, -73.2, -0.93},  /* OTA63 , OTA73 */
     49   { -31.2,  11.2,  0.23}, { -10.3,  -2.1,  0.14},  /* OTA04 , OTA14 */
     50   {  33.2, 207.9, -0.40}, { -75.7,-105.9,  0.93},  /* OTA24 , OTA34 */
     51   {   8.1, -15.9, -0.03}, { -16.1, -13.3, -0.06},  /* OTA44 , OTA54 */
     52   {   4.1,  47.6,  1.26}, {  71.6,  -6.0,  0.42},  /* OTA64 , OTA74 */
     53   { -23.4,  46.7,  2.65}, {  31.1,   5.5, -0.64},  /* OTA05 , OTA15 */
     54   { -43.2,  -6.5,  1.68}, { -26.0, -53.2,  0.00},  /* OTA25 , OTA35 */
     55   { -43.0,   9.1, -0.69}, {  30.1,  69.7,  0.62},  /* OTA45 , OTA55 */
     56   { -48.5,  61.6, -0.51}, {  65.5, -30.1,  0.69},  /* OTA65 , OTA75 */
     57   {   2.5,  57.2,  0.17}, {   0.6,  25.4, -0.91},  /* OTA06 , OTA16 */
     58   { -70.8, -17.4,  1.36}, {  13.6, -24.2,  0.53},  /* OTA26 , OTA36 */
     59   {  -6.8,  28.1, -1.35}, {  20.9,  42.0,  0.19},  /* OTA46 , OTA56 */
     60   {   6.2,  13.2, -1.50}, {  36.5,  48.8, -0.36},  /* OTA66 , OTA76 */
     61   {   0.0,   0.0,  0.00}, {  20.4,   1.7,  0.09},  /* OTA07 , OTA17 */
     62   {  83.8,  11.8, -0.56}, { -26.5, -21.2,  0.56},  /* OTA27 , OTA37 */
     63   { -70.5,   7.2, -1.05}, { -41.2,  -3.6, -1.89},  /* OTA47 , OTA57 */
     64   { -35.0,  49.5, -0.40}, {   0.0,   0.0,  0.00}}; /* OTA67 , OTA77 */
     65
     66/* Offsets and rotations of each OTA (um, millirad) */
     67#ifdef RUN_THREE_V1
     68PSC_OFFROT_T psc_otaoff[PSC_NX*PSC_NY]={        /* Offsets and rotations derived o4885 090228 */
    3169   {   0.0,   0.0,  0.00}, {  20.2, -59.5, -1.23},  /* OTA00 , OTA10 */
    3270   {  28.1,-138.1,  0.18}, {   2.0, -43.6, -1.22},  /* OTA20 , OTA30 */
     
    6199   { -74.8,   0.3, -0.92}, { -44.6,  -1.6, -1.78},  /* OTA47 , OTA57 */
    62100   { -50.3,  72.1, -0.47}, {   0.0,   0.0,  0.00}}; /* OTA67 , OTA77 */
     101#endif
    63102
    64103#ifdef RUN_TWO
     
    136175#endif
    137176
    138 static int DOOFFSET;    /* Do these offsets or no? */
     177static int DOOFFSET=1;  /* Do these offsets or no? */
    139178
    140179#if 0
     
    143182#endif
    144183
    145 /* Enable application of chip offsets? */
     184/* Enable application of chip offsets (um, mrad)? */
     185int psc_load_otaoff(const char *fname)
     186{
     187   int i;
     188   char rbuf[1024];
     189   FILE *fp;
     190   if( (fp=fopen(fname, "r")) == NULL) {
     191      fprintf(stderr, "error: Error opening OTA offset file '%s'\n", fname);
     192      return(-1);
     193   }
     194   for(i=0; i<PSC_NX*PSC_NY; i++) {
     195      if(fgets(rbuf, 1024, fp) == NULL ||
     196         sscanf(rbuf, "%lf %lf %lf", &psc_otaoff[i].dx,
     197                &psc_otaoff[i].dy, &psc_otaoff[i].rot) != 3) {
     198         fprintf(stderr, "error: Error reading OTA offset file '%s' line %d\n",
     199                 fname, i);
     200         fclose(fp);
     201         return(-1);
     202      }
     203   }
     204   fclose(fp);
     205   return(0);
     206}
     207
     208/* Load up a new offset table? */
    146209int psc_do_chipoff(int doit)
    147210{
     
    196259/* Position wrt OTA center after correction for offset and rotation */
    197260   if(DOOFFSET) {
    198       x =  (xp-psc_otaoff[idx].dx)*cos(psc_otaoff[idx].rot*0.001) +
    199          (yp-psc_otaoff[idx].dy)*sin(psc_otaoff[idx].rot*0.001);
    200       y = -(xp-psc_otaoff[idx].dx)*sin(psc_otaoff[idx].rot*0.001) +
    201          (yp-psc_otaoff[idx].dy)*cos(psc_otaoff[idx].rot*0.001);
     261      x =  (xp-psc_otaoff[idx].dx)*cos(psc_otaoff[idx].rot*MRAD2) +
     262         (yp-psc_otaoff[idx].dy)*sin(psc_otaoff[idx].rot*MRAD2);
     263      y = -(xp-psc_otaoff[idx].dx)*sin(psc_otaoff[idx].rot*MRAD2) +
     264         (yp-psc_otaoff[idx].dy)*cos(psc_otaoff[idx].rot*MRAD2);
    202265   } else {
    203266      x = xp;
     
    228291/* Position wrt nominal OTA center after its offset and rotation */
    229292   if(DOOFFSET) {
    230       xp = psc_otaoff[idx].dx + x*cos(psc_otaoff[idx].rot*0.001) - y*sin(psc_otaoff[idx].rot*0.001);
    231       yp = psc_otaoff[idx].dy + x*sin(psc_otaoff[idx].rot*0.001) + y*cos(psc_otaoff[idx].rot*0.001);
     293      xp = psc_otaoff[idx].dx + x*cos(psc_otaoff[idx].rot*MRAD2) - y*sin(psc_otaoff[idx].rot*MRAD2);
     294      yp = psc_otaoff[idx].dy + x*sin(psc_otaoff[idx].rot*MRAD2) + y*cos(psc_otaoff[idx].rot*MRAD2);
    232295   } else {
    233296      xp = x;
     
    292355
    293356/* Evaluate an optical model: arcsec -> microns notionally */
     357/* Offset, scale with quadratic and cubic distortion, rotate */
     358int psc_psoptics2(double x, double y, double dx, double dy, double dpa,
     359         double pscale, double d2, double d3, double *xfp, double *yfp)
     360{
     361   double w2=((x-dx)*(x-dx)+(y-dy)*(y-dy)), w;
     362   w = sqrt(w2);
     363   x = pscale * (1.0 + d2*w + d3*w2) * (x-dx);
     364   y = pscale * (1.0 + d2*w + d3*w2) * (y-dy);
     365/* Apply any extra TP-FP rotation */
     366   *xfp =  x * cos(dpa) + y * sin(dpa);
     367   *yfp = -x * sin(dpa) + y * cos(dpa);
     368   return(0);
     369}
     370
     371/* Evaluate an inverse optical model: microns -> arcsec notionally */
     372/* Offset, scale with *small* quadratic and cubic distortion, rotate */
     373int psc_invoptics2(double xfp, double yfp, double dx, double dy, double dpa,
     374          double pscale, double d2, double d3, double *x, double *y)
     375{
     376   double xp, yp, w;
     377/* Undo any extra TP-FP rotation */
     378   xp = (xfp * cos(dpa) - yfp * sin(dpa)) / pscale;
     379   yp = (xfp * sin(dpa) + yfp * cos(dpa)) / pscale;
     380   w = sqrt(xp*xp+yp*yp);
     381   *x = xp / (1.0 + d2*w + d3*(xp*xp+yp*yp)) + dx;
     382   *y = yp / (1.0 + d2*w + d3*(xp*xp+yp*yp)) + dy;
     383   return(0);
     384}
     385
     386
     387/* Evaluate an optical model: arcsec -> microns notionally */
    294388/* Offset, scale with distortion, rotate */
    295389int psc_psoptics(double x, double y, double dx, double dy, double dpa,
     
    318412   return(0);
    319413}
    320 
    321414
    322415/* Project RA,Dec (a,d) to the tangent plane (x,y) at (a0,d0,pa) [radians] */
  • trunk/extsrc/gpcsw/gpcsrc/analysis/libpscoords/pscoords.h

    r23924 r24391  
    22#define NINT(x) (x<0?(int)((x)-0.5):(int)((x)+0.5))
    33
     4#define OTA_CTE (5.0e-6)        /* Coefficient of thermal expansion of Si+Mo */
     5#define CFFP_CTE (0.5e-6)       /* Coefficient of thermal expansion of CFFP */
     6#define DELTA_T (-100.0)        /* Operating temp minus metrology temp */
     7
     8#define OTA_SCALE (1.0+OTA_CTE*DELTA_T) /* Room temp um to operating um of Si+Mo */
     9#define CFFP_SCALE ((1.0+CFFP_CTE*DELTA_T)*25400) /* Room temp inches to um on CFFP */
     10
    411/* Silicon layout of OTAs (um) */
    5 #define PSC_PIXEL     10.0      /* Pixel size of an OTA */
    6 #define PSC_HCELL   5900.0      /* Horizontal cell size */
    7 #define PSC_VCELL   5980.0      /* Vertical cell size */
    8 #define PSC_HSTREET  120.0      /* Horizontal street between cells (HS) */
    9 #define PSC_VSTREET  180.0      /* Vertical street between cells (VS) */
    10 #define PSC_LBORDER  442.0      /* Left border (to left-most cell) (LB) */
    11 #define PSC_RBORDER  418.0      /* Right border (to right-most vertical street) (RB) */
    12 #define PSC_TBORDER  354.5      /* Top border (to top-most cell) (TB) */
    13 #define PSC_BBORDER  975.5      /* Bottom border (to lowest horizontal street) (BB) */
    14 #define PSC_HDIE   49500.0      /* Horizontal size of silicon die */
    15 #define PSC_VDIE   50130.0      /* Vertical size of silicon die */
     12#define PSC_PIXEL     (10.0*OTA_SCALE)  /* Pixel size of an OTA */
     13#define PSC_HCELL   (5900.0*OTA_SCALE)  /* Horizontal cell size */
     14#define PSC_VCELL   (5980.0*OTA_SCALE)  /* Vertical cell size */
     15#define PSC_HSTREET  (120.0*OTA_SCALE)  /* Horizontal street between cells (HS) */
     16#define PSC_VSTREET  (180.0*OTA_SCALE)  /* Vertical street between cells (VS) */
     17#define PSC_LBORDER  (442.0*OTA_SCALE)  /* Left border (to left-most cell) (LB) */
     18#define PSC_RBORDER  (418.0*OTA_SCALE)  /* Right border (to right-most vertical street) (RB) */
     19#define PSC_TBORDER  (354.5*OTA_SCALE)  /* Top border (to top-most cell) (TB) */
     20#define PSC_BBORDER  (975.5*OTA_SCALE)  /* Bottom border (to lowest horizontal street) (BB) */
     21#define PSC_HDIE   (49500.0*OTA_SCALE)  /* Horizontal size of silicon die */
     22#define PSC_VDIE   (50130.0*OTA_SCALE)  /* Vertical size of silicon die */
    1623
    1724/* Mechanical layout of OTAs (um) */
    18 #define PSC_HMECH  (1.957*25400)        /* Horizontal mech spacing of OTA placement */
    19 #define PSC_VMECH  (2.025*25400)        /* Vertical mech spacing of OTA placement */
    20 #define PSC_VMOFF (PSC_VDIE-(1.568+0.375)*25400) /* Vert die offset between sides */
     25#define PSC_HMECH  (1.957*CFFP_SCALE)   /* Horizontal mech spacing of OTA placement */
     26#define PSC_VMECH  (2.025*CFFP_SCALE)   /* Vertical mech spacing of OTA placement */
     27#define PSC_VMOFF (PSC_VDIE-(1.568+0.375)*CFFP_SCALE) /* Vert die offset between sides */
    2128
    2229#define PSC_REFRACT_CONST 60.0  /* Standard refraction ("/tanz) at STP */
     
    123130
    124131/* Overall focal plane offset and rotation (um, rad) */
    125 const PSC_OFFROT_T psc_fpoff;
     132PSC_OFFROT_T psc_fpoff;
    126133
    127134/* Offsets and rotations of each OTA (um, millirad) */
    128 const PSC_OFFROT_T psc_otaoff[PSC_NX*PSC_NY];
    129 
     135PSC_OFFROT_T psc_otaoff[PSC_NX*PSC_NY];
     136
     137
     138/* This is from Run 3, 090516 */
     139#define PS_scale 38.7932        /* Default PS plate scale [um/arcsec] */
     140#define PS_d2  9.78e-7  /* Default quadratic PS distortion [arcsec^-1] */
     141#define PS_d3  3.16e-11 /* Default cubic PS distortion [arcsec^-2] */
     142
     143
     144#ifdef RUN_THREE_V1     /* This is from Run 3, 090228 */
    130145#define PS_scale 38.860 /* Default PS plate scale [um/arcsec] */
    131 #define PS_d3  1.49e-10 /* Default PS distortion [arcsec^-2] */
     146#define PS_d3  1.49e-10 /* Default cubic PS distortion [arcsec^-2] */
     147#endif
     148
     149
    132150#define PS_airdens 0.71 /* Default PS1 qir density (Haleakala) */
    133151
     
    139157 * ---------------------------------------------------------------------------
    140158 *   psc_tproject(a, d, a0, d0, pa, density, pi/2-alt, vertical, &x, &y);
    141  *   psc_psoptics(x/sec2rad, y/sec2rad, dx, dy, dpa, pscale, d3, &xfp, &yfp);
     159 *   psc_psoptics2(x/sec2rad, y/sec2rad, dx, dy, dpa, pscale, d2, d3, &xfp, &yfp);
    142160 *   psc_fp_to_pixel(xfp, yfp, &ota_xid, &ota_yid, &xota, &yota);
    143161 *   psc_pixel_to_cell(xota, yota, &cell_xid, &cell_yid, &xcell, &ycell);
     162 *
     163 *  can also use
     164 *   psc_psoptics(x/sec2rad, y/sec2rad, dx, dy, dpa, pscale, d3, &xfp, &yfp);
     165 *
    144166 *
    145167 * To go from cell coords to a position (a,d) relative to (a0,d0,pa) pointing:
     
    147169 *   psc_cell_to_pixel(cell_xid,cell_yid, xcell,ycell, &xota,&yota);
    148170 *   psc_pixel_to_fp(ota_xid, ota_yid, xota, yota, &xfp, &yfp);
     171 *   psc_invoptics2(xfp, yfp, dx, dy, dpa, pscale, d2, d3, &x, &y);
     172 *   psc_tplonglat(x*sec2rad, y*sec2rad, a0, d0, pa, density,  pi/2-alt, vertical, &a, &d);
     173 *
     174 *  can also use
    149175 *   psc_invoptics(xfp, yfp, dx, dy, dpa, pscale, d3, &x, &y);
    150  *   psc_tplonglat(x*sec2rad, y*sec2rad, a0, d0, pa, density,  pi/2-alt, vertical, &a, &d);
    151176 */
    152177
     
    155180/**************/
    156181/* Enable application of chip offsets? */
    157 int psc_do_chipoff(int doit);   /* Apply chip offsets? (0/1, default=0) */
     182int psc_do_chipoff(int doit);   /* Apply chip offsets? (0/1, default=1) */
    158183
    159184/* Convert a focal plane position to OTA otax,otay, Cell cellx,celly, Pixel */
     
    202227                 double pscale/*38.86um/sec*/, double d3/*1.49e-10sec^-2*/,
    203228                 double *xfp_um, double *yfp_um);
     229
     230/* Evaluate an inverse optical model: microns -> arcsec notionally */
     231/* Offset, scale with *small* distortion, rotate */
     232int psc_invoptics2(double xfp_um, double yfp_um, double dx_sec, double dy_sec, double dpa_rad,
     233                   double pscale/*38.793um/sec*/,
     234                   double d2/*9.8e-7sec^-2*/, double d3/*3.1e-11sec^-2*/,
     235                   double *x_sec, double *y_sec);
     236
     237/* Evaluate an optical model: arcsec -> microns notionally */
     238/* Offset, scale with distortion, rotate */
     239int psc_psoptics2(double x_sec, double y_sec, double dx_sec, double dy_sec, double dpa_rad,
     240                  double pscale/*38.793um/sec*/,
     241                  double d2/*9.8e-7sec^-2*/, double d3/*3.1e-11sec^-2*/,
     242                  double *xfp_um, double *yfp_um);
     243
     244/* Enable application of chip offsets (um, mrad)? */
     245int psc_load_otaoff(const char *fname);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/Makefile

    r24302 r24391  
    3232  pscoords/pscoords.h
    3333
    34 $(OBJ)/psfstats.o: psfstats.c burntool.h
     34$(OBJ)/psfstats.o: psfstats.c burntool.h psf/psf.h
    3535
    3636$(OBJ)/sort.o: sort.c
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnfix.c

    r23490 r24391  
    105105      if(!cell->persist[k].fiterr)
    106106         sub_fit(nx, ny, NX, buf, &(cell->persist[k]), -1);
     107   }
     108   return(0);
     109}
     110
     111
     112/****************************************************************/
     113/* burn_apply(): Subtract the trail fits from the image */
     114STATIC int burn_apply(int nx, int ny, int NX, IMTYPE *buf, CELL *cell)
     115{
     116   int k;
     117
     118/* Restore all the burns */
     119   for(k=0; k<cell->npersist; k++) {
     120      if(!cell->persist[k].fiterr)
     121         sub_fit(nx, ny, NX, buf, &(cell->persist[k]), +1);
    107122   }
    108123   return(0);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c

    r23924 r24391  
    3333   int otanum;
    3434   int nextend, cellxy, cell, cellcode;
    35    int ext, update, restore, psfsize, psfavg;
     35   int ext, update, restore, apply, tableonly, psfsize, psfavg;
    3636   IMTYPE *buf;
    3737   const char *burnfile=NULL,  *persistfile=NULL, *persistfitsfile=NULL;
     
    102102/* Parse the args */
    103103   cellxy = -1;
    104    update = 1;
    105    restore = 0;
     104   update = 1;          /* Calc fits, apply fits, write img and table */
     105   restore = 0;         /* Restore previous fit only, write img */
     106   apply = 0;           /* Apply previous fit only, write img */
     107   tableonly = 0;       /* Calc fits (apply fits), write table only */
    106108   psfsize = 32;
    107109   psfavg = 0;
     
    137139         update = argv[i][7] == 'y' || argv[i][7] == '1' || argv[i][7] == 't';
    138140
    139 /* Modify the input MEF by subtracting fits? */
     141/* Modify the input MEF by adding back fits? */
    140142      } else if(strncmp(argv[i], "restore=", 8) == 0) { /* restore={t|f} */
    141143         restore = argv[i][8] == 'y' || argv[i][8] == '1' || argv[i][8] == 't';
     144
     145/* Modify the input MEF by subtracting previously calculated fits? */
     146      } else if(strncmp(argv[i], "apply=", 6) == 0) {   /* apply={t|f} */
     147         apply = argv[i][6] == 'y' || argv[i][6] == '1' || argv[i][6] == 't';
     148
     149/* Calculate and write tables only? */
     150      } else if(strncmp(argv[i], "tableonly=", 10) == 0) {/* tableonly={t|f} */
     151         tableonly = argv[i][10] == 'y' || argv[i][10] == '1' || argv[i][10] == 't';
    142152
    143153/* Output file for burn streaks */
     
    150160
    151161/* Input text file for previous burn persistence streaks */
    152       } else if(strncmp(argv[i], "infits=", 8) == 0) {  /* in=fname */
     162      } else if(strncmp(argv[i], "trailin=", 8) == 0) {/* trailin=fname */
    153163         persistfile = argv[i] + 8;
    154164
    155165/* Same thing, but information is stored in tables in a FITS file. */
    156       } else if(strncmp(argv[i], "trailinfits=", 8) == 0) { /* infits=fname */
     166      } else if(strncmp(argv[i], "trailinfits=", 12) == 0) { /* trailinfits=fname */
    157167         persistfitsfile = argv[i] + 12;
    158168
     
    162172
    163173/* Same thing, but information is stored in tables in a FITS file. */
    164       } else if(strncmp(argv[i], "trailinfits=", 8) == 0) { /* trailin=fname */
    165          persistfitsfile = argv[i] + 12;
     174      } else if(strncmp(argv[i], "infits=", 7) == 0) { /* infits=fname */
     175         persistfitsfile = argv[i] + 7;
    166176
    167177/* Output file for PSF gallery */
     
    322332   /* If there is no other persistence info supplied, try getting
    323333    * it from the input FITS file. */
    324    if(restore && persistfile == NULL) {
    325      if(persistfitsfile == NULL) persistfitsfile = ifilename;
     334   if((restore || apply) && persistfile == NULL) {
     335      if(persistfitsfile == NULL) persistfitsfile = ifilename;
    326336   }
    327337
     
    334344
    335345/* Read the persistence data for this OTA */
    336    if(persistfile != NULL) {
     346   if(persistfile != NULL) {                    /* Text data file */
    337347      if(persist_read(OTA, persistfile)) exit(EXIT_FAILURE);
    338    }
    339    else if(persistfitsfile != NULL) {
    340      if(persist_fits_read(OTA, persistfitsfile) != FH_SUCCESS) exit(EXIT_FAILURE);
     348   } else if(persistfitsfile != NULL) {         /* FITS table */
     349      if(persist_fits_read(OTA, persistfitsfile) != FH_SUCCESS)
     350        exit(EXIT_FAILURE);
    341351   }
    342352
     
    369379               "warning: Restoring old burns, but header indicates no burns previously corrected.\n");             
    370380     }
    371      else if (update && (burn_applied == FH_TRUE)) {
     381     else if ((update||apply) && (burn_applied == FH_TRUE)) {
    372382       fprintf(stderr,
    373383               "warning: Applying burn correction, but header indicates burns previously corrected.\n");             
     
    491501
    492502      if(VERBOSE & VERB_NORM) {
    493          printf("nx=%d ny=%d prex=%d postx=%d posty=%d BZERO=%.1f\n",
     503         printf("nx=%d ny=%d prex=%d postx=%d posty=%d BZERO=%d\n",
    494504                naxis1, naxis2, prescan1, ovrscan1, ovrscan2, BZERO);
    495505      }
     
    542552         }
    543553
    544 
    545          if(!restore) {
    546 
     554         if(apply) {
     555/* Use the table-driven fits instead of calculating new ones */
     556            burn_apply(naxis1-ovrscan1, naxis2-ovrscan2, naxis1,
     557                       buf, OTA+cell);
     558/* Tell us about it? */
     559            if(VERBOSE & VERB_NORM) burn_blab(OTA+cell);
     560
     561         } else if(restore) {
     562/* Restore the old burns */
     563            burn_restore(naxis1-ovrscan1, naxis2-ovrscan2, naxis1,
     564                         buf, OTA+cell);
     565
     566         } else {
    547567/* Fix up the burns */
    548568            burn_fix(naxis1-ovrscan1, naxis2-ovrscan2, naxis1, naxis2, buf,
     
    559579            if(VERBOSE & VERB_NORM) burn_blab(OTA+cell);
    560580
    561 /* Fix up the streaks */
    562             persist_fix(naxis1-ovrscan1, naxis2-ovrscan2, naxis1, buf,
    563                         OTA+cell);
    564 
     581/* Fix up the streaks (don't bother if table only) */
     582            if(!tableonly) {
     583               persist_fix(naxis1-ovrscan1, naxis2-ovrscan2, naxis1, buf,
     584                           OTA+cell);
    565585/* Tell us about it? */
    566             if(VERBOSE & VERB_NORM) persist_blab(OTA+cell);
    567 
    568          } else {
    569 /* Restore the old burns */
    570             burn_restore(naxis1-ovrscan1, naxis2-ovrscan2, naxis1,
    571                          buf, OTA+cell);
     586               if(VERBOSE & VERB_NORM) persist_blab(OTA+cell);
     587            }
    572588         }
    573589
    574590/* Write the corrected data back to the FITS. */
    575          if(update) {
     591         if(!tableonly && update) {
    576592            fh_ehu(ehu, 0);     /* Seek back to the start of data */
    577593            if (fh_write_padded_image(ehu, fh_file_desc(ehu), buf,
     
    590606
    591607/* Dump out the postage stamp file */
    592    if(psffile != NULL) {
     608   if(psffile != NULL && !restore && !apply) {
    593609      psf_write(psfsize, psfsize, OTA, otanum, psffile);
    594610   }
    595611
    596612/* Dump out the PSF stats */
    597    if(psfstatfile != NULL) {
     613   if(psfstatfile != NULL && !restore && !apply) {
    598614      psf_write_stats(psfsize, psfsize, OTA, otanum, psfstatfile, psfavg);
    599615   }
     
    601617/* Write burn info to FITS file. */
    602618   if(update) persist_fits_write(OTA, ihu);
    603 
    604619   
    605    if(restore) {   
     620   if(restore || tableonly) {   
    606621     /* Indicate in the header that the burns are not applied. */
    607      fh_set_bool(ihu, FH_AUTO, PHU_NAME_BURN_APPLIED,
    608                  FH_FALSE, PHU_COMMENT_BURN_APPLIED);
    609      fh_rewrite(ihu);
     622      fh_set_bool(ihu, FH_AUTO, PHU_NAME_BURN_APPLIED,
     623                  FH_FALSE, PHU_COMMENT_BURN_APPLIED);
     624      fh_rewrite(ihu);
     625   } else if(apply) {
     626     /* Indicate in the header that the burns have been applied. */
     627      fh_set_bool(ihu, FH_AUTO, PHU_NAME_BURN_APPLIED,
     628                  FH_TRUE, PHU_COMMENT_BURN_APPLIED);
     629      fh_rewrite(ihu);
    610630   }
    611631
     
    711731   printf(" cell=N         Work on just one cell? Cell count [0:63] mode.\n");
    712732   printf(" mask=0101...   64 digits to work on cells 0:63.\n");
    713    printf(" update={t|f}   Modify the input MEF by subtracting fits?\n");
     733   printf(" update={t|f}   Modify the input MEF writing table and subtracting fits?\n");
    714734   printf(" restore={t|f}  Restore the input MEF by adding input fits?\n");
     735   printf(" apply={t|f}    Modify the input MEF by subtracting previously calculated fits?\n");
     736   printf(" tableonly={t|f} Calculate fits but do *not* modify the input MEF images, only write tables\n");
    715737   printf(" in=fname       Input file for previous burn persistence streaks\n");
    716738   printf(" infits=fname   Input FITS file for previous burn persistence streaks (stored\n");
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.h

    r23924 r24391  
    173173                     MTYPE *mask, OBJBOX *box);
    174174STATIC int burn_restore(int nx, int ny, int NX, IMTYPE *buf, CELL *cell);
     175STATIC int burn_apply(int nx, int ny, int NX, IMTYPE *buf, CELL *cell);
    175176STATIC int persist_read(CELL *cell, const char *infile);
    176177STATIC int persist_write(CELL *cell, const char *outfile);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1

    r23924 r24391  
    6666        inhibited from subtracting the fits by "update=f".
    6767       
     68        Two other modes can be invoked using "tableonly=t" and "apply=t".
     69        The first mode is just like "update=t", except that it does not write
     70        the modified images, only the FITS table and/or tabulated fit data.
     71        The second mode is like "restore=t", except that it subtracts the
     72        tabulated fits instead of adding them back in.  Note that this requires
     73        slightly different specifications for the "in=" file:
     74
     75                update or tableonly:    in=previous_file_for_persistence
     76                restore or apply:       in=this_file_for_burn_and_persistence
     77
     78        Thus a sequence of images could be processed (leaving off usual
     79        arguments such as mask=, etc) to immediately fit and subtract:
     80
     81           burntool o4991g0001o24.fits \
     82                                   out=o4991g0001o24.burn \
     83             psfstat=o4991g0001o24.stat psf=o4991g0001o24.psf
     84
     85           burntool o4991g0002o24.fits \
     86             in=o4991g0001o24.burn out=o4991g0002o24.burn \
     87             psfstat=o4991g0002o24.stat psf=o4991g0002o24.psf
     88
     89           burntool o4991g0003o24.fits \
     90             in=o4991g0002o24.burn out=o4991g0003o24.burn \
     91             psfstat=o4991g0003o24.stat psf=o4991g0003o24.psf
     92
     93        or as a two step process of generating tables:
     94
     95           burntool o4991g0001o24.fits tableonly=t \
     96                                   out=o4991g0001o24.burn \
     97             psfstat=o4991g0001o24.stat psf=o4991g0001o24.psf
     98
     99           burntool o4991g0002o24.fits tableonly=t \
     100             in=o4991g0001o24.burn out=o4991g0002o24.burn \
     101             psfstat=o4991g0002o24.stat psf=o4991g0002o24.psf
     102
     103           burntool o4991g0003o24.fits tableonly=t \
     104             in=o4991g0002o24.burn out=o4991g0003o24.burn \
     105             psfstat=o4991g0003o24.stat psf=o4991g0003o24.psf
     106
     107        and then later on carrying out the subtractions of the fits:
     108
     109           burntool o4991g0001o24.fits apply=t
     110           burntool o4991g0002o24.fits apply=t
     111           burntool o4991g0003o24.fits apply=t
     112
    68113        The identification of significant (but unsaturated) stars is an
    69114        important component of burntool's mask generation, and if requested
    70115        burntool can assemble a gallery of postage stamps of suitable stars.
     116        This does not work with "restore=t" or "apply=t" of course, since
     117        these work only on previous tables and do not examine the images.
    71118       
    72119        Any star whose maximum exceeds PSF_THRESH above sky but is not deemed
     
    125172           qt=-5.201       Tangential quadrupole [pix^2] (-99.99 if fails)
    126173                                q+ * cos(2*phi) + qx * sin(2*phi)
     174           q3c=-1.193      Cosine trefoil measure [pix^2] (-99.99 if fails)
     175           q3s=-0.038      Sine trefoil measure [pix^2] (-99.99 if fails)
    127176           qpm=5.154       Plus quadrupole averaged over psfavg
    128177           qcm=0.560       Cross quadrupole averaged over psfavg
    129178           qtm=-5.201      Tangential averaged over psfavg
     179           q3cm=-1.230     Cosine trefoil averaged over psfavg
     180           q3sm=-0.079     Sine trefoil averaged over psfavg
     181
     182        The net, polar coordinate quadrupole can be assembled from
     183
     184           Qmagnitude = sqrt(qpm^2+qcm^2)
     185           Qtheta     = 0.5 * atan2(qcm, qpm)
    130186
    131187        Helpful utilities include:
     
    151207
    152208        update={t|f}   
    153                 Modify the input MEF by subtracting fits (default t)?
     209                Calculate fits and modify the input MEF images by subtracting
     210                the trail fits and writing a FITS table (default t).  If
     211                false the MEF is not altered, although PSF can be calculated.
    154212
    155213        restore={t|f} 
    156                 Restore the input MEF by adding input fits (default f)?
     214                Restore the input MEF by adding input fits (default f)
     215
     216        apply={t|f}
     217                Use previously calculated fits to modify the input MEF image
     218                by subtraction (default f)
     219
     220        tableonly={t|f}
     221                Calculate fits but do *not* modify the input MEF images,
     222                only write the fit data as a FITS and/or text table (default f)
    157223
    158224        in=fname       
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/psfstamp.c

    r23490 r24391  
    136136   int i, k, l, nstar, fdout, otacx, otacy, xid, yid, ntot=0, sumax;
    137137   int cellcount, ota_xid, ota_yid;
    138    double scale, phi, fwhm[3], q[3], qt, xfp, yfp, pi=4*atan(1.0);
     138   double scale, phi, fwhm[3], q[5], qt, xfp, yfp, pi=4*atan(1.0);
    139139   IMTYPE *median_image;
    140140   CELL *cell;
     
    203203   qt = -q[1] * cos(2*phi) - q[2] * sin(2*phi);
    204204
    205    printf("N= %d PSFmaj= %.2f min= %.2f theta= %.1f m2= %.2f q+= %.3f qx= %.3f qt= %.3f\n",
    206           nstar, fwhm[0], fwhm[1], fwhm[2]*180/pi, q[0], q[1], q[2], qt);
     205   printf("N= %d PSFmaj= %.2f min= %.2f theta= %.1f m2= %.2f q+= %.3f qx= %.3f qt= %.3f q3c= %.3f q3s= %.3f\n",
     206          nstar, fwhm[0], fwhm[1], fwhm[2]*180/pi, q[0], q[1], q[2], qt,
     207          q[3], q[4]);
    207208
    208209   if(CONCAT_FITS) {
     
    258259   double m2[MAXPSFMEDIAN], qp[MAXPSFMEDIAN], qc[MAXPSFMEDIAN];
    259260   double qt[MAXPSFMEDIAN], fwavg[MAXPSFMEDIAN];
     261   double q3c[MAXPSFMEDIAN], q3s[MAXPSFMEDIAN];
    260262   double qpavg[MAXPSFMEDIAN], qcavg[MAXPSFMEDIAN], qtavg[MAXPSFMEDIAN];
     263   double q3cavg[MAXPSFMEDIAN], q3savg[MAXPSFMEDIAN];
    261264   int nstar[MAXCELL], nfw[MAXCELL];
    262265   double fwmed[MAXCELL], m2med[MAXCELL];
    263266   double qpmed[MAXCELL], qcmed[MAXCELL], qtmed[MAXCELL];
    264    double qpmacro, qcmacro, qtmacro, fwmacro;
     267   double q3cmed[MAXCELL], q3smed[MAXCELL];
     268   double qpmacro, qcmacro, qtmacro, fwmacro, q3cmacro, q3smacro;
    265269   FILE *fp;
    266270   CELL *cell;
     
    304308                     qp[nstar[k]] = q[1];
    305309                     qc[nstar[k]] = q[2];
     310                     q3c[nstar[k]] = q[3];
     311                     q3s[nstar[k]] = q[4];
    306312/* Get the position in the focal plane and therefore the qt statistic */
    307313                     psc_cell_to_pixel(cellx, celly, 0.5*PSC_HCELL/PSC_PIXEL,
     
    325331                  qcmed[k] = double_median(nstar[k], qc);
    326332                  qtmed[k] = double_median(nstar[k], qt);
     333                  q3cmed[k] = double_median(nstar[k], q3c);
     334                  q3smed[k] = double_median(nstar[k], q3s);
    327335               } else {
    328336                  m2med[k] = qpmed[k] = qcmed[k] = qtmed[k] = -99.99;
     337                  q3cmed[k] = q3smed[k] = -99.99;
    329338               }
    330339/* Toss these results into the macrocell median hopper */
     
    337346                     qcavg[nqavg] = qc[l];
    338347                     qtavg[nqavg] = qt[l];
     348                     q3cavg[nqavg] = q3c[l];
     349                     q3savg[nqavg] = q3s[l];
    339350                     nqavg++;
    340351                  }
     
    346357         qcmacro = double_median(nqavg, qcavg);
    347358         qtmacro = double_median(nqavg, qtavg);
    348          if(nqavg == 0) qpmacro = qcmacro = qtmacro = -99.99;
     359         q3cmacro = double_median(nqavg, q3cavg);
     360         q3smacro = double_median(nqavg, q3savg);
     361         if(nqavg == 0) qpmacro = qcmacro = qtmacro = q3cmacro = q3smacro = -99.99;
    349362         fwmacro = double_median(nfwave, fwavg);
    350363
     
    357370               cell = ota + k;
    358371
    359                fprintf(fp, "ext=xy%1d%1d bias=%d sky=%d rmssky=%d npsf=%d fwhm=%.2f fwmed=%.2f m2=%.2f qp=%.3f qc=%.3f qt=%.3f qpm=%.3f qcm=%.3f qtm=%.3f\n",
     372               fprintf(fp, "ext=xy%1d%1d bias=%d sky=%d rmssky=%d npsf=%d fwhm=%.2f fwmed=%.2f m2=%.2f qp=%.3f qc=%.3f qt=%.3f q3c=%.3f q3s=%.3f qpm=%.3f qcm=%.3f qtm=%.3f q3cm=%.3f q3sm=%.3f\n",
    360373                       cellx, celly, cell->bias, cell->sky, cell->rms,
    361374                       nstar[k], fwmed[k], fwmacro, m2med[k],
    362                        qpmed[k], qcmed[k], qtmed[k],
    363                        qpmacro, qcmacro, qtmacro);
     375                       qpmed[k], qcmed[k], qtmed[k], q3cmed[k], q3smed[k],
     376                       qpmacro, qcmacro, qtmacro, q3cmacro, q3smacro);
    364377            }
    365378         }
  • trunk/extsrc/gpcsw/gpcsrc/fits/libfh/fh.c

    r23490 r24391  
    200200/* Functions that do file operations WITH RETRY: */
    201201static int write_file(int fd, const void* buf, int len);
    202 static int read_file(int fd, const void* buf, int len);
     202static int read_file(int fd, void* buf, int len);
    203203static int seek_file(int fd, off_t off); /* Performs lseek(SEEK_SET) */
    204204static int fh_lock_file(HeaderUnit hu, int fd, fh_mode mode);
     
    234234 * this information in debug mode.
    235235 */
     236const char* fh_rcs_version(void); /* proto to make gcc happy */
    236237const char* fh_rcs_version(void) { return rcs_id; }
    237238
     
    274275
    275276static void
    276 null_log(const char* s) { if (s) ; }
     277null_log(const char* s) { if (s) return; }
    277278/*
    278279 * It's also possible to pass a NULL to fh_log_xxx() and rely only on the
     
    309310
    310311HeaderUnit
    311 fh_create()
     312fh_create(void)
    312313{
    313314   HeaderUnitStruct* rtn;
     
    19411942   HeaderUnitStruct* list = FH_HU(hu);
    19421943   char writebuf[FH_BLOCK_SIZE];
    1943    int i = 0, writelen;
     1944   int i = 0;
     1945   unsigned int writelen;
    19441946   int blocks_left;
    19451947   fh_result result;
     
    24462448   else /* byte-swapping case requires a temporary buffer */
    24472449   {
    2448       unsigned char outbuf[32768];
     2450      unsigned char* outbuf[32768];
    24492451
    24502452      while (bytes_left)
     
    28112813   while (len)
    28122814   {
    2813       rtn = write(fd, (char*)buf, len);
     2815      rtn = write(fd, (const char*)buf, len);
     2816
     2817      switch (rtn)
     2818      {
     2819         case -1: if (errno == EINTR || errno == EAGAIN)
     2820            continue; /* retry */
     2821            return -1; /* permanent failure */
     2822         case 0: return count;
     2823         default:
     2824         {
     2825            len -= rtn;
     2826            count += rtn;
     2827            buf = (const char*)buf + rtn;
     2828         }
     2829      }
     2830   }
     2831   return count;
     2832}
     2833
     2834static int
     2835read_file(int fd, void* buf, int len)
     2836{
     2837   int rtn;
     2838   int count = 0;
     2839
     2840   while (len)
     2841   {
     2842      rtn = read(fd, (char*)buf, len);
    28142843
    28152844      switch (rtn)
     
    28312860
    28322861static int
    2833 read_file(int fd, const void* buf, int len)
    2834 {
    2835    int rtn;
    2836    int count = 0;
    2837 
    2838    while (len)
    2839    {
    2840       rtn = read(fd, (char*)buf, len);
    2841 
    2842       switch (rtn)
    2843       {
    2844          case -1: if (errno == EINTR || errno == EAGAIN)
    2845             continue; /* retry */
    2846             return -1; /* permanent failure */
    2847          case 0: return count;
    2848          default:
    2849          {
    2850             len -= rtn;
    2851             count += rtn;
    2852             buf = (char*)buf + rtn;
    2853          }
    2854       }
    2855    }
    2856    return count;
    2857 }
    2858 
    2859 static int
    28602862seek_file(int fd, off_t off)
    28612863{
     
    29692971fh_compare(const void* a, const void* b)
    29702972{
    2971    double diff = (*((FitsCard**)a))->idx - (*((FitsCard**)b))->idx;
     2973   double diff = (*((FitsCard* const*)a))->idx - (*((FitsCard* const*)b))->idx;
    29722974
    29732975   if (diff < 0) return -1;
  • trunk/extsrc/gpcsw/gpcsrc/fits/libfh/fh_table.c

    r23924 r24391  
    180180
    181181   /* Write the format specifiers for each column. */
    182    for(i=0; i < table->num_cols; i++)
    183    {
     182   for (i=0; i < table->num_cols; i++)
     183   {
     184      int n;
     185
    184186      idx = 5.0 + i/10.;
    185       int n = i + 1; /* FITS numbering scheme starts from 1. */
     187      n = i + 1; /* FITS numbering scheme starts from 1. */
    186188      snprintf(keyword, FH_NAME_SIZE + 1, "TFORM%d", n);
    187189      if((table->cols[i].format == FH_TABLE_FORMAT_FLOAT) ||
     
    214216    * nice to have from a self-documenting perspective, isn't strictly
    215217    * necessary to interpret the actual table values. */
    216    for(i=0; i < table->num_cols; i++)
    217    {
     218   for (i=0; i < table->num_cols; i++)
     219   {
     220      int n;
     221
    218222      idx = 7.0 + i/10.;
    219       int n = i + 1; /* FITS numbering scheme starts from 1. */
     223      n = i + 1; /* FITS numbering scheme starts from 1. */
    220224      snprintf(keyword, FH_NAME_SIZE + 1, "TTYPE%d", n);
    221225      fh_set_str(hu, idx, keyword, table->cols[i].name,
  • trunk/extsrc/gpcsw/gpcsrc/fits/libfhreg/gpc_telescope.h

    r23924 r24391  
    8989MK_PFL(  523.3, COMALT  ,6, "Commanded telescope pointing altitude (degrees)" )
    9090MK_PFL(  523.4, COMROT  ,6, "Commanded telescope rotator angle (degrees)"     )
     91MK_PFL(  523.5, MOONANG ,6, "Angular distance to moon (degrees)" )
    9192MK_CMT(  530.00,CMTTELO1,   "NOTE: Telescope RA DEC or ALT AZ already include")
    9293MK_CMT(  530.10,CMTTELO2,   "      the following offsets.  Do not re-apply!"  )
Note: See TracChangeset for help on using the changeset viewer.