IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40523


Ignore:
Timestamp:
Aug 30, 2018, 5:07:23 PM (8 years ago)
Author:
eugene
Message:

add avselect function to dvo (returns all matched objects within a radius of a list of points)

Location:
trunk/Ohana/src/opihi
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo/Makefile

    r40408 r40523  
    4646$(SRC)/avextract.$(ARCH).o              \
    4747$(SRC)/avmatch.$(ARCH).o                \
     48$(SRC)/avselect.$(ARCH).o               \
    4849$(SRC)/avperiodogram.$(ARCH).o          \
    4950$(SRC)/avperiodomatch.$(ARCH).o         \
  • trunk/Ohana/src/opihi/dvo/avmatch.c

    r39457 r40523  
    209209    }
    210210
    211     find_matches_by_vectors (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, index);
     211    find_matches_by_vectors_closest (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, index);
    212212
    213213    for (j = 0; (j < NPTS) && !interrupt; j++) {
  • trunk/Ohana/src/opihi/dvo/avperiodomatch.c

    r40408 r40523  
    264264    dvo_catalog_unlock (&catalog);
    265265
    266     find_matches_by_vectors (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, idxValue);
     266    find_matches_by_vectors_closest (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, idxValue);
    267267
    268268    // Scan the catalog for objects which match the WHERE clause
  • trunk/Ohana/src/opihi/dvo/find_matches.c

    r37807 r40523  
    55// attempt to match every RA,DEC entry with an entry in the catalog.  the result is stored in 'index'
    66// index >= 0 : valid match; index == -2 : no valid match; index == -1 : not contained by this catalog
    7 int find_matches_by_vectors (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index) {
     7int find_matches_by_vectors_closest (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index) {
    88
    99  off_t i, j, J, Jmin, Npoints, Nmatch;
     
    148148  return (TRUE);
    149149}
     150
     151// attempt to match every RA,DEC entry with an entry in the catalog.  the result is stored in 'result'
     152AvselectResult *find_matches_by_vectors_allmatch (SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *nresult) {
     153
     154  off_t i, j, J;
     155  double dX, dY, dR, Doff, Dmin, Dmax, Rmin, Rmax;
     156  int status;
     157  double RADIUS2;
     158  Coords tcoords;
     159
     160  // XXX dvoconvert does not correctly maintain 'sorted'
     161  // assert(catalog[0].sorted);
     162
     163  off_t Npoints = RAvec->Nelements;
     164
     165  /** allocate local arrays (points) **/
     166  ALLOCATE_PTR (X1, double, Npoints);
     167  ALLOCATE_PTR (Y1, double, Npoints);
     168  ALLOCATE_PTR (N1, off_t,  Npoints);
     169
     170  ALLOCATE_PTR (inCatalog, int,  Npoints);
     171
     172  /** allocate local arrays (catalog) **/
     173  off_t Nave = catalog[0].Naverage;
     174  ALLOCATE_PTR (X2, double, Nave);
     175  ALLOCATE_PTR (Y2, double, Nave);
     176  ALLOCATE_PTR (N2, off_t,  Nave);
     177
     178  off_t Nresult = 0;
     179  off_t NRESULT = 1000;
     180  ALLOCATE_PTR (result, AvselectResult, NRESULT);
     181
     182  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ARC projection has
     183   * the advantage that every point in R,D has a mapping to a unique X,Y.  However, note
     184   * that not all possible X,Y points map back to R,D and the local plate scale changes
     185   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
     186   */
     187  InitCoords (&tcoords, "DEC--ARC");
     188  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
     189  if (region[0].Dmax < 90) {
     190    tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
     191  } else {
     192    tcoords.crval2 = 90.0;
     193  }
     194  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
     195
     196  // this region includes a boundary layer of size RADIUS
     197  if (fabs(region[0].Dmin) < fabs(region[0].Dmax)) {
     198    Doff = RAD_DEG*region[0].Dmax;
     199  } else {
     200    Doff = RAD_DEG*region[0].Dmin;
     201  }   
     202  if (Doff < 80) {
     203    Rmin = region[0].Rmin - RADIUS / 3600.0 / cos(Doff);
     204    Rmax = region[0].Rmax + RADIUS / 3600.0 / cos(Doff);
     205  } else {
     206    Rmin = 0.0;
     207    Rmax = 360.0;
     208  }
     209  Dmin = region[0].Dmin - RADIUS / 3600.0;
     210  Dmax = region[0].Dmax + RADIUS / 3600.0;
     211
     212  // identify the entries contained by this catalog
     213  for (i = 0; i < Npoints; i++) {
     214    inCatalog[i] = FALSE;
     215    if (RAvec->elements.Flt[i] < Rmin) continue;
     216    if (RAvec->elements.Flt[i] > Rmax) continue;
     217    if (DECvec->elements.Flt[i] < Dmin) continue;
     218    if (DECvec->elements.Flt[i] > Dmax) continue;
     219    inCatalog[i] = TRUE;
     220  }
     221
     222  /* build spatial index (RA sort) referencing input array sequence */
     223  for (i = 0; i < Npoints; i++) {
     224    // we need to have a finite number for the sort below; inCatalog == 0 entries are skipped
     225    // in the matching process
     226    X1[i] = Y1[i] = 0.0;
     227    N1[i] = i;
     228    if (!inCatalog[i]) continue;
     229    status = RD_to_XY (&X1[i], &Y1[i], RAvec->elements.Flt[i], DECvec->elements.Flt[i], &tcoords);
     230    assert (status);
     231  }
     232  if (Npoints > 1) sort_coords_index (X1, Y1, N1, Npoints);
     233
     234  /* build spatial index (RA sort) */
     235  for (i = 0; i < Nave; i++) {
     236    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     237    N2[i] = i;
     238  }
     239  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
     240
     241  /* choose a radius for matches */
     242  RADIUS2 = RADIUS*RADIUS;
     243
     244# define NEXTi { i++; continue; }
     245# define NEXTj { j++; continue; }
     246                                                                                                                                                                                 
     247  /** find matched stars **/
     248  for (i = j = 0; (i < Npoints) && (j < Nave); ) {
     249    if (!inCatalog[N1[i]]) NEXTi;
     250    if (!finite(X1[i]) || !finite(Y1[i])) NEXTi;
     251    if (!finite(X2[j]) || !finite(Y2[j])) NEXTj;
     252   
     253    /* negative dX: j is too large */
     254    dX = X1[i] - X2[j];
     255    if (dX <= -1.02*RADIUS) NEXTi;
     256
     257    /* positive dX, i is too large */
     258    if (dX >= 1.02*RADIUS) NEXTj;
     259
     260    /* within match range; look for matches */
     261    for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) {
     262      /* find closest match for this detection */
     263      dX = X1[i] - X2[J];
     264      dY = Y1[i] - Y2[J];
     265      dR = dX*dX + dY*dY;
     266      if (dR > RADIUS2) continue;
     267
     268      /*** a match is found, set the result for this entry ***/
     269      result[Nresult].Ncat = N2[J];
     270      result[Nresult].Nseq = N1[i];
     271      result[Nresult].Roff = sqrt(dR);
     272
     273      Nresult ++;
     274      CHECK_REALLOCATE (result, AvselectResult, NRESULT, Nresult, 1000);
     275    }
     276    NEXTi;
     277  }
     278
     279  free (X1);
     280  free (Y1);
     281  free (N1);
     282  free (N2);
     283  free (X2);
     284  free (Y2);
     285
     286  *nresult = Nresult;
     287  return (result);
     288}
  • trunk/Ohana/src/opihi/dvo/init.c

    r40408 r40523  
    33int avextract       PROTO((int, char **));
    44int avmatch         PROTO((int, char **));
     5int avselect        PROTO((int, char **));
    56int avperiodogram   PROTO((int, char **));
    67int avperiodomatch  PROTO((int, char **));
     
    6970  {1, "avextract",   avextract,    "extract average data values"},
    7071  {1, "avmatch",     avmatch,      "extract average data values matched to RA,DEC points"},
     72  {1, "avselect",    avselect,     "extract average data values within range of a list of RA,DEC points"},
    7173  {1, "avperiodogram",  avperiodogram, "perform periodogram on objects based on restrictions"},
    7274  {1, "avperiodomatch", avperiodomatch, "perform periodogram on objects based on ra,dec list"},
  • trunk/Ohana/src/opihi/dvo/mmatch.c

    r39457 r40523  
    8484
    8585  // parse the fields to be extracted and returned
    86   int first = 3;
    87   if (CoordsFile) {
    88     first = 1;
    89   }
     86  // this is a syntax check that we can perform before reading the input vectors
     87  // NOTE: This block is missing in avmatch / avselect
     88  int first = CoordsFile ? 1 : 3;
    9089  fields = dbCmdlineFields (argc-first, &argv[first], DVO_TABLE_MEASURE, &last, &Nfields);
    9190  if (fields == NULL) goto help;
     
    166165    }     
    167166
     167    // NOTE: image metadata is only needed to mmatch (not avmatch) since measures are tied to images, not averages
    168168    if (loadImages) {
    169169      Image *image;
     
    245245    char hostfile[1024];
    246246    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     247
    247248    dvo_catalog_init (&catalog, TRUE);
    248249    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
     
    265266
    266267    // returns the matches to AVERAGE objects; what do we do for each MEASURE?
    267     find_matches_by_vectors (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, index);
     268    find_matches_by_vectors_closest (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, index);
    268269
    269270    for (j = 0; (j < Nelem) && !interrupt; j++) {
     
    331332  ClearInterrupt (old_sigaction);
    332333
     334  // XXXX ???? this seems odd
    333335  for (n = 0; n < Nfields; n++) {
    334336    ResetVector (vec[n], fields[n].type, Npts);
  • trunk/Ohana/src/opihi/include/dvoshell.h

    r40408 r40523  
    5252} PeriodogramResult;
    5353
     54typedef struct {
     55  off_t Ncat;
     56  off_t Nseq;
     57  float Roff;
     58} AvselectResult;
     59
    5460/*** Periodogram functions (avperiodogram and avperiodomatch) ***/
    5561void PeriodogramResultFree (PeriodogramResult *result);
     
    98104SkyList      *SelectRegionsByCoordVectors PROTO((Vector *RA, Vector *DEC));
    99105
    100 int           find_matches_by_vectors PROTO((SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index));
     106int             find_matches_by_vectors_closest PROTO((SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *index));
     107AvselectResult *find_matches_by_vectors_allmatch PROTO((SkyRegion *region, Catalog *catalog, Vector *RAvec, Vector *DECvec, float RADIUS, off_t *Nresult));
    101108
    102109int           SetImageSelection     PROTO((int mode, SkyRegionSelection *selection));
Note: See TracChangeset for help on using the changeset viewer.