How to use the getdist.IniFile function in getdist

To help you get started, we’ve selected a few getdist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cmbant / getdist / getdist / gui / mainwindow.py View on Github external
Callback for action 'Show plot settings'
        """
        self.getPlotter()
        settings = self.default_plot_settings
        pars = []
        skips = ['param_names_for_labels', 'progress']
        comments = {}
        for line in settings.__doc__.split("\n"):
            if 'ivar' in line:
                items = line.split(':', 2)
                par = items[1].split('ivar ')[1]
                if par not in skips:
                    pars.append(par)
                    comments[par] = items[2].strip()
        pars.sort()
        ini = IniFile()
        for par in pars:
            ini.getAttr(settings, par, comment=[comments.get(par, None)])
            if isinstance(ini.params[par], matplotlib.colors.Colormap):
                ini.params[par] = ini.params[par].name
        ini.params.update(self.custom_plot_settings)
        self.plotSettingIni = ini

        self.plotSettingDlg = self.plotSettingDlg or DialogPlotSettings(self, ini, pars, title='Plot Settings',
                                                                        width=420)
        self.plotSettingDlg.show()
        self.plotSettingDlg.activateWindow()
github cmbant / getdist / getdist / mcsamples.py View on Github external
def saveTextMetadata(self, root, properties={}):
        """
        Saves metadata about the sames to text files with given file root

        :param root: root file name
        :param properties: optional dictiory of values to save in root.properties.ini
        """
        super(MCSamples, self).saveTextMetadata(root)
        self.ranges.saveToFile(root + '.ranges')
        if properties or self.properties or self.label:
            ini_name = root + '.properties.ini'
            if os.path.exists(ini_name):
                ini = IniFile(ini_name)
            else:
                ini = IniFile()
            if self.properties:
                ini.params.update(self.properties)
            if self.label:
                ini.params.update({'label': self.label})
            ini.params.update(properties)
            ini.saveFile(ini_name)
github cmbant / getdist / getdist / mcsamples.py View on Github external
:param settings: The a dict containing settings to set, taking preference over any values in ini
        :param ini: The name of .ini file to get settings from, or an :class:`~.inifile.IniFile` instance; by default
                    uses current settings
        :param doUpdate: True if should update internal computed values, False otherwise (e.g. if want to make
                         other changes first)
        """
        assert (settings is None or hasattr(settings, "keys"))
        if not ini:
            ini = self.ini
        elif isinstance(ini, six.string_types):
            ini = IniFile(ini)
        else:
            ini = copy.deepcopy(ini)
        if not ini:
            ini = IniFile(getdist.default_getdist_settings)
        if settings:
            ini.params.update(settings)
        self.ini = ini
        if ini:
            self.initParameters(ini)
        if doUpdate and self.samples is not None:
            self.updateBaseStatistics()
github cmbant / getdist / getdist / mcsamples.py View on Github external
def saveTextMetadata(self, root, properties={}):
        """
        Saves metadata about the sames to text files with given file root

        :param root: root file name
        :param properties: optional dictiory of values to save in root.properties.ini
        """
        super(MCSamples, self).saveTextMetadata(root)
        self.ranges.saveToFile(root + '.ranges')
        if properties or self.properties or self.label:
            ini_name = root + '.properties.ini'
            if os.path.exists(ini_name):
                ini = IniFile(ini_name)
            else:
                ini = IniFile()
            if self.properties:
                ini.params.update(self.properties)
            if self.label:
                ini.params.update({'label': self.label})
            ini.params.update(properties)
            ini.saveFile(ini_name)
