From 4d1fdace51c7e89c83dcb6ca9fdd28c73ef76108 Mon Sep 17 00:00:00 2001
From: "gregory.ashton" <gregory.ashton@ligo.org>
Date: Wed, 22 Feb 2017 15:59:47 +0100
Subject: [PATCH] Improvements to grid searches

- Adds a simple interface to get grid search given uniform prior
- Fixes detector -> detectors bug (previous versions, the constrains
  where not actually set)
- Adds title functionality to plot2D
---
 pyfstat/core.py                |  2 +-
 pyfstat/grid_based_searches.py | 26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/pyfstat/core.py b/pyfstat/core.py
index 7839cdc..152c758 100755
--- a/pyfstat/core.py
+++ b/pyfstat/core.py
@@ -228,7 +228,7 @@ class ComputeFstat(object):
         logging.info('Initialising SFTCatalog')
         constraints = lalpulsar.SFTConstraints()
         if self.detectors:
-            constraints.detectors = self.detectors
+            constraints.detector = self.detectors
         if self.minStartTime:
             constraints.minStartTime = lal.LIGOTimeGPS(self.minStartTime)
         if self.maxStartTime:
diff --git a/pyfstat/grid_based_searches.py b/pyfstat/grid_based_searches.py
index d86364c..59e3b52 100644
--- a/pyfstat/grid_based_searches.py
+++ b/pyfstat/grid_based_searches.py
@@ -21,7 +21,7 @@ class GridSearch(BaseSearchClass):
                  Alphas=[0], Deltas=[0], tref=None, minStartTime=None,
                  maxStartTime=None, BSGL=False, minCoverFreq=None,
                  maxCoverFreq=None, earth_ephem=None, sun_ephem=None,
-                 detector=None):
+                 detectors=None):
         """
         Parameters
         ----------
@@ -54,7 +54,7 @@ class GridSearch(BaseSearchClass):
             tref=self.tref, sftfilepath=self.sftfilepath,
             minCoverFreq=self.minCoverFreq, maxCoverFreq=self.maxCoverFreq,
             earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
-            detector=self.detector, transient=False,
+            detectors=self.detectors, transient=False,
             minStartTime=self.minStartTime, maxStartTime=self.maxStartTime,
             BSGL=self.BSGL)
 
@@ -154,7 +154,7 @@ class GridSearch(BaseSearchClass):
 
     def plot_2D(self, xkey, ykey, ax=None, save=True, vmin=None, vmax=None,
                 add_mismatch=None, xN=None, yN=None, flat_keys=[],
-                rel_flat_idxs=[], flatten_method=np.max,
+                rel_flat_idxs=[], flatten_method=np.max, title=None,
                 predicted_twoF=None, cm=None, cbarkwargs={}):
         """ Plots a 2D grid of 2F values
 
@@ -205,6 +205,9 @@ class GridSearch(BaseSearchClass):
         ax.set_xlabel(labels[xkey])
         ax.set_ylabel(labels[ykey])
 
+        if title:
+            ax.set_title(title)
+
         if xN:
             ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(xN))
         if yN:
@@ -231,6 +234,23 @@ class GridSearch(BaseSearchClass):
             print('  {}={}'.format(k, v))
 
 
+class GridUniformPriorSearch():
+    def __init__(self, theta_prior, NF0, NF1, label, outdir, sftfilepath,
+                 tref, minStartTime, maxStartTime, BSGL=False, detectors=None,
+                 **kwargs):
+        dF0 = (theta_prior['F0']['upper'] - theta_prior['F0']['lower'])/NF0
+        dF1 = (theta_prior['F1']['upper'] - theta_prior['F1']['lower'])/NF1
+        F0s = [theta_prior['F0']['lower'], theta_prior['F0']['upper'], dF0]
+        F1s = [theta_prior['F1']['lower'], theta_prior['F1']['upper'], dF1]
+        search = GridSearch(
+            label, outdir, sftfilepath, F0s=F0s, F1s=F1s, tref=tref,
+            Alphas=[theta_prior['Alpha']], Deltas=[theta_prior['Delta']],
+            minStartTime=minStartTime, maxStartTime=maxStartTime, BSGL=BSGL,
+            detectors=detectors)
+        search.run()
+        search.plot_2D('F0', 'F1', **kwargs)
+
+
 class GridGlitchSearch(GridSearch):
     """ Grid search using the SemiCoherentGlitchSearch """
     @helper_functions.initializer
-- 
GitLab