IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37176


Ignore:
Timestamp:
Aug 2, 2014, 6:17:20 AM (12 years ago)
Author:
eugene
Message:

consolidate dvo to detection translations; add calibrated mags to stack outputs

Location:
branches/eam_branches/ipp-20140717/Ohana/src/dvopsps
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/include/dvopsps.h

    r36188 r37176  
    99
    1010typedef struct {
    11   int imageID;
    12   unsigned int ippDetectID;
     11  uint64_t objID;
    1312  uint64_t detectID;
    1413  uint64_t ippObjID;
    15   uint64_t objID;
    16   int      photcode;
    17   unsigned int flags;
    18   float zp;
    19   float zpErr;
    20   float airMass;
    21   float expTime;
     14  unsigned int ippDetectID;
     15  int imageID;
    2216  double ra;
    2317  double dec;
    2418  float raErr;
    2519  float decErr;
     20  float zp;
     21  float telluricExt;
     22  float airmass;
     23  float expTime;
     24
     25  float Mpsf;
     26  float dMpsf;
     27  float Mkron;
     28  float dMkron;
     29  float Map;
     30  float dMap;
     31
     32  unsigned int flags;
    2633} Detections;
    2734
     
    7885     
    7986int    insert_detections_mysql_commit     PROTO((IOBuffer *buffer, MYSQL *mysql));
    80 int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
     87// int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
    8188int    insert_detections_mysql_init       PROTO((IOBuffer *buffer));
    8289
    8390int    insert_detections_mysql_array      PROTO((MYSQL *mysql, Detections *detections, int Ndetections));
    8491int    insert_detections_mysql_detvalue   PROTO((IOBuffer *buffer, Detections *detection));
     92int    assign_detection_values            PROTO((Detections *detection, Measure *measure, Average *average));
    8593
    8694int    init_detections                    PROTO(());
  • branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/DetectionOps.c

    r35578 r37176  
    11# include "dvopsps.h"
    2 # define BZERO_INT16 1.0*0x8000
    3 # define BZERO_INT32 1.0*0x80000000
    4 # define BZERO_INT64 1.0*0x8000000000000000
    52
    63# define GET_COLUMN(OUT,NAME,TYPE)                                      \
     
    4946 
    5047  // need to create and assign to flat-field correction
    51   GET_COLUMN(imageID     , "imageID",     int);
    52   GET_COLUMN(ippDetectID , "ippDetectID", int);
     48  GET_COLUMN(objID       , "objID",       int64_t);
    5349  GET_COLUMN(detectID    , "detectID",    int64_t);
    5450  GET_COLUMN(ippObjID    , "ippObjID",    int64_t);
    55   GET_COLUMN(objID       , "objID",       int64_t);
    56   GET_COLUMN(photcode    , "photcode",    int);
    57   GET_COLUMN(flags       , "flags",       int);
    58   GET_COLUMN(zp          , "zp",          float);
    59   GET_COLUMN(zpErr       , "zpErr",       float);
    60   GET_COLUMN(airMass     , "airMass",     float);
    61   GET_COLUMN(expTime     , "expTime",     float);
     51  GET_COLUMN(ippDetectID , "ippDetectID", int);
     52  GET_COLUMN(imageID     , "imageID",     int);
    6253  GET_COLUMN(ra          , "ra",          double); // XXX signed vs unsigned?
    6354  GET_COLUMN(dec         , "dec",         double);
    6455  GET_COLUMN(raErr       , "raErr",       float);
    6556  GET_COLUMN(decErr      , "decErr",      float);
     57  GET_COLUMN(zp          , "zp",          float);
     58  GET_COLUMN(telluricExt , "telluricExt", float);
     59  GET_COLUMN(airmass     , "airmass",     float);
     60  GET_COLUMN(expTime     , "expTime",     float);
     61  GET_COLUMN(Mpsf        , "Mpsf",        float);
     62  GET_COLUMN(dMpsf       , "dMpsf",       float);
     63  GET_COLUMN(Mkron       , "Mkron",       float);
     64  GET_COLUMN(dMkron      , "dMkron",      float);
     65  GET_COLUMN(Map         , "Map",         float);
     66  GET_COLUMN(dMap        , "dMap",        float);
     67  GET_COLUMN(flags       , "flags",       int);
    6668  gfits_free_header (&theader);
    6769  gfits_free_table  (&ftable);
     
    6971  ALLOCATE (detections, Detections, Nrow);
    7072  for (i = 0; i < Nrow; i++) {
    71     detections[i].imageID      = imageID[i];   
    72     detections[i].ippDetectID  = ippDetectID[i];
     73    detections[i].objID        = objID[i];     
    7374    detections[i].detectID     = detectID[i];   
    7475    detections[i].ippObjID     = ippObjID[i];   
    75     detections[i].objID        = objID[i];     
    76     detections[i].photcode     = photcode[i];     
    77     detections[i].flags        = flags[i];     
    78     detections[i].zp           = zp[i];         
    79     detections[i].zpErr        = zpErr[i];     
    80     detections[i].airMass      = airMass[i];   
    81     detections[i].expTime      = expTime[i];   
     76    detections[i].ippDetectID  = ippDetectID[i];
     77    detections[i].imageID      = imageID[i];   
    8278    detections[i].ra           = ra[i];         
    8379    detections[i].dec          = dec[i];       
    8480    detections[i].raErr        = raErr[i];     
    8581    detections[i].decErr       = decErr[i];     
     82    detections[i].zp           = zp[i];         
     83    detections[i].telluricExt  = telluricExt[i];     
     84    detections[i].airmass      = airmass[i];   
     85    detections[i].expTime      = expTime[i];   
     86    detections[i].Mpsf         = Mpsf[i];   
     87    detections[i].dMpsf        = dMpsf[i];   
     88    detections[i].Mkron        = Mkron[i];   
     89    detections[i].dMkron       = dMkron[i];   
     90    detections[i].Map          = Map[i];   
     91    detections[i].dMap         = dMap[i];   
     92    detections[i].flags        = flags[i];     
    8693  }
    8794  fprintf (stderr, "loaded data for %lld detections\n", (long long) Nrow);
    8895
    89   free (imageID    );
    90   free (ippDetectID);
     96  free (objID      );
    9197  free (detectID   );
    9298  free (ippObjID   );
    93   free (objID      );
    94   free (photcode   );
    95   free (flags      );
    96   free (zp         );
    97   free (zpErr      );
    98   free (airMass    );
    99   free (expTime    );
     99  free (ippDetectID);
     100  free (imageID    );
    100101  free (ra         );
    101102  free (dec        );
    102103  free (raErr      );
    103104  free (decErr     );
     105  free (zp         );
     106  free (telluricExt);
     107  free (airmass    );
     108  free (expTime    );
     109  free (Mpsf       );
     110  free (dMpsf      );
     111  free (Mkron      );
     112  free (dMkron     );
     113  free (Map        );
     114  free (dMap       );
     115  free (flags      );
    104116
    105117  gfits_free_header (&header);
     
    149161
    150162  // XXX need to get the bzero values right
    151   gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, BZERO_INT32);
    152   gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, BZERO_INT32);
     163  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
    153164  gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, 0);
    154165  gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, 0);
    155   gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
    156   // gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, BZERO_INT64);
    157   // gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, BZERO_INT64);
    158   // gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, BZERO_INT64);
    159   gfits_define_bintable_column (&theader, "J", "photcode",    NULL, NULL, 1.0, 0.0);
    160   gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, BZERO_INT32);
    161   gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
    162   gfits_define_bintable_column (&theader, "E", "zpErr",       NULL, NULL, 1.0, 0.0);
    163   gfits_define_bintable_column (&theader, "E", "airMass",     NULL, NULL, 1.0, 0.0);
    164   gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
     166  gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, FT_BZERO_INT32);
     167  gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, FT_BZERO_INT32);
    165168  gfits_define_bintable_column (&theader, "D", "ra",          NULL, NULL, 1.0, 0.0);
    166169  gfits_define_bintable_column (&theader, "D", "dec",         NULL, NULL, 1.0, 0.0);
    167170  gfits_define_bintable_column (&theader, "E", "raErr",       NULL, NULL, 1.0, 0.0);
    168171  gfits_define_bintable_column (&theader, "E", "decErr",      NULL, NULL, 1.0, 0.0);
     172  gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
     173  gfits_define_bintable_column (&theader, "E", "telluricExt", NULL, NULL, 1.0, 0.0);
     174  gfits_define_bintable_column (&theader, "E", "airmass",     NULL, NULL, 1.0, 0.0);
     175  gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
     176  gfits_define_bintable_column (&theader, "E", "Mpsf",        NULL, NULL, 1.0, 0.0);
     177  gfits_define_bintable_column (&theader, "E", "dMpsf",       NULL, NULL, 1.0, 0.0);
     178  gfits_define_bintable_column (&theader, "E", "Mkron",       NULL, NULL, 1.0, 0.0);
     179  gfits_define_bintable_column (&theader, "E", "dMkron",      NULL, NULL, 1.0, 0.0);
     180  gfits_define_bintable_column (&theader, "E", "Map",         NULL, NULL, 1.0, 0.0);
     181  gfits_define_bintable_column (&theader, "E", "dMap",        NULL, NULL, 1.0, 0.0);
     182  gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, FT_BZERO_INT32);
    169183
    170184  // generate the output array that carries the data
     
    172186
    173187  // create intermediate storage arrays
    174    int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
    175   uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
     188  uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
    176189  uint64_t   *detectID    ; ALLOCATE (detectID    ,  uint64_t, Ndetections);
    177190  uint64_t   *ippObjID    ; ALLOCATE (ippObjID    ,  uint64_t, Ndetections);
    178   uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
    179   int        *photcode    ; ALLOCATE (photcode    ,  int,      Ndetections);
    180   uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
    181   float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
    182   float      *zpErr       ; ALLOCATE (zpErr       ,  float,    Ndetections);
    183   float      *airMass     ; ALLOCATE (airMass     ,  float,    Ndetections);
    184   float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
     191  uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
     192   int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
    185193  double     *ra          ; ALLOCATE (ra          ,  double,   Ndetections);
    186194  double     *dec         ; ALLOCATE (dec         ,  double,   Ndetections);
    187195  float      *raErr       ; ALLOCATE (raErr       ,  float,    Ndetections);
    188196  float      *decErr      ; ALLOCATE (decErr      ,  float,    Ndetections);
     197  float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
     198  float      *telluricExt ; ALLOCATE (telluricExt ,  float,    Ndetections);
     199  float      *airmass     ; ALLOCATE (airmass     ,  float,    Ndetections);
     200  float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
     201  float      *Mpsf        ; ALLOCATE (Mpsf        ,  float,    Ndetections);
     202  float      *dMpsf       ; ALLOCATE (dMpsf       ,  float,    Ndetections);
     203  float      *Mkron       ; ALLOCATE (Mkron       ,  float,    Ndetections);
     204  float      *dMkron      ; ALLOCATE (dMkron      ,  float,    Ndetections);
     205  float      *Map         ; ALLOCATE (Map         ,  float,    Ndetections);
     206  float      *dMap        ; ALLOCATE (dMap        ,  float,    Ndetections);
     207  uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
    189208
    190209  // assign the storage arrays
    191210  for (i = 0; i < Ndetections; i++) {
    192     imageID[i]     = detections[i].imageID     ;
    193     ippDetectID[i] = detections[i].ippDetectID ;
     211    objID[i]       = detections[i].objID       ;
    194212    detectID[i]    = detections[i].detectID    ;
    195213    ippObjID[i]    = detections[i].ippObjID    ;
    196     objID[i]       = detections[i].objID       ;
    197     photcode[i]    = detections[i].photcode    ;
    198     flags[i]       = detections[i].flags       ;
    199     zp[i]          = detections[i].zp          ;
    200     zpErr[i]       = detections[i].zpErr       ;
    201     airMass[i]     = detections[i].airMass     ;
    202     expTime[i]     = detections[i].expTime     ;
     214    ippDetectID[i] = detections[i].ippDetectID ;
     215    imageID[i]     = detections[i].imageID     ;
    203216    ra[i]          = detections[i].ra          ;
    204217    dec[i]         = detections[i].dec         ;
    205218    raErr[i]       = detections[i].raErr       ;
    206219    decErr[i]      = detections[i].decErr      ;
     220    zp[i]          = detections[i].zp          ;
     221    telluricExt[i] = detections[i].telluricExt ;
     222    airmass[i]     = detections[i].airmass     ;
     223    expTime[i]     = detections[i].expTime     ;
     224    Mpsf[i]        = detections[i].Mpsf        ;
     225    dMpsf[i]       = detections[i].dMpsf       ;
     226    Mkron[i]       = detections[i].Mkron       ;
     227    dMkron[i]      = detections[i].dMkron      ;
     228    Map[i]         = detections[i].Map         ;
     229    dMap[i]        = detections[i].dMap        ;
     230    flags[i]       = detections[i].flags       ;
    207231  }
    208232
    209233  // add the columns to the output array
    210   gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
    211   gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
     234  gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
    212235  gfits_set_bintable_column (&theader, &ftable, "detectID",    detectID    , Ndetections);
    213236  gfits_set_bintable_column (&theader, &ftable, "ippObjID",    ippObjID    , Ndetections);
    214   gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
    215   gfits_set_bintable_column (&theader, &ftable, "photcode",    photcode    , Ndetections);
    216   gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
    217   gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
    218   gfits_set_bintable_column (&theader, &ftable, "zpErr",       zpErr       , Ndetections);
    219   gfits_set_bintable_column (&theader, &ftable, "airMass",     airMass     , Ndetections);
    220   gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
     237  gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
     238  gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
    221239  gfits_set_bintable_column (&theader, &ftable, "ra",          ra          , Ndetections);
    222240  gfits_set_bintable_column (&theader, &ftable, "dec",         dec         , Ndetections);
    223241  gfits_set_bintable_column (&theader, &ftable, "raErr",       raErr       , Ndetections);
    224242  gfits_set_bintable_column (&theader, &ftable, "decErr",      decErr      , Ndetections);
    225 
    226   free (imageID     );
    227   free (ippDetectID );
     243  gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
     244  gfits_set_bintable_column (&theader, &ftable, "telluricExt", telluricExt , Ndetections);
     245  gfits_set_bintable_column (&theader, &ftable, "airmass",     airmass     , Ndetections);
     246  gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
     247  gfits_set_bintable_column (&theader, &ftable, "Mpsf",        Mpsf        , Ndetections);
     248  gfits_set_bintable_column (&theader, &ftable, "dMpsf",       dMpsf       , Ndetections);
     249  gfits_set_bintable_column (&theader, &ftable, "Mkron",       Mkron       , Ndetections);
     250  gfits_set_bintable_column (&theader, &ftable, "dMkron",      dMkron      , Ndetections);
     251  gfits_set_bintable_column (&theader, &ftable, "Map",         Map         , Ndetections);
     252  gfits_set_bintable_column (&theader, &ftable, "dMap",        dMap        , Ndetections);
     253  gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
     254
     255  free (objID       );
    228256  free (detectID    );
    229257  free (ippObjID    );
    230   free (objID       );
    231   free (photcode    );
    232   free (flags       );
    233   free (zp          );
    234   free (zpErr       );
    235   free (airMass     );
    236   free (expTime     );
     258  free (ippDetectID );
     259  free (imageID     );
    237260  free (ra          );
    238261  free (dec         );
    239262  free (raErr       );
    240263  free (decErr      );
     264  free (zp          );
     265  free (telluricExt );
     266  free (airmass     );
     267  free (expTime     );
     268  free (Mpsf        );
     269  free (dMpsf       );
     270  free (Mkron       );
     271  free (dMkron      );
     272  free (Map         );
     273  free (dMap        );
     274  free (flags       );
    241275
    242276  gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r37048 r37176  
    281281}
    282282
    283 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    284   if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
    285   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    286 
    287 int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
    288 
    289   PrintIOBuffer (buffer, "(%d, ", detection->imageID);    // imageID
    290   PrintIOBuffer (buffer, "%u, ", detection->ippDetectID); // ippDetectID
    291   PrintIOBuffer (buffer, "%lu, ", detection->detectID);   // detectID
    292   PrintIOBuffer (buffer, "%lu, ", detection->ippObjID);   // ippObjID
    293   PrintIOBuffer (buffer, "%lu, ", detection->objID);      // objID
    294   PrintIOBuffer (buffer, "%u, ", detection->flags);       // flags
    295   PRINT_FLOAT(buffer, detection->zp,      "%.6f, ");
    296   PRINT_FLOAT(buffer, detection->zpErr,   "%.6f, ");
    297   PRINT_FLOAT(buffer, detection->airMass, "%.6f, ");
    298   PRINT_FLOAT(buffer, detection->expTime, "%.6f, ");
    299   PRINT_FLOAT(buffer, detection->ra,      "%.8f, ");
    300   PRINT_FLOAT(buffer, detection->dec,     "%.8f, ");
    301   PRINT_FLOAT(buffer, detection->raErr,   "%.6f, ");
    302   PRINT_FLOAT(buffer, detection->decErr,  "%.6f),\n");
    303   return TRUE;
    304 }
  • branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r37048 r37176  
    4747      if (measure->photcode >=  PHOTCODE_END) continue;
    4848
    49       PhotCode *code = GetPhotcodebyCode(measure->photcode);
    50 
    51       detections[Ndetections].imageID     = measure->imageID;    // imageID
    52       detections[Ndetections].ippDetectID = measure->detID;   // ippDetectID
    53       detections[Ndetections].detectID    = measure->extID;   // detectID
    54       detections[Ndetections].ippObjID    = ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID; // ippObjID
    55       // NOTE: this is better, but the above is the current ippToPsps value
    56       // detections[Ndetections]. ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
    57       detections[Ndetections].objID        = average->extID;   // objID
    58       detections[Ndetections].photcode     = measure->photcode;   // photcode
    59       detections[Ndetections].flags        = measure->dbFlags;  // flags
    60       detections[Ndetections].zp           = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;   // zp
    61       detections[Ndetections].zpErr        = measure->dMcal;    // zpErr
    62       detections[Ndetections].airMass      = measure->airmass;
    63       detections[Ndetections].expTime      = pow(10.0, 0.4 * measure->dt);    // expTime
    64       detections[Ndetections].ra           = measure->R;    // ra
    65       detections[Ndetections].dec          = measure->D;    // dec
    66       detections[Ndetections].raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
    67       detections[Ndetections].decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
    68 
     49      assign_detection_values (&detections[Ndetections], measure, average);
    6950      Ndetections ++;
     51
    7052      myAssert (Ndetections <= NDETECTIONS, "programming error");
    7153    }
     
    143125
    144126      // XXX check return status
    145       if (!insert_detections_mysql_value (&buffer, &average[i], &measure[Nmeas])) {
     127      Detections detection;
     128      assign_detection_values (&detection, &measure[Nmeas], &average[i]);
     129
     130      if (!insert_detections_mysql_detvalue (&buffer, &detection)) {
    146131        fprintf (stderr, "failure to insert detections in mysql\n");
    147132        status = FALSE;
     
    194179  }
    195180
    196   // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    197   PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    198 
    199   return TRUE;
    200 }
    201 
    202 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    203   if (isinf(FIELD) || isnan(FIELD)) PrintIOBuffer (BUFFER, "NULL, ");   \
    204   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    205 
    206 int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) {
    207 
    208   PhotCode *code = GetPhotcodebyCode(measure->photcode);
    209   PrintIOBuffer (buffer, "(%d, ", measure->imageID);      // imageID
    210   PrintIOBuffer (buffer, "%u, ", measure->detID); // ippDetectID
    211   PrintIOBuffer (buffer, "%lu, ", measure->extID);        // detectID
    212   PrintIOBuffer (buffer, "%lu, ", ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID);    // ippObjID
    213   // NOTE: the following is better, but the above is the current ippToPsps value
    214   // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
    215   PrintIOBuffer (buffer, "%lu, ", average->extID);        // objID
    216   // XXX PrintIOBuffer (buffer, "%d, ", measure->photcode);       // photcode
    217   PrintIOBuffer (buffer, "%u, ", measure->dbFlags);       // flags
    218 
    219   float zp = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;
    220   float exptime = pow(10.0, 0.4 * measure->dt);
    221   double ra  = measure->R;
    222   double dec = measure->D;
    223   double dR = measure->dXccd * 0.01 * fabs(measure->pltscale);
    224   double dD = measure->dYccd * 0.01 * fabs(measure->pltscale);
    225 
    226   PRINT_FLOAT(buffer, zp,               "%.6f, ");
    227   PRINT_FLOAT(buffer, measure->dMcal,   "%.6f, ");
    228   PRINT_FLOAT(buffer, measure->airmass, "%.6f, ");
    229   PRINT_FLOAT(buffer, exptime,          "%.6f, ");
    230   PRINT_FLOAT(buffer, ra,               "%.8f, ");
    231   PRINT_FLOAT(buffer, dec,              "%.8f, ");
    232   PRINT_FLOAT(buffer, dR,               "%.6f, ");
    233   PRINT_FLOAT(buffer, dD,               "%.6f),\n");
    234  
    235   return TRUE;
    236 }
    237    
     181  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, ");
     182  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, telluricExt, airmass, expTime, Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags) VALUES \n");
     183
     184  return TRUE;
     185}
     186
    238187int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) {
    239188
     
    270219  return status;
    271220}
     221
     222# define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
     223  if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
     224  else PrintIOBuffer (BUFFER, FORMAT, FIELD);
     225
     226int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
     227
     228  PrintIOBuffer (buffer, "(%lu, ", detection->objID);       // objID
     229  PrintIOBuffer (buffer,  "%lu, ", detection->detectID);    // detectID
     230  PrintIOBuffer (buffer,  "%lu, ", detection->ippObjID);    // ippObjID
     231  PrintIOBuffer (buffer,  "%u,  ", detection->ippDetectID); // ippDetectID
     232  PrintIOBuffer (buffer,  "%d,  ", detection->imageID);     // imageID
     233
     234  PRINT_FLOAT(buffer, detection->ra,          "%.8f, ");
     235  PRINT_FLOAT(buffer, detection->dec,         "%.8f, ");
     236  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
     237  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
     238  PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
     239  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
     240  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
     241  PRINT_FLOAT(buffer, detection->expTime,     "%.6f, ");
     242
     243  PRINT_FLOAT(buffer, detection->Mpsf,        "%.6f, ");
     244  PRINT_FLOAT(buffer, detection->dMpsf,       "%.6f, ");
     245  PRINT_FLOAT(buffer, detection->Mkron,       "%.6f, ");
     246  PRINT_FLOAT(buffer, detection->dMkron,      "%.6f, ");
     247  PRINT_FLOAT(buffer, detection->Map,         "%.6f, ");
     248  PRINT_FLOAT(buffer, detection->dMap,        "%.6f, ");
     249
     250  PrintIOBuffer (buffer, "%u),\n", detection->flags);     // flags
     251  return TRUE;
     252}
     253
     254int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
     255
     256  PhotCode *code = GetPhotcodebyCode(measure->photcode);
     257
     258  uint64_t ippObjID = ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
     259
     260  float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
     261  float zp          = nominalZP - measure->Mcal;
     262  float telluricExt = - measure->Mcal;
     263  float expTime     = pow(10.0, 0.4 * measure->dt);
     264  float airmass     = measure->airmass;
     265
     266  detection->objID        = average->extID;   // objID
     267  detection->detectID     = measure->extID;   // detectID
     268  detection->ippObjID     = ippObjID;          // ippObID
     269  detection->ippDetectID  = measure->detID;   // ippDetectID
     270  detection->imageID      = measure->imageID; // imageID
     271
     272  detection->ra           = measure->R;    // ra
     273  detection->dec          = measure->D;    // dec
     274  detection->raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
     275  detection->decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
     276
     277  detection->zp           = zp;
     278  detection->telluricExt  = telluricExt;
     279  detection->airmass      = airmass;
     280  detection->expTime      = expTime;
     281
     282  // XXX clean this up with dvo_photcode_ops calls:
     283  detection->Mpsf   = (measure->FluxPSF  > 0.0) ? zp - 2.5*log10(measure->FluxPSF)  : NAN;
     284  detection->Mkron  = (measure->FluxKron > 0.0) ? zp - 2.5*log10(measure->FluxKron) : NAN;
     285  detection->Map    = (measure->FluxAp   > 0.0) ? zp - 2.5*log10(measure->FluxAp)   : NAN;
     286
     287  detection->dMpsf  = (measure->FluxPSF  > 0.0) ? measure->dFluxPSF / measure->FluxPSF : NAN;
     288  detection->dMkron = (measure->FluxKron > 0.0) ? measure->dFluxKron/ measure->FluxKron: NAN;
     289  detection->dMap   = (measure->FluxAp   > 0.0) ? measure->dFluxAp  / measure->FluxAp  : NAN;
     290
     291  detection->flags  = measure->dbFlags;  // flags
     292
     293  return TRUE;
     294}
     295
  • branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r37115 r37176  
    9090  // Only send the necessary fields (eg, do not sent parallax and pm)
    9191  PrintIOBuffer (&buffer, "CREATE TABLE %s_cpt ("
    92                  "EXT_ID      BIGINT"
    93                  "OBJ_ID      INT,  "     
    94                  "CAT_ID      INT,  "     
    95                  "DVO_REGION  INT"
    96                  "FLAGS       INT,  "       
    97                  "RA_STK      DOUBLE,  "         
    98                  "DEC_STK     DOUBLE,  "         
     92                 "EXT_ID      BIGINT, "
     93                 "OBJ_ID      INT,    "     
     94                 "CAT_ID      INT,    "     
     95                 "DVO_REGION  INT,    "
     96                 "RA_STK      DOUBLE, "         
     97                 "DEC_STK     DOUBLE, "         
    9998                 "RA_STK_ERR  FLOAT,  "     
    10099                 "DEC_STK_ERR FLOAT,  "     
    101                  "RA_MEAN     DOUBLE,  "         
    102                  "DEC_MEAN    DOUBLE,  "         
     100                 "RA_MEAN     DOUBLE, "         
     101                 "DEC_MEAN    DOUBLE, "         
    103102                 "RA_ERR      FLOAT,  "     
    104103                 "DEC_ERR     FLOAT,  "     
    105104                 "CHISQ_POS   FLOAT,  "   
    106105                 "CHISQ_PM    FLOAT,  "   
    107                  "CHISQ_PAP   FLOAT,  "   
     106                 "CHISQ_PAR   FLOAT,  "   
     107                 "FLAGS       INT     "       
    108108                 ")\n", basename);
    109109
     
    153153
    154154  PrintIOBuffer (&buffer, "CREATE TABLE %s_cps ("
    155                  "MAG       FLOAT,  "             
    156                  "MAG_ERR   FLOAT,  "         
    157                  "MAG_STDEV FLOAT,  "         
    158                  "MAG_MIN   FLOAT,  "         
    159                  "MAG_MAX   FLOAT,  "         
    160                  "NUSED     SMALLINT,  "           
    161 
     155                 "MAG            FLOAT,  "             
     156                 "MAG_ERR        FLOAT,  "         
     157                 "MAG_STDEV      FLOAT,  "         
     158                 "MAG_MIN        FLOAT,  "         
     159                 "MAG_MAX        FLOAT,  "         
     160                 "NUSED          SMALLINT,  "           
    162161                 "MAG_KRON       FLOAT,  "       
    163162                 "MAG_KRON_ERR   FLOAT,  "   
    164163                 "MAG_KRON_STDEV FLOAT,  "   
    165164                 "NUSED_KRON     SMALLINT,  "   
    166 
    167165                 "MAG_AP         FLOAT,  "             
    168166                 "MAG_AP_ERR     FLOAT,  "             
    169167                 "MAG_AP_STDEV   FLOAT,  "             
    170168                 "NUSED_AP       SMALLINT,  "   
    171 
    172                  "FLAGS INT,  "           
     169                 "NCODE          SMALLINT,  "           
     170                 "FLAGS          INT  "           
    173171                 ")\n", basename);
    174172
     
    194192
    195193  PrintIOBuffer (ave_buffer, "INSERT INTO %s_cpt ("
    196                  "EXT_ID"
    197                  "OBJ_ID, "     
    198                  "CAT_ID, "     
    199                  "DVO_REGION, "
    200                  "FLAGS, "       
    201                  "RA_STK, "         
    202                  "DEC_STK, "         
    203                  "RA_STK_ERR, "     
     194                 "EXT_ID,      "
     195                 "OBJ_ID,      "     
     196                 "CAT_ID,      "     
     197                 "DVO_REGION,  "
     198                 "RA_STK,      "         
     199                 "DEC_STK,     "         
     200                 "RA_STK_ERR,  "     
    204201                 "DEC_STK_ERR, "     
    205                  "RA_MEAN, "         
    206                  "DEC_MEAN, "         
    207                  "RA_ERR, "     
    208                  "DEC_ERR, "     
    209                  "CHISQ_POS, "   
    210                  "CHISQ_PM, "   
    211                  "CHISQ_PAP, "   
     202                 "RA_MEAN,     "         
     203                 "DEC_MEAN,    "         
     204                 "RA_ERR,      "     
     205                 "DEC_ERR,     "     
     206                 "CHISQ_POS,   "   
     207                 "CHISQ_PM,    "   
     208                 "CHISQ_PAR,   "   
     209                 "FLAGS        "       
    212210                 ") VALUES \n", basename);
    213211
     
    234232                 "NUSED_AP, "           
    235233
    236                  "FLAGS, "           
     234                 "NCODE, "           
     235                 "FLAGS "           
    237236                 ") VALUES \n", basename);
    238237  return TRUE;
     
    249248// XXX this bit could/should be autocoded...
    250249  PrintIOBuffer (ave_buffer, " (");
    251   PrintIOBuffer (ave_buffer, "%lu",  average->extID);         
    252   PrintIOBuffer (ave_buffer, "%u, ", average->objID);         
    253   PrintIOBuffer (ave_buffer, "%u, ", average->catID);         
     250  PrintIOBuffer (ave_buffer, "%lu, ", average->extID);         
     251  PrintIOBuffer (ave_buffer, "%u,  ", average->objID);         
     252  PrintIOBuffer (ave_buffer, "%u,  ", average->catID);         
    254253
    255254  int dvoRegion = 1;
    256255  PrintIOBuffer (ave_buffer, "%u, ",  dvoRegion);         
    257   PrintIOBuffer (ave_buffer, "%u, ",  average->flags);         
    258256
    259257  PRINT_FLOAT(ave_buffer, average->Rstk,     "%.8f, ");  // 0.036 mas precision
     
    270268  PRINT_FLOAT(ave_buffer, average->ChiSqPM,  "%.4f, ");
    271269  PRINT_FLOAT(ave_buffer, average->ChiSqPar, "%.4f, ");
     270
     271  PrintIOBuffer (ave_buffer, "%u ",  average->flags);         
    272272
    273273  PrintIOBuffer (ave_buffer, "),\n");
     
    323323    PRINT_FLOAT(sec_buffer, meanApMagStd,  "%.6f, "); // umag precision
    324324    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedAp);       
    325 
    326     PrintIOBuffer (sec_buffer, "%u,   ", secfilt->flags);       
     325    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);       
     326    PrintIOBuffer (sec_buffer, "%u    ", secfilt->flags);       
     327
    327328    PrintIOBuffer (sec_buffer, "),\n");
    328329    secfilt ++;
Note: See TracChangeset for help on using the changeset viewer.