Fix reading of latex_labels in prior file to avoid multiple escape characters
Currently when reading in a prior dictionary to file it adds additional \
escape characters to strings containing \
s, e.g., LaTeX labels. For example, if I create:
import bilby
pd = {}
pd['iota'] = bilby.core.prior.Uniform(name='iota', minimum=0.0, maximum=1.0, latex_label=r"$\iota$")
pdd = bilby.core.prior.PriorDict(pd)
pdd.to_file('.', 'test')
then the output file looks like:
iota = Uniform(minimum=0.0, maximum=1.0, name='iota', latex_label='$\\iota$', unit=None, boundary=None)
which is fine. But, if I read this back in, e.g.:
pd2 = bilby.core.prior.PriorDict(filename='test.prior')
the latex label contains extra escape characters:
print(pd2)
PriorDict([('iota',
Uniform(minimum=0.0, maximum=1.0, name='iota', latex_label='$\\\\iota$', unit=None, boundary=None))])
If you then use this read-in prior in a Results
object, for example, the LaTeX label will cause problems in plotting.
This is caused by how open
interprets escape characters and can be fixed by using the encoding='unicode_escape'
argument to open
. For Python 2 compatibility you have to use the open
function from the io
module (which in Python 3 is already the alias for the standard open
function).
Merge request reports
Activity
added 1 commit
- 68e5828a - prior.py: fix reading of latex_labels to avoid multiple escape characters
added 1 commit
- a2c40c50 - Try and fix Python 2 test failure with unicode_literals
added 1 commit
- a67878ee - Fix test errors by reverting back to the standard open function in most cases
- Resolved by Matthew David Pitkin
changed milestone to %0.5.6
mentioned in commit f76d9c34