def run_computefstatistic_single_point_no_noise(self): Writer = pyfstat.Writer( self.label, outdir=self.outdir, add_noise=False, duration=86400, h0=1, sqrtSX=1, ) Writer.make_data() predicted_FS = Writer.predict_fstat() search = pyfstat.ComputeFstat( tref=Writer.tref, assumeSqrtSX=1, sftfilepattern="{}/*{}*sft".format(Writer.outdir, Writer.label), ) FS = search.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.3)
def test_injectSources(self): # This seems to be writing with a signal... Writer = pyfstat.Writer( self.label, outdir=self.outdir, add_noise=False, duration=86400, h0=1, sqrtSX=1, ) Writer.make_cff() injectSources = Writer.config_file_name search = pyfstat.ComputeFstat( tref=Writer.tref, assumeSqrtSX=1, injectSources=injectSources, minCoverFreq=28, maxCoverFreq=32, minStartTime=Writer.tstart, maxStartTime=Writer.tstart + Writer.duration, detectors=Writer.detectors, ) 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() self.assertTrue(np.abs(predicted_FS - FS_from_file) / FS_from_file < 0.3) 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)
def test_run_computefstatistic_allowedMismatchFromSFTLength(self): long_Tsft_params = default_Writer_params.copy() long_Tsft_params["Tsft"] = 3600 long_Tsft_params["duration"] = 4 * long_Tsft_params["Tsft"] long_Tsft_params["label"] = "long_Tsft" long_Tsft_params["F0"] = 1500 long_Tsft_params["Band"] = 2.0 long_Tsft_Writer = pyfstat.Writer(**long_Tsft_params) long_Tsft_Writer.run_makefakedata() search = pyfstat.ComputeFstat( tref=long_Tsft_Writer.tref, sftfilepattern=long_Tsft_Writer.sftfilepath, minCoverFreq=1499.5, maxCoverFreq=1500.5, allowedMismatchFromSFTLength=0.1, ) with pytest.raises(RuntimeError): search.get_fullycoherent_twoF(F0=1500, F1=0, F2=0, Alpha=0, Delta=0) search = pyfstat.ComputeFstat( tref=long_Tsft_Writer.tref, sftfilepattern=long_Tsft_Writer.sftfilepath, minCoverFreq=1499.5, maxCoverFreq=1500.5, allowedMismatchFromSFTLength=0.5, ) search.get_fullycoherent_twoF(F0=1500, F1=0, F2=0, Alpha=0, Delta=0)
def setup_method(self, method): self.transientWindowType = "rect" self.transientStartTime = int(self.tstart + 0.25 * self.duration) self.transientTau = int(0.5 * self.duration) self.Writer = pyfstat.Writer( label=self.label, tstart=self.tstart, duration=self.duration, tref=self.tref, **default_signal_params, outdir=self.outdir, sqrtSX=self.sqrtSX, Band=self.Band, detectors=self.detectors, SFTWindowType=self.SFTWindowType, SFTWindowBeta=self.SFTWindowBeta, randSeed=self.randSeed, transientWindowType=self.transientWindowType, transientStartTime=self.transientStartTime, transientTau=self.transientTau, ) self.Writer.make_data(verbose=True) self.basic_theta = { "F0": self.F0, "F1": self.F1, "F2": self.F2, "Alpha": self.Alpha, "Delta": self.Delta, } self.MCMC_params = { "nsteps": [50, 50], "nwalkers": 50, "ntemps": 2, "log10beta_min": -1, }
def test_get_semicoherent_twoF_allowedMismatchFromSFTLength(self): long_Tsft_params = default_Writer_params.copy() long_Tsft_params["Tsft"] = 3600 long_Tsft_params["duration"] = 4 * long_Tsft_params["Tsft"] long_Tsft_params["label"] = "long_Tsft" long_Tsft_params["F0"] = 1500 long_Tsft_params["Band"] = 2.0 long_Tsft_Writer = pyfstat.Writer(**long_Tsft_params) long_Tsft_Writer.run_makefakedata() search = pyfstat.SemiCoherentSearch( label=self.label, outdir=self.outdir, tref=long_Tsft_Writer.tref, sftfilepattern=long_Tsft_Writer.sftfilepath, nsegs=self.nsegs, minCoverFreq=1499.5, maxCoverFreq=1500.5, allowedMismatchFromSFTLength=0.1, ) with pytest.raises(RuntimeError): search.get_semicoherent_twoF(F0=1500, F1=0, F2=0, Alpha=0, Delta=0) search = pyfstat.SemiCoherentSearch( label=self.label, outdir=self.outdir, tref=long_Tsft_Writer.tref, sftfilepattern=long_Tsft_Writer.sftfilepath, nsegs=self.nsegs, minCoverFreq=1499.5, maxCoverFreq=1500.5, allowedMismatchFromSFTLength=0.5, ) search.get_semicoherent_twoF(F0=1500, F1=0, F2=0, Alpha=0, Delta=0)
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)
def test_fully_coherent(self): h0 = 1 sqrtSX = 1 F0 = 30 F1 = -1e-10 F2 = 0 minStartTime = 700000000 duration = 1 * 86400 maxStartTime = minStartTime + duration Alpha = 5e-3 Delta = 1.2 tref = minStartTime Writer = pyfstat.Writer( F0=F0, F1=F1, F2=F2, label=self.label, h0=h0, sqrtSX=sqrtSX, outdir=self.outdir, tstart=minStartTime, Alpha=Alpha, Delta=Delta, tref=tref, duration=duration, Band=4, ) Writer.make_data() predicted_FS = Writer.predict_fstat() theta = { "F0": {"type": "norm", "loc": F0, "scale": np.abs(1e-10 * F0)}, "F1": {"type": "norm", "loc": F1, "scale": np.abs(1e-10 * F1)}, "F2": F2, "Alpha": Alpha, "Delta": Delta, } search = pyfstat.MCMCSearch( label=self.label, outdir=self.outdir, theta_prior=theta, tref=tref, sftfilepattern="{}/*{}*sft".format(Writer.outdir, Writer.label), minStartTime=minStartTime, maxStartTime=maxStartTime, nsteps=[100, 100], nwalkers=100, ntemps=2, log10beta_min=-1, ) search.run(create_plots=False) _, FS = search.get_max_twoF() print(("Predicted twoF is {} while recovered is {}".format(predicted_FS, FS))) self.assertTrue( FS > predicted_FS or np.abs((FS - predicted_FS)) / predicted_FS < 0.3 )
def test_run_makefakedata(self): Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=3600) Writer.make_cff() Writer.run_makefakedata() self.assertTrue( os.path.isfile( "./{}/H-2_H1_1800SFT_TestWriter-700000000-3600.sft".format(self.outdir) ) )
def writer(data_parameters): data_parameters["label"] = "Test" data_parameters["outdir"] = "TestData/" data_parameters["F0"] = 10.0 data_parameters["Band"] = 0.1 data_parameters["sqrtSX"] = 1e-23 this_writer = pyfstat.Writer(**data_parameters) yield this_writer if os.path.isdir(this_writer.outdir): shutil.rmtree(this_writer.outdir)
def test_run_computefstatistic_single_point(self): Writer = pyfstat.Writer( self.label, outdir=self.outdir, duration=86400, h0=1, sqrtSX=1, detectors="H1", ) Writer.make_data() predicted_FS = Writer.predict_fstat() search_H1L1 = pyfstat.ComputeFstat( tref=Writer.tref, sftfilepattern="{}/*{}*sft".format(Writer.outdir, Writer.label), ) FS = search_H1L1.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.3) Writer.detectors = "H1" predicted_FS = Writer.predict_fstat() 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.3)
def test_makefakedata_usecached(self): Writer = pyfstat.Writer(self.label, outdir=self.outdir, duration=3600) if os.path.isfile(Writer.sftfilepath): os.remove(Writer.sftfilepath) # first run: make everything from scratch Writer.make_cff() Writer.run_makefakedata() time_first = os.path.getmtime(Writer.sftfilepath) # second run: should re-use .cff and .sft Writer.make_cff() Writer.run_makefakedata() time_second = os.path.getmtime(Writer.sftfilepath) self.assertTrue(time_first == time_second) # third run: touch the .cff to force regeneration time.sleep(1) # make sure timestamp is actually different! os.system("touch {}".format(Writer.config_file_name)) Writer.run_makefakedata() time_third = os.path.getmtime(Writer.sftfilepath) self.assertFalse(time_first == time_third)
def setUpClass(self): # ensure a clean working directory if os.path.isdir(self.outdir): try: shutil.rmtree(self.outdir) except OSError: logging.warning("{} not removed prior to tests".format(self.outdir)) # skip making outdir, since Writer should do so on first call # os.makedirs(self.outdir, exist_ok=True) # create fake data SFTs # if we directly set any options as self.xy = 1 here, # then values set for derived classes may get overwritten, # so use a default dict and only insert if no value previous set for key, val in {**default_Writer_params, **default_signal_params}.items(): if not hasattr(self, key): setattr(self, key, val) self.tref = self.tstart self.Writer = pyfstat.Writer( label=self.label, tstart=self.tstart, duration=self.duration, tref=self.tref, F0=self.F0, F1=self.F1, F2=self.F2, Alpha=self.Alpha, Delta=self.Delta, h0=self.h0, cosi=self.cosi, Tsft=self.Tsft, outdir=self.outdir, sqrtSX=self.sqrtSX, Band=self.Band, detectors=self.detectors, SFTWindowType=self.SFTWindowType, SFTWindowBeta=self.SFTWindowBeta, randSeed=self.randSeed, ) self.Writer.make_data(verbose=True) self.search_keys = ["F0", "F1", "F2", "Alpha", "Delta"] self.search_ranges = {key: [getattr(self, key)] for key in self.search_keys}
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 setUpClass(self): if os.path.isdir(self.outdir): try: shutil.rmtree(self.outdir) except OSError: logging.warning("{} not removed prior to tests".format(self.outdir)) h0 = 1 sqrtSX = 1 F0 = 30 F1 = -1e-10 F2 = 0 minStartTime = 700000000 duration = 2 * 86400 Alpha = 5e-3 Delta = 1.2 tref = minStartTime Writer = pyfstat.Writer( F0=F0, F1=F1, F2=F2, label="test", h0=h0, sqrtSX=sqrtSX, outdir=self.outdir, tstart=minStartTime, Alpha=Alpha, Delta=Delta, tref=tref, duration=duration, Band=4, ) Writer.make_data() self.sftfilepath = Writer.sftfilepath self.minStartTime = minStartTime self.maxStartTime = minStartTime + duration self.duration = duration
def test_grid_search_on_data_with_line(self): # We reuse the default multi-IFO SFTs # but add an additional single-detector artifact to H1 only. # For simplicity, this is modelled here as a fully modulated CW-like signal, # just restricted to the single detector. SFTs_H1 = self.Writer.sftfilepath.split(";")[0] SFTs_L1 = self.Writer.sftfilepath.split(";")[1] extra_writer = pyfstat.Writer( label=self.label + "_with_line", outdir=self.outdir, tref=self.tref, F0=self.Writer.F0 + 0.0005, F1=self.Writer.F1, F2=self.Writer.F2, Alpha=self.Writer.Alpha, Delta=self.Writer.Delta, h0=10 * self.Writer.h0, cosi=self.Writer.cosi, sqrtSX=0, # don't add yet another set of Gaussian noise noiseSFTs=SFTs_H1, SFTWindowType=self.Writer.SFTWindowType, SFTWindowBeta=self.Writer.SFTWindowBeta, ) extra_writer.make_data() data_with_line = ";".join([SFTs_L1, extra_writer.sftfilepath]) # now run a standard F-stat search over this data searchF = pyfstat.GridSearch( label="grid_search", outdir=self.outdir, sftfilepattern=data_with_line, F0s=self.F0s, F1s=[self.Writer.F1], F2s=[self.Writer.F2], Alphas=[self.Writer.Alpha], Deltas=[self.Writer.Delta], tref=self.tref, BSGL=False, ) searchF.run() self.assertTrue(os.path.isfile(searchF.out_file)) max2F_point_searchF = searchF.get_max_twoF() self.assertTrue( np.all(max2F_point_searchF["twoF"] >= searchF.data["twoF"])) # also run a BSGL search over the same data searchBSGL = pyfstat.GridSearch( label="grid_search", outdir=self.outdir, sftfilepattern=data_with_line, F0s=self.F0s, F1s=[self.Writer.F1], F2s=[self.Writer.F2], Alphas=[self.Writer.Alpha], Deltas=[self.Writer.Delta], tref=self.tref, BSGL=True, ) searchBSGL.run() self.assertTrue(os.path.isfile(searchBSGL.out_file)) max2F_point_searchBSGL = searchBSGL.get_max_twoF() self.assertTrue( np.all(max2F_point_searchBSGL["twoF"] >= searchBSGL.data["twoF"])) # Since we search the same grids and store all output, # the twoF from both searches should be the same. self.assertTrue( max2F_point_searchBSGL["twoF"] == max2F_point_searchF["twoF"]) maxBSGL_point = searchBSGL.get_max_det_stat() self.assertTrue( np.all(maxBSGL_point["log10BSGL"] >= searchBSGL.data["log10BSGL"])) # The BSGL search should produce a lower max2F value than the F search. self.assertTrue(maxBSGL_point["twoF"] < max2F_point_searchF["twoF"]) # But the maxBSGL_point should be the true multi-IFO signal # while max2F_point_searchF should have fallen for the single-IFO line. self.assertTrue( np.abs(maxBSGL_point["F0"] - self.F0) < np.abs(max2F_point_searchF["F0"] - self.F0))
inj = { "tref": tref, "F0": 30.0, "F1": -1e-10, "F2": 0, "Alpha": 1.0, "Delta": 1.5, "h0": sqrtSX / depth, "cosi": 0.0, } data = pyfstat.Writer( label=label, outdir=outdir, tstart=tstart, duration=duration, sqrtSX=sqrtSX, detectors=IFOs, **inj, ) data.make_data() m = 0.01 dF0 = np.sqrt(12 * m) / (np.pi * duration) dF1 = np.sqrt(180 * m) / (np.pi * duration**2) dF2 = 1e-17 N = 100 DeltaF0 = N * dF0 DeltaF1 = N * dF1 F0s = [inj["F0"] - DeltaF0 / 2.0, inj["F0"] + DeltaF0 / 2.0, dF0] F1s = [inj["F1"] - DeltaF1 / 2.0, inj["F1"] + DeltaF1 / 2.0, dF1]
# Properties of the signal depth = 10 signal_parameters = { "F0": 30.0, "F1": -1e-10, "F2": 0, "Alpha": np.radians(83.6292), "Delta": np.radians(22.0144), "tref": mid_time, "h0": data_parameters["sqrtSX"] / depth, "cosi": 1.0, } data = pyfstat.Writer(label=label, outdir=outdir, **data_parameters, **signal_parameters) data.make_data() # The predicted twoF, given by lalapps_predictFstat can be accessed by twoF = data.predict_fstat() print("Predicted twoF value: {}\n".format(twoF)) DeltaF0 = 1e-7 DeltaF1 = 1e-13 VF0 = (np.pi * data_parameters["duration"] * DeltaF0)**2 / 3.0 VF1 = (np.pi * data_parameters["duration"]**2 * DeltaF1)**2 * 4 / 45.0 print("\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n".format(VF0 * VF1, VF0, VF1)) theta_prior = { "F0": {
duration = 100 * 86400 tend = tstart + duration tref = 0.5 * (tstart + tend) depth = 70 data_label = "grided_frequency_depth_{:1.0f}".format(depth) h0 = sqrtSX / depth data = pyfstat.Writer( label=data_label, outdir="data", tref=tref, tstart=tstart, F0=F0, F1=F1, F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX, ) data.make_data() m = 0.001 dF0 = np.sqrt(12 * m) / (np.pi * duration) DeltaF0 = 800 * dF0 F0s = [F0 - DeltaF0 / 2.0, F0 + DeltaF0 / 2.0, dF0] F1s = [F1] F2s = [F2] Alphas = [Alpha]
Delta = 1 minStartTime = 1000000000 maxStartTime = minStartTime + 200 * 86400 transient_tstart = minStartTime + 50 * 86400 transient_duration = 100 * 86400 tref = minStartTime h0 = 1e-23 sqrtSX = 1e-22 transient = pyfstat.Writer( label="simulated_transient_signal", outdir="data_l", tref=tref, tstart=transient_tstart, F0=F0, F1=F1, F2=F2, duration=transient_duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX, minStartTime=minStartTime, maxStartTime=maxStartTime, transientWindowType="rect", ) transient.make_data()
def test_make_cff(self): Writer = pyfstat.Writer(self.label, outdir=self.outdir) Writer.make_cff() self.assertTrue(os.path.isfile("./{}/{}.cff".format(self.outdir, self.label)))
Alpha = 0 Delta = 0 Band = 2.0 # create sfts with a strong signal in them # window options are optional here noise_and_signal_writer = pyfstat.Writer( label="test_noiseSFTs_noise_and_signal", outdir=outdir, h0=h0, cosi=cosi, F0=F0, Alpha=Alpha, Delta=Delta, tstart=tstart, duration=duration_Tsft * Tsft, Tsft=Tsft, Band=Band, detectors=IFO, randSeed=randSeed, SFTWindowType="tukey", SFTWindowBeta=0.001, ) sftfilepattern = os.path.join( noise_and_signal_writer.outdir, "*{}*{}*sft".format(duration_Tsft, noise_and_signal_writer.label), ) noise_and_signal_writer.make_data()
# Properties of the signal depth = 10 signal_parameters = { "F0": 30.0, "F1": -1e-10, "F2": 0, "Alpha": np.radians(83.6292), "Delta": np.radians(22.0144), "tref": mid_time, "h0": data_parameters["sqrtSX"] / depth, "cosi": 1.0, } data = pyfstat.Writer( label=label, outdir=outdir, **data_parameters, **signal_parameters ) data.make_data() # Now we add an additional single-detector artifact to H1 only. # For simplicity, this is modelled here as a fully modulated CW-like signal, # just restricted to the single detector. SFTs_H1 = data.sftfilepath.split(";")[0] data_parameters_line = data_parameters.copy() signal_parameters_line = signal_parameters.copy() data_parameters_line["detectors"] = "H1" data_parameters_line["sqrtSX"] = 0 # don't add yet another set of Gaussian noise signal_parameters_line["F0"] += 1e-6 signal_parameters_line["h0"] *= 10.0 extra_writer = pyfstat.Writer( label=label,
transient_tstart = tstart + 0.25 * duration transient_duration = 0.5 * duration tref = tstart h0 = 1e-23 cosi = 0 sqrtSX = 1e-22 detectors = "H1,L1" transient = pyfstat.Writer( label="simulated_transient_signal", outdir=outdir, tref=tref, tstart=tstart, duration=duration, F0=F0, F1=F1, F2=F2, Alpha=Alpha, Delta=Delta, h0=h0, cosi=cosi, detectors=detectors, sqrtSX=sqrtSX, transientStartTime=transient_tstart, transientTau=transient_duration, transientWindowType="rect", ) transient.make_data()
sqrtSX = ",".join(np.repeat(sqrtS, len(IFOs.split(",")))) tstart = 1000000000 duration = 100 * 86400 tend = tstart + duration tref = 0.5 * (tstart + tend) data = pyfstat.Writer( label=label, outdir=outdir, tref=tref, tstart=tstart, duration=duration, F0=F0, F1=F1, F2=F2, Alpha=Alpha, Delta=Delta, h0=h0, cosi=cosi, sqrtSX=sqrtSX, detectors=IFOs, SFTWindowType="tukey", SFTWindowBeta=0.001, Band=1, ) data.make_data() # Now we add an additional single-detector artifact to H1 only. # For simplicity, this is modelled here as a fully modulated CW-like signal, # just restricted to the single detector. SFTs_H1 = data.sftfilepath.split(";")[0]
def test_glitch_injection(self): Band = 1 vanillaWriter = pyfstat.Writer( label=self.label + "_vanilla", outdir=self.outdir, duration=self.duration, tstart=self.tstart, detectors=self.detectors, Band=Band, **default_signal_params, ) vanillaWriter.make_cff(verbose=True) vanillaWriter.run_makefakedata() noGlitchWriter = self.writer_class_to_test( label=self.label + "_noglitch", outdir=self.outdir, duration=self.duration, tstart=self.tstart, detectors=self.detectors, Band=Band, **default_signal_params, ) noGlitchWriter.make_cff(verbose=True) noGlitchWriter.run_makefakedata() glitchWriter = self.writer_class_to_test( label=self.label + "_glitch", outdir=self.outdir, duration=self.duration, tstart=self.tstart, detectors=self.detectors, Band=Band, **default_signal_params, dtglitch=2 * 1800, delta_F0=0.1, ) glitchWriter.make_cff(verbose=True) glitchWriter.run_makefakedata() ( freqs_vanilla, times_vanilla, data_vanilla, ) = pyfstat.helper_functions.get_sft_as_arrays( vanillaWriter.sftfilepath) ( freqs_noglitch, times_noglitch, data_noglitch, ) = pyfstat.helper_functions.get_sft_as_arrays( noGlitchWriter.sftfilepath) ( freqs_glitch, times_glitch, data_glitch, ) = pyfstat.helper_functions.get_sft_as_arrays( glitchWriter.sftfilepath) for ifo in self.detectors.split(","): max_freq_vanilla = freqs_vanilla[np.argmax(np.abs( data_vanilla[ifo]), axis=0)] max_freq_noglitch = freqs_noglitch[np.argmax(np.abs( data_noglitch[ifo]), axis=0)] max_freq_glitch = freqs_glitch[np.argmax(np.abs(data_glitch[ifo]), axis=0)] print([max_freq_vanilla, max_freq_noglitch, max_freq_glitch]) self.assertTrue(np.all(times_noglitch[ifo] == times_vanilla[ifo])) self.assertTrue(np.all(times_glitch[ifo] == times_vanilla[ifo])) self.assertEqual(len(np.unique(max_freq_vanilla)), 1) self.assertEqual(len(np.unique(max_freq_noglitch)), 1) self.assertEqual(len(np.unique(max_freq_glitch)), 2) self.assertEqual(max_freq_noglitch[0], max_freq_vanilla[0]) self.assertEqual(max_freq_glitch[0], max_freq_noglitch[0]) self.assertTrue(max_freq_glitch[-1] > max_freq_noglitch[-1])
tref = 0.5 * (tstart + tend) IFOs = "H1" depth = 20 h0 = sqrtSX / depth cosi = 0 data = pyfstat.Writer( label=label, outdir=outdir, tref=tref, tstart=tstart, F0=F0, F1=F1, F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, cosi=cosi, sqrtSX=sqrtSX, detectors=IFOs, ) data.make_data() m = 0.01 dF0 = np.sqrt(12 * m) / (np.pi * duration) dF1 = np.sqrt(180 * m) / (np.pi * duration**2) dF2 = 1e-17 N = 100 DeltaF0 = N * dF0
) plt.xlim([min(res[xkey]), max(res[xkey])]) plt.ylim([min(res[ykey]), max(res[ykey])]) plt.savefig(plotfilename_base + ".png") plt.close() if __name__ == "__main__": print("Generating SFTs with injected signal...") writer = pyfstat.Writer( label="simulated_signal", outdir=outdir, tstart=tstart, duration=duration, detectors=detectors, sqrtSX=sqrtSX, Tsft=Tsft, **inj, Band=1, # default band estimation would be too narrow for a wide grid/prior ) writer.make_data() print("") # set up square search grid with fixed (F0,F1) mismatch # and (optionally) some ad-hoc sky coverage m = 0.001 dF0 = np.sqrt(12 * m) / (np.pi * duration) dF1 = np.sqrt(180 * m) / (np.pi * duration ** 2) DeltaF0 = 500 * dF0 DeltaF1 = 200 * dF1
def test_MCMC_search_on_data_with_line(self): # We reuse the default multi-IFO SFTs # but add an additional single-detector artifact to H1 only. # For simplicity, this is modelled here as a fully modulated CW-like signal, # just restricted to the single detector. SFTs_H1 = self.Writer.sftfilepath.split(";")[0] SFTs_L1 = self.Writer.sftfilepath.split(";")[1] extra_writer = pyfstat.Writer( label=self.label + "_with_line", outdir=self.outdir, tref=self.tref, F0=self.Writer.F0 + 0.5e-2, F1=0, F2=0, Alpha=self.Writer.Alpha, Delta=self.Writer.Delta, h0=10 * self.Writer.h0, cosi=self.Writer.cosi, sqrtSX=0, # don't add yet another set of Gaussian noise noiseSFTs=SFTs_H1, SFTWindowType=self.Writer.SFTWindowType, SFTWindowBeta=self.Writer.SFTWindowBeta, ) extra_writer.make_data() data_with_line = ";".join([SFTs_L1, extra_writer.sftfilepath]) # use a single fixed prior and search F0 only for speed thetas = { "F0": { "type": "unif", "lower": self.F0 - 1e-2, "upper": self.F0 + 1e-2, }, "F1": self.F1, "F2": self.F2, "Alpha": self.Alpha, "Delta": self.Delta, } # now run a standard F-stat search over this data self.search = pyfstat.MCMCSearch( label=self.label + "-F", outdir=self.outdir, theta_prior=thetas, tref=self.tref, sftfilepattern=data_with_line, nsteps=[20, 20], nwalkers=20, ntemps=2, log10beta_min=-1, BSGL=False, ) self.search.run(plot_walkers=True) self.search.print_summary() # The standard checks here are expected to fail, # as the F-search will get confused by the line # and recover a much higher maxTwoF than predicted. self._check_twoF_predicted(assertTrue=False) mode_F0_Fsearch = self.max_dict["F0"] maxTwoF_Fsearch = self.maxTwoF self._check_mcmc_quantiles(assertTrue=False) self.assertTrue(maxTwoF_Fsearch > self.twoF_predicted) self._test_plots() # also run a BSGL search over the same data self.search = pyfstat.MCMCSearch( label=self.label + "-BSGL", outdir=self.outdir, theta_prior=thetas, tref=self.tref, sftfilepattern=data_with_line, nsteps=[20, 20], nwalkers=20, ntemps=2, log10beta_min=-1, BSGL=True, ) self.search.run(plot_walkers=True) self.search.print_summary() # Still skipping the standard checks, # as we're using too cheap a MCMC setup here for them to be robust. self._check_twoF_predicted(assertTrue=False) mode_F0_BSGLsearch = self.max_dict["F0"] maxTwoF_BSGLsearch = self.maxTwoF self._check_mcmc_quantiles(assertTrue=False) # But for sure, the BSGL search should find a lower-F mode # closer to the true multi-IFO signal. self.assertTrue(maxTwoF_BSGLsearch < maxTwoF_Fsearch) self.assertTrue(mode_F0_BSGLsearch < mode_F0_Fsearch) self.assertTrue( np.abs(mode_F0_BSGLsearch - self.F0) < np.abs(mode_F0_Fsearch - self.F0)) self.assertTrue(maxTwoF_BSGLsearch < self.twoF_predicted) self._test_plots()