IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35255


Ignore:
Timestamp:
Mar 7, 2013, 4:33:58 AM (13 years ago)
Author:
eugene
Message:

add test for existing externID entries

Location:
branches/eam_branches/ipp-20130306/Ohana/src/addstar
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/Makefile

    r34405 r35255  
    9090$(SRC)/GetFileMode.$(ARCH).o \
    9191$(SRC)/ReadImageHeader.$(ARCH).o \
     92$(SRC)/ExternImageIDs.$(ARCH).o \
    9293$(SRC)/UpdateImageIDs.$(ARCH).o \
    9394$(SRC)/update_coords.$(ARCH).o \
     
    207208$(SRC)/ReadStarsTEXT.$(ARCH).o \
    208209$(SRC)/ReadStarsSDSS.$(ARCH).o \
     210$(SRC)/ExternImageIDs.$(ARCH).o \
    209211$(SRC)/UpdateImageIDs.$(ARCH).o \
    210212$(SRC)/FilterStars.$(ARCH).o \
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/include/addstar.h

    r34405 r35255  
    5656  char *refcat;
    5757} DVO_DATA;
     58
     59# define IDTYPE int
     60
     61typedef struct {
     62  IDTYPE Nimage;
     63  IDTYPE minID;
     64  IDTYPE maxID;
     65  IDTYPE range;
     66  IDTYPE *imageID;
     67  IDTYPE *externID;
     68  char *found;
     69} ExtID_Index;
    5870
    5971typedef struct sockaddr_in SockAddress;
     
    275287int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages);
    276288
     289int CheckDuplicateImageIDs (Image *images, off_t Nimages);
     290
    277291int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages);
    278292int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars);
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/ExternImageIDs.c

    r35254 r35255  
    11# include "addstar.h"
    2 
    3 typedef struct {
    4   off_t Nimage;
    5   off_t minID;
    6   off_t maxID;
    7   off_t range;
    8   off_t *value;
    9   char *found;
    10 } ExtID_Index;
    112
    123ExtID_Index *ExtID_Load (char *filename) {
     
    2415  FILE *f = fopen (filename, "r");
    2516  if (!f) {
    26     fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
     17    fprintf (stderr, "ERROR: cannot open imageID/externID file %s\n", filename);
    2718    return NULL;
    2819  }
     
    3021  /* load in PHU segment (ignore) */
    3122  if (!gfits_fread_header (f, &header)) {
    32     if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
     23    if (VERBOSE) fprintf (stderr, "can't read imageID/externID header\n");
    3324    fclose (f);
    3425    return NULL;
    3526  }
    3627  if (!gfits_fread_matrix (f, &matrix, &header)) {
    37     if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
     28    if (VERBOSE) fprintf (stderr, "can't read imageID/externID matrix\n");
    3829    gfits_free_header (&header);
    3930    fclose (f);
     
    5647  fclose (f);
    5748
    58   // a bit annoying : we read the entire block of data, then extract the columns, then set the image structure values.
    59   // this means I need 3 copies in memory at some point.  ugh.
     49  char type[16];
     50  extID->externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
     51  myAssert (!strcmp(type, "int"), "wrong column type");
    6052
    61   char type[16];
    62 
    63   extID->value = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
     53  extID->imageID  = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol);
    6454  myAssert (!strcmp(type, "int"), "wrong column type");
    6555
    6656  extID->Nimage = Nrow;
    6757
     58  // find the range of externID values
    6859  extID->minID = -1;
    6960  extID->maxID = -1;
    7061  for (i = 0; i < extID->Nimage; i++) {
    71     if (extID->minID == -1) extID->minID = extID->value[i];
    72     extID->minID = MIN(extID->minID, extID->value[i]);
    73     extID->maxID = MAX(extID->maxID, extID->value[i]);
     62    if (extID->minID == -1) extID->minID = extID->externID[i];
     63    extID->minID = MIN(extID->minID, extID->externID[i]);
     64    extID->maxID = MAX(extID->maxID, extID->externID[i]);
    7465  }
    7566  extID->range = extID->maxID- extID->minID + 1;
    7667 
     68  // init the index
    7769  ALLOCATE (extID->found, char, extID->range);
    7870  for (i = 0; i < extID->range; i++) extID->found[i] = FALSE;
    7971
     72  // generate the index (set this value to the imageID?)
    8073  for (i = 0; i < extID->Nimage; i++) {
    81     off_t N = extID->value[i] - extID->minID;
    82     extID->found[N] = TRUE
     74    IDTYPE N = extID->externID[i] - extID->minID;
     75    extID->found[N] = TRUE;
    8376  }
    8477
     
    8679}
    8780
     81// STATUS is value expected for success
     82# define CHECK_STATUS(STATUS,MSG,...)                                   \
     83  if (!(STATUS)) {                                                      \
     84    fprintf (stderr, MSG, __VA_ARGS__);                                 \
     85    return FALSE;                                                       \
     86  }
     87
     88int ExtID_Save (char *filename, ExtID_Index *extID) {
     89
     90  Header header;
     91  Header theader;
     92  Matrix matrix;
     93  FTable ftable;
     94
     95  gfits_init_header (&header);
     96  header.extend = TRUE;
     97  gfits_create_header (&header);
     98  gfits_create_matrix (&header, &matrix);
     99
     100  gfits_create_table_header (&theader, "BINTABLE", "EXTERN_ID");
     101  gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 0);
     102  gfits_define_bintable_column (&theader, "J", "EXTERN_ID", "extern ID", NULL, 1.0, 0);
     103
     104  // generate the output array that carries the data
     105  gfits_create_table (&theader, &ftable);
     106
     107  // add the columns to the output array
     108  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",       extID->imageID,  extID->Nimage);
     109  gfits_set_bintable_column (&theader, &ftable, "EXTERN_ID",      extID->externID, extID->Nimage);
     110
     111  FILE *f = fopen (filename, "w");
     112  if (!f) {
     113    fprintf (stderr, "ERROR: cannot open extID file for output %s\n", filename);
     114    return FALSE;
     115  }
     116
     117  int status;
     118  status = gfits_fwrite_header  (f, &header);
     119  CHECK_STATUS (status, "ERROR: cannot write header for imageID/externID %s\n", filename);
     120
     121  status = gfits_fwrite_matrix  (f, &matrix);
     122  CHECK_STATUS (status, "ERROR: cannot write matrix for imageID/externID %s\n", filename);
     123
     124  status = gfits_fwrite_Theader (f, &theader);
     125  CHECK_STATUS (status, "ERROR: cannot write table header for imageID/externID %s\n", filename);
     126
     127  status = gfits_fwrite_table  (f, &ftable);
     128  CHECK_STATUS (status, "ERROR: cannot write table data for imageID/externID %s\n", filename);
     129
     130  gfits_free_header (&header);
     131  gfits_free_matrix (&matrix);
     132  gfits_free_header (&theader);
     133  gfits_free_table (&ftable);
     134
     135  int fd = fileno (f);
     136
     137  status = fflush (f);
     138  CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename);
     139
     140  status = fsync (fd);
     141  CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename);
     142
     143  status = fclose (f);
     144  CHECK_STATUS (!status, "ERROR: problem closing imageID/externID file %s\n", filename);
     145
     146  return TRUE;
     147}
     148
    88149int CheckDuplicateImageIDs (Image *images, off_t Nimages) {
     150
     151  IDTYPE i, offset;
    89152
    90153  // load the image ID table
     
    94157  ExtID_Index *extID = ExtID_Load (filename);
    95158
    96   for (i = 0; i < Nimages; i++) {
    97     off_t ID = images[i].externID;
     159  // if we
     160
     161  for (i = 0; extID && (i < Nimages); i++) {
     162    IDTYPE ID = images[i].externID;
    98163    if (ID == 0) continue;
    99164
     
    106171
    107172    if (!extID->found[offset]) continue;
    108     fprintf (stderr, "duplicate external image ID "OFF_T_FMT" found, exiting\n", extID);
     173    fprintf (stderr, "duplicate external image ID %lld found, exiting\n", (long long) ID);
    109174    exit (1);
    110175  }
    111176 
     177  if (!extID) {
     178    ALLOCATE (extID, ExtID_Index, 1);
     179    ALLOCATE (extID->imageID,  IDTYPE, 1);
     180    ALLOCATE (extID->externID, IDTYPE, 1);
     181    extID->Nimage = 0;
     182  }
     183
     184  // extend the storage arrays
     185  REALLOCATE (extID->imageID,  IDTYPE, extID->Nimage + Nimages);
     186  REALLOCATE (extID->externID, IDTYPE, extID->Nimage + Nimages);
     187
    112188  // append the new ext IDs and save
    113189  for (i = 0; i < Nimages; i++) {
    114     append();
     190    if (images[i].externID == 0) continue;
     191    extID->imageID[extID->Nimage] = images[i].imageID;
     192    extID->externID[extID->Nimage] = images[i].externID;
     193    extID->Nimage ++;
    115194  }
    116195
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/UpdateImageIDs.c

    r28248 r35255  
    5151  }
    5252
     53  // set and update the imageID sequence
     54  CheckDuplicateImageIDs (images, Nimages);
     55
    5356  imageID += Nimages;
    5457  status = gfits_modify (&db.header, "IMAGEID", "%u", 1, imageID);
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/addstar.c

    r35253 r35255  
    5656
    5757      // set and update the imageID sequence
    58       CheckDuplicateImageIDs (images, Nimages);
    59 
    60       // set and update the imageID sequence
    6158      UpdateImageIDs (stars, Nstars, images, Nimages);
    6259
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/test/simple.dvo

    r34405 r35255  
    6868
    6969  for i 0 $testfields:n
     70    if ($TAP_VERBOSE) echo $testfields:$i
    7071    list name -split $testfields:$i
    7172    if ("$name:0" == "SKIP") continue
     
    337338  PSF_INST_FLUX     : SKIP # not ingested into DVO
    338339  PSF_INST_FLUX_SIG : SKIP # not ingested into DVO
    339   AP_MAG_STANDARD   : mag:aperinst # FAIL
     340  AP_MAG            : mag:aperinst # FAIL
    340341  AP_MAG_RAW        : SKIP # not ingested into DVO
    341342  AP_MAG_RADIUS     : SKIP # not ingested into DVO
     
    346347  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
    347348  SKY               : sky       
    348   SKY_SIG           : sky_err   
     349  SKY_SIGMA         : sky_err   
    349350  PSF_CHISQ         : psf_chisq
    350351  CR_NSIGMA         : cr_nsigma
Note: See TracChangeset for help on using the changeset viewer.