def test_interpolate1(self): a = TimeSeries([0, 5, 10], [1, 2, 3]) self.assertEqual(a.interpolate([-100, 100]), TimeSeries([-100, 100], [1, 3])) with self.assertRaises(TypeError): a.interpolate({'a': 1, 'b': 2})
def test_interpolate(self): """ test TimeSeries.interpolate """ tzstr = "US/Eastern" tz = pytz.timezone(tzstr) h = TimeSeries.hour n = datetime.datetime.now() times1 = [n, n+h, n+2*h, n+3*h] times2 = [n, n+3*h] times2 = TimeSeries.makeAware(times2, tz) values = [6.0, 8.0] ts = TimeSeries("test", times2, values, tzstr) res = ts.interpolate(times1) target = [6.0, 6.66667, 7.33333, 8.0] for i in range(len(res)): self.failUnlessAlmostEqual(res[i], target[i], places=4) times3 = [n-h, n+2*h, n+4*h] res = ts.interpolate(times3) target = [None, 7.3333333, None] for i in range(len(res)): self.failUnlessAlmostEqual(res[i], target[i], places=4)
def load_ts_file(filepath): ''' Takes in file and reads time series from it Parameters ---------- filepath: path of the file Returns ------- timeSeries object : TimeSeries class >>> ts=load_ts_file('169975.dat_folded.txt') >>> ts._values[0] 15.137 ''' #Only considers the first two columns of the text file (other columns are discarded) #Only evaluates time values between 0 and 1 #First column is presumed to be times and second column is presumed to be light curve values. data = np.loadtxt(filepath, delimiter=' ', dtype=str) clean_input = [] for i in range(len(data)): row = data[i].split("\\t") clean_input.append([float(row[0][2:]), float(row[1])]) data = np.array(clean_input) _, indices = np.unique(data[:, 0], return_index=True) data = data[indices, :] times, values = data.T full_ts = TimeSeries(times=list(times), values=list(values)) interpolated_ts = full_ts.interpolate( list(np.arange(0.0, 1.0, (1.0 / 100)))) full_ts_interpolated = TimeSeries(times=list( np.arange(0.0, 1.0, (1.0 / 100))), values=list(interpolated_ts)) return full_ts_interpolated
def test_lazy_interpolate(): ts = TimeSeries([1, 2, 3, 4, 5], [0, 5, 10, 15, 20]) assert ts.interpolate([-100, 100]).lazy.eval() == TimeSeries([1, 5], [-100, 100])
def test_interpolate3(self): a = TimeSeries([0, 5, 10], [1, 2, 3]) b = TimeSeries([2.5, 7.5], [100, -100]) self.assertEqual(a.interpolate([1]), TimeSeries([1], [1.2]))
def test_interpolate2(self): a = TimeSeries([0, 5, 10], [1, 2, 3]) b = TimeSeries([2.5, 7.5], [100, -100]) self.assertEqual(a.interpolate(b.times), TimeSeries([2.5, 7.5], [1.5, 2.5]))
def test_interpolate3(self): a = TimeSeries([0,5,10], [1,2,3]) b = TimeSeries([2.5,7.5], [100, -100]) self.assertEqual(a.interpolate([1]),TimeSeries([1], [1.2]))
def test_interpolate2(self): a = TimeSeries([0,5,10], [1,2,3]) b = TimeSeries([2.5,7.5], [100, -100]) self.assertEqual(a.interpolate(b.times),TimeSeries([2.5, 7.5], [1.5, 2.5]))
def test_interpolate1(self): a = TimeSeries([0,5,10], [1,2,3]) self.assertEqual(a.interpolate([-100,100]),TimeSeries([-100, 100], [1, 3])) with self.assertRaises(TypeError): a.interpolate({'a':1,'b':2})
def test_interpolate(self): a = TimeSeries([0, 5, 10], [ 1, 2, 3]) b = TimeSeries([2.5,7.5], [100, -100]) self.assertTrue ( a.interpolate([1]) == TimeSeries([1],[1.2]) ) self.assertTrue ( a.interpolate(b.times) == TimeSeries([2.5,7.5], [1.5, 2.5])) self.assertTrue ( a.interpolate([-100, 100]) == TimeSeries([-100,100], [1,3]))