IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24522


Ignore:
Timestamp:
Jun 19, 2009, 4:11:25 PM (17 years ago)
Author:
eugene
Message:

updates to tiltystreak from JT & SI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/extsrc/gpcsw/gpcsrc/fits/tiltystreak/tiltystreak.c

    r24390 r24522  
     1/* -*- c-file-style: "Ellemtel" -*- */
    12/* tiltystreak.c - fit and subtract tilted streaks from a row of cells */
    23/* Assumes that biastool has already been run -- zero streakiness near bias */
     
    5253static int parabola_streak_fit(int sx, int nx, int ny, int NX, CELL otarow[]);
    5354int linearfit(int npt, double *y, int nx, double *x, double *param);
     55static void syntax(const char *prog);
    5456
    5557static int nmedian_buf=0;
     
    5961int main(int argc, const char* argv[])
    6062{
    61    int i, row, col, ext;
     63   int i, j, row, col, ext;
    6264   HeaderUnit ihu = fh_create();
    6365   HeaderUnit ehu = NULL;
     
    6668   int nextend;
    6769   CELL otarow[NCELL];
    68    int naxis, naxis1, naxis2, naxis3;
     70   int naxis, naxis1=0, naxis2=0;
     71   int n1, n2;
    6972   int prescan1, ovrscan1, ovrscan2;
    7073   double bzero_d;
    7174   int bzero = 32768, firstime = 1, algo=2;
     75   int cellmask[NCELL*NCELL];
    7276
    7377   if(argc < 2) {
     78      syntax(argv[0]);
    7479      fprintf(stderr, "error: syntax: tiltystreak Uncompressed_GPC1_MEF.fits\n");
    7580      exit(EXIT_FAILURE);
     
    7782   ifilename = argv[1];
    7883
    79 /* Choose different algorithms? */
    80    if(argc > 2 && strncmp(argv[2], "alg=", 4) == 0) {
    81       if(strcmp(argv[2]+4, "line") == 0) {
    82          algo = 1;
    83       } else if(strcmp(argv[2]+4, "parabola") == 0) {
    84          algo = 2;
    85       } else if(strcmp(argv[2]+4, "bent") == 0) {
    86          algo = 3;
     84/* Defaults */
     85   for(i=0; i<NCELL*NCELL; i++) cellmask[i] = 1;        /* Use all cells */
     86   algo = 2;                    /* Default algorithm is a parabola */
     87
     88/* Process arguments */
     89   for(i=2; i<argc; i++) {
     90
     91/* Veto cells by a 64 digit mask (0/1 for cells 0-63) */
     92      if(strncmp(argv[i], "mask=", 5) == 0) {   /* mask=64_digits */
     93         if(strlen(argv[i]) < 5+NCELL*NCELL) {
     94            fprintf(stderr, "\rerror: cannot get mask from `%s'\n", argv[i]);
     95            exit(EXIT_FAILURE);
     96         } else {
     97            for(j=0; j<NCELL*NCELL; j++) cellmask[j] = argv[i][5+j] != '0';
     98         }
     99
     100      } else if(strncmp(argv[2], "alg=", 4) == 0) {     /* Algorithm */
     101         if(strcmp(argv[2]+4, "line") == 0) {
     102            algo = 1;
     103         } else if(strcmp(argv[2]+4, "parabola") == 0) {
     104            algo = 2;
     105         } else if(strcmp(argv[2]+4, "bent") == 0) {
     106            algo = 3;
     107         } else {
     108            fprintf(stderr, "error: `%s' is not a valid algorithm\n", argv[2]);
     109            exit(EXIT_FAILURE);
     110         }
     111
     112      } else if(strncmp(argv[i], "help", 4) == 0) {     /* help output */
     113         syntax(argv[0]);
     114         exit(EXIT_SUCCESS);
     115
    87116      } else {
    88          fprintf(stderr, "error: `%s' is not a valid algorithm\n", argv[2]);
     117         fprintf(stderr, "\rerror: unrecognized option `%s'\n", argv[i]);
     118         syntax(argv[0]);
    89119         exit(EXIT_FAILURE);
    90120      }
    91121   }
     122
    92123
    93124   if (fh_file(ihu, ifilename, FH_FILE_RDWR) != FH_SUCCESS) {
     
    139170
    140171/* Positioned at the desired cell now */
    141          naxis3 = 1;
    142172         if (fh_get_PRESCAN1(ehu, &prescan1) != FH_SUCCESS ||
    143173             fh_get_OVRSCAN1(ehu, &ovrscan1) != FH_SUCCESS ||
    144174             fh_get_OVRSCAN2(ehu, &ovrscan2) != FH_SUCCESS ||
    145175             fh_get_NAXIS(ehu, &naxis) != FH_SUCCESS ||
    146              fh_get_NAXIS1(ehu, &naxis1) != FH_SUCCESS ||
    147              fh_get_NAXIS2(ehu, &naxis2) != FH_SUCCESS) {
     176             fh_get_NAXIS1(ehu, &n1) != FH_SUCCESS ||
     177             fh_get_NAXIS2(ehu, &n2) != FH_SUCCESS) {
    148178            fprintf(stderr, "error: Cannot get NAXIS* in extension %d row %d col %d\n", ext, row, col);
    149179            exit(EXIT_FAILURE);
     
    157187/* Make some space now that we finally know the size */
    158188         if(firstime) {
     189            naxis1 = n1;
     190            naxis2 = n2;
    159191            firstime = 0;
    160192            for(i=0; i<NCELL; i++) {
     
    167199            Bbuf = (double *)calloc(naxis2, sizeof(double));
    168200            Xbuf = (double *)calloc(NPOLY*naxis2, sizeof(double));
     201         }
     202         else {
     203            if(naxis1 != n1 || naxis2 != n2) {
     204               fprintf(stderr, "error: All cells must be same size (%dx%d != %dx%d)\n",
     205                       n1, n2, naxis1, naxis2);
     206               exit(EXIT_FAILURE);
     207            }
    169208         }
    170209
     
    214253#ifdef DEBUG
    215254      for(col=0; col<NCELL; col++) {
    216          printf("%1d %1d %3d %3d %6d %6d %6d %6d %8.3f\n",
     255         printf("%1d %1d %3d %3d 0x%08x %6d %6d %6d %6d %8.3f\n",
    217256                col, row, otarow[col].cell, otarow[col].mefxt,
     257                (int)otarow[col].hu,
    218258                otarow[col].bias, otarow[col].sky, otarow[col].rms,
    219259                otarow[col].nsat, otarow[col].ampl);
     
    258298/* Return to all the cells in the MEF and rewrite the data */
    259299      for(col=0; col<NCELL; col++) {
     300#ifdef DEBUG
     301         printf("Now writing cell %d %d ext %d (hu 0x%08x)\n",
     302                col, row, otarow[col].mefxt, (int)otarow[col].hu);
     303#endif
    260304         if(otarow[col].mefxt < 0) continue;
     305/* Skip if cell mask not set */
     306         if(cellmask[col+NCELL*row] != 1) continue;
    261307/* This seeks back to the start of data from this cell again... */
    262308         ehu = otarow[col].hu;
    263309         fh_ehu(ehu, 0);
    264310
     311#ifdef DEBUG
     312         printf("Now writing cell %d %d ext %d (hu 0x%08x)\n",
     313                col, row, otarow[col].mefxt, (int)otarow[col].hu);
     314#endif
    265315         if (fh_write_padded_image(ehu, fh_file_desc(ehu), otarow[col].data,
    266316                                   naxis1*naxis2*sizeof(short),
     
    272322      }
    273323
    274    }
     324   }    /* Loop over rows */
    275325
    276326   fh_destroy(ihu);
     
    439489      A = Abuf[j] - (par[0] + j*par[1] + j*j*par[2]);
    440490#ifdef DEBUG
    441       if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f\n", j, Abuf[j], A);
     491//      if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f\n", j, Abuf[j], A);
    442492#endif
    443493      for(k=0; k<NCELL; k++) {
     
    504554      B = Bbuf[j] - (Bpar[0] + j*Bpar[1] + j*j*Bpar[2]);
    505555#ifdef DEBUG
    506       if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f %9.3f %9.3f\n",
    507                                       j, Abuf[j], A, Bbuf[j], B);
     556//      if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f %9.3f %9.3f\n",
     557//                                    j, Abuf[j], A, Bbuf[j], B);
    508558#endif
    509559/* Parabola passes through 0 at i=sx+nx, A at sx+nx/6, B at sx+nx/2 */
     
    590640
    591641#ifdef DEBUG
    592       if(otarow[3].mefxt == 4) printf("%4d %4d %9.3f %9.3f %9.3f\n",
    593                                       j, i0, A, B, C);
     642//      if(otarow[3].mefxt == 4) printf("%4d %4d %9.3f %9.3f %9.3f\n",
     643//                                    j, i0, A, B, C);
    594644#endif
    595645
     
    609659   return(0);
    610660}
     661
     662static void syntax(const char *prog)
     663{
     664   printf("Syntax: %s mef_file [options]\n", prog);
     665   printf("   where options include:\n\n");
     666   printf(" mask=0101...   64 digits to work on cells 0:63.\n");
     667   printf(" alg=N          Use fit algorithm 1=linear, 2=parabola (default)\n");   printf("                   3=bent linear (not yet fully implemented)\n");
     668}
Note: See TracChangeset for help on using the changeset viewer.