Repository: gwastro/pycbc

Issue:
PSD variation options break pycbc inference
PR #2079  has broken `pycbc_inference`, perhaps `pycbc_inspiral` too. Trying to run `pycbc_inference`, I get:
```
Traceback (most recent call last):
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/bin/pycbc_inference", line 4, in <module>
    __import__('pkg_resources').run_script('PyCBC==97rc816', 'pycbc_inference')
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 750, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1527, in run_script
    exec(code, namespace, namespace)
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/lib/python2.7/site-packages/PyCBC-97rc816-py2.7.egg/EGG-INFO/scripts/pycbc_inference", line 206, in <module>
    strain_dict, stilde_dict, psd_dict = option_utils.data_from_cli(opts)
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/lib/python2.7/site-packages/PyCBC-97rc816-py2.7.egg/pycbc/inference/option_utils.py", line 462, in data_from_cli
    precision="double")
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/lib/python2.7/site-packages/PyCBC-97rc816-py2.7.egg/pycbc/strain.py", line 443, in from_cli_multi_ifos
    strain[ifo] = from_cli_single_ifo(opt, ifo, **kwargs)
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/lib/python2.7/site-packages/PyCBC-97rc816-py2.7.egg/pycbc/strain.py", line 435, in from_cli_single_ifo
    return from_cli(single_det_opt, **kwargs)
  File "/work/cdcapano/virtualenv/pptests-pycbc_inference/lib/python2.7/site-packages/PyCBC-97rc816-py2.7.egg/pycbc/strain.py", line 425, in from_cli
    if opt.psdvar_short_segment is not None:
AttributeError: 'Namespace' object has no attribute 'psdvar_short_segment'
```
The issue appears to be that the psd variation options were added to `insert_strain_option_group`, but not to `insert_strain_option_group_multi_ifo`, which is what `pycbc_inference` (and I think `pycbc_inspiral`) uses.


Discussion:

Resolving patch:
diff --git a/pycbc/psd/__init__.py b/pycbc/psd/__init__.py
--- a/pycbc/psd/__init__.py
+++ b/pycbc/psd/__init__.py
@@ -175,6 +175,19 @@ def insert_psd_option_group(parser, output=True, include_data_options=True):
                              help="(Optional) The maximum length of the "
                              "impulse response of the overwhitening "
                              "filter (s)")
+    # Options for PSD variation
+    psd_options.add_argument("--psdvar_short_segment", type=float,
+                             metavar="SECONDS", help="Length of short segment "
+                             "when calculating the PSD variability.")
+    psd_options.add_argument("--psdvar_long_segment", type=float,
+                             metavar="SECONDS", help="Length of long segment "
+                             "when calculating the PSD variability.")
+    psd_options.add_argument("--psdvar_overlap", type=float, metavar="SECONDS",                              help="Sample length of the PSD.")
+    psd_options.add_argument("--psdvar_low_freq", type=float, metavar="HERTZ",                               help="Minimum frequency to consider in PSD "
+                             "comparison.")
+    psd_options.add_argument("--psdvar_high_freq", type=float, metavar="HERTZ",                              help="Maximum frequency to consider in PSD "
+                             "comparison.")
+
     if include_data_options :
         psd_options.add_argument("--psd-estimation",
                                  help="Measure PSD from the data, using "
@@ -258,6 +271,19 @@ def insert_psd_option_group_multi_ifo(parser):
                           action=MultiDetOptionAction, metavar='IFO:FILE',
                           help="(Optional) Write PSD to specified file")
 
+    # Options for PSD variation
+    psd_options.add_argument("--psdvar_short_segment", type=float,
+                             metavar="SECONDS", help="Length of short segment "
+                             "when calculating the PSD variability.")
+    psd_options.add_argument("--psdvar_long_segment", type=float,
+                             metavar="SECONDS", help="Length of long segment "
+                             "when calculating the PSD variability.")
+    psd_options.add_argument("--psdvar_overlap", type=float, metavar="SECONDS",                              help="Sample length of the PSD.")
+    psd_options.add_argument("--psdvar_low_freq", type=float, metavar="HERTZ",                               help="Minimum frequency to consider in PSD "
+                             "comparison.")
+    psd_options.add_argument("--psdvar_high_freq", type=float, metavar="HERTZ",                              help="Maximum frequency to consider in PSD "
+                             "comparison.")
+
     return psd_options
 
 ensure_one_opt_groups = []
diff --git a/pycbc/strain.py b/pycbc/strain.py
--- a/pycbc/strain.py
+++ b/pycbc/strain.py
@@ -279,13 +279,6 @@ def from_cli(opt, dyn_range_fac=1, precision='single',
         else:
             raise ValueError("Unrecognized precision {}".format(precision))
 
-        if opt.psdvar_short_segment is not None:
-            logging.info("Calculating PSD variation")
-            psd_var = pycbc.psd.calc_psd_variation(strain,
-                    opt.psdvar_short_segment, opt.psdvar_long_segment,
-                    opt.psdvar_overlap, opt.psdvar_low_freq,
-                    opt.psdvar_high_freq)
-
         if opt.gating_file is not None:
             logging.info("Gating glitches")
             gate_params = numpy.loadtxt(opt.gating_file)
@@ -422,10 +415,7 @@ def from_cli(opt, dyn_range_fac=1, precision='single',
         strain.injections = injections
     strain.gating_info = gating_info
 
-    if opt.psdvar_short_segment is not None:
-        return strain, psd_var
-    else:
-        return strain  
+    return strain  
 
 def from_cli_single_ifo(opt, ifo, **kwargs):
     """
@@ -590,26 +580,6 @@ def insert_strain_option_group(parser, gps_times=True):
     data_reading_group.add_argument("--witness-filter-length", type=float,
                     help="filter length in seconds for the transfer function")
 
-    # Options for PSD variation
-    data_reading_group.add_argument('--psdvar_short_segment', type=float,
-                                    metavar='SECONDS',
-                                    help='Length of short segment when '
-                                         'calculating the PSD variability.')
-    data_reading_group.add_argument('--psdvar_long_segment', type=float,
-                                    metavar='SECONDS',
-                                    help='Length of long segment when '
-                                         'calculating the PSD variability.')
-    data_reading_group.add_argument('--psdvar_overlap', type=float,
-                                    metavar='SECONDS',
-                                    help='Sample length of the PSD.')
-    data_reading_group.add_argument('--psdvar_low_freq', type=float,
-                                    metavar='HERTZ',
-                                    help='Minimum frequency to consider in '
-                                         'PSD comparison.')
-    data_reading_group.add_argument('--psdvar_high_freq', type=float,
-                                    metavar='HERTZ',
-                                    help='Maximum frequency to consider in '
-                                         'PSD comparison.')
     return data_reading_group
 
 # FIXME: This repeats almost all of the options above. Any nice way of reducing


Test patch: