-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_data.py
49 lines (37 loc) · 1.25 KB
/
test_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import division, print_function
__author__ = "adrn <adrn@astro.columbia.edu>"
# Standard library
from os.path import exists, join
# Third-party
import astropy.time as atime
import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
import pytest
from .data import RVData
def test_rvdata():
# test various initializations
t = np.random.uniform(55555., 56012., size=1024)
rv = 100 * np.sin(0.5*t) * u.km/u.s
ivar = 1 / (np.random.normal(0,5,size=1024)*u.km/u.s)**2
RVData(t=t, rv=rv, ivar=ivar)
t = atime.Time(t, format='mjd', scale='utc')
RVData(t=t, rv=rv, ivar=ivar)
with pytest.raises(TypeError):
RVData(t=t, rv=rv.value, ivar=ivar)
with pytest.raises(TypeError):
RVData(t=t, rv=rv, ivar=ivar.value)
# check that copy works
t = atime.Time(t, format='mjd', scale='utc')
data1 = RVData(t=t, rv=rv, ivar=ivar)
data2 = data1.copy()
data1._t *= 1.5
data1._rv *= 1.5
data1._ivar *= 1.5
assert np.all(data2._t != data1._t)
assert np.all(data2._rv != data1._rv)
assert np.all(data2._ivar != data1._ivar)
# check that plotting at least succeeds (TODO: could be better)
# data1.plot()
# data1.plot(color='r')
# data1.plot(ax=plt.gca())