Repository: gwastro/pycbc

Issue:
PyCBC inference "Simulated BBH example" pycbc_create_injections call fails with HDF5 error
I am trying to follow the PyCBC inference instructions in http://pycbc.org/pycbc/latest/html/inference.html#simulated-bbh-example. The example is failing in the first call to `pycbc_create_injections`:

```
$ cat > injection.ini <<EOF
> [variable_params]
> 
> [static_params]
> tc = 1126259462.420
> mass1 = 37
> mass2 = 32
> ra = 2.2
> dec = -1.25
> inclincation = 2.5
> coa_phase = 1.5
> polarization = 1.75
> distance = 100
> f_ref = 20
> f_lower = 18
> approximant = IMRPhenomPv2
> taper = start
> EOF
$ pycbc_create_injections --verbose \
>         --config-files injection.ini \
>         --ninjections 1 \
>         --seed 10 \
>         --output-file injection.hdf \
>         --variable-params-section variable_params \
>         --static-params-section static_params \
>         --dist-section prior
2019-10-30 00:18:14,835 Loading config file
2019-10-30 00:18:14,836 Reading configuration file
2019-10-30 00:18:14,836 Reading distributions
2019-10-30 00:18:14,836 Drawing samples
2019-10-30 00:18:14,837 Writing results
Traceback (most recent call last):
  File "/opt/miniconda3/envs/ligo-py37/bin/pycbc_create_injections", line 210, in <module>
    cmd=" ".join(sys.argv))
  File "/opt/miniconda3/envs/ligo-py37/lib/python3.7/site-packages/pycbc/inject/inject.py", line 857, in write
    **metadata)
  File "/opt/miniconda3/envs/ligo-py37/lib/python3.7/site-packages/pycbc/inject/inject.py", line 430, in write
    fp.attrs["static_args"] = static_args.keys()
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/opt/miniconda3/envs/ligo-py37/lib/python3.7/site-packages/h5py/_hl/attrs.py", line 95, in __setitem__
    self.create(name, data=value, dtype=base.guess_dtype(value))
  File "/opt/miniconda3/envs/ligo-py37/lib/python3.7/site-packages/h5py/_hl/attrs.py", line 177, in create
    htype = h5t.py_create(original_dtype, logical=True)
  File "h5py/h5t.pyx", line 1630, in h5py.h5t.py_create
  File "h5py/h5t.pyx", line 1652, in h5py.h5t.py_create
  File "h5py/h5t.pyx", line 1707, in h5py.h5t.py_create
TypeError: Object dtype dtype('O') has no native HDF5 equivalent
```

I am using the ligo-py37 reference environment on a macOS Mojave system.


Discussion:

Resolving patch:
diff --git a/pycbc/inject/inject.py b/pycbc/inject/inject.py
--- a/pycbc/inject/inject.py
+++ b/pycbc/inject/inject.py
@@ -334,7 +334,7 @@ def __init__(self, sim_file, hdf_group=None, **kwds):
         group = fp if hdf_group is None else fp[hdf_group]
         self.filehandler = fp
         # get parameters
-        parameters = group.keys()
+        parameters = list(group.keys())
         # get all injection parameter values
         injvals = {param: group[param][()] for param in parameters}
         # if there were no variable args, then we only have a single injection
@@ -421,7 +421,7 @@ def write(cls, filename, samples, write_params=None, static_args=None,
             # write metadata
             if static_args is None:
                 static_args = {}
-            fp.attrs["static_args"] = static_args.keys()
+            fp.attrs["static_args"] = list(static_args.keys())
             fp.attrs['injtype'] = cls.injtype
             for key, val in metadata.items():
                 fp.attrs[key] = val


Test patch: