def loadFromFile(self, fileName): """ loads from fileName, a plain text .paramnames file or a "full" yaml file """ self.filenameLoadedFrom = os.path.split(fileName)[1] extension = os.path.splitext(fileName)[-1] if extension == '.paramnames': with open(fileName, encoding='utf-8-sig') as f: self.names = [ ParamInfo(line) for line in [s.strip() for s in f] if line != '' ] elif extension.lower() in ('.yaml', '.yml'): from getdist import yaml_tools from getdist.cobaya_interface import get_info_params, is_sampled_param from getdist.cobaya_interface import is_derived_param, _p_label, _p_renames self.info_dict = yaml_tools.yaml_load_file(fileName) info_params = get_info_params(self.info_dict) # first sampled, then derived self.names = [ ParamInfo(name=param, label=(info or {}).get(_p_label, param), renames=(info or {}).get(_p_renames)) for param, info in info_params.items() if is_sampled_param(info) ] self.names += [ ParamInfo(name=param, label=(info or {}).get(_p_label, param), renames=(info or {}).get(_p_renames), derived=True) for param, info in info_params.items() if is_derived_param(info) ]
def loadFromFile(self, fileName): self.filenameLoadedFrom = os.path.split(fileName)[1] extension = os.path.splitext(fileName)[-1] if extension in ('.ranges', '.bounds'): with open(fileName) as f: for line in f: strings = [text.strip() for text in line.split()] if len(strings) == 3: self.setRange(strings[0], strings[1:]) elif extension in ('.yaml', '.yml'): from getdist.cobaya_interface import get_range, is_fixed_param, get_info_params from getdist.yaml_tools import yaml_load_file info_params = get_info_params(yaml_load_file(fileName)) for p, info in info_params.items(): if not is_fixed_param(info): self.setRange(p, get_range(info))
def loadFromFile(self, fileName): self.filenameLoadedFrom = os.path.split(fileName)[1] extension = os.path.splitext(fileName)[-1] if extension in ('.ranges', '.bounds'): with open(fileName, encoding='utf-8-sig') as f: for line in f: strings = [text.strip() for text in line.split()] if len(strings) == 3: self.setRange(strings[0], strings[1:]) elif extension in ('.yaml', '.yml'): from getdist.cobaya_interface import get_range, get_info_params, is_parameter_with_range info_params = get_info_params(fileName) for p, info in info_params.items(): if is_parameter_with_range(info): self.setRange(p, get_range(info)) else: raise ValueError('ParamBounds must be loaded from .bounds, .ranges or .yaml/.yml file, ' 'not %s' % fileName)