本文整理汇总了Python中pycmbs.data.Data.time方法的典型用法代码示例。如果您正苦于以下问题:Python Data.time方法的具体用法?Python Data.time怎么用?Python Data.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycmbs.data.Data
的用法示例。
在下文中一共展示了Data.time方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lomb_basic
# 需要导入模块: from pycmbs.data import Data [as 别名]
# 或者: from pycmbs.data.Data import time [as 别名]
def test_lomb_basic(self):
def _sample_data(t, w, A, B):
e = np.random.random(len(t))*0.
y = A * np.cos(w*self.t + B)
return y, e
def _test_ratio(x,y, thres=0.05):
r = np.abs(1. - x / y)
print r, x/y
self.assertTrue(r <= thres) # accuracy of ration by 5%
# test with single frequency
p_ref = 10.
w = 2.*np.pi / p_ref
y, e = _sample_data(self.t, w, 5., 0.1)
P = np.arange(2., 20., 2.) # target period [days]
Ar, Br = lomb_scargle_periodogram(self.t, P, y+e, corr=False)
_test_ratio(Ar[4], 5.)
_test_ratio(Br[4], 0.1)
Ar, Br, Rr, Pr = lomb_scargle_periodogram(self.t, P, y)
_test_ratio(Ar[4], 5.)
_test_ratio(Br[4], 0.1)
#~ self.assertEqual(Rr[4], 1.)
#~ self.assertEqual(Pr[4], 0.)
# test for functions with overlapping frequencies
p_ref1 = 365.
p_ref2 = 365.
w1 = 2.*np.pi / p_ref1
w2 = 2.*np.pi / p_ref2
y1, e1 = _sample_data(self.t, w1, 4., 0.1)
y2, e2 = _sample_data(self.t, w2, 3.6, 0.1)
P = np.arange(1., 366., 1.) # target period [days]
Ar, Br = lomb_scargle_periodogram(self.t, P, y1+e1+y2+e2, corr=False)
_test_ratio(Ar[-1], 7.6)
_test_ratio(Br[-1], 0.1)
# overlapping frequencies 2
p_ref1 = 100.
p_ref2 = 200.
w1 = 2.*np.pi / p_ref1
w2 = 2.*np.pi / p_ref2
y1, e1 = _sample_data(self.t, w1, 2., np.pi*0.3) # don't choose pi for phase, as this will result in an optimization with negative amplitude and zero phase (= sin)
y2, e2 = _sample_data(self.t, w2, 3., np.pi*0.5)
P = np.arange(1., 366., 1.) # target period [days]
hlp = y1+e1+y2+e2
Ar, Br = lomb_scargle_periodogram(self.t, P, hlp, corr=False)
# sample data object
D = Data(None, None)
D._init_sample_object(nt=len(y), ny=1, nx=1)
D.data[:,0,0] = np.ma.array(hlp, mask=hlp!=hlp)
D.time = self.t
D_dummy = Data(None, None)
D_dummy._init_sample_object(nt=len(y), ny=1, nx=1)
with self.assertRaises(ValueError):
D_dummy.time_str = 'hours since 2001-01-01' # only days currently supported!
xx, yy = D_dummy.lomb_scargle_periodogram(P, return_object=False)
AD, BD = D.lomb_scargle_periodogram(P, return_object=False, corr=False)
AD1, BD1 = D.lomb_scargle_periodogram(P, return_object=True, corr=False)
self.assertEqual(AD.shape, BD.shape)
self.assertEqual(D.ny, AD.shape[1])
self.assertEqual(D.nx, AD.shape[2])
_test_ratio(Ar[99], 2.)
_test_ratio(AD[99,0,0], 2.)
_test_ratio(AD1.data[99, 0,0], 2.)
_test_ratio(Ar[199], 3.)
_test_ratio(AD[199,0,0], 3.)
_test_ratio(AD1.data[199,0,0], 3.)
_test_ratio(Br[99], np.pi*0.3)
_test_ratio(BD[99,0,0], np.pi*0.3)
_test_ratio(BD1.data[99,0,0], np.pi*0.3)
_test_ratio(Br[199], np.pi*0.5)
_test_ratio(BD[199,0,0], np.pi*0.5)
_test_ratio(BD1.data[199,0,0], np.pi*0.5)
# test for data with gaps
# tests are not very robust yet as results depend on noise applied!
p_ref1 = 100.
p_ref2 = 200.
w1 = 2.*np.pi / p_ref1
w2 = 2.*np.pi / p_ref2
y1, e1 = _sample_data(self.t, w1, 2., np.pi*0.3) # don't choose pi for phase, as this will result in an optimization with negative amplitude and zero phase (= sin)
y2, e2 = _sample_data(self.t, w2, 3., np.pi*0.5)
P = np.arange(1., 366., 1.) # target period [days]
ran = np.random.random(len(self.t))
msk = ran > 0.1
#.........这里部分代码省略.........