本文整理匯總了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