IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36474


Ignore:
Timestamp:
Feb 5, 2014, 6:09:47 AM (12 years ago)
Author:
eugene
Message:

finished the tess table modifications; code seems ready to support 3pi and MD

Location:
branches/eam_branches/ipp-20131211/Ohana/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20131211/Ohana/src/addstar/src/findskycell.c

    r36473 r36474  
    4141int skycellIDoff = -1;
    4242
     43int APPEND = FALSE;
     44
    4345int main (int argc, char **argv) {
    4446
     
    5557  if (get_argument (argc, argv, "-h")) usage ();
    5658
    57   NX_SUB = NY_SUB = 1;
    5859  if ((N = get_argument (argc, argv, "-nx"))) {
    5960    remove_argument (N, &argc, argv);
     
    6869
    6970  /* pixel scale (arcsec/pixel) */
    70   SCALE = 1.0;
    7171  if ((N = get_argument (argc, argv, "-scale"))) {
    7272    remove_argument (N, &argc, argv);
    7373    SCALE = atof (argv[N]);
    7474    remove_argument (N, &argc, argv);
     75  }
     76
     77  /* pixel scale (arcsec/pixel) */
     78  if ((N = get_argument (argc, argv, "-append"))) {
     79    remove_argument (N, &argc, argv);
     80    APPEND = TRUE;
    7581  }
    7682
     
    410416  MARKTIME("-- test %d pts: %f sec\n", Npts, dtime);
    411417
    412   BoundaryTreeSave (treefile, &tree);
     418  if (APPEND) {
     419    int Ntess = 0;
     420    TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     421    REALLOCATE (tess, TessellationTable, Ntess + 1);
     422    TessellationTableInit (&tess[Ntess], 1);
     423    tess[Ntess].tree = &tree;
     424    tess[Ntess].type = TESS_RINGS;
     425    tess[Ntess].Rmin =   0;
     426    tess[Ntess].Rmax = 360;
     427    tess[Ntess].Dmin = -90;
     428    tess[Ntess].Dmax = +90;
     429
     430    if (BASENAME) {
     431      tess[Ntess].Nbasename = strlen(BASENAME);
     432      tess[Ntess].basename = strcreate(BASENAME);
     433      tess[Ntess].projectIDoff = projectIDoff;
     434      tess[Ntess].skycellIDoff = skycellIDoff;
     435    }
     436     
     437    // add basename an related here...
     438    Ntess ++;
     439    TessellationTableSave (treefile, tess, Ntess);
     440  } else {
     441    BoundaryTreeSave (treefile, &tree);
     442  }
    413443
    414444  return TRUE;
     
    416446
    417447int apply_tree (char *treefile, char *datafile) {
     448
     449  int Ntess = 0;
     450  TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     451  if (!tess) {
     452    fprintf (stderr, "error loading tessellation table file %s\n", treefile);
     453    exit (2);
     454  }
     455
     456  FILE *f = fopen (datafile, "r");
     457  if (!f) {
     458    fprintf (stderr, "error opening data file %s\n", datafile);
     459    exit (3);
     460  }
     461
     462  double ra, dec;
     463  int Nvalue = 0;
     464  while ((Nvalue = fscanf (f, "%lf %lf", &ra, &dec)) != EOF) {
     465
     466    int tessID, projID, skycellID;
     467
     468    if (!TessellationPrimaryCellIDs (tess, Ntess, &tessID, &projID, &skycellID, ra, dec)) {
     469      fprintf (stderr, "error finding cell for %f,%f\n", ra, dec);
     470      continue;
     471    }
     472
     473    fprintf (stdout, "%10.6f %10.6f : %2d  %04d %03d : %s\n", ra, dec, tessID, projID, skycellID, tess[tessID].basename);
     474  }
     475
     476  exit (0);
     477}
     478
     479int apply_tree_old (char *treefile, char *datafile) {
    418480
    419481  BoundaryTree *tree = BoundaryTreeLoad (treefile);
     
    479541int mklocal (char *treefile, char *catdir) {
    480542
    481   int i, status;
     543  int i, j, status;
    482544  FITS_DB db;
    483545  Image *image;
     
    515577 
    516578  // generate an empty BoundaryTree
    517   int Ntess = Nimage;
    518579  TessellationTable *tess = NULL;
    519   ALLOCATE (tess, TessellationTable, Ntess);
    520  
     580
     581  int NtessDisk = 0;
     582  if (APPEND) {
     583    tess = TessellationTableLoad (treefile, &NtessDisk);
     584    REALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     585  } else {
     586    ALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     587  }
     588
     589  TessellationTableInit (&tess[NtessDisk], Nimage);
     590
    521591  // find the RA,DEC of the image centers & assign to cells
    522   for (i = 0; i < Ntess; i++) {
     592  int Ntess = NtessDisk;
     593  for (i = 0; i < Nimage; i++) {
    523594    // user supplied values, do not try to derive from Image.dat
    524     tess[i].NX_SUB = NX_SUB;
    525     tess[i].NY_SUB = NY_SUB;
    526     tess[i].dPix = SCALE/3600.0;
     595    tess[Ntess].NX_SUB = NX_SUB;
     596    tess[Ntess].NY_SUB = NY_SUB;
     597    tess[Ntess].dPix = SCALE/3600.0;
    527598
    528599    x = 0.5*image[i].NX;
     
    530601    XY_to_RD (&ra, &dec, x, y, &image[i].coords);
    531602
    532     tess[i].Ro  = ra;
    533     tess[i].Do  = dec;
    534     tess[i].Xo  = x;
    535     tess[i].Yo  = y;
    536     tess[i].dX  = image[i].NX / NX_SUB;
    537     tess[i].dY  = image[i].NY / NY_SUB;
     603    tess[Ntess].Ro  = ra;
     604    tess[Ntess].Do  = dec;
     605    tess[Ntess].Xo  = x;
     606    tess[Ntess].Yo  = y;
     607    tess[Ntess].dX  = image[i].NX / NX_SUB;
     608    tess[Ntess].dY  = image[i].NY / NY_SUB;
    538609
    539610    // find the minimum or maximum containing region
     
    547618
    548619      if (REGION_OPTION == REGION_MIN) {
    549         for (i = 0; i < 4; i++) {
    550           R_MIN = (R[i] < ra)  ? (isfinite(R_MIN) ? MAX(R_MIN, R[i]) : R[i]) : R_MIN;
    551           R_MAX = (R[i] > ra)  ? (isfinite(R_MAX) ? MIN(R_MAX, R[i]) : R[i]) : R_MAX;
    552           D_MIN = (D[i] < dec) ? (isfinite(D_MIN) ? MAX(D_MIN, D[i]) : D[i]) : D_MIN;
    553           D_MAX = (D[i] > dec) ? (isfinite(D_MAX) ? MIN(D_MAX, D[i]) : D[i]) : D_MAX;
     620        for (j = 0; j < 4; j++) {
     621          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MAX(R_MIN, R[j]) : R[j]) : R_MIN;
     622          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MIN(R_MAX, R[j]) : R[j]) : R_MAX;
     623          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MAX(D_MIN, D[j]) : D[j]) : D_MIN;
     624          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MIN(D_MAX, D[j]) : D[j]) : D_MAX;
    554625        }
    555626      } else {
    556         for (i = 0; i < 4; i++) {
    557           R_MIN = (R[i] < ra)  ? (isfinite(R_MIN) ? MIN(R_MIN, R[i]) : R[i]) : R_MIN;
    558           R_MAX = (R[i] > ra)  ? (isfinite(R_MAX) ? MAX(R_MAX, R[i]) : R[i]) : R_MAX;
    559           D_MIN = (D[i] < dec) ? (isfinite(D_MIN) ? MIN(D_MIN, D[i]) : D[i]) : D_MIN;
    560           D_MAX = (D[i] > dec) ? (isfinite(D_MAX) ? MAX(D_MAX, D[i]) : D[i]) : D_MAX;
     627        for (j = 0; j < 4; j++) {
     628          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MIN(R_MIN, R[j]) : R[j]) : R_MIN;
     629          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MAX(R_MAX, R[j]) : R[j]) : R_MAX;
     630          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MIN(D_MIN, D[j]) : D[j]) : D_MIN;
     631          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MAX(D_MAX, D[j]) : D[j]) : D_MAX;
    561632        }
    562633      }
    563634    }
    564     tess[i].Rmin = R_MIN;
    565     tess[i].Rmax = R_MAX;
    566     tess[i].Dmin = D_MIN;
    567     tess[i].Dmax = D_MAX;
    568 
    569     tess[i].type = TESS_LOCAL;
     635    tess[Ntess].Rmin = R_MIN;
     636    tess[Ntess].Rmax = R_MAX;
     637    tess[Ntess].Dmin = D_MIN;
     638    tess[Ntess].Dmax = D_MAX;
     639
     640    tess[Ntess].type = TESS_LOCAL;
    570641
    571642    // XXX I don't really want to do the work of discovering the rule...
    572     tess[i].Nbasename = strlen(BASENAME);
    573     tess[i].basename = strcreate(BASENAME);
    574 
    575     tess[i].projectIDoff = projectIDoff;
    576     tess[i].skycellIDoff = skycellIDoff;
     643    tess[Ntess].Nbasename = strlen(BASENAME);
     644    tess[Ntess].basename = strcreate(BASENAME);
     645
     646    tess[Ntess].projectIDoff = projectIDoff;
     647    tess[Ntess].skycellIDoff = skycellIDoff;
     648
     649    Ntess ++;
    577650  }
    578651
  • branches/eam_branches/ipp-20131211/Ohana/src/libdvo/include/dvo.h

    r36472 r36474  
    810810TessellationTable *TessellationTableLoad(char *filename, int *Ntess);
    811811int TessellationTableSave(char *filename, TessellationTable *tess, int Ntess);
     812int TessellationPrimaryCellIDs (TessellationTable *tess, int Ntess, int *tessID, int *projID, int *skycellID, double ra, double dec);
     813void TessellationTableInit (TessellationTable *tess, int Ntess);
    812814
    813815void dvo_average_init (Average *average);
  • branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/TessellationTable.c

    r36472 r36474  
    1010
    1111# define DEBUG 0
     12
     13void TessellationTableInit (TessellationTable *tess, int Ntess) {
     14
     15  int i;
     16
     17  for (i = 0; i < Ntess; i++) {
     18    tess[i].Rmin = NAN;
     19    tess[i].Rmax = NAN;
     20    tess[i].Dmin = NAN;
     21    tess[i].Dmax = NAN;
     22
     23    tess[i].Xo = NAN;
     24    tess[i].Yo = NAN;
     25    tess[i].Ro = NAN;
     26    tess[i].Do = NAN;
     27
     28    tess[i].dPix = NAN;
     29
     30    tess[i].dX = 0;
     31    tess[i].dY = 0;
     32
     33    tess[i].NX_SUB = 0;
     34    tess[i].NY_SUB = 0;
     35
     36    tess[i].basename = NULL;
     37    tess[i].Nbasename = 0;
     38
     39    tess[i].projectIDoff = 0;
     40    tess[i].skycellIDoff = 0;
     41
     42    tess[i].type = TESS_NONE;
     43    tess[i].tree = NULL;
     44  }
     45  return;
     46}
    1247
    1348// backwards compatible load : if the first table is a BoundaryTree, not a TessellationTable, just load that.
     
    6499   
    65100    ALLOCATE (tess, TessellationTable, 1);
     101    TessellationTableInit (tess, 1);
    66102    tess[0].tree = tree;
    67103    tess[0].type = TESS_RINGS;
     104    tess[0].Rmin =   0;
     105    tess[0].Rmax = 360;
     106    tess[0].Dmin = -90;
     107    tess[0].Dmax = +90;
    68108    *Ntess = 1;
    69109    return tess;
     
    86126  GET_COLUMN_NEW(dY,     "Y_GRID", int);
    87127  GET_COLUMN_NEW(Rmin,   "R_MIN",  double);
    88   GET_COLUMN_NEW(Rmax,   "R_MIN",  double);
     128  GET_COLUMN_NEW(Rmax,   "R_MAX",  double);
    89129  GET_COLUMN_NEW(Dmin,   "D_MIN",  double);
    90130  GET_COLUMN_NEW(Dmax,   "D_MAX",  double);
     
    92132  GET_COLUMN_NEW(NX_SUB, "NX_SUB", int);
    93133  GET_COLUMN_NEW(NY_SUB, "NY_SUB", int);
     134  GET_COLUMN_NEW(TYPE,   "TYPE",   int);
     135
     136  GET_COLUMN_NEW(PROJECT_ID_OFF, "PROJECT_ID_OFF", int);
     137  GET_COLUMN_NEW(SKYCELL_ID_OFF, "SKYCELL_ID_OFF", int);
     138
     139  GET_COLUMN_NEW(BASENAME, "BASENAME", char);
    94140
    95141  *Ntess = Nrow;
     
    109155    tess[i].NX_SUB = NX_SUB[i];
    110156    tess[i].NY_SUB = NY_SUB[i];
    111     tess[i].type   = TESS_LOCAL;
     157    tess[i].type   = TYPE[i];
     158
     159    tess[i].projectIDoff = PROJECT_ID_OFF[i];
     160    tess[i].skycellIDoff = SKYCELL_ID_OFF[i];
     161
     162    ALLOCATE (tess[i].basename, char, BOUNDARY_TREE_NAME_LENGTH);
     163    memcpy (tess[i].basename, &BASENAME[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
     164    tess[i].Nbasename = strlen (tess[i].basename);
     165
    112166    tess[i].tree   = NULL;
    113167  }
     
    126180  free(NX_SUB);
    127181  free(NY_SUB);
     182  free(TYPE);
     183
     184  free(PROJECT_ID_OFF);
     185  free(SKYCELL_ID_OFF);
    128186
    129187  gfits_free_header (&theader);
     
    134192  /*** check for a RINGS entry ***/
    135193
     194  // find the RINGS tessellation (if present)
     195  TessellationTable *rings = NULL;
     196  for (i = 0; i < *Ntess; i++) {
     197    if (tess[i].type == TESS_LOCAL) continue;
     198    if (tess[i].type != TESS_RINGS) continue;
     199    rings = &tess[i];
     200  }
     201
     202  if (!rings) {
     203    fclose (f);
     204    gfits_free_header (&header);
     205    gfits_free_matrix (&matrix);
     206    return (tess);
     207  }
     208
    136209  // load data for this header, or exit
    137210  if (!gfits_load_header (f, &theader))  {
     211    fprintf (stderr, "warning : RINGS tessellation listed in table but not present\n");
     212    gfits_free_header (&header);
     213    gfits_free_matrix (&matrix);
    138214    return tess;
    139215  }
     
    142218  gfits_scan (&theader, "EXTNAME", "%s", 1, extname);
    143219
    144   // is this a BoundaryTree?  if so, it must be stand-alone: load just that and generate a
    145   // containing TessellationTable.
    146   if (!strcmp(extname, "ZONE_DATA")) {
    147     BoundaryTree *tree = BoundaryTreeRead (&header, &theader, f);
     220  if (strcmp(extname, "ZONE_DATA")) {
     221    fprintf (stderr, "warning : RINGS tessellation listed in table but not present\n");
    148222    gfits_free_header (&theader);
    149223    gfits_free_header (&header);
    150224    gfits_free_matrix (&matrix);
    151     fclose (f);
    152    
    153     (*Ntess) ++;
    154     REALLOCATE (tess, TessellationTable, *Ntess);
    155     tess[(*Ntess - 1)].tree = tree;
    156     tess[(*Ntess - 1)].type = TESS_RINGS;
    157225    return tess;
    158226  }
    159  
     227
     228  // is this a BoundaryTree?  if so, it must be stand-alone: load just that and generate a
     229  // containing TessellationTable.
     230  BoundaryTree *tree = BoundaryTreeRead (&header, &theader, f);
    160231  gfits_free_header (&theader);
    161232  gfits_free_header (&header);
    162233  gfits_free_matrix (&matrix);
    163234  fclose (f);
    164 
     235   
     236  rings->tree = tree;
    165237  return tess;
    166238
     
    237309  gfits_define_bintable_column (&theader, "J", "NX_SUB", "skycell subdivision in x", "none", 1.0, 0.0);
    238310  gfits_define_bintable_column (&theader, "J", "NY_SUB", "skycell subdivision in y", "none", 1.0, 0.0);
     311  gfits_define_bintable_column (&theader, "J", "TYPE",   "type of tessellation", "none", 1.0, 0.0);
     312
     313  gfits_define_bintable_column (&theader, "J", "PROJECT_ID_OFF", "offset in image name to projection cell ID", "none", 1.0, 0.0);
     314  gfits_define_bintable_column (&theader, "J", "SKYCELL_ID_OFF", "offset in image name to skycell ID", "none", 1.0, 0.0);
     315
     316  char fmt[16];
     317  snprintf (fmt, 16, "%dA", BOUNDARY_TREE_NAME_LENGTH);
     318  gfits_define_bintable_column (&theader, fmt, "BASENAME", "image base name", "none", 1.0, 0.0);
    239319
    240320  // generate the output array that carries the data
    241321  gfits_create_table (&theader, &ftable);
    242322 
    243   int Nout = (rings == NULL) ? Ntess : Ntess - 1;
     323  // int Nout = (rings == NULL) ? Ntess : Ntess - 1;
     324  int Nout = Ntess;
    244325
    245326  // create intermediate storage arrays
     
    258339  int    *NX_SUB        ; ALLOCATE (NX_SUB,    int,    Nout);
    259340  int    *NY_SUB        ; ALLOCATE (NY_SUB,    int,    Nout);
     341  int    *TYPE          ; ALLOCATE (TYPE,      int,    Nout);
     342
     343  int    *PROJECT_ID_OFF; ALLOCATE (PROJECT_ID_OFF, int, Nout);
     344  int    *SKYCELL_ID_OFF; ALLOCATE (SKYCELL_ID_OFF, int, Nout);
     345
     346  char   *BASENAME      ; ALLOCATE (BASENAME,  char,   Nout*BOUNDARY_TREE_NAME_LENGTH);
     347  memset (BASENAME, 0, Nout*BOUNDARY_TREE_NAME_LENGTH);
    260348
    261349  // assign the storage arrays
     350  // XXX I was not writing out the RINGS tess entry, but that probably is not useful (drop
     351  // N vs i in future?)
    262352  int N = 0;
    263353  for (i = 0; i < Ntess; i++) {
    264     if (tess->type != TESS_LOCAL) continue;
     354    // if (tess->type != TESS_LOCAL) continue;
    265355    Ro[N]     = tess[i].Ro;
    266356    Do[N]     = tess[i].Do;
     
    276366    NX_SUB[N] = tess[i].NX_SUB;
    277367    NY_SUB[N] = tess[i].NY_SUB;
     368    TYPE[N]   = tess[i].type;
     369
     370    PROJECT_ID_OFF[N] = tess[i].projectIDoff;
     371    SKYCELL_ID_OFF[N] = tess[i].skycellIDoff;
     372
     373    if (tess[i].basename) {
     374      memcpy(&BASENAME[N*BOUNDARY_TREE_NAME_LENGTH], tess[i].basename, BOUNDARY_TREE_NAME_LENGTH);
     375    }
     376
    278377    N++;
    279378  }
     
    293392  gfits_set_bintable_column (&theader, &ftable, "NX_SUB", NX_SUB, Nout);
    294393  gfits_set_bintable_column (&theader, &ftable, "NY_SUB", NY_SUB, Nout);
     394  gfits_set_bintable_column (&theader, &ftable, "TYPE",   TYPE,   Nout);
     395
     396  gfits_set_bintable_column (&theader, &ftable, "PROJECT_ID_OFF", PROJECT_ID_OFF, Nout);
     397  gfits_set_bintable_column (&theader, &ftable, "SKYCELL_ID_OFF", SKYCELL_ID_OFF, Nout);
     398  gfits_set_bintable_column (&theader, &ftable, "BASENAME", BASENAME, Nout);
    295399
    296400  free (Ro    );
     
    307411  free (NX_SUB);
    308412  free (NY_SUB);
     413  free (TYPE);
     414
     415  free (PROJECT_ID_OFF);
     416  free (SKYCELL_ID_OFF);
     417  free (BASENAME);
    309418
    310419  gfits_fwrite_Theader (f, &theader);
     
    321430  return TRUE;
    322431}
     432
     433int TessellationLocalProjection (double *x, double *y, double r, double d, TessellationTable *tess) {
     434
     435    double Xo = tess->Xo;
     436    double Yo = tess->Yo;
     437    double Ro = tess->Ro;
     438    double Do = tess->Do;
     439    double dPix = tess->dPix;
     440
     441    // this block only depends on Ro, Do
     442
     443    double sdp  = sin(RAD_DEG*Do);
     444    double cdp  = cos(RAD_DEG*Do);
     445    double salp = sin(RAD_DEG*(r - Ro));
     446    double calp = cos(RAD_DEG*(r - Ro));
     447    double sdel = sin(RAD_DEG*d);
     448    double cdel = cos(RAD_DEG*d);
     449   
     450    double stht = sdel*sdp + cdel*cdp*calp;    /* sin(theta) */
     451    double sphi = cdel*salp;                   /* = cos(theta)*sin(phi) */
     452    double cphi = cdel*sdp*calp - sdel*cdp;    /* = cos(theta)*cos(phi) */
     453
     454    // defines the TAN projection (one of zenithal projections available, libdvo/src/coordops.c
     455    // R = cot (theta) = cos(theta) / sin(theta)
     456    double L, M;
     457    if (stht == 0) {
     458        double Rc = hypot(sphi, cphi);
     459        L = 180.0 * sphi / Rc;
     460        M = 180.0 * cphi / Rc;
     461    } else {
     462        L = +DEG_RAD * sphi / stht;
     463        M = -DEG_RAD * cphi / stht;
     464    }
     465
     466    // scale, rotation, parity:
     467    // rotation == 0.0 (pc1_1 == pc2_2 == 1.0, pc1_2 = pc2_1 = 0.0)
     468
     469    // if there were rotation or parity:
     470    // Ro = (coords[0].pc1_1*coords[0].pc2_2 - coords[0].pc1_2*coords[0].pc2_1);
     471    // Xo = (coords[0].pc2_2*L - coords[0].pc1_2*M) / Ro;
     472    // Yo = (coords[0].pc1_1*M - coords[0].pc2_1*L) / Ro;
     473
     474    double X = L;
     475    double Y = M;
     476
     477    // scale is dPix
     478
     479    *x = Xo - X / dPix;
     480    *y = Yo + Y / dPix;
     481   
     482    return TRUE;
     483}
     484
     485static int Nfail = 0;
     486
     487// for the given ra,dec : find the valid tessellation and the containing projection / skycell IDs
     488int TessellationPrimaryCellIDs (TessellationTable *tess, int Ntess, int *tessID, int *projID, int *skycellID, double ra, double dec) {
     489
     490  int i, zone, band;
     491
     492  *tessID = -1;
     493  *projID = -1;
     494  *skycellID = -1;
     495
     496  if (!tess) return FALSE;
     497
     498  // find the tessellation which includes this location
     499  int myTess = -1;
     500  for (i = 0; i < Ntess; i++) {
     501    if (ra  <  tess[i].Rmin) continue;
     502    if (ra  >= tess[i].Rmax) continue;
     503    if (dec <  tess[i].Dmin) continue;
     504    if (dec >= tess[i].Dmax) continue;
     505    myTess = i;
     506    break;
     507  }
     508  if (myTess < 0) {
     509    if (Nfail < 100) {
     510      fprintf (stderr, "no matching tessellation @ %f,%f\n", ra, dec);
     511    }
     512    Nfail ++;
     513    return FALSE;
     514  }
     515
     516  if (tess[myTess].type == TESS_NONE) {
     517    if (Nfail < 100) {
     518      fprintf (stderr, "tess has invalid type\n");
     519      Nfail ++;
     520    }
     521    return FALSE;
     522  }
     523
     524  if (tess[myTess].type == TESS_LOCAL) {
     525    // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
     526    // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
     527   
     528    double x = 0.0;
     529    double y = 0.0;
     530    TessellationLocalProjection (&x, &y, ra, dec, &tess[myTess]);
     531 
     532    int xi = x / tess[myTess].dX;
     533    int yi = y / tess[myTess].dY;
     534    int N = xi + tess[myTess].NX_SUB * yi;
     535 
     536    *tessID = myTess;
     537    *projID = 0;
     538    *skycellID = N;
     539
     540    // *projID = tess[myTess].projID :: NOTE : The projection cell may be non-zero like eg
     541    // STS.  However, I'm not certain we are going to implement it like this.
     542
     543    return TRUE;
     544  }
     545
     546  if (tess[myTess].type == TESS_RINGS) {
     547    if (!BoundaryTreeCellCoords (tess[myTess].tree, &zone, &band, ra, dec)) {
     548      fprintf (stderr, "mismatch!\n");
     549      return FALSE;
     550    }
     551 
     552    // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
     553    // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
     554   
     555    double x = 0.0;
     556    double y = 0.0;
     557    BoundaryTreeProjection (&x, &y, ra, dec, tess[myTess].tree, zone, band);
     558 
     559    int xi = x / tess[myTess].tree->dX[zone][band];
     560    int yi = y / tess[myTess].tree->dY[zone][band];
     561    int N = xi + tess[myTess].tree->NX_SUB * yi;
     562 
     563    *tessID = myTess;
     564    *projID = tess[myTess].tree->projID[zone][band];
     565    *skycellID = N;
     566
     567    return TRUE;
     568  }
     569
     570  fprintf (stderr, "invalid tessellation type!\n");
     571  return FALSE;
     572}
     573
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/include/relphot.h

    r35806 r36474  
    116116  unsigned int photom_map_id;
    117117  unsigned int flags;
     118  int tessID;
    118119  int projID;
    119120  int skycellID;
     
    401402
    402403int MatchImageName (off_t meas, int cat, char *name);
    403 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID);
    404 
    405 int load_tree (char *treefile);
    406 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
    407 int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
     404int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID);
     405
     406int load_tess (char *treefile);
     407int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec);
     408int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name);
     409
     410// int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
     411// int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
    408412
    409413int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/BoundaryTreeOps.c

    r36466 r36474  
    11# include "relphot.h"
    22
    3 static int Nfail = 0;
    43static int Ntess = 0;
    5 static TessllationBoundary *tess = NULL;
     4static TessellationTable *tess = NULL;
    65
    7 // for the given ra,dec : find the valid tessallation and the containing projection / skycell IDs
    8 int TessallationPrimaryCellIDs (int *tessID, int *projID, int *skycellID, double ra, double dec) {
     6int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name) {
    97
    10   int zone, band;
    11 
    12   *tessID = -1;
    13   *projID = -1;
    14   *skycellID = -1;
    15 
    16   if (!tess) return FALSE;
    17 
    18   // find the tessellation which includes this location
    19   int myTess = -1;
    20   for (i = 0; i < Ntess; i++) {
    21     if (ra  <  tess[i].Rmin) continue;
    22     if (ra  >= tess[i].Rmax) continue;
    23     if (dec <  tess[i].Dmin) continue;
    24     if (dec >= tess[i].Dmax) continue;
    25     myTess = i;
    26     break;
    27   }
    28   if (myTess < 0) {
    29     if (Nfail < 100) {
    30       fprintf (stderr, "no matching tessallation @ %f,%f\n", ra, dec);
    31     }
    32     Nfail ++;
    33     return FALSE;
    34   }
    35 
    36   if (tess[myTess].type == TESS_NONE) {
    37     if (Nfail < 100) {
    38       fprintf (stderr, "tess has invalid type\n");
    39       Nfail ++;
    40     }
    41     return FALSE;
    42   }
    43 
    44   if (tess[myTess].type == TESS_LOCAL) {
    45     // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    46     // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    47    
    48     double x = 0.0;
    49     double y = 0.0;
    50     TessallationLocalProjection (&x, &y, ra, dec, &tess[myTess]);
    51  
    52     int xi = x / tess[myTess].dX;
    53     int yi = y / tess[myTess].dY;
    54     int N = xi + tess[myTess].NX_SUB * yi;
    55  
    56     *tessID = myTess;
    57     *projID = tess[myTess].projID;
    58     *skycellID = N;
    59 
    60     return TRUE;
    61   }
    62 
    63   if (tess[myTess].type == TESS_RINGS) {
    64     if (!BoundaryTreeCellCoords (tess[myTess].tree, &zone, &band, ra, dec)) {
    65       fprintf (stderr, "mismatch!\n");
    66       return FALSE;
    67     }
    68  
    69     // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    70     // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    71    
    72     double x = 0.0;
    73     double y = 0.0;
    74     BoundaryTreeProjection (&x, &y, ra, dec, tess[myTess].tree, zone, band);
    75  
    76     int xi = x / tess[myTess].tree->dX[zone][band];
    77     int yi = y / tess[myTess].tree->dY[zone][band];
    78     int N = xi + tess[myTess].tree->NX_SUB * yi;
    79  
    80     *tessID = myTess;
    81     *projID = tess[myTess].tree->projID[zone][band];
    82     *skycellID = N;
    83 
    84     return TRUE;
    85   }
    86 }
    87 
    88 int TessallationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name) {
     8  int i;
    899
    9010  *tessID = -1;
     
    9818    if (!strncmp (name, tess[i].basename, tess[i].Nbasename)) {
    9919      *tessID    = i;
    100       *projID    = atoi(&name[tess[i].projectIDoff]);
    101       *skycellID = atoi(&name[tess[i].skycellIDoff]);
     20      if (tess[i].projectIDoff >= 0) {
     21        *projID    = atoi(&name[tess[i].projectIDoff]);
     22      } else {
     23        *projID    = 0;
     24      }
     25      if (tess[i].skycellIDoff >= 0) {
     26        *skycellID = atoi(&name[tess[i].skycellIDoff]);
     27      } else {
     28        *skycellID = 0;
     29      }
    10230      return TRUE;
    10331    }
     
    10836int load_tess (char *tessfile) {
    10937
    110   tess = TessBoundaryLoad (tessfile, &Ntess);
     38  tess = TessellationTableLoad (tessfile, &Ntess);
    11139  if (!tess) {
    112     fprintf (stderr, "failed to load tessallation boundary file %s\n", tessfile);
     40    fprintf (stderr, "failed to load tessellation boundary file %s\n", tessfile);
    11341    exit (2);
    11442  }
     
    11644  return TRUE;
    11745}
     46
     47int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec) {
     48
     49  int status;
     50
     51  if (!tess) return FALSE;
     52
     53  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
     54  return status;
     55}
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/ImageOps.c

    r36466 r36474  
    4848// stack image.  for now, we generate these ID arrays based on the image names when we load in the image table (initImages).
    4949// When we pass data to the remote clients via the ImageSubset, the projID/skycellID values are carried directly in the table.
     50int *tessID    = NULL;
    5051int *projectID = NULL;
    5152int *skycellID = NULL;
     
    8182
    8283  // for stack images, assign projection cell ID and skycell ID based on filenames
     84  ALLOCATE (tessID,      int, Nimage);
    8385  ALLOCATE (projectID,   int, Nimage);
    8486  ALLOCATE (skycellID,   int, Nimage);
     
    8890    imageIDs[i] = image[i].imageID;
    8991
    90     tessID[i] = -1;
     92    tessID[i]    = -1;
    9193    projectID[i] = -1;
    9294    skycellID[i] = -1;
    9395
    94     TessallationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
     96    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
    9597  }
    9698
     
    107109  // create full a Image array and save the needed values
    108110  ALLOCATE (image, Image, N);
     111
     112  ALLOCATE (tessID,    int, N);
    109113  ALLOCATE (projectID, int, N);
    110114  ALLOCATE (skycellID, int, N);
     
    119123    image[i].trate         = input[i].trate        ;
    120124    image[i].ubercalDist   = input[i].ubercalDist  ;
     125    tessID[i]              = input[i].tessID       ;
    121126    projectID[i]           = input[i].projID       ;
    122127    skycellID[i]           = input[i].skycellID    ;
     
    154159    subset[i].trate         = image[i].trate        ;
    155160    subset[i].ubercalDist   = image[i].ubercalDist  ;
     161    subset[i].tessID        = tessID[i];
    156162    subset[i].projID        = projectID[i];
    157163    subset[i].skycellID     = skycellID[i];
     
    462468
    463469// returns image.Mcal - ff(x,y)
    464 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID) {
     470int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) {
    465471
    466472  off_t i;
     
    471477  if (i == -1) return FALSE;
    472478
     479  if (tessID[i]    == -1) return FALSE;
    473480  if (projectID[i] == -1) return FALSE;
    474481  if (skycellID[i] == -1) return FALSE;
    475482
     483  if (tessID[i]    != myTessID) return FALSE;
    476484  if (projectID[i] != myProjectionID) return FALSE;
    477485  if (skycellID[i] != mySkycellID) return FALSE;
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/ImageSubset.c

    r35759 r36474  
    6363  GET_COLUMN (map,       "PHOTOM_MAP",   int);
    6464  GET_COLUMN (flags,     "FLAGS",        int);
     65  GET_COLUMN (tessID,    "TESS_ID",      int);
    6566  GET_COLUMN (projID,    "PROJ_ID",      int);
    6667  GET_COLUMN (skycellID, "SKYCELL_ID",   int);
     
    7879    image[i].photom_map_id = map[i];
    7980    image[i].flags         = flags[i];
     81    image[i].tessID        = tessID[i];
    8082    image[i].projID        = projID[i];
    8183    image[i].skycellID     = skycellID[i];
     
    9193  free (map);
    9294  free (flags);
     95  free (tessID);
    9396  free (projID);
    9497  free (skycellID);
     
    130133  gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
    131134
     135  gfits_define_bintable_column (&theader, "J", "TESS_ID", "ID", NULL, 1.0, 0.0);
    132136  gfits_define_bintable_column (&theader, "J", "PROJ_ID", "ID", NULL, 1.0, 0.0);
    133137  gfits_define_bintable_column (&theader, "J", "SKYCELL_ID", "ID", NULL, 1.0, 0.0);
     
    143147  float *Mcal, *dMcal;
    144148  unsigned int *imageID, *map, *flags, *tzero;
    145   int *projID, *skycellID;
     149  int *tessID, *projID, *skycellID;
    146150  unsigned short *trate;
    147151  short *ucdist;
     
    153157  ALLOCATE (map,       unsigned int,   Nimage);
    154158  ALLOCATE (flags,     unsigned int,   Nimage);
     159  ALLOCATE (tessID,    int,            Nimage);
    155160  ALLOCATE (projID,    int,            Nimage);
    156161  ALLOCATE (skycellID, int,            Nimage);
     
    169174    trate[i]     = image[i].trate;
    170175    ucdist[i]    = image[i].ubercalDist;
     176    tessID[i]    = image[i].tessID;
    171177    projID[i]    = image[i].projID;
    172178    skycellID[i] = image[i].skycellID;
     
    179185  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP",   map,       Nimage);
    180186  gfits_set_bintable_column (&theader, &ftable, "FLAGS",        flags,     Nimage);
     187  gfits_set_bintable_column (&theader, &ftable, "TESS_ID",      tessID,    Nimage);
    181188  gfits_set_bintable_column (&theader, &ftable, "PROJ_ID",      projID,    Nimage);
    182189  gfits_set_bintable_column (&theader, &ftable, "SKYCELL_ID",   skycellID, Nimage);
     
    190197  free (map);
    191198  free (flags);
     199  free (tessID);
    192200  free (projID);
    193201  free (skycellID);
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/StarOps.c

    r35759 r36474  
    328328int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    329329
     330  fprintf (stderr, "??? should you still be using the old version of setMrel_catalog??\n");
     331  exit (3);
     332
    330333  off_t j, k, m, ID;
    331334  int N;
     
    366369    if (isSetMrelFinal) {
    367370      // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
    368       BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
     371      // XXX : this whole function is deprecated
     372      // BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
    369373    }
    370374
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/args.c

    r36466 r36474  
    223223    remove_argument (N, &argc, argv);
    224224    BOUNDARY_TREE = strcreate(argv[N]);
    225     load_tree (BOUNDARY_TREE);
     225    load_tess (BOUNDARY_TREE);
    226226    remove_argument (N, &argc, argv);
    227227  }
     
    426426    remove_argument (N, &argc, argv);
    427427    BOUNDARY_TREE = strcreate(argv[N]);
    428     load_tree (BOUNDARY_TREE);
     428    load_tess (BOUNDARY_TREE);
    429429    remove_argument (N, &argc, argv);
    430430  }
  • branches/eam_branches/ipp-20131211/Ohana/src/relphot/src/setMrelCatalog.c

    r36466 r36474  
    409409  int projectID = -1;
    410410  int skycellID = -1;
    411   TessallationTreePrimaryCellIDs(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
     411  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
    412412
    413413  int NstackGood = 0;
     
    477477      // which stack image should we use for the mean value?
    478478      // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
    479       if (MatchImageSkycellID (meas, cat, projectID, skycellID)) {
     479      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    480480        float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    481481        if (stackPrimaryOffset < stackPrimaryOffsetMin) {
Note: See TracChangeset for help on using the changeset viewer.