IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33114


Ignore:
Timestamp:
Jan 17, 2012, 4:36:22 PM (15 years ago)
Author:
eugene
Message:

setphot + ubercal table seems to work & writes out the flat-field correction table

Location:
branches/eam_branches/ipp-20111122/Ohana/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/flatcorr_io.c

    r33104 r33114  
    104104    MaxID = MAX(flatcorrTable->image[i].ID, MaxID);
    105105  }
     106  MaxID ++; // we want the outer bound, not the last value
    106107
    107108  // generate the index and init values to -1
     
    126127    assert (seq != -1);
    127128
    128     flatcorrTable->offset[i][x][y] = flatcorrTable->corr[i].offset;     
     129    flatcorrTable->offset[seq][x][y] = flatcorrTable->corr[i].offset;     
    129130  }
    130131
     
    142143  FTable ftableCorr;
    143144  FILE *f;
     145
     146  FlatCorrectionImage *image;
     147  FlatCorrection *corr;
     148
     149  // these output functions byteswap their buffers. make a copy for output
     150  ALLOCATE (image, FlatCorrectionImage, flatcorrTable->Nimage);
     151  memcpy (image, flatcorrTable->image, flatcorrTable->Nimage*sizeof(FlatCorrectionImage));
     152
     153  ALLOCATE (corr, FlatCorrection, flatcorrTable->Ncorr);
     154  memcpy (corr, flatcorrTable->corr, flatcorrTable->Ncorr*sizeof(FlatCorrection));
    144155
    145156  /* make phu header (no matrix needed) */
     
    150161
    151162  ftableImage.header = &theaderImage;
    152   gfits_table_set_FlatCorrectionImage (&ftableImage, flatcorrTable->image, flatcorrTable->Nimage);
     163  gfits_table_set_FlatCorrectionImage (&ftableImage, image, flatcorrTable->Nimage);
    153164
    154165  ftableCorr.header = &theaderCorr;
    155   gfits_table_set_FlatCorrection (&ftableCorr, flatcorrTable->corr, flatcorrTable->Ncorr);
     166  gfits_table_set_FlatCorrection (&ftableCorr, corr, flatcorrTable->Ncorr);
    156167
    157168  f = fopen (filename, "w");
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h

    r33104 r33114  
    7777time_t       TSTOP;
    7878PhotCode    *photcode;
     79
     80// hard-wired values which describe the ubercal analysis
     81# define NFILTER 5
     82# define NSEASON 4
     83# define NCHIP_X 8
     84# define NCHIP_Y 8
     85# define NCELL_X 2
     86# define NCELL_Y 2
     87
     88// these are initialized by initialize_setphot (in initialize.c)
     89e_time tstart    [NSEASON];
     90e_time tstop     [NSEASON];
     91char   filter    [NFILTER];
    7992
    8093enum {black, white, red, orange, yellow, green, blue, indigo, violet};
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ConfigInit.c

    r27790 r33114  
    77  double ZERO_POINT;
    88  char  *config, *file;
    9   char CatdirPhotcodeFile[256];
    10   char MasterPhotcodeFile[256];
    119
    1210  /*** load configuration info ***/
     
    2321  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
    2422  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
    25   ScanConfig (config, "PHOTCODE_FILE",          "%s",  0, MasterPhotcodeFile);
    2623
    2724  sprintf (ImageCat, "%s/Images.dat", CATDIR);
     
    4340  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
    4441  if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
    45 
    46   /* XXX this does not yet write out the master photcode table */
    47   sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
    48   if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile, TRUE)) {
    49     fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
    50     exit (1);
    51   }
    52 
    5342}
    5443
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/args.c

    r33103 r33114  
    9595
    9696  if (argc != 2) {
    97     fprintf (stderr, "ERROR: USAGE: setphot (zptfile) [options]\n");
     97    fprintf (stderr, "USAGE: setphot (zptfile) [options]\n");
     98    fprintf (stderr, "  options:\n");
     99    fprintf (stderr, "    -v : verbose mode\n");
     100    fprintf (stderr, "    -ubercal : interpret zpt file as a GPC1 ubercal FITS table\n");
     101    fprintf (stderr, "    -update : actually write results to detections tables\n");
     102    fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
    98103    exit (2);
    99104  }
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize.c

    r31160 r33114  
    2323void initialize_setphot (int argc, char **argv) {
    2424
     25  struct stat statbuffer;
     26
     27  char CatdirPhotcodeFile[256];
     28
    2529  /* are these set correctly? */
    2630  ConfigInit (&argc, argv);
    2731  args_setphot (argc, argv);
     32
     33  if (stat (CATDIR, &statbuffer)) {
     34    fprintf (stderr, "error accessing dvo database directory '%s'\n", CATDIR);
     35    exit (1);
     36  }
     37
     38  /* XXX this does not yet write out the master photcode table */
     39  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
     40  if (!LoadPhotcodes (CatdirPhotcodeFile, NULL, TRUE)) {
     41    fprintf (stderr, "error loading photcode table %s\n", CatdirPhotcodeFile);
     42    exit (1);
     43  }
     44
     45  // we have hard-coded the MJD season ranges from Eddie in uniphot.h
     46
     47  double tstart_mjd[] = {55000.0, 55296.0, 55327.0, 55662.0};
     48  double tstop_mjd[]  = {55296.0, 55327.0, 55662.0, 60000.0};
     49  filter[0] = 'g';
     50  filter[1] = 'r';
     51  filter[2] = 'i';
     52  filter[3] = 'z';
     53  filter[4] = 'y';
     54
     55  int i;
     56  for (i = 0; i < NSEASON; i++) {
     57    tstart[i] = ohana_mjd_to_sec(tstart_mjd[i]);
     58    tstop[i]  = ohana_mjd_to_sec(tstop_mjd[i]);
     59  }
    2860}
    2961
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c

    r33104 r33114  
    4141  return zpts;
    4242}
    43 
    44 # define NFILTER 5
    45 # define NSEASON 4
    46 
    47 char   filter[NFILTER] = {'g', 'r', 'i', 'z', 'y'};
    48 double tstart[NSEASON] = {55000.0, 55296.0, 55327.0, 55662.0};
    49 double tstop[NSEASON]  = {55296.0, 55327.0, 55662.0, 60000.0};
    50 
    51 # define NCHIP_X 8
    52 # define NCHIP_Y 8
    53 # define NCELL_X 2
    54 # define NCELL_Y 2
    5543
    5644ZptTable *load_zpt_ubercal (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable) {
     
    9785  ALLOCATE (flatcorrTable->corr, FlatCorrection, flatcorrTable->Ncorr);
    9886  ALLOCATE (flatcorrTable->image, FlatCorrectionImage, flatcorrTable->Nimage);
     87  memset (flatcorrTable->corr, 0, flatcorrTable->Ncorr*sizeof(FlatCorrection));
    9988
    10089  int corrID = 1;
     
    10695
    10796    // read the fits table bytes
    108     if (gfits_fread_ftable_data (f, &ftable, FALSE)) return (NULL);
     97    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (NULL);
    10998 
    11099    // skip over remaining bytes in data segment
     
    118107    assert (!strcmp(type, "double"));
    119108     
    120     double *zperr = gfits_get_bintable_column_data (&theader, &ftable, "resid", type, &Nrow, &Ncol);
    121     assert (!strcmp(type, "double"));
     109    float *zperr = gfits_get_bintable_column_data (&theader, &ftable, "resid", type, &Nrow, &Ncol);
     110    assert (!strcmp(type, "float"));
    122111     
    123112    NZPTS += Nrow;
     
    136125
    137126    // read the fits table bytes
    138     if (gfits_fread_matrix (f, &matrix, FALSE)) return (NULL);
     127    if (!gfits_fread_matrix (f, &matrix, &header)) return (NULL);
    139128
    140129    for (nseason = 0; nseason < NSEASON; nseason++) { // seasons
    141130      for (iy = 0; iy < NCHIP_Y; iy++) { // y-chip
    142131        for (ix = 0; ix < NCHIP_X; ix++) { // x-chip
     132
     133          // photcode name
     134          char photname[64];
     135          snprintf (photname, 64, "GPC1.%c.XY%d%d", filter[nfilter], ix, iy);
     136          // note that the XY00, XY07, etc, chips will have photcode values of 0
     137
     138          flatcorrTable->image[Nimage].photcode = GetPhotcodeCodebyName(photname);
    143139          flatcorrTable->image[Nimage].Nx = NCELL_X;
    144140          flatcorrTable->image[Nimage].Ny = NCELL_Y;
     
    146142          flatcorrTable->image[Nimage].DX = 4880;
    147143          flatcorrTable->image[Nimage].DY = 4864;
    148           flatcorrTable->image[Nimage].tstart = ohana_mjd_to_sec(tstart[nseason]);
    149           flatcorrTable->image[Nimage].tstop  = ohana_mjd_to_sec(tstop[nseason]);
    150          
    151           // photcode name
    152           char photname[64];
    153           snprintf (photname, 64, "GPC1.%c.XY%d%d", filter[nfilter], ix, iy);
    154           // note that the XY00, XY07, etc, chips will have photcode values of 0
    155           flatcorrTable->image[Nimage].photcode = GetPhotcodeCodebyName(photname);
    156144          flatcorrTable->image[Nimage].tstart = tstart[nseason];
    157145          flatcorrTable->image[Nimage].tstop  = tstop[nseason];
     
    160148            for (ixc = 0; ixc < NCELL_X; ixc++) {
    161149              if (ix > 3) {
    162                 seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + NCELL_Y - 1 - iyc)*NCHIP_X + (ix*NCELL_X + NCELL_X - 1 - ixc);
     150                seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + NCELL_Y - 1 - iyc)*NCHIP_X*NCELL_X + (ix*NCELL_X + NCELL_X - 1 - ixc);
    163151              } else {
    164                 seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + iyc)*NCHIP_X + (ix*NCELL_X + ixc);
     152                seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + iyc)*NCHIP_X*NCELL_X + (ix*NCELL_X + ixc);
    165153              }
     154              assert (!flatcorrTable->corr[seq].ID);
    166155              flatcorrTable->corr[seq].x = ixc;
    167156              flatcorrTable->corr[seq].y = iyc;
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_flatcorr_to_images.c

    r33104 r33114  
    11# include "uniphot.h"
     2
     3// the date/time of the image is used to find the 'season'
     4// the photcode is used to find the actual flat correction
    25
    36int match_flatcorr_to_images (Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable) {
     
    58  int i, j;
    69
     10  // make 4 lookup tables for the photcodes (one for each season)
     11
     12  short **index;
     13
     14  short maxCode = 0;
     15  for (i = 0; i < flatcorrTable->Nimage; i++) {
     16    maxCode = MAX (maxCode, flatcorrTable->image[i].photcode);
     17  }
     18  maxCode ++; // we want the outer bound, not the last value
     19
     20  ALLOCATE (index, short *, NSEASON);
     21  for (i = 0; i < NSEASON; i++) {
     22      ALLOCATE (index[i], short, maxCode);
     23      for (j = 0; j < maxCode; j++) {
     24        index[i][j] = -1;
     25      }
     26  }
     27
     28  for (j = 0; j < NSEASON; j++) {
     29    assert (tstart[j]);
     30    assert (tstop[j]);
     31  }
     32
     33  for (i = 0; i < flatcorrTable->Nimage; i++) {
     34    // the flat-field correction is defined for non-existent images (eg, XY00)
     35    // these have photcode == 0, so skip them
     36    if (!flatcorrTable->image[i].photcode) continue;
     37
     38    // which season?
     39    for (j = 0; j < NSEASON; j++) {
     40      if (flatcorrTable->image[i].tstart == tstart[j]) {
     41        assert (index[j][flatcorrTable->image[i].photcode] == -1);
     42        index[j][flatcorrTable->image[i].photcode] = i;
     43        break;
     44      }
     45    }
     46  }
     47
    748  for (i = 0; i < Nimage; i++) {
     49    if (!image[i].photcode) continue; // skip PHU images
    850
    951    int found = FALSE;
    10     for (j = 0; !found && (j < flatcorrTable->Nimage); j++) {
     52    for (j = 0; !found && (j < NSEASON); j++) {
     53      if (image[i].tzero < tstart[j]) continue;
     54      if (image[i].tzero > tstop[j]) continue;
    1155
    12       if (image[i].tzero < flatcorrTable->image[j].tstart) continue;
    13       if (image[i].tzero > flatcorrTable->image[j].tstop) continue;
    14       if (image[i].photcode != flatcorrTable->image[j].photcode) continue;
    15       image[i].photom_map_id = flatcorrTable->image[j].ID;
     56      int seq = index[j][image[i].photcode];
     57      if (seq == -1) break;
     58
     59      image[i].photom_map_id = flatcorrTable->image[seq].ID;
    1660      found = TRUE;
    1761    }
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_zpts_to_images.c

    r29001 r33114  
    4242  for (i = Nz = 0; (i < Nimage) && (Nz < Nzpts); ) {
    4343
    44     if (i % 1000 == 0) fprintf (stderr, ".");
    45     if (Nz % 100 == 0) fprintf (stderr, "!");
     44    // if (i % 1000 == 0) fprintf (stderr, ".");
     45    // if (Nz % 100 == 0) fprintf (stderr, "!");
    4646
    4747    Ni = index[i];
Note: See TracChangeset for help on using the changeset viewer.