本文整理汇总了Python中pycbc.types.FrequencySeries.to_timeseries方法的典型用法代码示例。如果您正苦于以下问题:Python FrequencySeries.to_timeseries方法的具体用法?Python FrequencySeries.to_timeseries怎么用?Python FrequencySeries.to_timeseries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycbc.types.FrequencySeries
的用法示例。
在下文中一共展示了FrequencySeries.to_timeseries方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _shift_and_ifft
# 需要导入模块: from pycbc.types import FrequencySeries [as 别名]
# 或者: from pycbc.types.FrequencySeries import to_timeseries [as 别名]
def _shift_and_ifft(self, fdsinx, tshift, fseries=None):
"""Calls apply_fd_time_shift, and iFFTs to the time domain.
"""
start_time = self.time_series.start_time
tdshift = apply_fd_time_shift(fdsinx, start_time+tshift,
fseries=fseries)
if not isinstance(tdshift, FrequencySeries):
# cast to FrequencySeries so time series will work
tdshift = FrequencySeries(tdshift, delta_f=fdsinx.delta_f,
epoch=fdsinx.epoch)
return tdshift.to_timeseries()
示例2: calculate_acf
# 需要导入模块: from pycbc.types import FrequencySeries [as 别名]
# 或者: from pycbc.types.FrequencySeries import to_timeseries [as 别名]
def calculate_acf(data, delta_t=1.0, unbiased=False):
""" Calculates the autocorrelation function (ACF) and returns the one-sided
ACF.
The ACF is defined as the autocovariance divided by the variance. The ACF
can be estimated using
\hat{R}(k) = \frac{1}{\left( n \sigma^{2}} \right) \sum_{t=1}^{n-k} \left( X_{t} - \mu \right) \left( X_{t+k} - \mu \right)
Where \hat{R}(k) is the ACF, X_{t} is the data series at time t, \mu is the
mean of X_{t}, and \sigma^{2} is the variance of X_{t}.
Parameters
-----------
data : {TimeSeries, numpy.array}
A TimeSeries or numpy.array of data.
delta_t : float
The time step of the data series if it is not a TimeSeries instance.
unbiased : bool
If True the normalization of the autocovariance function is n-k
instead of n. This is called the unbiased estimation of the
autocovariance. Note that this does not mean the ACF is unbiased.
Returns
-------
acf : numpy.array
If data is a TimeSeries then acf will be a TimeSeries of the
one-sided ACF. Else acf is a numpy.array.
"""
# if given a TimeSeries instance then get numpy.array
if isinstance(data, TimeSeries):
y = data.numpy()
delta_t = data.delta_t
else:
y = data
# FFT data minus the mean
fdata = TimeSeries(y-y.mean(), delta_t=delta_t).to_frequencyseries()
# correlate
# do not need to give the congjugate since correlate function does it
cdata = FrequencySeries(zeros(len(fdata), dtype=numpy.complex64),
delta_f=fdata.delta_f, copy=False)
correlate(fdata, fdata, cdata)
# IFFT correlated data to get unnormalized autocovariance time series
acf = cdata.to_timeseries()
# normalize the autocovariance
# note that dividing by acf[0] is the same as ( y.var() * len(acf) )
if unbiased:
acf /= ( y.var() * numpy.arange(len(acf), 0, -1) )
else:
acf /= acf[0]
# return input datatype
if isinstance(data, TimeSeries):
return TimeSeries(acf, delta_t=delta_t)
else:
return acf
示例3: calculate_acf
# 需要导入模块: from pycbc.types import FrequencySeries [as 别名]
# 或者: from pycbc.types.FrequencySeries import to_timeseries [as 别名]
def calculate_acf(data, delta_t=1.0, unbiased=False):
r"""Calculates the one-sided autocorrelation function.
Calculates the autocorrelation function (ACF) and returns the one-sided
ACF. The ACF is defined as the autocovariance divided by the variance. The
ACF can be estimated using
.. math::
\hat{R}(k) = \frac{1}{n \sigma^{2}} \sum_{t=1}^{n-k} \left( X_{t} - \mu \right) \left( X_{t+k} - \mu \right)
Where :math:`\hat{R}(k)` is the ACF, :math:`X_{t}` is the data series at
time t, :math:`\mu` is the mean of :math:`X_{t}`, and :math:`\sigma^{2}` is
the variance of :math:`X_{t}`.
Parameters
-----------
data : TimeSeries or numpy.array
A TimeSeries or numpy.array of data.
delta_t : float
The time step of the data series if it is not a TimeSeries instance.
unbiased : bool
If True the normalization of the autocovariance function is n-k
instead of n. This is called the unbiased estimation of the
autocovariance. Note that this does not mean the ACF is unbiased.
Returns
-------
acf : numpy.array
If data is a TimeSeries then acf will be a TimeSeries of the
one-sided ACF. Else acf is a numpy.array.
"""
# if given a TimeSeries instance then get numpy.array
if isinstance(data, TimeSeries):
y = data.numpy()
delta_t = data.delta_t
else:
y = data
# Zero mean
y = y - y.mean()
ny_orig = len(y)
npad = 1
while npad < 2*ny_orig:
npad = npad << 1
ypad = numpy.zeros(npad)
ypad[:ny_orig] = y
# FFT data minus the mean
fdata = TimeSeries(ypad, delta_t=delta_t).to_frequencyseries()
# correlate
# do not need to give the congjugate since correlate function does it
cdata = FrequencySeries(zeros(len(fdata), dtype=fdata.dtype),
delta_f=fdata.delta_f, copy=False)
correlate(fdata, fdata, cdata)
# IFFT correlated data to get unnormalized autocovariance time series
acf = cdata.to_timeseries()
acf = acf[:ny_orig]
# normalize the autocovariance
# note that dividing by acf[0] is the same as ( y.var() * len(acf) )
if unbiased:
acf /= ( y.var() * numpy.arange(len(acf), 0, -1) )
else:
acf /= acf[0]
# return input datatype
if isinstance(data, TimeSeries):
return TimeSeries(acf, delta_t=delta_t)
else:
return acf