Exemplo n.º 1
0
    def _timmerkoenig(self, pds_shape):
        """Straight application of T&K method to a PDS shape.

        """
        pds_size = pds_shape.size

        real = np.random.normal(size=pds_size) * np.sqrt(0.5 * pds_shape)
        imaginary = np.random.normal(size=pds_size) * np.sqrt(0.5 * pds_shape)
        imaginary[-1] = 0

        counts = self._find_inverse(real, imaginary)

        self.std = counts.std()

        rescaled_counts = self._extract_and_scale(counts)
        err = np.zeros_like(rescaled_counts)

        if self.poisson:
            bad = rescaled_counts < 0
            if np.any(bad):
                warnings.warn(
                    "Some bins of the light curve have counts < 0. Setting to 0"
                )
                rescaled_counts[bad] = 0
            lc = Lightcurve(self.time,
                            np.random.poisson(rescaled_counts),
                            err_dist='poisson',
                            dt=self.dt,
                            skip_checks=True)
            lc.smooth_counts = rescaled_counts
        else:
            lc = Lightcurve(self.time,
                            rescaled_counts,
                            err=err,
                            err_dist='gauss',
                            dt=self.dt,
                            skip_checks=True)

        return lc