IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2012, 3:24:39 PM (14 years ago)
Author:
eugene
Message:

support for parallel dvo in mextract, avextract, avmerge, gstar, gcat; remove some if-def-ed out code already moved to libdvo; list -vectors and -buffers options (store names of vectors and buffers in lists); list -copy give error if missing source; catlist, hosts & remote functions to support parallel dvos; skyregion -save option; new skycoverage modes (-min-ubercal; -min-dmag-sys; -min-mcal; -max-mcal); gstar output formatting cleanups; add more average info to gstar output; functions for spectral similarity analysis; coords returns nans for projections off the sphere; fix cumulative function; add name:type option to opihi/read function (eg read a:float 2 b:time 3 c:int 4); line -frac option; vtype function to get vector types; threshold function; write -fits option; code for unfinished mtype function (matching vtype)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo/avmatch.c

    r28241 r33662  
    1414 
    1515  off_t i, j, n, m, *index;
    16   int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt;
     16  int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt, Ninvec;
    1717  int VERBOSE;
    18   char name[1024];
     18  char name[1024], *found;
    1919  void *Signal;
    2020  float RADIUS;
     
    2222  Catalog catalog;
    2323
    24   Vector **vec, *RAvec, *DECvec;
     24  Vector **vec, **invec, *RAvec, *DECvec;
    2525  dbField *fields;
    2626  dbValue *values;
     
    2929  /* defaults */
    3030  vec = NULL;
     31  invec = NULL;
    3132  fields = NULL;
    3233  values = NULL;
    3334  skylist = NULL;
     35  Ninvec = 0;
    3436
    3537  if ((N = get_argument (argc, argv, "-h"))) goto help;
    3638  if ((N = get_argument (argc, argv, "--help"))) goto help;
    37   if (argc < 5) goto help;
    3839
    3940  VERBOSE = FALSE;
     
    4344  }
    4445
     46  int PARALLEL = FALSE;
     47  if ((N = get_argument (argc, argv, "-parallel"))) {
     48    remove_argument (N, &argc, argv);
     49    PARALLEL = TRUE;
     50  }
     51
     52  // dump results directly to fits file (esp for parallel dvo)
     53  char *CoordsFile = NULL;
     54  if ((N = get_argument (argc, argv, "-coords"))) {
     55    remove_argument (N, &argc, argv);
     56    CoordsFile = strcreate(argv[N]);
     57    remove_argument (N, &argc, argv);
     58  }
     59
     60  if (!CoordsFile && (argc < 5)) goto help;
     61  if ( CoordsFile && (argc < 3)) goto help;
     62
    4563  dvo_catalog_init (&catalog, TRUE);
    4664
     
    4967  Nsecfilt = GetPhotcodeNsecfilt ();
    5068
     69  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     70  RAvec  = NULL;
     71  DECvec = NULL;
     72  if (PARALLEL && !HOST_ID) {
     73    if (!CoordsFile) {
     74      // get vectors corresponding to coordinates of interest
     75      if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     76      if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     77     
     78      ALLOCATE (vec, Vector *, 2);
     79      vec[0] = RAvec;
     80      vec[1] = DECvec;
     81
     82      CoordsFile = abspath("coords.fits", 1024);
     83      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     84      if (!status) goto escape;
     85    }
     86
     87    char *targv1 = argv[1];
     88    char *targv2 = argv[2];
     89    argv[1] = strcreate ("-coords");
     90    argv[2] = strcreate (CoordsFile);
     91    free (CoordsFile);
     92
     93    // I need to pass the RA & DEC vectors to the remote clients...
     94    int status = HostTableParallelOps (argc, argv, RESULT_FILE, RAvec->Nelements, VERBOSE);
     95    if (vec) free (vec);
     96   
     97    free (argv[1]);
     98    free (argv[2]);
     99    argv[1] = targv1;
     100    argv[2] = targv2;
     101
     102    return status;
     103  }
     104
    51105  // get vectors corresponding to coordinates of interest
    52   if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
    53   if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
    54   RADIUS = atof (argv[3]);
    55 
    56   // strip off RA, DEC, RADIUS arguments
    57   remove_argument (1, &argc, argv);
    58   remove_argument (1, &argc, argv);
     106  if (CoordsFile) {
     107    // read RAvec, DECvec from coords file (1st 2 fields?)
     108    Ninvec = 0;
     109    invec = ReadVectorTableFITS (CoordsFile, "COORDS", &Ninvec);
     110    RAvec = invec[0];
     111    DECvec = invec[1];
     112  } else {
     113    if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
     114    if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
     115    // strip off RA & DEC
     116    remove_argument (1, &argc, argv);
     117    remove_argument (1, &argc, argv);
     118  }
     119  RADIUS = atof (argv[1]);
    59120  remove_argument (1, &argc, argv);
    60121
     
    92153  }
    93154  ALLOCATE (index, off_t, NPTS);
     155  ALLOCATE (found, char, NPTS);
     156  memset (found, 0, NPTS*sizeof(char));
    94157
    95158  // grab data from all selected sky regions
     
    97160  interrupt = FALSE;
    98161  for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) {
     162
     163    // does this host ID match the desired location for the table?
     164    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
     165
    99166    /* lock, load, unlock catalog */
    100     catalog.filename = skylist[0].filename[i];
     167    char hostfile[1024];
     168    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     169    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    101170    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    102171    catalog.Nsecfilt = 0;
     
    124193      if (Ncat == -2) continue;
    125194
    126       // XXX set a 'found' vector to double check we catch everything?
    127195      m = catalog.average[Ncat].measureOffset;
    128196
     
    141209        }
    142210      }
     211      found[Npts] = TRUE;
    143212    }
    144213    dvo_catalog_free (&catalog);
     
    147216  interrupt = FALSE;
    148217
     218  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
     219  // only write the fields which were in a valid catalog
     220  if (RESULT_FILE) {
     221    // extend the array by one to hold index array
     222    REALLOCATE (vec, Vector *, Nfields + 1);
     223    vec[Nfields] = InitVector();
     224    strcpy (vec[Nfields]->name, "index");
     225    ResetVector (vec[Nfields], OPIHI_INT, NPTS);
     226    Vector *idxVec = vec[Nfields];
     227
     228    // only write out the rows which were found
     229    Npts = 0;
     230    for (i = 0; i < NPTS; i++) {
     231      if (!found[i]) continue;
     232      idxVec->elements.Int[Npts] = i;
     233      Npts ++;
     234    }
     235    int Nfound = Npts;
     236    idxVec->Nelements = Nfound;
     237
     238    fprintf (stderr, "found %d of %d pts\n", Nfound, NPTS);
     239
     240    for (i = 0; i < Nfields; i++) {
     241      if (vec[i][0].type == OPIHI_FLT) {
     242        opihi_flt *tmp = NULL;
     243        ALLOCATE (tmp, opihi_flt, Nfound);
     244        Npts = 0;
     245        for (j = 0; j < NPTS; j++) {
     246          if (!found[j]) continue;
     247          tmp[Npts] = vec[i][0].elements.Flt[j];
     248          Npts++;
     249        }
     250        free (vec[i][0].elements.Flt);
     251        vec[i][0].elements.Flt = tmp;
     252      } else {
     253        opihi_int *tmp = NULL;
     254        ALLOCATE (tmp, opihi_int, Nfound);
     255        Npts = 0;
     256        for (j = 0; j < NPTS; j++) {
     257          if (!found[j]) continue;
     258          tmp[Npts] = vec[i][0].elements.Int[j];
     259          Npts++;
     260        }
     261        free (vec[i][0].elements.Int);
     262        vec[i][0].elements.Int = tmp;
     263      }
     264      vec[i][0].Nelements = Nfound;
     265    }
     266    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL);
     267    free (vec[Nfields]->elements.Int);
     268    free (vec[Nfields]);
     269    if (!status) goto escape;
     270  }
     271
    149272  if (vec) free (vec);
    150273  if (values) free (values);
     274  if (invec) FreeVectorArray (invec, Ninvec);
    151275  dbFreeFields (fields, Nfields);
    152276  SkyListFree (skylist);
     
    156280  if (vec) free (vec);
    157281  if (values) free (values);
     282  if (invec) FreeVectorArray (invec, Ninvec);
    158283  dbFreeFields (fields, Nfields);
    159284  SkyListFree (skylist);
     
    162287 help:
    163288  gprint (GP_ERR, "USAGE: avmatch (RA) (DEC) (RADIUS) field[,field,field...]\n");
     289  gprint (GP_ERR, "   OR: avmatch -coords (filename.fits) (RADIUS) field[,field,field...]\n");
    164290
    165291  if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
Note: See TracChangeset for help on using the changeset viewer.