Commit 6090bd65 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

General improvements to the documentation and imports

parent e22e9b59
from __future__ import division from __future__ import division as _division
from .core import BaseSearchClass, ComputeFstat, Writer from .core import BaseSearchClass, ComputeFstat, Writer, SemiCoherentSearch, SemiCoherentGlitchSearch
from .mcmc_based_searches import * from .mcmc_based_searches import MCMCSearch, MCMCGlitchSearch, MCMCSemiCoherentSearch, MCMCFollowUpSearch, MCMCTransientSearch
from .grid_based_searches import * from .grid_based_searches import GridSearch, GridUniformPriorSearch, GridGlitchSearch
from .helper_functions import texify_float
...@@ -37,7 +37,7 @@ class BaseSearchClass(object): ...@@ -37,7 +37,7 @@ class BaseSearchClass(object):
earth_ephem_default = earth_ephem earth_ephem_default = earth_ephem
sun_ephem_default = sun_ephem sun_ephem_default = sun_ephem
def add_log_file(self): def _add_log_file(self):
""" Log output to a file, requires class to have outdir and label """ """ Log output to a file, requires class to have outdir and label """
logfilename = '{}/{}.log'.format(self.outdir, self.label) logfilename = '{}/{}.log'.format(self.outdir, self.label)
fh = logging.FileHandler(logfilename) fh = logging.FileHandler(logfilename)
...@@ -47,7 +47,7 @@ class BaseSearchClass(object): ...@@ -47,7 +47,7 @@ class BaseSearchClass(object):
datefmt='%y-%m-%d %H:%M')) datefmt='%y-%m-%d %H:%M'))
logging.getLogger().addHandler(fh) logging.getLogger().addHandler(fh)
def shift_matrix(self, n, dT): def _shift_matrix(self, n, dT):
""" Generate the shift matrix """ Generate the shift matrix
Parameters Parameters
...@@ -78,7 +78,7 @@ class BaseSearchClass(object): ...@@ -78,7 +78,7 @@ class BaseSearchClass(object):
m[i, j] = float(dT)**(j-i) / factorial(j-i) m[i, j] = float(dT)**(j-i) / factorial(j-i)
return m return m
def shift_coefficients(self, theta, dT): def _shift_coefficients(self, theta, dT):
""" Shift a set of coefficients by dT """ Shift a set of coefficients by dT
Parameters Parameters
...@@ -96,30 +96,30 @@ class BaseSearchClass(object): ...@@ -96,30 +96,30 @@ class BaseSearchClass(object):
""" """
n = len(theta) n = len(theta)
m = self.shift_matrix(n, dT) m = self._shift_matrix(n, dT)
return np.dot(m, theta) return np.dot(m, theta)
def calculate_thetas(self, theta, delta_thetas, tbounds, theta0_idx=0): def _calculate_thetas(self, theta, delta_thetas, tbounds, theta0_idx=0):
""" Calculates the set of coefficients for the post-glitch signal """ """ Calculates the set of coefficients for the post-glitch signal """
thetas = [theta] thetas = [theta]
for i, dt in enumerate(delta_thetas): for i, dt in enumerate(delta_thetas):
if i < theta0_idx: if i < theta0_idx:
pre_theta_at_ith_glitch = self.shift_coefficients( pre_theta_at_ith_glitch = self._shift_coefficients(
thetas[0], tbounds[i+1] - self.tref) thetas[0], tbounds[i+1] - self.tref)
post_theta_at_ith_glitch = pre_theta_at_ith_glitch - dt post_theta_at_ith_glitch = pre_theta_at_ith_glitch - dt
thetas.insert(0, self.shift_coefficients( thetas.insert(0, self._shift_coefficients(
post_theta_at_ith_glitch, self.tref - tbounds[i+1])) post_theta_at_ith_glitch, self.tref - tbounds[i+1]))
elif i >= theta0_idx: elif i >= theta0_idx:
pre_theta_at_ith_glitch = self.shift_coefficients( pre_theta_at_ith_glitch = self._shift_coefficients(
thetas[i], tbounds[i+1] - self.tref) thetas[i], tbounds[i+1] - self.tref)
post_theta_at_ith_glitch = pre_theta_at_ith_glitch + dt post_theta_at_ith_glitch = pre_theta_at_ith_glitch + dt
thetas.append(self.shift_coefficients( thetas.append(self._shift_coefficients(
post_theta_at_ith_glitch, self.tref - tbounds[i+1])) post_theta_at_ith_glitch, self.tref - tbounds[i+1]))
self.thetas_at_tref = thetas self.thetas_at_tref = thetas
return thetas return thetas
def generate_loudest(self): def _generate_loudest(self):
params = read_par(self.label, self.outdir) params = read_par(self.label, self.outdir)
for key in ['Alpha', 'Delta', 'F0', 'F1']: for key in ['Alpha', 'Delta', 'F0', 'F1']:
if key not in params: if key not in params:
...@@ -133,7 +133,7 @@ class BaseSearchClass(object): ...@@ -133,7 +133,7 @@ class BaseSearchClass(object):
self.maxStartTime) self.maxStartTime)
subprocess.call([cmd], shell=True) subprocess.call([cmd], shell=True)
def get_list_of_matching_sfts(self): def _get_list_of_matching_sfts(self):
matches = [glob.glob(p) for p in self.sftfilepath] matches = [glob.glob(p) for p in self.sftfilepath]
matches = [item for sublist in matches for item in sublist] matches = [item for sublist in matches for item in sublist]
if len(matches) > 0: if len(matches) > 0:
...@@ -685,7 +685,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat): ...@@ -685,7 +685,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
delta_thetas = np.atleast_2d( delta_thetas = np.atleast_2d(
np.array([delta_phi, delta_F0s, delta_F1s, delta_F2]).T) np.array([delta_phi, delta_F0s, delta_F1s, delta_F2]).T)
thetas = self.calculate_thetas(theta, delta_thetas, tboundaries, thetas = self._calculate_thetas(theta, delta_thetas, tboundaries,
theta0_idx=self.theta0_idx) theta0_idx=self.theta0_idx)
twoFSum = 0 twoFSum = 0
...@@ -713,9 +713,9 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat): ...@@ -713,9 +713,9 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
delta_theta = [delta_F0, delta_F1, 0] delta_theta = [delta_F0, delta_F1, 0]
tref = self.tref tref = self.tref
theta_at_glitch = self.shift_coefficients(theta, tglitch - tref) theta_at_glitch = self._shift_coefficients(theta, tglitch - tref)
theta_post_glitch_at_glitch = theta_at_glitch + delta_theta theta_post_glitch_at_glitch = theta_at_glitch + delta_theta
theta_post_glitch = self.shift_coefficients( theta_post_glitch = self._shift_coefficients(
theta_post_glitch_at_glitch, tref - tglitch) theta_post_glitch_at_glitch, tref - tglitch)
twoFsegA = self.run_computefstatistic_single_point( twoFsegA = self.run_computefstatistic_single_point(
...@@ -849,7 +849,7 @@ transientTauDays={:1.3f}\n""") ...@@ -849,7 +849,7 @@ transientTauDays={:1.3f}\n""")
""" """
thetas = self.calculate_thetas(self.theta, self.delta_thetas, thetas = self._calculate_thetas(self.theta, self.delta_thetas,
self.tbounds) self.tbounds)
content = '' content = ''
......
...@@ -65,6 +65,7 @@ def set_up_command_line_arguments(): ...@@ -65,6 +65,7 @@ def set_up_command_line_arguments():
def set_up_ephemeris_configuration(): def set_up_ephemeris_configuration():
""" Returns the earth_ephem and sun_ephem """
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 = {}
......
This diff is collapsed.
...@@ -49,7 +49,7 @@ class TestBaseSearchClass(Test): ...@@ -49,7 +49,7 @@ class TestBaseSearchClass(Test):
def test_shift_matrix(self): def test_shift_matrix(self):
BSC = pyfstat.BaseSearchClass() BSC = pyfstat.BaseSearchClass()
dT = 10 dT = 10
a = BSC.shift_matrix(4, dT) a = BSC._shift_matrix(4, dT)
b = np.array([[1, 2*np.pi*dT, 2*np.pi*dT**2/2.0, 2*np.pi*dT**3/6.0], b = np.array([[1, 2*np.pi*dT, 2*np.pi*dT**2/2.0, 2*np.pi*dT**3/6.0],
[0, 1, dT, dT**2/2.0], [0, 1, dT, dT**2/2.0],
[0, 0, 1, dT], [0, 0, 1, dT],
...@@ -71,16 +71,16 @@ class TestBaseSearchClass(Test): ...@@ -71,16 +71,16 @@ class TestBaseSearchClass(Test):
self.assertTrue( self.assertTrue(
np.array_equal( np.array_equal(
thetaB, BSC.shift_coefficients(thetaA, dT))) thetaB, BSC._shift_coefficients(thetaA, dT)))
def test_shift_coefficients_loop(self): def test_shift_coefficients_loop(self):
BSC = pyfstat.BaseSearchClass() BSC = pyfstat.BaseSearchClass()
thetaA = np.array([10., 1e2, 10., 1e2]) thetaA = np.array([10., 1e2, 10., 1e2])
dT = 1e1 dT = 1e1
thetaB = BSC.shift_coefficients(thetaA, dT) thetaB = BSC._shift_coefficients(thetaA, dT)
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
thetaA, BSC.shift_coefficients(thetaB, -dT), thetaA, BSC._shift_coefficients(thetaB, -dT),
rtol=1e-9, atol=1e-9)) rtol=1e-9, atol=1e-9))
...@@ -257,8 +257,7 @@ class TestAuxillaryFunctions(Test): ...@@ -257,8 +257,7 @@ class TestAuxillaryFunctions(Test):
DeltaFs = [1e-4, 1e-14] DeltaFs = [1e-4, 1e-14]
fiducial_freq = 100 fiducial_freq = 100
detector_names = ['H1', 'L1'] detector_names = ['H1', 'L1']
earth_ephem = pyfstat.earth_ephem earth_ephem, sun_ephem = pyfstat.helper_functions.set_up_ephemeris_configuration()
sun_ephem = pyfstat.sun_ephem
def test_get_V_estimate_sky_F0_F1(self): def test_get_V_estimate_sky_F0_F1(self):
......
Markdown is supported
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