-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_misc.py
135 lines (109 loc) · 4.49 KB
/
test_misc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import unittest
from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
from dateutil.tz import tzlocal
from ipywidgets import widgets
from pynwb import NWBFile
from pynwb.misc import AnnotationSeries, DecompositionSeries
from nwbwidgets.base import render_dataframe
from nwbwidgets.misc import (
PSTHWidget,
RasterGridWidget,
RasterWidget,
raster_grid,
show_annotations,
show_decomposition_series,
show_decomposition_traces,
show_psth_raster,
show_session_raster,
)
def test_show_psth():
data = np.random.random([6, 50])
assert isinstance(show_psth_raster(data=data, start=0, end=1), plt.Subplot)
def test_show_annotations():
timestamps = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
annotations = AnnotationSeries(name="test_annotations", timestamps=timestamps)
show_annotations(annotations)
class ShowPSTHTestCase(unittest.TestCase):
def setUp(self):
"""
Trials must exist.
"""
start_time = datetime(2017, 4, 3, 11, tzinfo=tzlocal())
create_date = datetime(2017, 4, 15, 12, tzinfo=tzlocal())
self.nwbfile = NWBFile(
session_description="NWBFile for PSTH",
identifier="NWB123",
session_start_time=start_time,
file_create_date=create_date,
)
self.nwbfile.add_unit_column("location", "the anatomical location of this unit")
self.nwbfile.add_unit_column("quality", "the quality for the inference of this unit")
self.nwbfile.add_unit(
spike_times=[2.2, 3.0, 4.5],
obs_intervals=[[1, 10]],
location="CA1",
quality=0.95,
)
self.nwbfile.add_unit(
spike_times=[2.2, 3.0, 25.0, 26.0],
obs_intervals=[[1, 10], [20, 30]],
location="CA3",
quality=0.85,
)
self.nwbfile.add_unit(
spike_times=[1.2, 2.3, 3.3, 4.5],
obs_intervals=[[1, 10], [20, 30]],
location="CA1",
quality=0.90,
)
self.nwbfile.add_trial_column(name="stim", description="the visual stimuli during the trial")
self.nwbfile.add_trial(start_time=0.0, stop_time=1.0, stim="person")
self.nwbfile.add_trial(start_time=0.1, stop_time=2.0, stim="person")
self.nwbfile.add_trial(start_time=3.0, stop_time=4.0, stim="ocean")
self.nwbfile.add_trial(start_time=4.0, stop_time=5.0, stim="ocean")
self.nwbfile.add_trial(start_time=5.0, stop_time=6.0, stim="desert")
self.nwbfile.add_trial(start_time=6.0, stop_time=8.0, stim="desert")
def test_psth_widget(self):
widget = PSTHWidget(self.nwbfile.units)
assert isinstance(widget, widgets.Widget)
widget.psth_type_radio = "gaussian"
widget.trial_event_controller.value = ("start_time", "stop_time")
widget.unit_controller.value = 1
widget.gas.group_dd.value = "stim"
widget.gas.group_dd.value = None
def test_multipsth_widget(self):
psth_widget = PSTHWidget(self.nwbfile.units)
assert isinstance(psth_widget, widgets.Widget)
start_labels = ("start_time", "stop_time")
fig = psth_widget.update(index=0, start_labels=start_labels)
assert len(fig.axes) == 2 * len(start_labels)
def test_raster_widget(self):
assert isinstance(RasterWidget(self.nwbfile.units), widgets.Widget)
def test_show_session_raster(self):
assert isinstance(show_session_raster(self.nwbfile.units), plt.Axes)
def test_raster_grid_widget(self):
assert isinstance(RasterGridWidget(self.nwbfile.units), widgets.Widget)
def test_raster_grid(self):
trials = self.nwbfile.units.get_ancestor("NWBFile").trials
assert isinstance(
raster_grid(
self.nwbfile.units,
time_intervals=trials,
index=0,
start=-0.5,
end=20.0,
),
plt.Figure,
)
def test_render_dataframe(self):
render_dataframe(self.nwbfile.units)
class ShowDecompositionTestCase(unittest.TestCase):
def setUp(self):
data = np.random.rand(160, 2, 3)
self.ds = DecompositionSeries(name="Test Decomposition", data=data, metric="amplitude", rate=1.0)
def test_show_decomposition_traces(self):
assert isinstance(show_decomposition_traces(self.ds), widgets.Widget)
def test_show_decomposition_series(self):
assert isinstance(show_decomposition_series(self.ds), widgets.Widget)