Directions for Using HKQuery

HKQuery operates on a list of HK or SED input files, restricting the data contained in those files according to user-supplied rules and produce a single data file as output.

Input Data Files

Input files can be either FITS or HK-ASCII format (the human-readable format created by HKQuery by default). Input files NOT in either of these formats will be ignored. An input file list can be a single file or a list of files. In either case, shell name-completion wild cards may be used. Examples:

Operate only on the file "blah.fit":

HKQuery [rules] blah.fit

Operate on all files in the directory "foo", along with the local file "blah.fit":

HKQuery [rules] blah.fit foo/*

When operating on file lists generated by wild cards, HKQuery will process the files in the same order they are listed using the same wild cards. The following will show the processing sequence in the example above:

ls blah.fit foo/*

The formats of files in an input list need not be the same - they can be a mixture of FITS or HK-ASCII files. HKQuery will read each appropriately, and combine their data to produce its output.

HKQuery can also operate on a file from stdin. Because it ignores files which don't have formats which it recognizes, HKQuery can be run on the contents of a directory, regardless of file type. It will only use those which look like HK or SED data files. Of course the screening is far from fool-proof, as any FITS table will be assumed to contain HK/SED data.

Timetags - The SCET and SCLK

HK and SED data packets are organized by time stamps which give the (rough) time measurements were made. By default, these timestamps are maintained in an HKQuery output file, although this behavior can be shut off using the "-t|timestamp" option.

Time stamps come in two forms - the floating point "SCLK" and the human-readable "SCET". SCLK represents the number of "clock ticks" of the instruments since the beginning of January 1st, 1980. Each clock tick is meant to represent exactly one second, which until launch they do precisely. After launch, a certain amount of drift is expected, which is tracked and updated once a week. To translate to the SCET, this drift must be taken into account (not yet implemented!!!).

All HK programs use the SCLK. The SCET is provided in HK-ASCII output files and on HK2D plots for the sake of readability.

Output

Output is always a single file, to stdout. By default it is HK-ASCII format, a human readable table format. If the command line argument "-fits" is used, the output will be in FITS format. If you are expecting lots of output data, FITS is far more efficient.

Because it can read its own output, HKQuery operations can be chained together:

HKQuery [some rules] *.fit | HKQuery [some other rules] > out.dat

Data Restriction Rules

There are three ways to restrict data:

  1. Rows restrictions, which are applied to each input file. These limit the output to specific numbered rows in each input file (rows are equivalent to HK/SED data packets). Row restrictions can be an arbitrarily complex comma (or space) separated list of any of the following:
    • Positive numbers, indicating rows which should be included
    • Negative numbers, indicating rows counting from the file end (-1 is the second to last row, -2 the third to last, etc)
    • The words "FIRST" and "LAST", indicating what you think they do

    The row restrictions can also be specified by a file name (preceded by the "@" character). The file contains restrictions following the same rules as above, although they can be newline separated and can also contain comment lines (following double slash "//" characters).

    Examples:

    Get the first, third, and second to last rows from each of the .fit files in the directory foo/:

    HKQuery -r "FIRST, 3, -1" foo/*.fit
    

    Operate on the same input file set, but restrict to rows as described in the "row_restrictions.txt" file:

    HKQuery -r "@row_restrictions.txt" foo/*.fit
    
  2. Query rules, which are based on the values of HK/SED data within packets. Packets which pass query rules will be included in output, those which do not will be discarded. Query rules are based on the names of keywords. The rules can be arbitrarily complex combination of the keywords with logical operators, arithmetic operators, or functions.

    The query is performed using a CFITSIO function "fits_select_rows". The structure of query rules is described in the document "CFITSIO User's Reference Guide"(Version 2.4) in section 10.10.

    Permitted logical operators include ==, !=, <, <=, =<, >, >=, =>, ||, &&, !, and ~ (approximately equal to). English language and Fortran style translations may be used in place of the operators (see the CFITSIO documentation for details).

    Arithmetic operators and functions include +, -, *, /, ** (or ^), abs(x), cos(x), sin(x), tan(x), arccos(x), arcsin(x), arctan(x), arctan2(x,y), exp(x), sqrt(x), log(x), log10(x), x % y, random(), min(x,y), max(x,y), and b?x:y (C-style if-then-else). Once again, English language translations are available for all operators and functions. These are described in the CFITSIO documentation.

    The query can also be specified as a file containing a list of query rules. The file name must be preceded by the "@" character. The file can also contain comments following double slash characters ("//").

    Examples:

    Pull the packets where "NASATIME" is greater than zero or less than -100 from all .fit files in directory foo/:

    HKQuery -q "(NASATIME > 0) || (NASATIME < -100)" foo/*.fit
    

    Use the query rules in "query_rules.txt" on the same file set:

    HKQuery -q "@query_rules.txt" foo/*.fit
    
  3. Extraction requests, which will include only specific HK/SED data in the output. Extraction requests take the form of a list of keywords, all of which will be included in the output (a keyword which isn't in the input will be handled gracefully). An extraction request can also be given in the form of a text file containing keywords by preceding it with the "@" character.

    Examples:

    Get "NASATIME" and "SCTIME_C" data from all .fit files in the directory foo/:

    HKQuery -e "NASATIME, SCTIME_C" foo/*.fit
    

    Get the keywords specified in "my_keywords.txt" from the same files:

    HKQuery -e "@my_keywords.txt" foo/*.fit
    

    Any, all, or none of these rules may be used in a single HKQuery operation (although each should only be used ONCE in a single operation). Row restrictions are applied to input data first, then query rules, with extraction requests last. The omission of any restriction rule type will be the equivalent of saying "ALL" - i.e. not including any row restrictions will include all rows in the output, etc.

    Examples:

    Get the "NASATIME" data from all .fit files:

    HKQuery -e "NASATIME" *.fit
    

    Get the "NASATIME" data only when "SCTIME_C" is greater than 0:

    HKQuery -q "SCTIME_C > 0" -e "NASATIME" *.fit
    

    Do the same, but we are only interested in the first and last packet in each file:

    HKQuery -q "SCTIME_C > 0" -e "NASATIME" -r "FIRST, LAST" *.fit
    

    Note that because of the order restrictions are run (row, query, extract), the following chain of HKQuery would produce the same results:

    HKQuery -r "FIRST, LAST" *.fit | HKQuery -q "SCTIME_C > 0" |
    HKQuery -e "NASATIME"
    

    but this would not:

    HKQuery -q "SCTIME_C > 0" *.fit | HKQuery -e "NASATIME" |
    HKQuery -r "FIRST, LAST"
    

Merging Commands Files

A file of IRAC "commands" may be merged into the output from HKQuery. using the "-m" or "-merge" command, followed by the name of the file containing the commands. All data HK/SED data packets and commands in a Commands File are accompanied by a time stamp. These time stamps are used to include commands in the output in sequence with the data.

It is not possible to merge commands into a FITS output file, nor is it possible to merge commands into a file without timestamps. For this reason, using the "-m|merge" option will override both the "-fits|FITS" and "-t|timestamp" options.

Commands are included in the human-readable HK-ASCII output files as "events", which can be included in plots (see Plotting Events in the HK2D documentation).

Online Help

The online help system for HKQuery is pretty good, at least compared to the type of help I normally provide with my software. Help can either be general, which you get by running with the "-h" or "-help" option without any further arguments:

HKQuery -help

or it can be about a specific subtopic:

HKQuery -help [subtopic]

The subtopics available (presently) are:

debug
error
extract
FITS
filelist
help
merge
query
rows

Topics generally match the command line inputs, although there are some additional ones.

Help will be sent to stderr. HKQuery will stop after providing help.

Process Tracking

When HKQuery is run, a record of its version, who ran it, when, with what arguments and with what input files is included in the output (both FITS and HK-ASCII format). Any of this tracking information found in input files is also included in the output. Thus it should be possible to reconstruct all processing steps used to get to a given output file from information contained within it.

Summary of Command Line Arguments

The following is a list of command line arguments and a brief description of what they do:

-c|case
Make column keyword searches case sensitive. By default they are not case sensitive. It looks to me like the HK/SED keywords are all upper case.
-d|debug
Increment the debug level. You can repeatedly use this option if you want a higher debug level (as in "HKQuery -d -d -d", etc). Debug level 1 information contains recoverable errors (like input files in unknown formats), debug 2 information is basic processing steps (maybe useful to monitor progress), debug 3 is somewhat more detailed about processing steps, and debug 4 is more information than you'd ever want.
-e|extract [string]
Extract a list of keywords from the input or a list specified by a file name. See above.
-fits|FITS
Force output in FITS format. By default output is in HK-ASCII format, but FITS can be more efficient if lots of data are created.
-h|help [subtopic]
Provide online help (program terminates after help) to stderr. An optional subtopic will provide detailed help about that subtopic. See Online Help.
-m|merge [string]
Merge commands from the given commands file. See Merging Commands Files.
-q|query [string]
Include only packets which pass a rule set. The string is either a set of rules or the name of a file containing those rules. See above.
-r|rows [string]
Include only indicated row numbers from each input file. The string is either a list of row numbers or a file containing that list. See above.
-t|timestamp
Do not include time stamps in output. Normally they are always included (see Timetags - The SCET and SCLK).
-v|version
Print the program version