Пример #1
0
 def test_timeseries_rmul(self):
     d1 = [1., 2.]
     d_sum = [2., 4.]
     time = [0., 1.]
     s1 = ts.TimeSeries(d1, time)
     expected = ts.TimeSeries(d_sum, time)
     actual = 2 * s1
     self.assertEqual(actual, expected)
Пример #2
0
 def test_timeseries_round(self):
     data = [1.1, 2.2, 1.01]
     r_data = [1., 2., 1.]
     time = [0., 1., 2.]
     series = ts.TimeSeries(data, time)
     expected = ts.TimeSeries(r_data, time)
     calculated = round(series)
     self.assertEqual(expected, calculated)
Пример #3
0
 def test_timeseries_mul(self):
     d1 = [1., 2.]
     d2 = [10., 20.]
     d_sum = [10., 40.]
     time = [0., 1.]
     s1 = ts.TimeSeries(d1, time)
     s2 = ts.TimeSeries(d2, time)
     expected = ts.TimeSeries(d_sum, time)
     actual = s2 * s1
     self.assertEqual(actual, expected)
Пример #4
0
 def test_timeseries_iteration(self):
     series = ts.TimeSeries()
     series.append('foo', 0.)
     series.append('bar', 1.)
     for de, te, (d, t) in zip(['foo', 'bar'], [0., 1.], series):
         self.assertEqual(d, de)
         self.assertEqual(t, te)
Пример #5
0
 def test_timeseries_array_init(self):
     data = [1, 2, 3]
     time = [0., 0.5, 1.5]
     series = ts.TimeSeries(data, time)
     self.assertEqual(data, series.data)
     self.assertEqual(time, series.time)
     self.assertEqual(3, len(series))
Пример #6
0
 def test_timeseries_append_null_init(self):
     series = ts.TimeSeries()
     series.append('foo', 0.)
     series.append('bar', 1.)
     expected_data = ['foo', 'bar']
     expected_time = [0., 1.]
     self.assertTrue(np.array_equal(series.data, expected_data))
     self.assertTrue(np.array_equal(series.time, expected_time))
Пример #7
0
 def test_timeseries_append_array_init(self):
     data = [1, 2, 3]
     time = [0., 0.5, 1.5]
     series = ts.TimeSeries(data, time)
     series.append(4, 3.5)
     expected_data = data + [4]
     expected_time = time + [3.5]
     self.assertTrue(np.array_equal(series.data, expected_data))
     self.assertTrue(np.array_equal(series.time, expected_time))
Пример #8
0
 def test_timeseries_equality(self):
     series1 = ts.TimeSeries()
     series2 = ts.TimeSeries()
     series3 = ts.TimeSeries()
     series4 = ts.TimeSeries()
     series1.append('foo', 0.)
     series1.append('bar', 1.)
     series2.append('foo', 0.)
     series2.append('bar', 1.)
     series3.append('foo', 0.)
     series3.append('baz', 1.)
     series4.append('foo', 0.)
     series4.append('bar', 2.)
     self.assertEqual(series1, series2)
     self.assertTrue(series1 == series2)
     self.assertFalse(series1 != series2)
     self.assertNotEqual(series1, series3)
     self.assertNotEqual(series1, series4)
     self.assertTrue(series1 != series3)
     self.assertFalse(series1 == series3)
Пример #9
0
    def test_rk_exponential(self):
        def deriv(y, t):
            return - y

        y0 = 1.
        t0 = 0.
        tf = 1.
        num_time = 50
        dt = (tf - t0) / (num_time - 1)
        t_correct = np.linspace(t0, tf, num_time)
        y_correct = np.exp(-t_correct)
        series_correct = ts.TimeSeries()

        for y, t in zip(y_correct, t_correct):
            series_correct.append(y, t)
        series_calculated = rk.rk_integrate(y0, t0, dt, tf, deriv)
        self.assertAlmostEqual(series_correct, series_calculated)
Пример #10
0
def rk_integrate(y0,
                 t0,
                 dt,
                 tf,
                 deriv,
                 interv=lambda x, t: (x, t),
                 rk_kwargs={},
                 deriv_kwargs={},
                 interv_kwargs={}):
    trajectory = ts.TimeSeries()
    trajectory.append(y0, t0)
    t = t0
    y = y0
    while t < tf:
        y, t = rk_step(y, t, dt, deriv, deriv_kwargs=deriv_kwargs, **rk_kwargs)
        y, t = interv(y, t, **interv_kwargs)
        trajectory.append(y, t)

    return trajectory
Пример #11
0
 def test_timeseries_null_init(self):
     series = ts.TimeSeries()
     self.assertEqual([], series.data)
     self.assertEqual([], series.time)
     self.assertEqual(0, len(series))
Пример #12
0
 def test_timeseries_len(self):
     series = ts.TimeSeries()
     series.append('foo', 0.)
     self.assertEqual(1, len(series))
     series.append('bar', 1.)
     self.assertEqual(2, len(series))
Пример #13
0
 def test_timeseries_getitem(self):
     series = ts.TimeSeries()
     series.append('foo', 0.)
     series.append('bar', 1.)
     self.assertEqual(series[0], ('foo', 0.))
     self.assertEqual(series[1], ('bar', 1.))
Пример #14
0
y = np.linspace(-0.5, 0.5, res_y)
z = np.linspace(-0.5, 0.5, res_z)
cart_grid = gr.CartesianGrid((x, y, z))

xg, yg, zg = cart_grid.grid
grid_list = []
time_list = []
for t in range(50):
    data = np.exp(-(xg - 0.25 * np.cos(t * np.pi / 25.))**2 / 0.25 -
                  (yg - 0.25 * np.sin(t * np.pi / 25.))**2 / 0.25 -
                  (zg)**2 / 0.25)
    funct_grid = gr.GridData(data, cart_grid)
    grid_list.append(funct_grid)
    time_list.append(t)

cartesian_series = ts.TimeSeries(grid_list, time_list)

# Make Spherical Grid
res_r = 50
res_theta = 50
res_phi = 50

r = np.linspace(0.0, 0.5, res_r)
theta = np.linspace(0., np.pi, res_theta)
phi = np.linspace(0., 2 * np.pi, res_phi)
spher_grid = gr.SphericalGrid((r, theta, phi))
xg, yg, zg = spher_grid.grid
grid_list = []
time_list = []
for t in range(50):
    data = np.exp(-(xg - 0.25 * np.cos(t * np.pi / 25.))**2 / 0.25 -