Beispiel #1
0
    def __init__(self, lc=None, norm='frac', gti=None):
        """
        Make a Periodogram (power spectrum) from a (binned) light curve.
        Periodograms can be Leahy normalized or fractional rms normalized.
        You can also make an empty Periodogram object to populate with your
        own fourier-transformed data (this can sometimes be useful when making
        binned periodograms).

        Parameters
        ----------
        lc: lightcurve.Lightcurve object, optional, default None
            The light curve data to be Fourier-transformed.

        norm: {"leahy" | "frac" | "abs" | "none" }, optional, default "frac"
            The normaliation of the periodogram to be used. Options are
            "leahy", "frac", "abs" and "none", default is "frac".

        Other Parameters
        ----------------
        gti: 2-d float array
            [[gti0_0, gti0_1], [gti1_0, gti1_1], ...] -- Good Time intervals.
            This choice overrides the GTIs in the single light curves. Use with
            care!

        Attributes
        ----------
        norm: {"leahy" | "frac" | "abs" | "none"}
            the normalization of the periodogram

        freq: numpy.ndarray
            The array of mid-bin frequencies that the Fourier transform samples

        power: numpy.ndarray
            The array of normalized squared absolute values of Fourier
            amplitudes

        power_err: numpy.ndarray
            The uncertainties of `power`.
            An approximation for each bin given by "power_err= power/Sqrt(m)".
            Where `m` is the number of power averaged in each bin (by frequency
            binning, or averaging powerspectrum). Note that for a single
            realization (m=1) the error is equal to the power.

        df: float
            The frequency resolution

        m: int
            The number of averaged powers in each bin

        n: int
            The number of data points in the light curve

        nphots: float
            The total number of photons in the light curve

        """

        Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
        self.nphots = self.nphots1
Beispiel #2
0
    def __init__(self, lc=None, norm='frac', gti=None):
        """
        Make a Periodogram (power spectrum) from a (binned) light curve.
        Periodograms can be Leahy normalized or fractional rms normalized.
        You can also make an empty Periodogram object to populate with your
        own fourier-transformed data (this can sometimes be useful when making
        binned periodograms).

        Parameters
        ----------
        lc: lightcurve.Lightcurve object, optional, default None
            The light curve data to be Fourier-transformed.

        norm: {"leahy" | "frac" | "abs" | "none" }, optional, default "frac"
            The normaliation of the periodogram to be used. Options are
            "leahy", "frac", "abs" and "none", default is "frac".

        Other Parameters
        ----------------
        gti: 2-d float array
            [[gti0_0, gti0_1], [gti1_0, gti1_1], ...] -- Good Time intervals.
            This choice overrides the GTIs in the single light curves. Use with
            care!

        Attributes
        ----------
        norm: {"leahy" | "frac" | "abs" | "none"}
            the normalization of the periodogram

        freq: numpy.ndarray
            The array of mid-bin frequencies that the Fourier transform samples

        power: numpy.ndarray
            The array of normalized squared absolute values of Fourier
            amplitudes

        power_err: numpy.ndarray
            The uncertainties of `power`.
            An approximation for each bin given by "power_err= power/Sqrt(m)".
            Where `m` is the number of power averaged in each bin (by frequency
            binning, or averaging powerspectrum). Note that for a single
            realization (m=1) the error is equal to the power.

        df: float
            The frequency resolution

        m: int
            The number of averaged powers in each bin

        n: int
            The number of data points in the light curve

        nphots: float
            The total number of photons in the light curve

        """

        Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
        self.nphots = self.nphots1
Beispiel #3
0
    def __init__(self, data=None, norm="frac", gti=None,
                 dt=None, lc=None):
        if lc is not None:
            warnings.warn("The lc keyword is now deprecated. Use data "
                          "instead", DeprecationWarning)
        if data is None:
            data = lc

        Crossspectrum.__init__(self, data1=data, data2=data, norm=norm, gti=gti,
                               dt=dt)
        self.nphots = self.nphots1
        self.dt = dt
Beispiel #4
0
    def __init__(self, lc=None, norm='frac', gti=None):
        """
        Make a Periodogram (power spectrum) from a (binned) light curve.
        Periodograms can be Leahy normalized or fractional rms normalized.
        You can also make an empty Periodogram object to populate with your
        own fourier-transformed data (this can sometimes be useful when making
        binned periodograms).

        Parameters
        ----------
        lc: lightcurve.Lightcurve object, optional, default None
            The light curve data to be Fourier-transformed.

        norm: {"leahy" | "rms"}, optional, default "rms"
            The normaliation of the periodogram to be used. Options are
            "leahy" or "rms", default is "rms".

        Other Parameters
        ----------------
        gti: 2-d float array
            [[gti0_0, gti0_1], [gti1_0, gti1_1], ...] -- Good Time intervals.
            This choice overrides the GTIs in the single light curves. Use with
            care!

        Attributes
        ----------
        norm: {"leahy" | "rms"}
            the normalization of the periodogram

        freq: numpy.ndarray
            The array of mid-bin frequencies that the Fourier transform samples

        power: numpy.ndarray
            The array of normalized squared absolute values of Fourier
            amplitudes

        df: float
            The frequency resolution

        m: int
            The number of averaged powers in each bin

        n: int
            The number of data points in the light curve

        nphots: float
            The total number of photons in the light curve

        """
        Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
        self.nphots = self.nphots1
