From 48b0cd0ed036bf36da6245112c05b53c59a54883 Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Mon, 10 Oct 2016 16:46:20 +0200 Subject: [PATCH] Four minor fixes 1) Fixes error in glitch logp ts check 2) Adds ts check to logp to avoid raising ValueError when one of the glitch times is before the tstart 3) Fixes bug in BSGL so that it can be used with glitch searches 4) Generates the output directory before attempting to write log file --- pyfstat.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pyfstat.py b/pyfstat.py index c340cce..c7124ec 100755 --- a/pyfstat.py +++ b/pyfstat.py @@ -286,7 +286,7 @@ class ComputeFstat(object): False, 1) self.twoFX = np.zeros(10) - self.whatToCompute = (lalpulsar.FSTATQ_2F + + self.whatToCompute = (self.whatToCompute + lalpulsar.FSTATQ_2F_PER_DET) if self.transient: @@ -527,12 +527,12 @@ class MCMCSearch(BaseSearchClass): self.minStartTime = tstart self.maxStartTime = tend + if os.path.isdir(outdir) is False: + os.mkdir(outdir) self.add_log_file() logging.info( 'Set-up MCMC search for model {} on data {}'.format( self.label, self.sftfilepath)) - if os.path.isdir(outdir) is False: - os.mkdir(outdir) self.pickle_path = '{}/{}_saved_data.p'.format(self.outdir, self.label) self.theta_prior['tstart'] = self.tstart self.theta_prior['tend'] = self.tend @@ -1238,12 +1238,12 @@ _ sftfilepath: str """ + if os.path.isdir(outdir) is False: + os.mkdir(outdir) self.add_log_file() logging.info(('Set-up MCMC glitch search with {} glitches for model {}' ' on data {}').format(self.nglitch, self.label, self.sftfilepath)) - if os.path.isdir(outdir) is False: - os.mkdir(outdir) self.minStartTime = tstart self.maxStartTime = tend self.pickle_path = '{}/{}_saved_data.p'.format(self.outdir, self.label) @@ -1277,7 +1277,7 @@ _ sftfilepath: str def logp(self, theta_vals, theta_prior, theta_keys, search): if self.nglitch > 1: - ts = [self.tstart] + theta_vals[-self.nglitch:] + [self.tend] + ts = [self.tstart] + list(theta_vals[-self.nglitch:]) + [self.tend] if np.array_equal(ts, np.sort(ts)) is False: return -np.inf if any(np.diff(ts) < self.dtglitchmin): @@ -1288,6 +1288,11 @@ _ sftfilepath: str return np.sum(H) def logl(self, theta, search): + if self.nglitch > 1: + ts = [self.tstart] + list(theta[-self.nglitch:]) + [self.tend] + if np.array_equal(ts, np.sort(ts)) is False: + return -np.inf + for j, theta_i in enumerate(self.theta_idxs): self.fixed_theta[theta_i] = theta[j] FS = search.compute_nglitch_fstat(*self.fixed_theta) -- GitLab