IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40400


Ignore:
Timestamp:
Apr 19, 2018, 4:00:59 PM (8 years ago)
Author:
eugene
Message:

updates to avperiodogram

File:
1 edited

Legend:

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

    r40398 r40400  
    22# define MIN_VAR 1e-8
    33# define NPERIODS 50
     4
     5/* basic outline of the code:
     6
     7 * parse optional arguments
     8 * -parallel : launch parallel jobs [below is called for non-parallel or for dvo_client
     9
     10 * parse optional -where-measure clause
     11 *
     12
     13 */
    414
    515typedef struct {
     
    1727int avperiodogram (int argc, char **argv) {
    1828 
     29# if (0)
     30
    1931  int N, next, Nfields;
    2032
     
    2537  SkyRegionSelection *selection = NULL;
    2638
     39  // **** parse the optional arguments ****
    2740  if ((N = get_argument (argc, argv, "-h"))) goto help;
    2841  if ((N = get_argument (argc, argv, "--help"))) goto help;
     
    4558    PARALLEL = TRUE;
    4659  }
     60
     61  // parse skyregion options.  NOTE: this is stripped off in parallel operation and always
     62  // defined for the client via the -skyregion option.  The dvo_client parses this
     63  // argument in the main program, before it is passed to the command (like mextract)
     64  if ((selection = SetRegionSelection (&argc, argv)) == NULL) {
     65    print_error();
     66    goto escape;
     67  }
     68
     69  /* load region corresponding to selection above */
     70  if ((skylist = SelectRegions (selection)) == NULL) goto escape;
     71
     72  // **** launch parallel / remote jobs ****
     73  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     74  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);
     81    FreeSkyRegionSelection (selection);
     82    dvo_catalog_free (&catalog);
     83
     84    return status;
     85  }
     86
     87  // NOTE: optional arguments below are parsed after the possible remote call so they are also passed to the dvo_client
    4788
    4889  if ((N = get_argument (argc, argv, "-min-period"))) {
     
    92133  ALLOCATE (mvalues, dbValue, Nmfields);
    93134
    94   // XXX : I've removed -parallel-local : see avextract for an example
     135  // use remote tables, but not dvo_client..
     136  int PARALLEL_LOCAL = FALSE;
     137  HostTable *table = NULL;
     138  if ((N = get_argument (argc, argv, "-parallel-local"))) {
     139    remove_argument (N, &argc, argv);
     140    PARALLEL_LOCAL = TRUE;
     141
     142    char *CATDIR = GetCATDIR();
     143    if (!CATDIR) {
     144      gprint (GP_ERR, "CATDIR is not set\n");
     145      return FALSE;
     146    }
     147    SkyTable *sky = GetSkyTable();
     148    if (!sky) {
     149      gprint (GP_ERR, "failed to load sky table for database\n");
     150      return FALSE;
     151    }
     152    table = HostTableLoad (CATDIR, sky->hosts);
     153    if (!table) {
     154      gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     155      return FALSE;
     156    }   
     157  }
    95158
    96159  Catalog catalog;
     
    101164  int Nsecfilt = GetPhotcodeNsecfilt ();
    102165
    103   // parse skyregion options.  NOTE: this is stripped off in parallel operation and always
    104   // defined for the client via the -skyregion option.  The dvo_client parses this
    105   // argument in the main program, before it is passed to the command (like mextract)
    106   if ((selection = SetRegionSelection (&argc, argv)) == NULL) {
    107     print_error();
    108     goto escape;
    109   }
    110 
    111166  // init locally static variables (time refs)
    112167  dbExtractAveragesInit ();
    113168
    114   // command-line is of the form: avperiodogram where (field op value)...
     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]);
    115172
    116173  // examine line for 'where' or 'match to'.  'match to' is forbidden
    117   int state = dbCmdlineConditions (argc, argv, 1, &next);
     174  int state = dbCmdlineConditions (argc, argv, 2, &next);
    118175  if (state == DVO_DB_CMDLINE_ERROR) goto escape;
    119176  if (state == DVO_DB_CMDLINE_IS_MATCH) goto escape; // not allowed for avperiodogram
     
    140197  ALLOCATE (values, dbValue, Nfields);
    141198
    142   /* load region corresponding to selection above */
    143   if ((skylist = SelectRegions (selection)) == NULL) goto escape;
    144 
    145   // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    146   if (PARALLEL && !HOST_ID) {
    147     int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
    148 
    149     dbFreeFields (fields, Nfields);
    150     dbFreeStack (stack, Nstack);
    151     free (stack);
    152     FreeSkyRegionSelection (selection);
    153     dvo_catalog_free (&catalog);
    154 
    155     return status;
    156   }
    157 
    158199  // grab data from all selected sky regions
    159200  struct sigaction *old_sigaction = SetInterrupt();
     
    180221    }
    181222    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);
    182244
    183245    // Scan the catalog for objects which match the WHERE clause
     
    236298
    237299      PeriodogramResult *result = periodogram_fm_raw (time, mag, dmag, Npts);
    238       // XXX write the periodogram result to a file
     300
     301      PeriodogramResultSave (result, extname, foutput);
    239302      PeriodogramResultFree (result);
    240303    }
     304
     305    fclose (foutput);
     306    fflush (foutput);
     307
    241308    dvo_catalog_free (&catalog);
    242309  }
     
    261328  return (FALSE);
    262329
     330
    263331 help:
    264   gprint (GP_ERR, "USAGE: avperiodogram where (expression) -where-measure (expression)\n");
     332
     333# endif
     334  gprint (GP_ERR, "USAGE: avperiodogram (output) where (expression) -where-measure (expression)\n");
    265335  gprint (GP_ERR, "  the where (expression) is a boolean to limit the objects analysed based on average properties\n");
    266336  gprint (GP_ERR, "  NOTE: the optional -where-measure (expression) MUST come after the average where expression\n");
    267337  return (FALSE);
     338
     339
    268340}
    269341
     
    397469  return;
    398470}
     471
     472/*
     473
     474// write the period and power vectors to an extension in this output file
     475void PeriodogramResultFree (PeriodogramResult *result, char *extname, FILE *foutput) {
     476
     477  // generate a binary table
     478  Header outheader;
     479  FTable outtable;
     480  gfits_init_header (&outheader);
     481  gfits_init_table  (&outtable);
     482  outtable.header = &outheader;
     483
     484  // XXX add some metadata to the header to identify the object
     485  // extname should be related to the object IDs
     486  gfits_create_table_header (&outheader, "BINTABLE", extname);
     487
     488  gfits_define_bintable_column (&outheader, "D", "PERIOD", NULL, NULL, 1.0, 0.0);
     489  gfits_define_bintable_column (&outheader, "D", "POWER", NULL, NULL, 1.0, 0.0);
     490
     491  gfits_create_table (theader, ftable);
     492
     493  gfits_set_bintable_column (&outheader, &outtable, "PERIOD", result->period, result->Nperiods);
     494  gfits_set_bintable_column (&outheader, &outtable, "POWER",  result->power,  result->Nperiods);
     495
     496  // write the actual table data
     497  gfits_fwrite_Theader (foutput, &outheader);
     498  gfits_fwrite_table   (foutput, &outtable);
     499   
     500  gfits_free_header (&outheader);
     501  gfits_free_table  (&outtable);
     502}
     503
     504*/
Note: See TracChangeset for help on using the changeset viewer.