IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2018, 9:41:13 PM (8 years ago)
Author:
eugene
Message:

updates to avperiodogram

File:
1 edited

Legend:

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

    r40400 r40401  
    2020
    2121void PeriodogramResultFree (PeriodogramResult *result);
     22void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average);
    2223PeriodogramResult *periodogram_fm_raw (opihi_flt *time, opihi_flt *flux, opihi_flt *dflux, int Npts);
    2324
     
    2728int avperiodogram (int argc, char **argv) {
    2829 
    29 # if (0)
    30 
    3130  int N, next, Nfields;
    3231
     
    7372  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    7473  if (PARALLEL && !HOST_ID) {
    75     // XXX this is not going to work : the measure args will have been stripped off
    76     int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
    77 
    78     dbFreeFields (fields, Nfields);
    79     dbFreeStack (stack, Nstack);
    80     free (stack);
     74    int status = HostTableParallelOps (skylist, argc, argv, NULL, TRUE, 0, VERBOSE);
     75    SkyListFree (skylist);
    8176    FreeSkyRegionSelection (selection);
    82     dvo_catalog_free (&catalog);
    83 
    8477    return status;
    8578  }
     
    157150  }
    158151
     152  // command-line is of the form: avperiodogram (output) where (field op value)...
     153  if (argc < 2) goto help;
     154  char *output = strcreate (argv[1]);
     155
     156  // **** generate output file ****
     157  // we save the results in a single FITS file, one extension per object
     158  FILE *foutput = NULL;
     159  if (RESULT_FILE) {
     160    foutput = fopen (RESULT_FILE, "w");
     161  } else {
     162    foutput = fopen (output, "w");
     163  }
     164  // generate the PHU and write to disk
     165  // XXX add some metadata here?
     166  Header header;
     167  Matrix matrix;
     168  gfits_init_header (&header);
     169  gfits_init_matrix (&matrix);
     170  header.extend = TRUE;
     171  gfits_create_header (&header);
     172  gfits_create_matrix (&header, &matrix);
     173  gfits_fwrite_header (foutput, &header);
     174  gfits_fwrite_matrix (foutput, &matrix);
     175  gfits_free_header (&header);
     176  gfits_free_matrix (&matrix);
     177 
    159178  Catalog catalog;
    160179  dvo_catalog_init (&catalog, TRUE);
     
    166185  // init locally static variables (time refs)
    167186  dbExtractAveragesInit ();
    168 
    169   // command-line is of the form: avperiodogram (output) where (field op value)...
    170   if (argc < 2) goto help;
    171   char *output = strcreate (argv[1]);
    172187
    173188  // examine line for 'where' or 'match to'.  'match to' is forbidden
     
    197212  ALLOCATE (values, dbValue, Nfields);
    198213
     214  int Nobject = 0;
     215  char extname[80];
     216
    199217  // grab data from all selected sky regions
    200218  struct sigaction *old_sigaction = SetInterrupt();
     
    221239    }
    222240    dvo_catalog_unlock (&catalog);
    223 
    224     // we save the results in a single FITS file, one extension per object
    225     FILE *foutput = NULL;
    226     if (RESULT_FILE) {
    227       foutput = fopen (RESULT_FILE, "w");
    228     } else {
    229       foutput = fopen (output, "w");
    230     }
    231 
    232     // generate the PHU and write to disk
    233     Header header;
    234     Matrix matrix;
    235     gfits_init_header (&header);
    236     gfits_init_matrix (&matrix);
    237     header.extend = TRUE;
    238     gfits_create_header (&header);
    239     gfits_create_matrix (&header, &matrix);
    240     gfits_fwrite_header (foutput, &header);
    241     gfits_fwrite_matrix (foutput, &matrix);
    242     gfits_free_header (&header);
    243     gfits_free_matrix (&matrix);
    244241
    245242    // Scan the catalog for objects which match the WHERE clause
     
    299296      PeriodogramResult *result = periodogram_fm_raw (time, mag, dmag, Npts);
    300297
    301       PeriodogramResultSave (result, extname, foutput);
     298      // XXX if we have 1e6 objects, we will have output files with sizes of ~80GB
     299      // XXX warn or exit if Nboject > 1e6?
     300      snprintf (extname, 80, "OBJ_%06d", Nobject);
     301      PeriodogramResultSave (result, extname, foutput, average);
    302302      PeriodogramResultFree (result);
     303      Nobject ++;
    303304    }
    304305
     
    330331
    331332 help:
    332 
    333 # endif
    334333  gprint (GP_ERR, "USAGE: avperiodogram (output) where (expression) -where-measure (expression)\n");
    335334  gprint (GP_ERR, "  the where (expression) is a boolean to limit the objects analysed based on average properties\n");
    336335  gprint (GP_ERR, "  NOTE: the optional -where-measure (expression) MUST come after the average where expression\n");
    337336  return (FALSE);
    338 
    339 
    340337}
    341338
     
    470467}
    471468
    472 /*
    473 
    474469// write the period and power vectors to an extension in this output file
    475 void PeriodogramResultFree (PeriodogramResult *result, char *extname, FILE *foutput) {
     470void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average) {
    476471
    477472  // generate a binary table
     
    482477  outtable.header = &outheader;
    483478
    484   // XXX add some metadata to the header to identify the object
    485   // extname should be related to the object IDs
    486479  gfits_create_table_header (&outheader, "BINTABLE", extname);
     480
     481  // add some metadata derived from average:
     482  gfits_modify (&outheader, "RA_OBJ",  "%lf", 1, average->R);
     483  gfits_modify (&outheader, "DEC_OBJ", "%lf", 1, average->D);
     484  gfits_modify (&outheader, "OBJ_ID",  "%d", 1, average->objID);
     485  gfits_modify (&outheader, "CAT_ID",  "%d", 1, average->catID);
    487486
    488487  gfits_define_bintable_column (&outheader, "D", "PERIOD", NULL, NULL, 1.0, 0.0);
    489488  gfits_define_bintable_column (&outheader, "D", "POWER", NULL, NULL, 1.0, 0.0);
    490489
    491   gfits_create_table (theader, ftable);
     490  gfits_create_table (&outheader, &outtable);
    492491
    493492  gfits_set_bintable_column (&outheader, &outtable, "PERIOD", result->period, result->Nperiods);
     
    501500  gfits_free_table  (&outtable);
    502501}
    503 
    504 */
Note: See TracChangeset for help on using the changeset viewer.