Beispiel #5
0
    def __init__(self, lc=None, norm='frac', gti=None):
        """
        Make a Periodogram (power spectrum) from a (binned) light curve.
        Periodograms can be Leahy normalized or fractional rms normalized.
        You can also make an empty Periodogram object to populate with your
        own fourier-transformed data (this can sometimes be useful when making
        binned periodograms).

        Parameters
        ----------
        lc: lightcurve.Lightcurve object, optional, default None
            The light curve data to be Fourier-transformed.

        norm: {"leahy" | "rms"}, optional, default "rms"
            The normaliation of the periodogram to be used. Options are
            "leahy" or "rms", default is "rms".

        Other Parameters
        ----------------
        gti: 2-d float array
            [[gti0_0, gti0_1], [gti1_0, gti1_1], ...] -- Good Time intervals.
            This choice overrides the GTIs in the single light curves. Use with
            care!

        Attributes
        ----------
        norm: {"leahy" | "rms"}
            the normalization of the periodogram

        freq: numpy.ndarray
            The array of mid-bin frequencies that the Fourier transform samples

        power: numpy.ndarray
            The array of normalized squared absolute values of Fourier
            amplitudes

        df: float
            The frequency resolution

        m: int
            The number of averaged powers in each bin

        n: int
            The number of data points in the light curve

        nphots: float
            The total number of photons in the light curve

        """
        Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
        self.nphots = self.nphots1
Beispiel #6
0
def load_pds(fname):
    """Load PDS from a file."""
    if get_file_format(fname) == 'pickle':
        data = _load_data_pickle(fname)
    elif get_file_format(fname) == 'nc':
        data = _load_data_nc(fname)

    type_string = data['__sr__class__type__']
    if 'AveragedPowerspectrum' in type_string:
        cpds = AveragedPowerspectrum()
    elif 'Powerspectrum' in type_string:
        cpds = Powerspectrum()
    elif 'AveragedCrossspectrum' in type_string:
        cpds = AveragedCrossspectrum()
    elif 'Crossspectrum' in type_string:
        cpds = Crossspectrum()
    else:
        raise ValueError('Unrecognized data type in file')

    data.pop('__sr__class__type__')
    for key in data.keys():
        setattr(cpds, key, data[key])

    lc1_name = fname.replace(HEN_FILE_EXTENSION,
                             '__lc1__' + HEN_FILE_EXTENSION)
    lc2_name = fname.replace(HEN_FILE_EXTENSION,
                             '__lc2__' + HEN_FILE_EXTENSION)
    pds1_name = fname.replace(HEN_FILE_EXTENSION,
                              '__pds1__' + HEN_FILE_EXTENSION)
    pds2_name = fname.replace(HEN_FILE_EXTENSION,
                              '__pds2__' + HEN_FILE_EXTENSION)
    cs_all_names = glob.glob(
        fname.replace(HEN_FILE_EXTENSION,
                      '__cs__[0-9]__' + HEN_FILE_EXTENSION))

    if os.path.exists(lc1_name):
        cpds.lc1 = load_lcurve(lc1_name)
    if os.path.exists(lc2_name):
        cpds.lc2 = load_lcurve(lc2_name)
    if os.path.exists(pds1_name):
        cpds.pds1 = load_pds(pds1_name)
    if os.path.exists(pds2_name):
        cpds.pds2 = load_pds(pds2_name)
    if len(cs_all_names) > 0:
        cs_all = []
        for c in cs_all_names:
            cs_all.append(load_pds(c))
        cpds.cs_all = cs_all

    return cpds
Beispiel #7
0
    def __init__(self, data=None, norm="frac", gti=None,
                 dt=None, lc=None, skip_checks=False, legacy=False):

        self._type = None
        if lc is not None:
            warnings.warn("The lc keyword is now deprecated. Use data "
                          "instead", DeprecationWarning)
        if data is None:
            data = lc

        good_input = True
        if not skip_checks:
            good_input = self.initial_checks(
                data1=data,
                data2=data,
                norm=norm,
                gti=gti,
                lc1=lc,
                lc2=lc,
                dt=dt
            )

        norm = norm.lower()
        self.norm = norm
        self.dt = dt

        if not good_input:
            return self._initialize_empty()

        if not legacy and data is not None:
            return self._initialize_from_any_input(data, dt=dt, norm=norm)

        Crossspectrum.__init__(self, data1=data, data2=data, norm=norm, gti=gti,
                               dt=dt, skip_checks=True, legacy=legacy)
        self.nphots = self.nphots1
        self.dt = dt
