Error reading file with ~ in file name
The following snippet raised an OSError
from pesummary.gw.read import read
data = read("~/PATH/TO/posterior_samples.h5")
~/.conda/envs/env/lib/python3.7/site-packages/pesummary/gw/file/read.py in read(path)
91 """
92 return CoreRead(
---> 93 path, HDF5_LOAD=GW_HDF5_LOAD, JSON_LOAD=GW_JSON_LOAD, DEFAULT=GW_DEFAULT
94 )
~/.conda/envs/env/lib/python3.7/site-packages/pesummary/core/file/read.py in read(path, HDF5_LOAD, JSON_LOAD, DEFAULT)
245
246 if extension in ["hdf5", "h5", "hdf"]:
--> 247 return _read(path, HDF5_LOAD, default=DEFAULT)
248 elif extension == "json":
249 return _read(path, JSON_LOAD, default=DEFAULT)
~/.conda/envs/env/lib/python3.7/site-packages/pesummary/core/file/read.py in _read(path, load_options, default)
211 """
212 for check, load in load_options.items():
--> 213 if check(path):
214 try:
215 return load(path)
~/.conda/envs/env/lib/python3.7/site-packages/pesummary/gw/file/read.py in is_lalinference_file(path)
57 """
58 import h5py
---> 59 f = h5py.File(path, 'r')
60 keys = list(f.keys())
61 f.close()
~/.conda/envs/env/lib/python3.7/site-packages/h5py/_hl/files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds)
406 fid = make_fid(name, mode, userblock_size,
407 fapl, fcpl=make_fcpl(track_order=track_order),
--> 408 swmr=swmr)
409
410 if isinstance(libver, tuple):
~/.conda/envs/env/lib/python3.7/site-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
171 if swmr and swmr_support:
172 flags |= h5f.ACC_SWMR_READ
--> 173 fid = h5f.open(name, flags, fapl=fapl)
174 elif mode == 'r+':
175 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5f.pyx in h5py.h5f.open()
OSError: Unable to open file (unable to open file: name = '~/PATH/TO/posterior_samples.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
This worked, so I guess the issue that it's unable to unpack the ~/
which is strange. Maybe wrapping the read file in an os.abspath
will resolve this?
from pesummary.gw.read import read
data = read("/home/colm.talbot/PATH/TO/posterior_samples.h5")
python = 3.7
PESummary == 0.4.0