-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_options.py
More file actions
30 lines (24 loc) · 931 Bytes
/
Copy pathread_options.py
File metadata and controls
30 lines (24 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import yaml
import re
def read_options( filename ):
"""Reads in the options file in YAML format
Args:
filename (str): filename of the options file
Returns:
config (dict): potential fitting options, as a dictionary
Notes:
fixes the YAML resolver for scientific notation: http://stackoverflow.com/questions/30458977/yaml-loads-5e-6-as-string-and-not-a-number
"""
loader = yaml.SafeLoader
loader.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(u'''^(?:
[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
|\\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
|[-+]?\\.(?:inf|Inf|INF)
|\\.(?:nan|NaN|NAN))$''', re.X),
list(u'-+0123456789.'))
config = yaml.load( open( filename ), Loader = loader )
return config