Module flavio.measurements
Functions for parsing the measurement data files
Functions
def load(obj)-
Expand source code
def load(obj): """Alias for `read_file` for backwards compatibility. Don't use.""" warnings.warn("The function `flavio.measurements.load` was replaced " "by `flavio.measurements.read_file` in v0.13 " "and might be removed in the future. " "Please update your code.", FutureWarning) return read_file(obj)Alias for
read_file()for backwards compatibility. Don't use. def read_default()-
Expand source code
def read_default(): """Read all measurements from `data/measurements.yml`. This function is invoked once when the package is loaded.""" return _load(pkgutil.get_data('flavio', 'data/measurements.yml'))Read all measurements from
data/measurements.yml.This function is invoked once when the package is loaded.
def read_file(filename)-
Expand source code
def read_file(filename): """Read measurements from a YAML file.""" with open(filename, 'r') as f: try: return _load_new(f) except: f.seek(0) # rewind return _load(f)Read measurements from a YAML file.
def read_url(url)-
Expand source code
def read_url(url): """Read measurements from a URL.""" try: import requests except: raise ImportError("You need to install the python requests module to load measurements from a URL.") res = requests.get(url) return _load(res.text)Read measurements from a URL.
def write_file(filename, measurements)-
Expand source code
def write_file(filename, measurements): """Write measurements to a YAML file. measurements can be a list of string names or a list of measurement instances.""" measurement_instances = [m if isinstance(m, Measurement) else Measurement[m] for m in measurements] with open(filename, 'w') as f: yaml.dump([m.get_yaml_dict(pname='observables') for m in measurement_instances], f)Write measurements to a YAML file.
measurements can be a list of string names or a list of measurement instances.