Beispiel #8
0
    def rebin(self, df=None, f=None, method="mean"):
        """
        Rebin the power spectrum.

        Parameters
        ----------
        df: float
            The new frequency resolution

        Other Parameters
        ----------------
        f: float
            the rebin factor. If specified, it substitutes ``df`` with ``f*self.df``

        Returns
        -------
        bin_cs = :class:`Powerspectrum` object
            The newly binned power spectrum.
        """
        bin_ps = Crossspectrum.rebin(self, df=df, f=f, method=method)
        bin_ps.nphots = bin_ps.nphots1

        return bin_ps
Beispiel #9
0
    def rebin(self, df=None, f=None, method="mean"):
        """
        Rebin the power spectrum.

        Parameters
        ----------
        df: float
            The new frequency resolution

        Other Parameters
        ----------------
        f: float
            the rebin factor. If specified, it substitutes ``df`` with ``f*self.df``

        Returns
        -------
        bin_cs = :class:`Powerspectrum` object
            The newly binned power spectrum.
        """
        bin_ps = Crossspectrum.rebin(self, df=df, f=f, method=method)
        bin_ps.nphots = bin_ps.nphots1

        return bin_ps
Beispiel #10
0
 def __init__(self, lc=None, norm='frac', gti=None):
     Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
     self.nphots = self.nphots1
Beispiel #11
0
def load_pds(fname, nosub=False):
    """Load PDS from a file."""
    if get_file_format(fname) == 'pickle':
        data = _load_data_pickle(fname)
    elif get_file_format(fname) == 'nc':
        data = _load_data_nc(fname)

    type_string = data['__sr__class__type__']
    if 'AveragedPowerspectrum' in type_string:
        cpds = AveragedPowerspectrum()
    elif 'Powerspectrum' in type_string:
        cpds = Powerspectrum()
    elif 'AveragedCrossspectrum' in type_string:
        cpds = AveragedCrossspectrum()
    elif 'Crossspectrum' in type_string:
        cpds = Crossspectrum()
    else:
        raise ValueError('Unrecognized data type in file')

    data.pop('__sr__class__type__')
    for key in data.keys():
        setattr(cpds, key, data[key])

    if 'amplitude' in list(data.keys()):
        cpds.amplitude = bool(data["amplitude"])

    outdir = fname.replace(HEN_FILE_EXTENSION, "")
    modelfiles = glob.glob(
        os.path.join(outdir, fname.replace(HEN_FILE_EXTENSION, '__mod*__.p')))
    cpds.best_fits = None
    if len(modelfiles) >= 1:
        bmodels = []
        for mfile in modelfiles:
            if os.path.exists(mfile):
                bmodels.append(load_model(mfile)[0])
        cpds.best_fits = bmodels

    if nosub:
        return cpds

    lc1_name = os.path.join(outdir, '__lc1__' + HEN_FILE_EXTENSION)
    lc2_name = os.path.join(outdir, '__lc2__' + HEN_FILE_EXTENSION)
    pds1_name = os.path.join(outdir, '__pds1__' + HEN_FILE_EXTENSION)
    pds2_name = os.path.join(outdir, '__pds2__' + HEN_FILE_EXTENSION)
    cs_all_names = glob.glob(
        os.path.join(outdir, '__cs__[0-9]__' + HEN_FILE_EXTENSION))

    if os.path.exists(lc1_name):
        cpds.lc1 = load_lcurve(lc1_name)
    if os.path.exists(lc2_name):
        cpds.lc2 = load_lcurve(lc2_name)
    if os.path.exists(pds1_name):
        cpds.pds1 = load_pds(pds1_name)
    if os.path.exists(pds2_name):
        cpds.pds2 = load_pds(pds2_name)
    if len(cs_all_names) > 0:
        cs_all = []
        for c in cs_all_names:
            cs_all.append(load_pds(c))
        cpds.cs_all = cs_all

    return cpds
Beispiel #12
0
    def rebin(self, df=None, f=None, method="mean"):
        bin_ps = Crossspectrum.rebin(self, df=df, f=f, method=method)
        bin_ps.nphots = bin_ps.nphots1

        return bin_ps
Beispiel #13
0
    def rebin(self, df, method="mean"):
        bin_ps = Crossspectrum.rebin(self, df=df, method=method)
        bin_ps.nphots = bin_ps.nphots1

        return bin_ps
Beispiel #14
0
 def __init__(self, lc=None, norm='frac', gti=None):
     Crossspectrum.__init__(self, lc1=lc, lc2=lc, norm=norm, gti=gti)
     self.nphots = self.nphots1