Example #1
0
    def _normalize_multitaper(self, unnorm_power, tseg):
        """Apply one of the allowed normalizations to the periodogram.

        Normalize the real part of the multitaper spectrum estimate to Leahy,
        absolute rms^2, fractional rms^2 normalization, or not at all.

        Parameters
        ----------
        unnorm_power: numpy.ndarray
            The unnormalized spectrum estimate.

        tseg: int
            The length of the Fourier segment, in seconds.

        Returns
        -------
        power: numpy.nd.array
            The normalized spectrum estimate (real part of the spectrum).
        """

        if self.err_dist == 'poisson':
            return normalize_crossspectrum(
                unnorm_power, tseg, self.n, self.nphots, self.nphots, self.norm,
                self.power_type)

        return normalize_crossspectrum_gauss(
            unnorm_power, np.sqrt(self.meancounts * self.meancounts),
            np.sqrt(self.var * self.var),
            dt=self.dt,
            N=self.n,
            norm=self.norm,
            power_type=self.power_type)
Example #2
0
 def test_failure_when_normalization_not_recognized(self):
     with pytest.raises(ValueError):
         power = normalize_crossspectrum(self.cs.power,
                                         self.lc1.tseg,
                                         self.lc1.n,
                                         self.cs.nphots1,
                                         self.cs.nphots2,
                                         norm="wrong")
Example #3
0
    def test_norm_frac(self):
        power = normalize_crossspectrum(self.cs.power,
                                        self.lc1.tseg,
                                        self.lc1.n,
                                        self.cs.nphots1,
                                        self.cs.nphots2,
                                        norm="frac")

        norm = 2. / self.rate1
        assert np.isclose(np.mean(power[1:]), norm, rtol=0.1)
Example #4
0
    def test_norm_leahy(self):

        power = normalize_crossspectrum(self.cs.power,
                                        self.lc1.tseg,
                                        self.lc1.n,
                                        self.cs.nphots1,
                                        self.cs.nphots2,
                                        norm="leahy")

        leahy_noise = 2.0  # expected Poisson noise level
        assert np.isclose(np.mean(power[1:]), leahy_noise, rtol=0.02)
Example #5
0
    def test_norm_abs(self):
        # Testing for a power spectrum of lc1
        power = normalize_crossspectrum(self.cs.power,
                                        self.lc1.tseg,
                                        self.lc1.n,
                                        self.cs.nphots1,
                                        self.cs.nphots2,
                                        norm="abs")

        abs_noise = 2. * self.rate1  # expected Poisson noise level
        assert np.isclose(np.mean(power[1:]), abs_noise, rtol=0.001)
 def test_failure_when_normalization_not_recognized(self):
     with pytest.raises(ValueError):
         power = normalize_crossspectrum(self.cs.power,
                                         self.lc1.tseg,
                                         self.lc1.n,
                                         self.cs.nphots1,
                                         self.cs.nphots2,
                                         norm="wrong")
     self.cs.norm = 'asdgfasdfa'
     self.cs_norm.norm = 'adfafaf'
     with pytest.raises(ValueError):
         power = self.cs._normalize_crossspectrum(self.cs.unnorm_power,
                                                  self.tseg)
     with pytest.raises(ValueError):
         power = self.cs_norm._normalize_crossspectrum(
             self.cs.unnorm_power, self.tseg)