github cmbant / getdist / getdist / command_line.py View on Github external
do_error('Parameter file does not exist: ' + args.ini_file)
    if chain_root and chain_root.endswith('.txt'):
        chain_root = chain_root[:-4]

    if chain_root is not None and ('*' in chain_root or '?' in chain_root):
        import glob
        import copy
        for ending in ['.paramnames', 'updated.yaml']:
            for f in glob.glob(chain_root + ending):
                fileargs = copy.copy(args)
                fileargs.chain_root = f.replace(ending, '')
                getdist_script(fileargs)
        return

    # Input parameters
    ini = IniFile(args.ini_file)

    for item in set(ini.params.keys()).intersection(
            {'make_single_samples', 'single_thin', 'dump_ND_bins', 'plot_meanlikes', 'shade_meanlikes',
             'plot_data_dir', 'force_twotail'}):
        if ini.string(item) not in [0, 'F']:
            logging.warning('%s is no longer supported by getdist, value ignored' % item)

    # File root
    if chain_root is not None:
        in_root = chain_root
    else:
        in_root = ini.params['file_root']
    if not in_root:
        do_error('Chain Root file name not given ')
    rootname = os.path.basename(in_root)
github cmbant / getdist / getdist / plots.py View on Github external
def reset(self, settings=None, chain_settings_have_priority=True):
        """
        Resets the caches, starting afresh optionally with new analysis settings

        :param settings: Either an :class:`~.inifile.IniFile` instance,
               the name of an .ini file, or a dict holding sample analysis settings.
        :param chain_settings_have_priority: whether to prioritize settings saved with the chain
        """
        self.analysis_settings = {}
        if isinstance(settings, IniFile):
            ini = settings
        elif isinstance(settings, dict):
            ini = IniFile(getdist.default_getdist_settings)
            ini.params.update(settings)
        else:
            ini = IniFile(settings or getdist.default_getdist_settings)
        if self.ini:
            self.ini.params.update(ini.params)
        else:
            self.ini = ini
        self.mcsamples = {}
        # Dicts. 1st key is root; 2nd key is param
        self.densities_1D = dict()
        self.densities_2D = dict()
        self.single_samples = dict()
        self.chain_settings_have_priority = chain_settings_have_priority
github cmbant / getdist / paramgrid / gridconfig.py View on Github external
def makeGrid(batchPath, settingName=None, settings=None, readOnly=False, interactive=False):
    batchPath = os.path.abspath(batchPath) + os.sep

    # 0: chains, 1: importance sampling, 2: best-fit, 3: best-fit and Hessian
    cosmomcAction = 0

    if not settings:
        if not settingName:
            if not pathIsGrid(batchPath):
                raise Exception('Need to give name of setting file if batchPath/config does not exist')
            readOnly = True
            sys.path.insert(0, batchPath + 'config')
            sys.modules['batchJob'] = batchjob  # old name
            settings = __import__(IniFile(batchPath + 'config/config.ini').params['setting_file'].replace('.py', ''))
        else:
            settings = __import__(settingName, fromlist=['dummy'])

    batch = batchjob.batchJob(batchPath, settings.ini_dir)

    if hasattr(settings, 'skip'): batch.skip = settings.skip
    batch.makeItems(settings, messages=not readOnly)
    if readOnly:
        for jobItem in [b for b in batch.jobItems]:
            if not jobItem.chainExists():
                batch.jobItems.remove(jobItem)
        batch.save()
        print('OK, configured grid with %u existing chains' % (len(batch.jobItems)))
        return batch
    else:
        batch.makeDirectories(settings.__file__)
github cmbant / getdist / getdist / mcsamples.py View on Github external
def updateSettings(self, settings=None, ini=None, doUpdate=True):
        """
        Updates settings from a .ini file or dictionary

        :param settings: The a dict containing settings to set, taking preference over any values in ini
        :param ini: The name of .ini file to get settings from, or an :class:`~.inifile.IniFile` instance; by default
                    uses current settings
        :param doUpdate: True if should update internal computed values, False otherwise (e.g. if want to make
                         other changes first)
        """
        assert (settings is None or hasattr(settings, "keys"))
        if not ini:
            ini = self.ini
        elif isinstance(ini, six.string_types):
            ini = IniFile(ini)
        else:
            ini = copy.deepcopy(ini)
        if not ini:
            ini = IniFile(getdist.default_getdist_settings)
        if settings:
            ini.params.update(settings)
        self.ini = ini
        if ini:
            self.initParameters(ini)
        if doUpdate and self.samples is not None:
            self.updateBaseStatistics()