Skip to content

Commit 17138dd

Browse files
committed
add test
1 parent b507562 commit 17138dd

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

neo/test/iotest/test_intanio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TestIntanIO(
2323
"intan/intan_fpc_rhs_test_240329_091637/info.rhs", # Format one-file-per-channel
2424
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
2525
"intan/rhd_fpc_multistim_240514_082044/info.rhd", # Multiple digital channels one-file-per-channel rhd
26+
"intan/rhs_stim_data_single_file_format/intanTestFile.rhs", # header-attached rhs data with stimulus current
2627
]
2728

2829

neo/test/rawiotest/test_intanrawio.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TestIntanRawIO(
2121
"intan/intan_fpc_rhs_test_240329_091637/info.rhs", # Format one-file-per-channel
2222
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
2323
"intan/rhd_fpc_multistim_240514_082044/info.rhd", # Multiple digital channels one-file-per-channel rhd
24+
"intan/rhs_stim_data_single_file_format/intanTestFile.rhs", # header-attached rhs data with stimulus current
2425
]
2526

2627
def test_annotations(self):
@@ -87,5 +88,54 @@ def test_correct_reading_one_file_per_channel(self):
8788
np.testing.assert_allclose(data_raw, data_from_neo)
8889

8990

91+
def test_correct_decoding_of_stimulus_current(self):
92+
93+
file_path = Path(self.get_local_path("intan/rhs_stim_data_single_file_format/intanTestFile.rhs"))
94+
intan_reader = IntanRawIO(filename=file_path)
95+
intan_reader.parse_header()
96+
97+
signal_streams = intan_reader.header['signal_streams']
98+
stream_ids = signal_streams['id'].tolist()
99+
stream_index = stream_ids.index('11')
100+
sampling_rate = intan_reader.get_signal_sampling_rate(stream_index=stream_index)
101+
sig_chunk = intan_reader.get_analogsignal_chunk(stream_index=stream_index, channel_ids=["D-016_STIM"])
102+
final_stim = intan_reader.rescale_signal_raw_to_float(sig_chunk, stream_index=stream_index, channel_ids=["D-016_STIM"])
103+
104+
# This contains only the first pulse and I got this by visual inspection
105+
data_to_test = final_stim[200:250]
106+
107+
positive_pulse_size = np.max(data_to_test).item()
108+
negative_pulse_size = np.min(data_to_test).item()
109+
110+
expected_value = 60 * 1e-6# 60 microamperes
111+
112+
# Assert is close float
113+
assert np.isclose(positive_pulse_size, expected_value)
114+
assert np.isclose(negative_pulse_size, -expected_value)
115+
116+
# Check that negative pulse is leading
117+
argmin = np.argmin(data_to_test)
118+
argmax = np.argmax(data_to_test)
119+
120+
assert argmin < argmax
121+
122+
123+
# Check that the negative pulse is 200 us long
124+
negative_pulse_frames = np.where(data_to_test > 0)[0]
125+
number_of_negative_frames = negative_pulse_frames.size
126+
duration_of_negative_pulse = number_of_negative_frames / sampling_rate
127+
128+
expected_duration = 200 * 1e-6 # 400 microseconds / 2
129+
130+
assert np.isclose(duration_of_negative_pulse, expected_duration, rtol=1e-05, atol=1e-08)
131+
132+
positive_pulse_frames = np.where(data_to_test > 0)[0]
133+
number_of_positive_frames = positive_pulse_frames.size
134+
duration_of_positive_pulse = number_of_positive_frames / sampling_rate
135+
expected_duration = 200 * 1e-6 # 400 microseconds / 2
136+
137+
assert np.isclose(duration_of_positive_pulse, expected_duration, rtol=1e-05, atol=1e-08)
138+
139+
90140
if __name__ == "__main__":
91141
unittest.main()

0 commit comments

Comments
 (0)