IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39299 for trunk


Ignore:
Timestamp:
Jan 1, 2016, 3:04:44 PM (11 years ago)
Author:
eugene
Message:

adding option to match by extern id

Location:
trunk/Ohana/src/dvomerge
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r39281 r39299  
    4646char  *UPDATE_CATCOMPRESS;
    4747
     48int    MATCH_BY_EXTERN_ID;
     49
    4850int    MATCHED_TABLES;
    4951int    REPAIR_BY_OBJID;
     
    202204off_t      getTgtIndex            PROTO((e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt));
    203205void       SortTgtByTimes         PROTO((e_time *S, off_t *I, short *C, off_t N));
    204 int        dvo_image_match_dbs    PROTO((IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src));
    205206int        dvomergeImagesGetMap   PROTO((IDmapType *IDmap, char *input, char *output));
    206207int        dvomergeFromList       PROTO((int argc, char **argv));
    207208int        dvomergeUpdate_threaded PROTO((int argc, char **argv));
    208209int        dvomergeUpdate_catalogs PROTO((char *input, char *output, SkyTable *outsky, SkyList *inlist, int NsecfiltInput, int NsecfiltOutput, IDmapType *IDmap, int *secfiltMap));
     210
     211int        dvo_image_match_dbs_by_time_and_photcode PROTO((IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src));
     212int        dvo_image_match_dbs_by_extern_id         PROTO((IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src));
    209213
    210214int        replace_match           PROTO((Average *average_out, Measure *measure_out, off_t *next_meas, Average *average_in, Measure *measure_in));
  • trunk/Ohana/src/dvomerge/src/args.c

    r38986 r39299  
    4444  if ((N = get_argument (*argc, argv, "-matched-tables"))) {
    4545    MATCHED_TABLES = TRUE;
     46    remove_argument (N, argc, argv);
     47  }
     48
     49  /* extra error messages */
     50  MATCH_BY_EXTERN_ID = FALSE;
     51  if ((N = get_argument (*argc, argv, "-match-by-extern-id"))) {
     52    MATCH_BY_EXTERN_ID = TRUE;
    4653    remove_argument (N, argc, argv);
    4754  }
     
    245252  }
    246253
     254  /* extra error messages */
     255  MATCH_BY_EXTERN_ID = FALSE;
     256  if ((N = get_argument (*argc, argv, "-match-by-extern-id"))) {
     257    MATCH_BY_EXTERN_ID = TRUE;
     258    remove_argument (N, argc, argv);
     259  }
     260
    247261  UPDATE_CATFORMAT = NULL;
    248262  if ((N = get_argument (*argc, argv, "-update-catformat"))) {
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r39142 r39299  
    33// utility functions
    44void sort_IDmap (IDmapType *IDmap);
     5
    56void SortTgtByTimes (e_time *S, off_t *I, short *C, off_t N);
    6 off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt);
     7void SortTgtByExtID (unsigned int *S, off_t *I, off_t N);
     8
     9off_t getTgtIndexByExtID (unsigned int extID, off_t *TgtIndex, unsigned int *TgtExtID, off_t NimagesTgt);
     10off_t getTgtIndexByTimeAndPhotcode (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt);
    711
    812void dvo_image_map_init (IDmapType *IDmap) {
     
    2226
    2327// we have two tables; 'tgt' contains some exposures from 'src' : find them and match a map
    24 int dvo_image_match_dbs (IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src) {
     28int dvo_image_match_dbs_by_extern_id (IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src) {
     29
     30  Image *imagesSrc, *imagesTgt;
     31  off_t NimagesSrc, NimagesTgt;
     32  off_t iSrc, iTgt;
     33  off_t  *TgtIndex;
     34  unsigned int *TgtExtID;
     35 
     36  imagesSrc = gfits_table_get_Image (&src[0].ftable, &NimagesSrc, &src[0].scaledValue, &src[0].nativeOrder);
     37  if (!imagesSrc) {
     38    fprintf (stderr, "ERROR: failed to read images from src\n");
     39    exit (2);
     40  }
     41
     42  imagesTgt = gfits_table_get_Image (&tgt[0].ftable, &NimagesTgt, &tgt[0].scaledValue, &tgt[0].nativeOrder);
     43  if (!imagesTgt) {
     44    fprintf (stderr, "ERROR: failed to read images from tgt\n");
     45    exit (2);
     46  }
     47
     48  ALLOCATE (IDmap->old, unsigned int, NimagesSrc);
     49  ALLOCATE (IDmap->new, unsigned int, NimagesSrc);
     50  IDmap->Nmap = NimagesSrc;
     51
     52  // match by time and photcode
     53  ALLOCATE (TgtIndex, off_t,        NimagesTgt);
     54  ALLOCATE (TgtExtID, unsigned int, NimagesTgt);
     55
     56  // save the Index, Times, Codes for all TGT images
     57  for (iTgt = 0; iTgt < NimagesTgt; iTgt++) {
     58    TgtIndex[iTgt] = iTgt;
     59    TgtExtID[iTgt] = imagesTgt[iTgt].externID;
     60  }
     61
     62  // sort the index, start, and stop by the start times:
     63  SortTgtByExtID (TgtExtID, TgtIndex, NimagesTgt);
     64
     65  for (iSrc = 0; iSrc < NimagesSrc; iSrc++) {
     66    iTgt = getTgtIndexByExtID (imagesSrc[iSrc].externID, TgtIndex, TgtExtID, NimagesTgt);
     67    if (iTgt < 0) Shutdown ("failure to find matching image: %s\n", imagesSrc[iSrc].name);
     68    IDmap[0].old[iSrc] = imagesSrc[iSrc].imageID;
     69    IDmap[0].new[iSrc] = imagesTgt[iTgt].imageID;
     70  }
     71
     72  create_IDmap_lookup (IDmap);
     73
     74  FREE(TgtIndex);
     75  FREE(TgtExtID);
     76
     77  // sort IDmap->old,new on the basis of IDmap->old:
     78  sort_IDmap (IDmap);
     79
     80  return TRUE;
     81}
     82
     83// we have two tables; 'tgt' contains some exposures from 'src' : find them and match a map
     84int dvo_image_match_dbs_by_time_and_photcode (IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src) {
    2585
    2686  Image *imagesSrc, *imagesTgt;
     
    63123
    64124  for (iSrc = 0; iSrc < NimagesSrc; iSrc++) {
    65     iTgt = getTgtIndex (imagesSrc[iSrc].tzero, imagesSrc[iSrc].tzero + (int) imagesSrc[iSrc].exptime, imagesSrc[iSrc].photcode, TgtIndex, TgtTimes, TgtCodes, NimagesTgt);
     125    iTgt = getTgtIndexByTimeAndPhotcode (imagesSrc[iSrc].tzero, imagesSrc[iSrc].tzero + (int) imagesSrc[iSrc].exptime, imagesSrc[iSrc].photcode, TgtIndex, TgtTimes, TgtCodes, NimagesTgt);
    66126    if (iTgt < 0) Shutdown ("failure to match images: %s\n", imagesSrc[iSrc].name);
    67127    IDmap[0].old[iSrc] = imagesSrc[iSrc].imageID;
     
    256316}
    257317
    258 off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt) {
     318off_t getTgtIndexByExtID (unsigned int extID, off_t *TgtIndex, unsigned int *TgtExtID, off_t NimagesTgt) {
     319
     320  // use bisection to find the starting entry by time
     321
     322  off_t Nlo, Nhi, N;
     323
     324  // find the last TGT before start
     325  Nlo = 0; Nhi = NimagesTgt;
     326  while (Nhi - Nlo > 10) {
     327    N = 0.5*(Nlo + Nhi);
     328    if (TgtExtID[N] < extID) {
     329      Nlo = MAX(N, 0);
     330    } else {
     331      Nhi = MIN(N + 1, NimagesTgt);
     332    }
     333  }
     334
     335  // check for the matched mosaic starting from Nlo
     336  // we may have to go much beyond Nlo since stop is not sorted
     337  // can we use a sorted version of stop to check when we are beyond the valid range??
     338  for (N = Nlo; N < NimagesTgt; N++) {
     339    if (TgtExtID[N] < extID) continue;
     340    if (TgtExtID[N] > extID) return (-1);
     341    return (TgtIndex[N]);
     342  }
     343  return (-1);
     344}
     345
     346off_t getTgtIndexByTimeAndPhotcode (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt) {
    259347
    260348  // use bisection to find the starting entry by time
     
    302390}
    303391
     392// sort two times vectors and an index by first time vector
     393void SortTgtByExtID (unsigned int *S, off_t *I, off_t N) {
     394
     395# define SWAPFUNC(A,B){ unsigned int tmp_s; off_t tmp_i;        \
     396  tmp_s = S[A]; S[A] = S[B]; S[B] = tmp_s; \
     397  tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \
     398}
     399# define COMPARE(A,B)(S[A] < S[B])
     400
     401  OHANA_SORT (N, COMPARE, SWAPFUNC);
     402
     403# undef SWAPFUNC
     404# undef COMPARE
     405}
     406
    304407// we need a lookup table of length (oldIDmax + 1) to record if a given oldIDmax has not been found in Tgt
    305408int create_IDmap_lookup (IDmapType *IDmap) {
  • trunk/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r38553 r39299  
    6262    // if so, then just match the image IDs
    6363    if (VERBOSE) fprintf (stderr, "already merged image table\n");
    64     dvo_image_match_dbs(IDmap, &outDB, &inDB);
     64    if (MATCH_BY_EXTERN_ID) {
     65      dvo_image_match_dbs_by_extern_id(IDmap, &outDB, &inDB);
     66    } else {
     67      dvo_image_match_dbs_by_time_and_photcode(IDmap, &outDB, &inDB);
     68    }
    6569    dvo_image_unlock (&outDB); // unlock output
    6670
     
    145149
    146150  // convert database table to internal structure & add to output image db
    147   dvo_image_match_dbs(IDmap, &outDB, &inDB);
     151  if (MATCH_BY_EXTERN_ID) {
     152    dvo_image_match_dbs_by_extern_id(IDmap, &outDB, &inDB);
     153  } else {
     154    dvo_image_match_dbs_by_time_and_photcode(IDmap, &outDB, &inDB);
     155  }
     156  // dvo_image_match_dbs(IDmap, &outDB, &inDB);
    148157
    149158  gfits_db_free (&inDB);
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r38986 r39299  
    300300    if (FORCE_MERGE)         { strextend (&command, "-force-merge"); }
    301301    if (MATCHED_TABLES)      { strextend (&command, "-matched-tables"); }
     302    if (MATCH_BY_EXTERN_ID)  { strextend (&command, "-match-by-extern-id"); }
    302303    if (UPDATE_CATFORMAT)    { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
    303304    if (UPDATE_CATCOMPRESS)  { strextend (&command, "-update-catcompress %s", UPDATE_CATCOMPRESS); }
Note: See TracChangeset for help on using the changeset viewer.