Skip to content
Snippets Groups Projects
Commit 6090bd65 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

General improvements to the documentation and imports

parent e22e9b59
No related branches found
No related tags found
No related merge requests found
from __future__ import division
from __future__ import division as _division
from .core import BaseSearchClass, ComputeFstat, Writer
from .mcmc_based_searches import *
from .grid_based_searches import *
from .helper_functions import texify_float
from .core import BaseSearchClass, ComputeFstat, Writer, SemiCoherentSearch, SemiCoherentGlitchSearch
from .mcmc_based_searches import MCMCSearch, MCMCGlitchSearch, MCMCSemiCoherentSearch, MCMCFollowUpSearch, MCMCTransientSearch
from .grid_based_searches import GridSearch, GridUniformPriorSearch, GridGlitchSearch
......@@ -37,7 +37,7 @@ class BaseSearchClass(object):
earth_ephem_default = earth_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 """
logfilename = '{}/{}.log'.format(self.outdir, self.label)
fh = logging.FileHandler(logfilename)
......@@ -47,7 +47,7 @@ class BaseSearchClass(object):
datefmt='%y-%m-%d %H:%M'))
logging.getLogger().addHandler(fh)
def shift_matrix(self, n, dT):
def _shift_matrix(self, n, dT):
""" Generate the shift matrix
Parameters
......@@ -78,7 +78,7 @@ class BaseSearchClass(object):
m[i, j] = float(dT)**(j-i) / factorial(j-i)
return m
def shift_coefficients(self, theta, dT):
def _shift_coefficients(self, theta, dT):
""" Shift a set of coefficients by dT
Parameters
......@@ -96,30 +96,30 @@ class BaseSearchClass(object):
"""
n = len(theta)
m = self.shift_matrix(n, dT)
m = self._shift_matrix(n, dT)
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 """
thetas = [theta]
for i, dt in enumerate(delta_thetas):
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)
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]))
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)
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]))
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:
......@@ -133,7 +133,7 @@ class BaseSearchClass(object):
self.maxStartTime)
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 = [item for sublist in matches for item in sublist]
if len(matches) > 0:
......@@ -685,7 +685,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
delta_thetas = np.atleast_2d(
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)
twoFSum = 0
......@@ -713,9 +713,9 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
delta_theta = [delta_F0, delta_F1, 0]
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 = self.shift_coefficients(
theta_post_glitch = self._shift_coefficients(
theta_post_glitch_at_glitch, tref - tglitch)
twoFsegA = self.run_computefstatistic_single_point(
......@@ -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)
content = ''
......
......@@ -65,6 +65,7 @@ def set_up_command_line_arguments():
def set_up_ephemeris_configuration():
""" Returns the earth_ephem and sun_ephem """
config_file = os.path.expanduser('~')+'/.pyfstat.conf'
if os.path.isfile(config_file):
d = {}
......
This diff is collapsed.
......@@ -49,7 +49,7 @@ class TestBaseSearchClass(Test):
def test_shift_matrix(self):
BSC = pyfstat.BaseSearchClass()
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],
[0, 1, dT, dT**2/2.0],
[0, 0, 1, dT],
......@@ -71,16 +71,16 @@ class TestBaseSearchClass(Test):
self.assertTrue(
np.array_equal(
thetaB, BSC.shift_coefficients(thetaA, dT)))
thetaB, BSC._shift_coefficients(thetaA, dT)))
def test_shift_coefficients_loop(self):
BSC = pyfstat.BaseSearchClass()
thetaA = np.array([10., 1e2, 10., 1e2])
dT = 1e1
thetaB = BSC.shift_coefficients(thetaA, dT)
thetaB = BSC._shift_coefficients(thetaA, dT)
self.assertTrue(
np.allclose(
thetaA, BSC.shift_coefficients(thetaB, -dT),
thetaA, BSC._shift_coefficients(thetaB, -dT),
rtol=1e-9, atol=1e-9))
......@@ -257,8 +257,7 @@ class TestAuxillaryFunctions(Test):
DeltaFs = [1e-4, 1e-14]
fiducial_freq = 100
detector_names = ['H1', 'L1']
earth_ephem = pyfstat.earth_ephem
sun_ephem = pyfstat.sun_ephem
earth_ephem, sun_ephem = pyfstat.helper_functions.set_up_ephemeris_configuration()
def test_get_V_estimate_sky_F0_F1(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment