Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 def _test_get_semicoherent_BSGL(self, **dataopts):
     search_noBSGL = pyfstat.SemiCoherentSearch(
         label=self.label,
         outdir=self.outdir,
         nsegs=self.nsegs,
         BSGL=False,
         singleFstats=True,
         **dataopts,
     )
     twoF = search_noBSGL.get_semicoherent_det_stat(
         self.Writer.F0,
         self.Writer.F1,
         self.Writer.F2,
         self.Writer.Alpha,
         self.Writer.Delta,
     )
     twoFX = search_noBSGL.get_semicoherent_single_IFO_twoFs()
     search_BSGL = pyfstat.SemiCoherentSearch(
         label=self.label,
         outdir=self.outdir,
         nsegs=self.nsegs,
         BSGL=True,
         **dataopts,
     )
     log10BSGL = search_BSGL.get_semicoherent_det_stat(
         self.Writer.F0,
         self.Writer.F1,
         self.Writer.F2,
         self.Writer.Alpha,
         self.Writer.Delta,
         record_segments=True,
     )
     self.assertTrue(log10BSGL > 0)
     self.assertTrue(log10BSGL == lalpulsar.ComputeBSGL(
         twoF, twoFX, search_BSGL.BSGLSetup))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_get_semicoherent_twoF(self):

        search = pyfstat.SemiCoherentSearch(
            label=self.label,
            outdir=self.outdir,
            nsegs=self.nsegs,
            sftfilepattern=self.Writer.sftfilepath,
            tref=self.Writer.tref,
            search_ranges=self.search_ranges,
            BSGL=False,
        )

        twoF_sc = search.get_semicoherent_det_stat(
            self.Writer.F0,
            self.Writer.F1,
            self.Writer.F2,
            self.Writer.Alpha,
            self.Writer.Delta,
            record_segments=True,
        )
        twoF_per_seg_computed = np.array(search.twoF_per_segment)

        twoF_predicted = self.Writer.predict_fstat()
        # now compute the predicted semi-coherent Fstat for each segment
        print(self.Writer.duration)
        self.Writer.duration /= self.nsegs
        tstart = self.Writer.tstart
        print(tstart)
        twoF_per_seg_predicted = np.zeros(self.nsegs)
        for n in range(self.nsegs):
            self.Writer.tstart = tstart + n * self.Writer.duration
            print(self.Writer.tstart)
            print(self.Writer.duration)
            twoF_per_seg_predicted[n] = self.Writer.predict_fstat()

        self.assertTrue(
            len(twoF_per_seg_computed) == len(twoF_per_seg_predicted))
        diffs = (np.abs(twoF_per_seg_computed - twoF_per_seg_predicted) /
                 twoF_per_seg_predicted)
        print(
            ("Predicted twoF per segment are {}"
             " while recovered values are {},"
             " relative difference: {}".format(twoF_per_seg_predicted,
                                               twoF_per_seg_computed, diffs)))
        self.assertTrue(np.all(diffs < 0.3))
        diff = np.abs(twoF_sc - twoF_predicted) / twoF_predicted
        print(("Predicted semicoherent twoF is {}"
               " while recovered value is {},"
               " relative difference: {}".format(twoF_predicted, twoF_sc,
                                                 diff)))
        self.assertTrue(diff < 0.3)
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    def _run_test(self, delta_F0):

        Writer = pyfstat.GlitchWriter(
            self.label,
            outdir=self.outdir,
            tstart=self.tstart,
            duration=self.duration,
            dtglitch=self.dtglitch,
            delta_F0=delta_F0,
            detectors=self.detectors,
            sqrtSX=self.sqrtSX,
            **default_signal_params,
            SFTWindowType=self.SFTWindowType,
            SFTWindowBeta=self.SFTWindowBeta,
            randSeed=self.randSeed,
            Band=self.Band,
        )

        Writer.make_data(verbose=True)

        vanilla_search = pyfstat.SemiCoherentSearch(
            label=self.label,
            outdir=self.outdir,
            nsegs=2,
            sftfilepattern=self.Writer.sftfilepath,
            tref=Writer.tref,
            search_ranges=self.search_ranges,
        )

        # Compute the predicted semi-coherent glitch Fstat for the first half
        Writer.transientStartTime = Writer.tstart
        Writer.transientTau = self.dtglitch
        FSA = Writer.predict_fstat()
        # same for the second half (tau stays the same)
        Writer.transientStartTime += self.dtglitch
        FSB = Writer.predict_fstat()
        predicted_FS = FSA + FSB

        # vanilla semicoherent search not knowing about potential glitch
        twoF_sc_vanilla = vanilla_search.get_semicoherent_det_stat(
            Writer.F0,
            Writer.F1,
            Writer.F2,
            Writer.Alpha,
            Writer.Delta,
            record_segments=True,
        )
        twoF_per_seg_vanilla = vanilla_search.twoF_per_segment
        diff = np.abs(twoF_sc_vanilla - predicted_FS) / predicted_FS
        print(("Predicted twoF is {}+{}={}"
               " while recovered value from SemiCoherentSearch is {}+{}={},"
               " relative difference: {}".format(FSA, FSB, predicted_FS,
                                                 *twoF_per_seg_vanilla,
                                                 twoF_sc_vanilla, diff)))
        if delta_F0 == 0:
            self.assertTrue(diff < 0.3)
        else:
            self.assertFalse(diff < 0.3)

        # glitch-robust search
        keys = ["F0", "F1", "F2", "Alpha", "Delta"]
        search_ranges = {
            key: [
                getattr(Writer, key),
                getattr(Writer, key) + getattr(Writer, "delta_" + key, 0.0),
            ]
            for key in keys
        }
        glitch_search = pyfstat.SemiCoherentGlitchSearch(
            label=self.label,
            outdir=self.outdir,
            sftfilepattern=Writer.sftfilepath,
            tref=Writer.tref,
            minStartTime=Writer.tstart,
            maxStartTime=Writer.tend,
            nglitch=1,
            search_ranges=search_ranges,
        )
        twoF_glitch = glitch_search.get_semicoherent_nglitch_twoF(
            Writer.F0,
            Writer.F1,
            Writer.F2,
            Writer.Alpha,
            Writer.Delta,
            Writer.delta_F0,
            Writer.delta_F1,
            glitch_search.minStartTime + self.dtglitch,
        )
        diff = np.abs(twoF_glitch - predicted_FS) / predicted_FS
        print(("Predicted twoF is {}+{}={}"
               " while recovered value from SemiCoherentGlitchSearch is {},"
               " relative difference: {}".format(FSA, FSB, predicted_FS,
                                                 twoF_glitch, diff)))
        self.assertTrue(diff < 0.3)
        diff2 = np.abs((twoF_glitch - twoF_sc_vanilla) / twoF_sc_vanilla)
        print("Relative difference between SemiCoherentSearch"
              "and SemiCoherentGlitchSearch: {}".format(diff2))
        if delta_F0 == 0:
            self.assertTrue(diff2 < 0.01)
        else:
            self.assertTrue(twoF_glitch > twoF_sc_vanilla)
            self.assertTrue(diff2 > 0.3)