Commit cf0fee06 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Several improvements to the basic usage

1) Adds option to force the use of cached data
2) Orders the output .par files
3) Adds maxtwoF to output par files
parent 47631be1
...@@ -9,6 +9,7 @@ import glob ...@@ -9,6 +9,7 @@ import glob
import inspect import inspect
from functools import wraps from functools import wraps
import subprocess import subprocess
from collections import OrderedDict
import numpy as np import numpy as np
import matplotlib import matplotlib
...@@ -19,6 +20,8 @@ import corner ...@@ -19,6 +20,8 @@ import corner
import dill as pickle import dill as pickle
import lalpulsar import lalpulsar
plt.rcParams['text.usetex'] = True
config_file = os.path.expanduser('~')+'/.pyfstat.conf' config_file = os.path.expanduser('~')+'/.pyfstat.conf'
if os.path.isfile(config_file): if os.path.isfile(config_file):
d = {} d = {}
...@@ -41,6 +44,7 @@ parser.add_argument("-q", "--quite", help="Decrease output verbosity", ...@@ -41,6 +44,7 @@ parser.add_argument("-q", "--quite", help="Decrease output verbosity",
action="store_true") action="store_true")
parser.add_argument("-c", "--clean", help="Don't use cached data", parser.add_argument("-c", "--clean", help="Don't use cached data",
action="store_true") action="store_true")
parser.add_argument("-u", "--use-old-data", action="store_true")
parser.add_argument('unittest_args', nargs='*') parser.add_argument('unittest_args', nargs='*')
args, unknown = parser.parse_known_args() args, unknown = parser.parse_known_args()
sys.argv[1:] = args.unittest_args sys.argv[1:] = args.unittest_args
...@@ -814,6 +818,10 @@ class MCMCSearch(BaseSearchClass): ...@@ -814,6 +818,10 @@ class MCMCSearch(BaseSearchClass):
return d return d
def check_old_data_is_okay_to_use(self): def check_old_data_is_okay_to_use(self):
if args.use_old_data:
logging.info("Forcing use of old data")
return True
if os.path.isfile(self.pickle_path) is False: if os.path.isfile(self.pickle_path) is False:
logging.info('No pickled data found') logging.info('No pickled data found')
return False return False
...@@ -872,7 +880,7 @@ class MCMCSearch(BaseSearchClass): ...@@ -872,7 +880,7 @@ class MCMCSearch(BaseSearchClass):
idxs = np.isfinite(self.lnlikes) idxs = np.isfinite(self.lnlikes)
jmax = np.nanargmax(self.lnlikes[idxs]) jmax = np.nanargmax(self.lnlikes[idxs])
maxtwoF = self.lnlikes[jmax] maxtwoF = self.lnlikes[jmax]
d = {} d = OrderedDict()
close_idxs = abs((maxtwoF - self.lnlikes[idxs]) / maxtwoF) < threshold close_idxs = abs((maxtwoF - self.lnlikes[idxs]) / maxtwoF) < threshold
for i, k in enumerate(self.theta_keys): for i, k in enumerate(self.theta_keys):
base_key = copy.copy(k) base_key = copy.copy(k)
...@@ -887,7 +895,7 @@ class MCMCSearch(BaseSearchClass): ...@@ -887,7 +895,7 @@ class MCMCSearch(BaseSearchClass):
def get_median_stds(self): def get_median_stds(self):
""" Returns a dict of the median and std of all production samples """ """ Returns a dict of the median and std of all production samples """
d = {} d = OrderedDict()
for s, k in zip(self.samples.T, self.theta_keys): for s, k in zip(self.samples.T, self.theta_keys):
d[k] = np.median(s) d[k] = np.median(s)
d[k+'_std'] = np.std(s) d[k+'_std'] = np.std(s)
...@@ -897,16 +905,17 @@ class MCMCSearch(BaseSearchClass): ...@@ -897,16 +905,17 @@ class MCMCSearch(BaseSearchClass):
""" Writes a .par of the best-fit params with an estimated std """ """ Writes a .par of the best-fit params with an estimated std """
logging.info('Writing {}/{}.par using the {} method'.format( logging.info('Writing {}/{}.par using the {} method'.format(
self.outdir, self.label, method)) self.outdir, self.label, method))
if method == 'med':
median_std_d = self.get_median_stds() median_std_d = self.get_median_stds()
filename = '{}/{}.par'.format(self.outdir, self.label) max_twoF_d, max_twoF = self.get_max_twoF()
with open(filename, 'w+') as f:
filename = '{}/{}.par'.format(self.outdir, self.label)
with open(filename, 'w+') as f:
f.write('MaxtwoF = {}\n'.format(max_twoF))
if method == 'med':
for key, val in median_std_d.iteritems(): for key, val in median_std_d.iteritems():
f.write('{} = {:1.16e}\n'.format(key, val)) f.write('{} = {:1.16e}\n'.format(key, val))
if method == 'twoFmax': if method == 'twoFmax':
max_twoF_d, _ = self.get_max_twoF()
filename = '{}/{}.par'.format(self.outdir, self.label)
with open(filename, 'w+') as f:
for key, val in max_twoF_d.iteritems(): for key, val in max_twoF_d.iteritems():
f.write('{} = {:1.16e}\n'.format(key, val)) f.write('{} = {:1.16e}\n'.format(key, val))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment