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

Various improvements to the test coverage

parent cb7b5658
......@@ -3,6 +3,7 @@ import numpy as np
import os
import shutil
import pyfstat
import lalpulsar
class Test(unittest.TestCase):
......@@ -25,14 +26,16 @@ class TestWriter(Test):
def test_make_cff(self):
Writer = pyfstat.Writer(self.label, outdir=self.outdir)
Writer.make_cff()
self.assertTrue(os.path.isfile('./TestData/{}.cff'.format(self.label)))
self.assertTrue(os.path.isfile(
'./{}/{}.cff'.format(self.outdir, self.label)))
def test_run_makefakedata(self):
Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=86400)
Writer.make_cff()
Writer.run_makefakedata()
self.assertTrue(os.path.isfile(
'./TestData/H-48_H1_1800SFT_TestWriter-700000000-86400.sft'))
'./{}/H-48_H1_1800SFT_TestWriter-700000000-86400.sft'
.format(self.outdir)))
def test_makefakedata_usecached(self):
Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=86400)
......@@ -56,7 +59,7 @@ class TestBunch(Test):
self.assertTrue(b.x == 10)
class TestPar(Test):
class Test_par(Test):
label = 'TestPar'
def test(self):
......@@ -73,7 +76,7 @@ class TestPar(Test):
return_type='dict')
self.assertTrue(par['x'] == 100)
self.assertTrue(par['y'] == 10)
os.system('rm -r TestData')
os.system('rm -r {}'.format(self.outdir))
class TestBaseSearchClass(Test):
......@@ -120,17 +123,25 @@ class TestComputeFstat(Test):
def test_run_computefstatistic_single_point(self):
Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=86400,
h0=1, sqrtSX=1)
h0=1, sqrtSX=1, detectors='H1,L1')
Writer.make_data()
predicted_FS = Writer.predict_fstat()
search = pyfstat.ComputeFstat(
tref=Writer.tref,
search_H1 = pyfstat.ComputeFstat(
tref=Writer.tref, detectors='H1',
sftfilepattern='{}/*{}*sft'.format(Writer.outdir, Writer.label),
SSBprec=lalpulsar.SSBPREC_RELATIVISTIC)
FS = search_H1.get_fullycoherent_twoF(
Writer.tstart, Writer.tend, Writer.F0, Writer.F1, Writer.F2,
Writer.Alpha, Writer.Delta)
self.assertTrue(np.abs(predicted_FS-FS)/FS < 0.2)
search_H1L1 = pyfstat.ComputeFstat(
tref=Writer.tref, detectors='H1,L1',
sftfilepattern='{}/*{}*sft'.format(Writer.outdir, Writer.label))
FS = search.get_fullycoherent_twoF(
FS = search_H1L1.get_fullycoherent_twoF(
Writer.tstart, Writer.tend, Writer.F0, Writer.F1, Writer.F2,
Writer.Alpha, Writer.Delta)
print predicted_FS, FS
self.assertTrue(np.abs(predicted_FS-FS)/FS < 0.2)
def run_computefstatistic_single_point_no_noise(self):
......@@ -148,7 +159,7 @@ class TestComputeFstat(Test):
print predicted_FS, FS
self.assertTrue(np.abs(predicted_FS-FS)/FS < 0.2)
def test_injectSources_from_file(self):
def test_injectSources(self):
Writer = pyfstat.Writer(self.label, outdir=self.outdir, add_noise=False,
duration=86400, h0=1, sqrtSX=1)
Writer.make_cff()
......@@ -159,13 +170,79 @@ class TestComputeFstat(Test):
minCoverFreq=28, maxCoverFreq=32, minStartTime=Writer.tstart,
maxStartTime=Writer.tstart+Writer.duration,
detectors=Writer.detectors)
FS = search.get_fullycoherent_twoF(
FS_from_file = search.get_fullycoherent_twoF(
Writer.tstart, Writer.tend, Writer.F0, Writer.F1, Writer.F2,
Writer.Alpha, Writer.Delta)
Writer.make_data()
predicted_FS = Writer.predict_fstat()
print predicted_FS, FS
self.assertTrue(np.abs(predicted_FS-FS)/FS < 0.2)
self.assertTrue(np.abs(predicted_FS-FS_from_file)/FS_from_file < 0.2)
injectSourcesdict = pyfstat.core.read_par(Writer.config_file_name)
injectSourcesdict['F0'] = injectSourcesdict['Freq']
injectSourcesdict['F1'] = injectSourcesdict['f1dot']
injectSourcesdict['F2'] = injectSourcesdict['f2dot']
search = pyfstat.ComputeFstat(
tref=Writer.tref, assumeSqrtSX=1, injectSources=injectSourcesdict,
minCoverFreq=28, maxCoverFreq=32, minStartTime=Writer.tstart,
maxStartTime=Writer.tstart+Writer.duration,
detectors=Writer.detectors)
FS_from_dict = search.get_fullycoherent_twoF(
Writer.tstart, Writer.tend, Writer.F0, Writer.F1, Writer.F2,
Writer.Alpha, Writer.Delta)
self.assertTrue(FS_from_dict == FS_from_file)
class TestSemiCoherentSearch(Test):
label = "TestSemiCoherentSearch"
def test_get_semicoherent_twoF(self):
duration = 10*86400
Writer = pyfstat.Writer(
self.label, outdir=self.outdir, duration=duration, h0=1, sqrtSX=1)
Writer.make_data()
search = pyfstat.SemiCoherentSearch(
label=self.label, outdir=self.outdir, nsegs=2,
sftfilepattern='{}/*{}*sft'.format(Writer.outdir, Writer.label),
tref=Writer.tref, minStartTime=Writer.tstart,
maxStartTime=Writer.tend)
search.get_semicoherent_twoF(
Writer.F0, Writer.F1, Writer.F2, Writer.Alpha, Writer.Delta,
record_segments=True)
# Compute the predicted semi-coherent Fstat
minStartTime = Writer.tstart
maxStartTime = Writer.tend
Writer.maxStartTime = minStartTime + duration / 2.0
FSA = Writer.predict_fstat()
Writer.tstart = minStartTime + duration / 2.0
Writer.tend = maxStartTime
FSB = Writer.predict_fstat()
FSs = np.array([FSA, FSB])
diffs = (np.array(search.detStat_per_segment) - FSs) / FSs
self.assertTrue(np.all(diffs < 0.3))
def test_get_semicoherent_BSGL(self):
duration = 10*86400
Writer = pyfstat.Writer(
self.label, outdir=self.outdir, duration=duration,
detectors='H1,L1')
Writer.make_data()
search = pyfstat.SemiCoherentSearch(
label=self.label, outdir=self.outdir, nsegs=2,
sftfilepattern='{}/*{}*sft'.format(Writer.outdir, Writer.label),
tref=Writer.tref, minStartTime=Writer.tstart,
maxStartTime=Writer.tend, BSGL=True)
BSGL = search.get_semicoherent_twoF(
Writer.F0, Writer.F1, Writer.F2, Writer.Alpha, Writer.Delta,
record_segments=True)
self.assertTrue(BSGL > 0)
class TestSemiCoherentGlitchSearch(Test):
......
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