Commit 3417c78a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: test fmrib datetime routines with nats

parent 70570d81
......@@ -23,35 +23,39 @@ TEST_DATES = tw.dedent("""
2017-01-01
2017-12-31
2018-01-01
2018-12-31
""").strip().split('\n')
EXPECT_DATES = [
2016.0, 2016.9972677595629,
2017.0, 2017.9972602739726,
2018.0, 2018.9972602739726]
2018.0, np.nan,
2018.9972602739726]
TEST_TIMES = tw.dedent("""
2016-01-01T07:00:00+0
2016-01-01T19:59:59+0
2016-12-31T07:00:00+0
2016-12-31T19:59:59+0
2017-01-01T07:00:00+0
2017-01-01T19:59:59+0
2017-12-31T07:00:00+0
2017-12-31T19:59:59+0
2018-01-01T07:00:00+0
2018-01-01T19:59:59+0
2018-12-31T07:00:00+0
2018-12-31T19:59:59+0
2016-01-01T07:00:00
2016-01-01T19:59:59
2016-12-31T07:00:00
2016-12-31T19:59:59
2017-01-01T07:00:00
2017-01-01T19:59:59
2017-12-31T07:00:00
2017-12-31T19:59:59
2018-01-01T07:00:00
2018-01-01T19:59:59
2018-12-31T07:00:00
2018-12-31T19:59:59
""").strip().split('\n')
EXPECT_TIMES = [
2016.0, 2016.002732182056, 2016.9972677595629, 2016.9999999416189,
2017.0, 2017.0027396674861, 2017.9972602739726, 2017.9999999414588,
2018.0, 2018.0027396674861, 2018.9972602739726, 2018.9999999414588]
2018.0, 2018.0027396674861, 2018.9972602739726, np.nan,
2018.9999999414588]
def test_columns_FMRIBImaging():
......@@ -94,8 +98,8 @@ def test_load_FMRIBImaging():
def test_normalisedDate():
dates = TEST_DATES
dexpect = EXPECT_DATES
dates = [pd.to_datetime(d) for d in dates]
dexpect = np.array(EXPECT_DATES)
dates = [pd.to_datetime(d, errors='ignore') for d in dates]
df = pd.DataFrame()
df['eid'] = range(1, len(dates) + 1)
......@@ -105,14 +109,18 @@ def test_normalisedDate():
dt = gen_DataTableFromDataFrame(df)
fmrib.normalisedDate(dt, 1)
assert np.all(np.isclose(dt[:, '1-0.0'], dexpect))
got = dt[:, '1-0.0']
notna = ~got.isna()
assert np.all((np.isfinite(dexpect) == notna))
assert np.all(np.isclose(got[notna], dexpect[notna]))
def test_normalisedAcquisitionTime():
times = TEST_TIMES
texpect = EXPECT_TIMES
times = [pd.to_datetime(t) for t in times]
texpect = np.array(EXPECT_TIMES)
times = [pd.to_datetime(t, errors='ignore') for t in times]
df = pd.DataFrame()
df['eid'] = range(1, len(times) + 1)
......@@ -122,4 +130,8 @@ def test_normalisedAcquisitionTime():
dt = gen_DataTableFromDataFrame(df)
fmrib.normalisedAcquisitionTime(dt, 1)
assert np.all(np.isclose(dt[:, '1-0.0'], texpect))
got = dt[:, '1-0.0']
notna = ~got.isna()
assert np.all((np.isfinite(texpect) == notna))
assert np.all(np.isclose(got[notna], texpect[notna]))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment