Esempio n. 1
0
    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)
            ]
Esempio n. 2
0
def yaml_file_or_dict(file_or_dict) -> Mapping:
    if isinstance(file_or_dict, str):
        from getdist.yaml_tools import yaml_load_file
        return yaml_load_file(file_or_dict)
    elif isinstance(file_or_dict, Mapping):
        return file_or_dict
    else:
        raise ValueError('Cobya parameter input must be a dictionary or filename')
Esempio n. 3
0
def get_sampler_type(filename_or_info):
    if isinstance(filename_or_info, string_types):
        from getdist.yaml_tools import yaml_load_file
        filename_or_info = yaml_load_file(filename_or_info)
    default_sampler_for_chain_type = "mcmc"
    sampler = list(
        filename_or_info.get(_sampler, [default_sampler_for_chain_type]))[0]
    return {
        "mcmc": "mcmc",
        "polychord": "nested",
        "minimize": "minimize"
    }[sampler]
Esempio n. 4
0
 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))
Esempio n. 5
0
def get_sample_label(filename_or_info):
    if isinstance(filename_or_info, string_types):
        from getdist.yaml_tools import yaml_load_file
        filename_or_info = yaml_load_file(filename_or_info)
    return filename_or_info.get(_label, None)