gwin.option_utils module

This module contains standard options used for inference-related programs.

gwin.option_utils.add_config_opts_to_parser(parser)[source]

Adds options for the configuration files to the given parser.

gwin.option_utils.add_density_option_group(parser)[source]

Adds the options needed to configure contours and density colour map.

Parameters:parser (object) – ArgumentParser instance.
gwin.option_utils.add_inference_results_option_group(parser, include_parameters_group=True)[source]

Adds the options used to call gwin.results_from_cli function to an argument parser. These are options releated to loading the results from a run of pycbc_inference, for purposes of plotting and/or creating tables.

Parameters:
  • parser (object) – ArgumentParser instance.
  • include_parameters_group (bool) – If true then include --parameters-group option.
gwin.option_utils.add_low_frequency_cutoff_opt(parser)[source]

Adds the low-frequency-cutoff option to the given parser.

gwin.option_utils.add_plot_posterior_option_group(parser)[source]

Adds the options needed to configure plots of posterior results.

Parameters:parser (object) – ArgumentParser instance.
gwin.option_utils.add_sampler_option_group(parser)[source]

Adds the options needed to set up an inference sampler.

Parameters:parser (object) – ArgumentParser instance.
gwin.option_utils.add_scatter_option_group(parser)[source]

Adds the options needed to configure scatter plots.

Parameters:parser (object) – ArgumentParser instance.
gwin.option_utils.config_parser_from_cli(opts)[source]

Loads a config file from the given options, applying any overrides specified. Specifically, config files are loaded from the --config-files options while overrides are loaded from --config-overrides.

gwin.option_utils.data_from_cli(opts)[source]

Loads the data needed for a model from the given command-line options. Gates specifed on the command line are also applied.

Parameters:opts (ArgumentParser parsed args) – Argument options parsed from a command line string (the sort of thing returned by parser.parse_args).
Returns:
  • strain_dict (dict) – Dictionary of instruments -> TimeSeries strain.
  • stilde_dict (dict) – Dictionary of instruments -> FrequencySeries strain.
  • psd_dict (dict) – Dictionary of instruments -> FrequencySeries psds.
gwin.option_utils.expected_parameters_from_cli(opts)[source]

Parses the –expected-parameters arguments from the plot_posterior option group.

Parameters:opts (ArgumentParser) – The parsed arguments from the command line.
Returns:Dictionary of parameter name -> expected value. Only parameters that were specified in the –expected-parameters option will be included; if no parameters were provided, will return an empty dictionary.
Return type:dict
gwin.option_utils.get_file_type(filename)[source]

Returns I/O object to use for file.

Parameters:filename (str) – Name of file.
Returns:file_type – The type of inference file object to use.
Return type:{InferenceFile, InferenceTXTFile}
gwin.option_utils.injections_from_cli(opts)[source]

Gets injection parameters from the inference file(s).

Parameters:opts (argparser) – Argparser object that has the command-line objects to parse.
Returns:Array of the injection parameters from all of the input files given by opts.input_file.
Return type:FieldArray
gwin.option_utils.low_frequency_cutoff_from_cli(opts)[source]

Parses the low frequency cutoff from the given options.

Returns:Dictionary of instruments -> low frequency cutoff.
Return type:dict
gwin.option_utils.parse_parameters_opt(parameters)[source]

Parses the –parameters opt in the results_reading_group.

Parameters:parameters (list of str or None) – The parameters to parse.
Returns:
  • parameters (list of str) – The parameters.
  • labels (dict) – A dictionary mapping parameters for which labels were provide to those labels.
gwin.option_utils.plot_ranges_from_cli(opts)[source]

Parses the mins and maxs arguments from the plot_posterior option group.

Parameters:opts (ArgumentParser) – The parsed arguments from the command line.
Returns:
  • mins (dict) – Dictionary of parameter name -> specified mins. Only parameters that were specified in the –mins option will be included; if no parameters were provided, will return an empty dictionary.
  • maxs (dict) – Dictionary of parameter name -> specified maxs. Only parameters that were specified in the –mins option will be included; if no parameters were provided, will return an empty dictionary.
gwin.option_utils.results_from_cli(opts, load_samples=True, **kwargs)[source]

Loads an inference result file along with any labels associated with it from the command line options.

Parameters:
  • opts (ArgumentParser options) – The options from the command line.
  • load_samples ({True, bool}) – Load samples from the results file using the parameters, thin_start, and thin_interval specified in the options. The samples are returned as a FieldArray instance.
  • **kwargs – All other keyword arguments are passed to the InferenceFile’s read_samples function.
Returns:

  • fp_all (pycbc.io.InferenceFile) – The result file as an InferenceFile. If more than one input file, then it returns a list.
  • parameters_all (list) – List of the parameters to use, parsed from the parameters option. If more than one input file, then it returns a list.
  • labels_all (list) – List of labels to associate with the parameters. If more than one input file, then it returns a list.
  • samples_all ({None, FieldArray}) – If load_samples, the samples as a FieldArray; otherwise, None. If more than one input file, then it returns a list.

gwin.option_utils.sampler_from_cli(opts, model, pool=None)[source]

Parses the given command-line options to set up a sampler.

Parameters:
  • opts (object) – ArgumentParser options.
  • model (model) – The model to use with the sampler.
Returns:

A sampler initialized based on the given arguments.

Return type:

gwin.sampler

gwin.option_utils.validate_checkpoint_files(checkpoint_file, backup_file)[source]

Checks if the given checkpoint and/or backup files are valid.

The checkpoint file is considered valid if:

  • it passes all tests run by InferenceFile.check_integrity;
  • it has at least one sample written to it (indicating at least one checkpoint has happened).

The same applies to the backup file. The backup file must also have the same number of samples as the checkpoint file, otherwise, the backup is considered invalid.

If the checkpoint (backup) file is found to be valid, but the backup (checkpoint) file is not valid, then the checkpoint (backup) is copied to the backup (checkpoint). Thus, this function ensures that checkpoint and backup files are either both valid or both invalid.

Parameters:
  • checkpoint_file (string) – Name of the checkpoint file.
  • backup_file (string) – Name of the backup file.
Returns:

checkpoint_valid – Whether or not the checkpoint (and backup) file may be used for loading samples.

Return type:

bool