IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3416


Ignore:
Timestamp:
Mar 14, 2005, 12:46:02 PM (21 years ago)
Author:
eugene
Message:

adding mosaic astrometry support and smp-fits files

Location:
trunk/Ohana/src
Files:
7 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/Makefile

    r3402 r3416  
    6161$(SRC)/update_coords.$(ARCH).o \
    6262$(SRC)/wcatalog.$(ARCH).o \
    63 $(SRC)/wimage.$(ARCH).o
     63$(SRC)/wimage.$(ARCH).o \
     64$(SRC)/rfits.$(ARCH).o \
     65$(SRC)/rtext.$(ARCH).o \
     66$(SRC)/ConvertStars.$(ARCH).o
    6467
    6568EXTRA = \
  • trunk/Ohana/src/addstar/include/addstar.h

    r3402 r3416  
    1717    fprintf (stderr, "ERROR:  photcode %s not found in photcode table\n", NAME); \
    1818    exit (0); }
     19
     20/* this structure is used for loading the data from the FITS smp file */
     21typedef struct {
     22  float X;
     23  float Y;
     24  float M;
     25  float dM;
     26  float Mgal;
     27  float Map;
     28  float sky;
     29  float fx;
     30  float fy;
     31  float df;
     32  char  dophot;
     33  char  dummy[3];
     34} StarData;
    1935
    2036typedef struct {
     
    198214GSCRegion *gregion_match (GSCRegion *regions, int *nregions);
    199215GSCRegion *gregion_patch (GSCRegion *patch, int *nregions);
     216int ConvertStars (StarData *data, int size, int nitems);
  • trunk/Ohana/src/addstar/src/gimages.c

    r3389 r3416  
    9898  ALLOCATE (pimage, Image, NPIMAGE);
    9999
     100  fprintf (stderr, "find overlapping images\n");
    100101  /* run through image table, reading images in blocks */
    101102  for (Ntimage = 0; Ntimage < Nimage; Ntimage += ntimage) {
     
    141142    }
    142143  }
     144  fprintf (stderr, "done\n");
    143145
    144146  BuildChipMatch (pimage, npimage);
     
    157159   if the WRP image is loaded near the beginning of a block, then the corresponding DIS
    158160   may be in the previous block, and thus missed
     161
     162   we are not adding the matching DIS image to the table.
    159163*/
  • trunk/Ohana/src/addstar/src/gstars.c

    r3402 r3416  
    11# include "addstar.h"
    2 # define D_NSTARS 1000
    3 # define BYTES_STAR 66
    4 # define BLOCK 1000
    52
    63Stars *gstars (char *file, int *NSTARS, Image *image) {
     
    85  FILE *f;
    96  Header header;
    10   int j, N, Ninstar;
     7  int j, N, Ninstar, extend;
    118  int nbytes, Nbytes;
    12   Stars *stars;
     9  Stars *stars, *rdstars;
    1310  char *buffer, *c, *c2, photcode[64];
    1411  double tmp;
     
    2219    exit (1);
    2320  }
    24 
    25   /* open file */
    26   f = fopen (file, "r");
    27   if (f == NULL) {
    28     fprintf (stderr, "ERROR: can't read data from %s\n", file);
    29     exit (1);
    30   }
    31   fseek (f, header.size, SEEK_SET);
    3221
    3322  /* find image rootname */
     
    147136    exit (1);
    148137  }
    149   ALLOCATE (stars, Stars, image[0].nstar);
    150138
    151139  /* this is really lame.  get sky background from Flips data */
     
    170158  }
    171159
    172   /* load in stars by blocks of 1000 */
    173   N = 0;
    174   ALLOCATE (buffer, char, (BLOCK*BYTES_STAR) + 1);
    175   buffer[BLOCK*BYTES_STAR] = 0;
    176   Nextra = 0;
    177   doneread = FALSE;
    178   while (!doneread) {
    179     Nbytes = BYTES_STAR * BLOCK - Nextra;
    180     nbytes = Fread (&buffer[Nextra], 1, Nbytes, f, "char");
    181     if (nbytes == 0) {
    182       doneread = TRUE;
    183       continue;
     160  /* read in data section */
     161  f = fopen (file, "r");
     162  if (f == NULL) {
     163    fprintf (stderr, "ERROR: can't read data from %s\n", file);
     164    exit (1);
     165  }
     166  fseek (f, header.size, SEEK_SET);
     167
     168  extend = FALSE;
     169  fits_scan (&header, "EXTEND",  "%t", 1, &extend);
     170  if (extend) {
     171    Nbytes = fits_matrix_size (&header);
     172    fseek (f, Nbytes, SEEK_CUR);
     173    rdstars = rfits (f, &image[0].nstar);
     174  } else {
     175    rdstars = rtext (f, &image[0].nstar);
     176  }
     177  fclose (f);
     178
     179  /* modify resulting star list */
     180  ALLOCATE (stars, Stars, image[0].nstar);
     181  for (N = j = 0; j < image[0].nstar; j++) {
     182    /* allow for some dynamic filtering of star list */
     183    if (rdstars[j].dM > 1000.0 / SNLIMIT) continue;
     184    if (XMAX && (rdstars[j].X > XMAX)) continue;
     185    if (XMIN && (rdstars[j].X < XMIN)) continue;
     186    if (YMAX && (rdstars[j].Y > YMAX)) continue;
     187    if (YMIN && (rdstars[j].Y < YMIN)) continue;
     188    stars[N] = rdstars[j];
     189
     190    XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords);
     191    while (stars[N].R < 0.0) stars[N].R += 360.0;
     192    while (stars[N].R >= 360.0) stars[N].R -= 360.0;
     193    stars[N].found = -1;
     194    stars[N].code = thiscode[0].code;
     195
     196    if (SKYPROBE) {
     197      dMs = get_subpix (stars[N].X, stars[N].Y);
     198      stars[N].M    -= dMs;
     199      stars[N].Mgal -= dMs;
     200      stars[N].Map  -= dMs;
     201      dMs = 1000.0*scat_subpix (stars[N].X, stars[N].Y);
     202      stars[N].dM = hypot (stars[N].dM, dMs);
    184203    }
    185     nbytes += Nextra;
    186     /* check line-by-line integrity */
    187     c = buffer;
    188     done = FALSE;
    189     while ((c < buffer + nbytes) && (!done)) {
    190       for (c2 = c; *c2 == '\n'; c2++);
    191       if (c2 > c) { /* extra return chars */
    192         memmove (c, c2, (int)(buffer + nbytes - c2));
    193         Nskip = c2 - c;
    194         nbytes -= Nskip;
    195         bzero (buffer + nbytes, Nskip);
    196         if (VERBOSE) fprintf (stderr, "deleted %d extra return chars\n", Nskip);
    197       }
    198       c2 = strchr (c, '\n');
    199       if (c2 == (char *) NULL) {
    200         done = TRUE;   
    201         continue;
    202       }
    203       c2++;
    204       if ((c2 - c) != BYTES_STAR) { /* bad line, delete it */
    205         memmove (c, c2, (int)(buffer + nbytes - c2));
    206         Nskip = c2 - c;
    207         nbytes -= Nskip;
    208         bzero (buffer + nbytes, Nskip);
    209         if (VERBOSE) fprintf (stderr, "deleted line, %d extra chars\n", Nskip);
    210       } else {
    211         c = c2;
    212       }
    213     }
    214     Ninstar = nbytes / BYTES_STAR;
    215     Nextra = nbytes % BYTES_STAR;
    216     for (j = 0; j < Ninstar; j++, N++) {
    217       dparse (&stars[N].X,  1, &buffer[j*BYTES_STAR]);
    218       dparse (&stars[N].Y,  2, &buffer[j*BYTES_STAR]);
    219       dparse (&stars[N].M,  3, &buffer[j*BYTES_STAR]);
    220 
    221       /* cmp files carry dM in millimags */
    222       dparse (&tmp, 4, &buffer[j*BYTES_STAR]);
    223       stars[N].dM = 0.001*tmp;
    224 
    225       /* allow for some dynamic filtering of star list */
    226       if (stars[N].dM > 1000.0 / SNLIMIT) { N--; continue; }
    227       if (XMAX && (stars[N].X > XMAX))    { N--; continue; }
    228       if (XMIN && (stars[N].X < XMIN))    { N--; continue; }
    229       if (YMAX && (stars[N].Y > YMAX))    { N--; continue; }
    230       if (YMIN && (stars[N].Y < YMIN))    { N--; continue; }
    231 
    232       dparse (&tmp,         5, &buffer[j*BYTES_STAR]);
    233       stars[N].dophot = tmp;
    234 
    235       dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]);
    236       dparse (&stars[N].Map,  8, &buffer[j*BYTES_STAR]);
    237       dparse (&stars[N].fx,   9, &buffer[j*BYTES_STAR]);
    238       dparse (&stars[N].fy,  10, &buffer[j*BYTES_STAR]);
    239       dparse (&stars[N].df,  11, &buffer[j*BYTES_STAR]);
    240 
    241       XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords);
    242       while (stars[N].R < 0.0) stars[N].R += 360.0;
    243       while (stars[N].R >= 360.0) stars[N].R -= 360.0;
    244       stars[N].found = -1;
    245       stars[N].code = thiscode[0].code;
    246 
    247       if (SKYPROBE) {
    248         dMs = get_subpix (stars[N].X, stars[N].Y);
    249         stars[N].M    -= dMs;
    250         stars[N].Mgal -= dMs;
    251         stars[N].Map  -= dMs;
    252         dMs = 1000.0*scat_subpix (stars[N].X, stars[N].Y);
    253         stars[N].dM = hypot (stars[N].dM, dMs);
    254       }
    255     }
    256   }
    257 
     204    N ++;
     205  }
    258206  image[0].nstar = N;
    259207  REALLOCATE (stars, Stars, image[0].nstar);
     208  free (rdstars);
     209
    260210  if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", image[0].nstar);
    261211  *NSTARS = image[0].nstar;
  • trunk/Ohana/src/mosastro/Makefile

    r3401 r3416  
    5757$(SRC)/clip.$(ARCH).o \
    5858$(SRC)/parse_time.$(ARCH).o \
    59 $(SRC)/testcoords.$(ARCH).o
     59$(SRC)/testcoords.$(ARCH).o \
     60$(SRC)/rfits.$(ARCH).o \
     61$(SRC)/wfits.$(ARCH).o \
     62$(SRC)/rtext.$(ARCH).o \
     63$(SRC)/ConvertStars.$(ARCH).o
    6064
    6165mosastro: $(BIN)/mosastro.$(ARCH)
  • trunk/Ohana/src/mosastro/include/mosastro.h

    r3401 r3416  
    2323  StarData *stars;
    2424  Header header;
     25  Header theader;
     26  Matrix matrix;
     27
    2528  char *buffer;
    2629  int Nbuffer;
     30  int FITS;
    2731
    2832  int Nmatch;
     
    5559
    5660typedef struct {
    57   double X;
    58   double Y;
    59   double M, dM;
    60   char   dophot;
    61   double sky;
    62   double fx, fy, df;
    63   double Mgal, Map;
     61  float X;
     62  float Y;
     63  float M;
     64  float dM;
     65  float Mgal;
     66  float Map;
     67  float sky;
     68  float fx;
     69  float fy;
     70  float df;
     71  char  dophot;
     72  char  dummy[3];
    6473} Stars;
    6574
     
    168177void wchip (char *filename, Chip *data);
    169178void wstars (char *filename, Stars *stars, int Nstars, Header *header);
     179int ConvertStars (Stars *data, int size, int nitems);
  • trunk/Ohana/src/mosastro/src/LoadStars.c

    r3401 r3416  
    11# include "mosastro.h"
    2 # define BYTES_STAR 66
    32
    43int LoadStars (int Nfile, char **file) {
    54
    6   int i, j, itmp, Nbytes, nbytes;
     5  int i, j, itmp, Nbytes, nbytes, status, extend;
    76  FILE *f;
    87  time_t tsval;
     
    2322      continue;
    2423    }
    25     f = fopen (chip[Nchip].file, "r");
    26     if (f == NULL) {
    27       fprintf (stderr, "ERROR: can't read data from %s\n", file[i]);
    28       free (chip[Nchip].file);
    29       continue;
    30     }
    31     fseek (f, chip[Nchip].header.size, SEEK_SET);
    3224
    3325    /* get image dimensions */
     
    3931      fprintf (stderr, "ERROR: no astrometric solution in header\n");
    4032      free (chip[Nchip].file);
     33      fits_free_header (&chip[Nchip].header);
    4134      continue;
    4235    }
     
    4942      fprintf (stderr, "ERROR: bad astrometric solution in header %s\n", file[i]);
    5043      free (chip[Nchip].file);
     44      fits_free_header (&chip[Nchip].header);
    5145      continue;
    5246    }
     
    5751    Year = tmval[0].tm_year;
    5852
    59     /* find expected number of stars */
    60     fits_scan (&chip[Nchip].header, "NSTARS", "%d", 1, &chip[Nchip].Nstars);
    61     if (chip[Nchip].Nstars == 0) {
    62       fprintf (stderr, "ERROR: can't get NSTARS from header for %s\n", file[i]);
     53    extend = FALSE;
     54    fits_scan (&chip[Nchip].header, "EXTEND",  "%t", 1, &extend);
     55    if (extend) {
     56      status = rfits (&chip[Nchip]);
     57    } else {
     58      status = rtext (&chip[Nchip]);
     59    }
     60    if (!status) {
     61      /* skip on failure */
    6362      free (chip[Nchip].file);
     63      fits_free_header (&chip[Nchip].header);
    6464      continue;
    65     }
    66     ALLOCATE (chip[Nchip].stars, StarData, chip[Nchip].Nstars);
    67    
    68     Nbytes = BYTES_STAR * chip[Nchip].Nstars;
    69     ALLOCATE (chip[Nchip].buffer, char, Nbytes + 1);
    70     nbytes = Fread (chip[Nchip].buffer, 1, Nbytes, f, "char");
    71     if (nbytes != Nbytes) { exit (1); }
    72     chip[Nchip].Nbuffer = Nbytes;
    73 
    74     for (j = 0; j < chip[Nchip].Nstars; j++) {
    75       bzero (&chip[Nchip].stars[j], sizeof(StarData));
    76       dparse (&chip[Nchip].stars[j].X,    1, &chip[Nchip].buffer[j*BYTES_STAR]);
    77       dparse (&chip[Nchip].stars[j].Y,    2, &chip[Nchip].buffer[j*BYTES_STAR]);
    78       dparse (&chip[Nchip].stars[j].Mag,  3, &chip[Nchip].buffer[j*BYTES_STAR]);
    79       dparse (&chip[Nchip].stars[j].dMag, 4, &chip[Nchip].buffer[j*BYTES_STAR]);
    80       chip[Nchip].stars[j].dMag *= 0.001;  /* millimag errors stored in file */
    8165    }
    8266
  • trunk/Ohana/src/mosastro/src/clip.c

    r3401 r3416  
    88  StarData *raw, *ref;
    99
    10   sigma = GetScatter (&Nscatter);
    11   fprintf (stderr, "scatter (chip) : %f for %d stars\n", sigma, Nscatter);
    12 
    1310  Nmask = Nkeep = 0;
     11  sigma = GetScatter (&Nscatter) / (3600.0 * field.project.cdelt1);
    1412
    1513  for (i = 0; i < Nchip; i++) {
  • trunk/Ohana/src/mosastro/src/dump.c

    r3401 r3416  
    66
    77  for (i = 0; i < Nstars; i++) {
    8     fprintf (f, "%4d  %10.6f %10.6f  %8.2f %8.2f  %8.2f %8.2f  %7.2f %7.2f  %7.2f %7.2f\n",
     8    fprintf (f, "%4d  %10.6f %10.6f  %8.2f %8.2f  %8.2f %8.2f  %7.2f %7.2f  %7.2f %7.2f  %d\n",
    99             i,
    1010             stars[i].R, stars[i].D,
     
    1212             stars[i].L, stars[i].M,
    1313             stars[i].X, stars[i].Y,
    14              stars[i].Mag, stars[i].dMag);
     14             stars[i].Mag, stars[i].dMag, stars[i].mask);
    1515  }
    1616  return (1);
  • trunk/Ohana/src/mosastro/src/mosastro.c

    r3404 r3416  
    5656  if ((DUMP != NULL) && !strcmp (DUMP, "fitchips_unclip")) dump_match();
    5757
    58   ClipOnFP (3.0);
     58  ClipOnFP (2.0);
    5959  Cerror   = GetScatter (&Nastro);
    6060  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
     
    6464  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
    6565
    66   ClipOnFP (3.0);
     66  ClipOnFP (2.0);
     67  Cerror   = GetScatter (&Nastro);
     68  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
     69
     70  FitChips (ChipOrder);
     71  Cerror   = GetScatter (&Nastro);
     72  fprintf (stderr, "scatter (chip) : %f for %d stars\n", Cerror, Nastro);
     73
     74  ClipOnFP (2.0);
    6775  Cerror   = GetScatter (&Nastro);
    6876  fprintf (stderr, "scatter (clip) : %f for %d stars\n", Cerror, Nastro);
  • trunk/Ohana/src/mosastro/src/output.c

    r3401 r3416  
    44
    55  int i, N;
    6   char *p;
    7   char outname[256];
     6  char *p, outname[256];
     7  FILE *f;
     8  Header *header;
    89 
    910  for (i = 0; i < Nchip; i++) {
     
    2627  }
    2728
    28   {
     29  field_combine ();
    2930
    30     Header *header;
    31     FILE *f;
    32    
    33     field_combine ();
    34 
    35     f = fopen (phu, "w");
    36     if (f == (FILE *) NULL) {
    37       fprintf (stderr, "ERROR: can't create output file %s\n", phu);
    38       exit (1);
    39     }
    40 
    41     header = mkmosaic (1, 1, 0, &field.project);
    42     fwrite (header[0].buffer, 1, header[0].size, f);
    43     fclose (f);
     31  f = fopen (phu, "w");
     32  if (f == (FILE *) NULL) {
     33    fprintf (stderr, "ERROR: can't create output file %s\n", phu);
     34    exit (1);
    4435  }
    4536
    46   {
    47 
    48     FILE *f;
    49     double R, D;
    50 
    51     fprintf (stderr, "starting test.dat\n");
    52     f = fopen ("test.dat", "w");
    53     if (f == (FILE *) NULL) {
    54       fprintf (stderr, "ERROR: can't create output file \n");
    55       exit (1);
    56     }
    57 
    58     RegisterMosaic (&field.project);
    59     for (i = 0; i < chip[0].Nmatch; i++) {
    60       XY_to_RD (&R, &D, chip[0].raw[i].X, chip[0].raw[i].Y, &chip[0].map);
    61       fprintf (f, "%4d  %10.6f %10.6f  %8.2f %8.2f\n",
    62                i, R, D, chip[0].raw[i].X, chip[0].raw[i].Y);
    63     }
    64     fclose (f);
    65   }
    66  
     37  header = mkmosaic (1, 1, 0, &field.project);
     38  fwrite (header[0].buffer, 1, header[0].size, f);
     39  fclose (f);
    6740}
  • trunk/Ohana/src/mosastro/src/wstars.c

    r3323 r3416  
    66  FILE *g;
    77
    8   g = fopen (filename, "w");
    9   if (g == (FILE *) NULL) {
    10     fprintf (stderr, "ERROR: can't create output file %s\n", filename);
    11     exit (1);
    12   }
     8  if (data[0].FITS) {
     9    wfits (filename, (Stars *) data[0].buffer, data[0].Nstars, &data[0].header);
     10  } else {
    1311
    14   fwrite (data[0].header.buffer, 1, data[0].header.size, g);
    15   fwrite (data[0].buffer, 1, data[0].Nbuffer, g);
    16   fclose (g);
     12    g = fopen (filename, "w");
     13    if (g == (FILE *) NULL) {
     14      fprintf (stderr, "ERROR: can't create output file %s\n", filename);
     15      exit (1);
     16    }
    1717
     18    fwrite (data[0].header.buffer, 1, data[0].header.size, g);
     19    fwrite (data[0].buffer, 1, data[0].Nbuffer, g);
     20    fclose (g);
     21  } 
    1822}
    1923
Note: See TracChangeset for help on using the changeset viewer.