From 99c8266f562588b79e02d90d9f6e5b4c91a6f9d2 Mon Sep 17 00:00:00 2001 From: "gregory.ashton" <gregory.ashton@ligo.org> Date: Wed, 19 Apr 2017 10:21:06 +0200 Subject: [PATCH] Minor changes to the core file - Expose generate_loudest - add check if par exists - All read_par to read_loudest - Make the default save_fig to be True in plot_corner --- pyfstat/core.py | 25 +++++++++++++++++-------- pyfstat/mcmc_based_searches.py | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pyfstat/core.py b/pyfstat/core.py index 2c087ae..e4bef7d 100755 --- a/pyfstat/core.py +++ b/pyfstat/core.py @@ -18,16 +18,25 @@ args, tqdm = helper_functions.set_up_command_line_arguments() earth_ephem, sun_ephem = helper_functions.set_up_ephemeris_configuration() -def read_par(label, outdir): - """ Read in a .par file, returns a dictionary of the values """ - filename = '{}/{}.par'.format(outdir, label) +def read_par(label=None, outdir=None, filename=None, suffix='par'): + """ Read in a .par file, returns a dictionary of the values + + Note, can also read in .loudest files + """ + if filename is None: + filename = '{}/{}.{}'.format(outdir, label, suffix) + if os.path.isfile(filename) is False: + raise ValueError("No file ({}) found".format(filename)) d = {} with open(filename, 'r') as f: for line in f: - if len(line.split('=')) > 1: - key, val = line.rstrip('\n').split(' = ') - key = key.strip() - d[key] = np.float64(eval(val.rstrip('; '))) + if line[0] not in ['%', '#'] and len(line.split('=')) == 2: + try: + key, val = line.rstrip('\n').split('=') + key = key.strip() + d[key] = np.float64(eval(val.rstrip('; '))) + except SyntaxError: + pass return d @@ -119,7 +128,7 @@ class BaseSearchClass(object): self.thetas_at_tref = thetas return thetas - def _generate_loudest(self): + def generate_loudest(self): params = read_par(self.label, self.outdir) for key in ['Alpha', 'Delta', 'F0', 'F1']: if key not in params: diff --git a/pyfstat/mcmc_based_searches.py b/pyfstat/mcmc_based_searches.py index 7d8edc1..29892cc 100644 --- a/pyfstat/mcmc_based_searches.py +++ b/pyfstat/mcmc_based_searches.py @@ -507,7 +507,7 @@ class MCMCSearch(core.BaseSearchClass): def plot_corner(self, figsize=(7, 7), add_prior=False, nstds=None, label_offset=0.4, dpi=300, rc_context={}, - tglitch_ratio=False, fig_and_axes=None, save_fig=False, + tglitch_ratio=False, fig_and_axes=None, save_fig=True, **kwargs): """ Generate a corner plot of the posterior -- GitLab