-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_tools_spikeinterface.py
More file actions
2428 lines (1954 loc) · 114 KB
/
test_tools_spikeinterface.py
File metadata and controls
2428 lines (1954 loc) · 114 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import unittest
from datetime import datetime
from pathlib import Path
from shutil import rmtree
from tempfile import mkdtemp
from unittest.mock import Mock
import numpy as np
import psutil
import pynwb.ecephys
import pytest
from hdmf.testing import TestCase
from pynwb import NWBFile
from pynwb.testing.mock.file import mock_NWBFile
from spikeinterface.core.generate import (
generate_ground_truth_recording,
generate_recording,
generate_sorting,
)
from spikeinterface.extractors import NumpyRecording
from neuroconv.tools.nwb_helpers import get_module
from neuroconv.tools.spikeinterface import (
_add_electrode_groups_to_nwbfile,
_check_if_recording_traces_fit_into_memory,
_stub_recording,
add_electrodes_to_nwbfile,
add_recording_as_spatial_series_to_nwbfile,
add_recording_as_time_series_to_nwbfile,
add_recording_to_nwbfile,
add_sorting_to_nwbfile,
write_recording_to_nwbfile,
write_sorting_analyzer_to_nwbfile,
)
from neuroconv.tools.spikeinterface.spikeinterfacerecordingdatachunkiterator import (
SpikeInterfaceRecordingDataChunkIterator,
)
testing_session_time = datetime.now().astimezone()
class TestAddElectricalSeriesWriting(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Use common recording objects and values."""
cls.num_channels = 3
cls.sampling_frequency = 1.0
cls.durations = [3.0] # 3 samples in the recorder
cls.test_recording_extractor = generate_recording(
sampling_frequency=cls.sampling_frequency, num_channels=cls.num_channels, durations=cls.durations
)
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
def test_default_values(self):
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
assert "ElectricalSeriesRaw" in acquisition_module
electrical_series = acquisition_module["ElectricalSeriesRaw"]
extracted_data = electrical_series.data[:]
expected_data = self.test_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_write_as_lfp(self):
write_as = "lfp"
add_recording_to_nwbfile(
recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None, write_as=write_as
)
processing_module = self.nwbfile.processing
assert "ecephys" in processing_module
ecephys_module = processing_module["ecephys"]
assert "LFP" in ecephys_module.data_interfaces
lfp_container = ecephys_module.data_interfaces["LFP"]
assert isinstance(lfp_container, pynwb.ecephys.LFP)
assert "ElectricalSeriesLFP" in lfp_container.electrical_series
electrical_series = lfp_container.electrical_series["ElectricalSeriesLFP"]
extracted_data = electrical_series.data[:]
expected_data = self.test_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_write_as_processing(self):
write_as = "processed"
add_recording_to_nwbfile(
recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None, write_as=write_as
)
processing_module = self.nwbfile.processing
assert "ecephys" in processing_module
ecephys_module = processing_module["ecephys"]
assert "Processed" in ecephys_module.data_interfaces
filtered_ephys_container = ecephys_module.data_interfaces["Processed"]
assert isinstance(filtered_ephys_container, pynwb.ecephys.FilteredEphys)
assert "ElectricalSeriesProcessed" in filtered_ephys_container.electrical_series
electrical_series = filtered_ephys_container.electrical_series["ElectricalSeriesProcessed"]
extracted_data = electrical_series.data[:]
expected_data = self.test_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_write_multiple_electrical_series_from_same_electrode_group(self):
metadata = dict(
Ecephys=dict(
ElectricalSeriesRaw=dict(name="ElectricalSeriesRaw", description="raw series"),
ElectricalSeriesLFP=dict(name="ElectricalSeriesLFP", description="lfp series"),
)
)
add_recording_to_nwbfile(
recording=self.test_recording_extractor,
nwbfile=self.nwbfile,
metadata=metadata,
es_key="ElectricalSeriesRaw",
iterator_type=None,
)
self.assertEqual(len(self.nwbfile.electrodes), len(self.test_recording_extractor.channel_ids))
self.assertIn("ElectricalSeriesRaw", self.nwbfile.acquisition)
add_recording_to_nwbfile(
recording=self.test_recording_extractor,
nwbfile=self.nwbfile,
metadata=metadata,
es_key="ElectricalSeriesLFP",
iterator_type=None,
)
self.assertIn("ElectricalSeriesRaw", self.nwbfile.acquisition)
self.assertIn("ElectricalSeriesLFP", self.nwbfile.acquisition)
self.assertEqual(len(self.nwbfile.electrodes), len(self.test_recording_extractor.channel_ids))
def test_write_multiple_electrical_series_with_different_electrode_groups(self):
metadata = dict(
Ecephys=dict(
ElectricalSeriesRaw1=dict(name="ElectricalSeriesRaw1", description="raw series"),
ElectricalSeriesRaw2=dict(name="ElectricalSeriesRaw2", description="lfp series"),
)
)
original_groups = self.test_recording_extractor.get_channel_groups()
self.test_recording_extractor.set_channel_groups(["group0"] * len(self.test_recording_extractor.channel_ids))
add_recording_to_nwbfile(
recording=self.test_recording_extractor,
nwbfile=self.nwbfile,
metadata=metadata,
es_key="ElectricalSeriesRaw1",
iterator_type=None,
)
self.assertEqual(len(self.nwbfile.electrodes), len(self.test_recording_extractor.channel_ids))
self.assertIn("ElectricalSeriesRaw1", self.nwbfile.acquisition)
# check channel names and group names
electrodes = self.nwbfile.acquisition["ElectricalSeriesRaw1"].electrodes[:]
np.testing.assert_equal(electrodes["channel_name"], self.test_recording_extractor.channel_ids.astype("str"))
np.testing.assert_equal(
electrodes["group_name"], self.test_recording_extractor.get_channel_groups().astype("str")
)
# set new channel groups to create a new electrode_group
self.test_recording_extractor.set_channel_groups(["group1"] * len(self.test_recording_extractor.channel_ids))
add_recording_to_nwbfile(
recording=self.test_recording_extractor,
nwbfile=self.nwbfile,
metadata=metadata,
es_key="ElectricalSeriesRaw2",
iterator_type=None,
)
self.assertIn("ElectricalSeriesRaw1", self.nwbfile.acquisition)
self.assertIn("ElectricalSeriesRaw2", self.nwbfile.acquisition)
self.assertEqual(len(self.nwbfile.electrodes), 2 * len(self.test_recording_extractor.channel_ids))
# check channel names and group names
electrodes = self.nwbfile.acquisition["ElectricalSeriesRaw2"].electrodes[:]
np.testing.assert_equal(electrodes["channel_name"], self.test_recording_extractor.channel_ids.astype("str"))
np.testing.assert_equal(
electrodes["group_name"], self.test_recording_extractor.get_channel_groups().astype("str")
)
self.test_recording_extractor.set_channel_groups(original_groups)
def test_invalid_write_as_argument_assertion(self):
write_as = "any_other_string_that_is_not_raw_lfp_or_processed"
reg_expression = f"'write_as' should be 'raw', 'processed' or 'lfp', but instead received value {write_as}"
with self.assertRaisesRegex(AssertionError, reg_expression):
add_recording_to_nwbfile(
recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None, write_as=write_as
)
class TestAddElectricalSeriesSavingTimestampsVsRates(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Use common recording objects and values."""
cls.num_channels = 3
cls.sampling_frequency = 1.0
cls.durations = [3.0] # 3 samples in the recorder
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
self.test_recording_extractor = generate_recording(
sampling_frequency=self.sampling_frequency, num_channels=self.num_channels, durations=self.durations
)
def test_uniform_timestamps(self):
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
expected_rate = self.sampling_frequency
extracted_rate = electrical_series.rate
assert extracted_rate == expected_rate
def test_non_uniform_timestamps(self):
expected_timestamps = np.array([0.0, 2.0, 10.0])
self.test_recording_extractor.set_times(times=expected_timestamps, with_warning=False)
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
assert electrical_series.rate is None
extracted_timestamps = electrical_series.timestamps.data
np.testing.assert_array_almost_equal(extracted_timestamps, expected_timestamps)
class TestAddElectricalSeriesVoltsScaling(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Use common recording objects and values."""
cls.sampling_frequency = 1.0
cls.num_channels = 3
cls.num_frames = 5
cls.channel_ids = ["a", "b", "c"]
cls.traces_list = [np.ones(shape=(cls.num_frames, cls.num_channels))]
# Combinations of gains and default
cls.gains_default = [1, 1, 1]
cls.offset_defaults = [0, 0, 0]
cls.gains_uniform = [2, 2, 2]
cls.offsets_uniform = [3, 3, 3]
cls.gains_variable = [1, 2, 3]
cls.offsets_variable = [1, 2, 3]
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
# Flat traces [1, 1, 1] per channel
self.test_recording_extractor = NumpyRecording(
self.traces_list, self.sampling_frequency, channel_ids=self.channel_ids
)
def test_uniform_values(self):
gains = self.gains_default
offsets = self.offset_defaults
self.test_recording_extractor.set_channel_gains(gains=gains)
self.test_recording_extractor.set_channel_offsets(offsets=offsets)
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
# Test conversion factor
conversion_factor_scalar = electrical_series.conversion
assert conversion_factor_scalar == 1e-6
# Test offset scalar
offset_scalar = electrical_series.offset
assert offset_scalar == offsets[0] * 1e-6
# Test equality of data in Volts. Data in spikeextractors is in microvolts when scaled
extracted_data = electrical_series.data[:]
data_in_volts = extracted_data * conversion_factor_scalar + offset_scalar
traces_data_in_volts = self.test_recording_extractor.get_traces(segment_index=0, return_in_uV=True) * 1e-6
np.testing.assert_array_almost_equal(data_in_volts, traces_data_in_volts)
def test_uniform_non_default(self):
gains = self.gains_uniform
offsets = self.offsets_uniform
self.test_recording_extractor.set_channel_gains(gains=gains)
self.test_recording_extractor.set_channel_offsets(offsets=offsets)
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
# Test conversion factor
conversion_factor_scalar = electrical_series.conversion
assert conversion_factor_scalar == 2e-6
# Test offset scalar
offset_scalar = electrical_series.offset
assert offset_scalar == offsets[0] * 1e-6
# Test equality of data in Volts. Data in spikeextractors is in microvolts when scaled
extracted_data = electrical_series.data[:]
data_in_volts = extracted_data * conversion_factor_scalar + offset_scalar
traces_data_in_volts = self.test_recording_extractor.get_traces(segment_index=0, return_in_uV=True) * 1e-6
np.testing.assert_array_almost_equal(data_in_volts, traces_data_in_volts)
def test_variable_gains(self):
gains = self.gains_variable
offsets = self.offsets_uniform
self.test_recording_extractor.set_channel_gains(gains=gains)
self.test_recording_extractor.set_channel_offsets(offsets=offsets)
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
# Test offset scalar
offset_scalar = electrical_series.offset
assert offset_scalar == offsets[0] * 1e-6
# Test channel conversion vector
channel_conversion_vector = electrical_series.channel_conversion
gains_to_V = np.array(gains) * 1e-6
np.testing.assert_array_almost_equal(channel_conversion_vector, gains_to_V)
# Test equality of data in Volts. Data in spikeextractors is in microvolts when scaled
extracted_data = electrical_series.data[:]
data_in_volts = extracted_data * channel_conversion_vector + offset_scalar
traces_data_in_volts = self.test_recording_extractor.get_traces(segment_index=0, return_scaled=True) * 1e-6
np.testing.assert_array_almost_equal(data_in_volts, traces_data_in_volts)
def test_variable_offsets_assertion(self):
gains = self.gains_default
offsets = self.offsets_variable
self.test_recording_extractor.set_channel_gains(gains=gains)
self.test_recording_extractor.set_channel_offsets(offsets=offsets)
reg_expression = "Recording extractors with heterogeneous offsets are not supported"
with self.assertRaisesRegex(ValueError, reg_expression):
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
def test_error_with_multiple_offset():
# Generate a mock recording with 5 channels and 1 second duration
recording = generate_recording(num_channels=5, durations=[1.0])
# Rename channels to specific identifiers for clarity in error messages
recording = recording.rename_channels(new_channel_ids=["a", "b", "c", "d", "e"])
# Set different offsets for the channels
recording.set_channel_gains(gains=[1, 1, 1, 1, 1])
recording.set_channel_offsets(offsets=[0, 0, 1, 1, 2])
# Create a mock NWBFile object
nwbfile = mock_NWBFile()
# Expected error message
expected_message_lines = [
"Recording extractors with heterogeneous offsets are not supported.",
"Multiple offsets were found per channel IDs:",
" Offset 0: Channel IDs ['a', 'b']",
" Offset 1: Channel IDs ['c', 'd']",
" Offset 2: Channel IDs ['e']",
]
expected_message = "\n".join(expected_message_lines)
# Use re.escape to escape any special regex characters in the expected message
expected_message_regex = re.escape(expected_message)
# Attempt to add electrical series to the NWB file
# Expecting a ValueError due to multiple offsets, matching the expected message
with pytest.raises(ValueError, match=expected_message_regex):
add_recording_to_nwbfile(recording=recording, nwbfile=nwbfile)
class TestAddElectricalSeriesChunking(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Use common recording objects and values."""
cls.sampling_frequency = 1.0
cls.num_channels = 3
cls.num_frames = 20
cls.channel_ids = ["a", "b", "c"]
cls.traces_list = [np.ones(shape=(cls.num_frames, cls.num_channels))]
# Flat traces [1, 1, 1] per channel
cls.test_recording_extractor = NumpyRecording(
cls.traces_list, cls.sampling_frequency, channel_ids=cls.channel_ids
)
# Combinations of gains and default
cls.gains_default = [2, 2, 2]
cls.offset_default = [1, 1, 1]
cls.test_recording_extractor.set_channel_gains(gains=cls.gains_default)
cls.test_recording_extractor.set_channel_offsets(offsets=cls.offset_default)
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
def test_default_iterative_writer(self):
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
electrical_series_data_iterator = electrical_series.data
assert isinstance(electrical_series_data_iterator, SpikeInterfaceRecordingDataChunkIterator)
extracted_data = np.concatenate([data_chunk.data for data_chunk in electrical_series_data_iterator])
expected_data = self.test_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_iterator_opts_propagation(self):
iterator_opts = dict(chunk_shape=(10, 3))
add_recording_to_nwbfile(
recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_opts=iterator_opts
)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
electrical_series_data_iterator = electrical_series.data
assert electrical_series_data_iterator.chunk_shape == iterator_opts["chunk_shape"]
def test_non_iterative_write(self):
add_recording_to_nwbfile(recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=None)
acquisition_module = self.nwbfile.acquisition
electrical_series = acquisition_module["ElectricalSeriesRaw"]
isinstance(electrical_series.data, np.ndarray)
def test_non_iterative_write_assertion(self):
# Estimate num of frames required to exceed memory capabilities
dtype = self.test_recording_extractor.get_dtype()
element_size_in_bytes = dtype.itemsize
num_channels = self.test_recording_extractor.get_num_channels()
available_memory_in_bytes = psutil.virtual_memory().available
excess = 1.5 # Of what is available in memory
num_frames_to_overflow = (available_memory_in_bytes * excess) / (element_size_in_bytes * num_channels)
# Mock recording extractor with as many frames as necessary to overflow memory
mock_recorder = Mock()
mock_recorder.get_dtype.return_value = dtype
mock_recorder.get_num_channels.return_value = num_channels
mock_recorder.get_num_samples.return_value = num_frames_to_overflow
reg_expression = "Memory error, full electrical series is (.*?) GiB are available. Use iterator_type='V2'"
with self.assertRaisesRegex(MemoryError, reg_expression):
_check_if_recording_traces_fit_into_memory(recording=mock_recorder)
def test_invalid_iterator_type_assertion(self):
iterator_type = "invalid_iterator_type"
reg_expression = "iterator_type (.*?)"
with self.assertRaisesRegex(ValueError, reg_expression):
add_recording_to_nwbfile(
recording=self.test_recording_extractor, nwbfile=self.nwbfile, iterator_type=iterator_type
)
class TestWriteRecording(unittest.TestCase):
@classmethod
def setUpClass(cls):
# 3 samples in each segment
cls.num_channels = 3
cls.sampling_frequency = 1.0
cls.single_segment_recording_extractor = generate_recording(
sampling_frequency=cls.sampling_frequency, num_channels=cls.num_channels, durations=[3.0]
)
cls.multiple_segment_recording_extractor = generate_recording(
sampling_frequency=cls.sampling_frequency, num_channels=cls.num_channels, durations=[3.0, 3.0]
)
# Add gains and offsets
cls.gains_default = [1, 1, 1]
cls.offset_default = [0, 0, 0]
cls.single_segment_recording_extractor.set_channel_gains(cls.gains_default)
cls.single_segment_recording_extractor.set_channel_offsets(cls.offset_default)
cls.multiple_segment_recording_extractor.set_channel_gains(cls.gains_default)
cls.multiple_segment_recording_extractor.set_channel_offsets(cls.offset_default)
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
def test_default_values_single_segment(self):
"""This test that the names are written appropriately for the single segment case (numbers not added)"""
write_recording_to_nwbfile(
recording=self.single_segment_recording_extractor, nwbfile=self.nwbfile, iterator_type=None
)
acquisition_module = self.nwbfile.acquisition
assert "ElectricalSeriesRaw" in acquisition_module
electrical_series = acquisition_module["ElectricalSeriesRaw"]
extracted_data = electrical_series.data[:]
expected_data = self.single_segment_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_write_multiple_segments(self):
write_recording_to_nwbfile(
recording=self.multiple_segment_recording_extractor, nwbfile=self.nwbfile, iterator_type=None
)
acquisition_module = self.nwbfile.acquisition
assert len(acquisition_module) == 2
assert "ElectricalSeriesRaw0" in acquisition_module
assert "ElectricalSeriesRaw1" in acquisition_module
electrical_series0 = acquisition_module["ElectricalSeriesRaw0"]
extracted_data = electrical_series0.data[:]
expected_data = self.multiple_segment_recording_extractor.get_traces(segment_index=0)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
electrical_series1 = acquisition_module["ElectricalSeriesRaw1"]
extracted_data = electrical_series1.data[:]
expected_data = self.multiple_segment_recording_extractor.get_traces(segment_index=1)
np.testing.assert_array_almost_equal(expected_data, extracted_data)
def test_write_bool_properties(self):
""" """
bool_property = np.array([False] * len(self.single_segment_recording_extractor.channel_ids))
bool_property[::2] = True
self.single_segment_recording_extractor.set_property("test_bool", bool_property)
add_electrodes_to_nwbfile(
recording=self.single_segment_recording_extractor,
nwbfile=self.nwbfile,
)
self.assertIn("test_bool", self.nwbfile.electrodes.colnames)
assert all(tb in [False, True] for tb in self.nwbfile.electrodes["test_bool"][:])
class TestAddElectrodes(TestCase):
@classmethod
def setUpClass(cls):
"""Use common recording objects and values."""
cls.num_channels = 4
cls.base_recording = generate_recording(num_channels=cls.num_channels, durations=[3], set_probe=False)
# Set group property to match the electrode group that will be created in setUp
cls.base_recording.set_channel_groups([0] * cls.num_channels)
def setUp(self):
"""Start with a fresh NWBFile, ElectrodeTable, and remapped BaseRecordings each time."""
self.nwbfile = NWBFile(
session_description="session_description1", identifier="file_id1", session_start_time=testing_session_time
)
self.recording_1 = self.base_recording.rename_channels(new_channel_ids=["a", "b", "c", "d"])
self.recording_2 = self.base_recording.rename_channels(new_channel_ids=["c", "d", "e", "f"])
self.device = self.nwbfile.create_device(name="extra_device")
self.electrode_group = self.nwbfile.create_electrode_group(
name="0", description="description", location="location", device=self.device
)
self.common_electrode_row_kwargs = dict(
group=self.electrode_group,
group_name="0",
location="unknown",
)
def test_default_electrode_column_names(self):
add_electrodes_to_nwbfile(recording=self.base_recording, nwbfile=self.nwbfile)
expected_electrode_column_names = ["location", "group", "group_name", "channel_name"]
actual_electrode_column_names = list(self.nwbfile.electrodes.colnames)
self.assertCountEqual(actual_electrode_column_names, expected_electrode_column_names)
def test_physical_unit_properties_excluded(self):
"""Test that SpikeInterface physical unit properties are excluded from electrodes table."""
# Set the properties that should be excluded
num_channels = len(self.base_recording.channel_ids)
self.base_recording.set_property(key="gain_to_physical_unit", values=[1.0] * num_channels)
self.base_recording.set_property(key="offset_to_physical_unit", values=[0.0] * num_channels)
self.base_recording.set_property(key="physical_unit", values=["uV"] * num_channels)
add_electrodes_to_nwbfile(recording=self.base_recording, nwbfile=self.nwbfile)
# Verify that these properties are NOT in the electrodes table
actual_electrode_column_names = list(self.nwbfile.electrodes.colnames)
excluded_properties = ["gain_to_physical_unit", "offset_to_physical_unit", "physical_unit"]
for prop in excluded_properties:
self.assertNotIn(
prop, actual_electrode_column_names, f"Property '{prop}' should be excluded from electrodes table"
)
def test_integer_channel_names(self):
"""Ensure channel names merge correctly after appending when channel names are integers."""
channel_ids = self.base_recording.get_channel_ids()
channel_ids_with_offset = [int(channel_id) + 2 for channel_id in channel_ids]
recorder_with_offset_channels = self.base_recording.rename_channels(new_channel_ids=channel_ids_with_offset)
add_electrodes_to_nwbfile(recording=self.base_recording, nwbfile=self.nwbfile)
add_electrodes_to_nwbfile(recording=recorder_with_offset_channels, nwbfile=self.nwbfile)
expected_channel_names_in_electrodes_table = ["0", "1", "2", "3", "4", "5"]
actual_channel_names_in_electrodes_table = list(self.nwbfile.electrodes["channel_name"].data)
self.assertListEqual(actual_channel_names_in_electrodes_table, expected_channel_names_in_electrodes_table)
def test_string_channel_names(self):
"""Ensure channel names merge correctly after appending when channel names are strings."""
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
expected_channel_names_in_electrodes_table = ["a", "b", "c", "d", "e", "f"]
actual_channel_names_in_electrodes_table = list(self.nwbfile.electrodes["channel_name"].data)
self.assertListEqual(actual_channel_names_in_electrodes_table, expected_channel_names_in_electrodes_table)
def test_non_overwriting_channel_names_property(self):
"add_electrodes_to_nwbfile function should not overwrite the recording object channel name property"
channel_names = ["name a", "name b", "name c", "name d"]
self.recording_1.set_property(key="channel_name", values=channel_names)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
expected_channel_names_in_electrodes_table = channel_names
channel_names_in_electrodes_table = list(self.nwbfile.electrodes["channel_name"].data)
self.assertListEqual(channel_names_in_electrodes_table, expected_channel_names_in_electrodes_table)
def test_channel_group_names_table(self):
"add_electrodes_to_nwbfile function should add new rows if same channel names, but different group_names"
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
original_groups = self.recording_1.get_channel_groups()
self.recording_1.set_channel_groups(["1"] * len(self.recording_1.channel_ids))
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
# reset channel_groups
self.recording_1.set_channel_groups(original_groups)
assert len(self.nwbfile.electrodes) == 2 * len(self.recording_1.channel_ids)
expected_channel_names_in_electrodes_table = list(self.recording_1.channel_ids) + list(
self.recording_1.channel_ids
)
channel_names_in_electrodes_table = list(self.nwbfile.electrodes["channel_name"].data)
self.assertListEqual(channel_names_in_electrodes_table, expected_channel_names_in_electrodes_table)
group_names_in_electrodes_table = list(self.nwbfile.electrodes["group_name"].data)
self.assertEqual(len(np.unique(group_names_in_electrodes_table)), 2)
def test_common_property_extension(self):
"""Add a property for a first recording that is then extended by a second recording."""
self.recording_1.set_property(key="common_property", values=["value_1"] * self.num_channels)
self.recording_2.set_property(key="common_property", values=["value_2"] * self.num_channels)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
actual_properties_in_electrodes_table = list(self.nwbfile.electrodes["common_property"].data)
expected_properties_in_electrodes_table = ["value_1", "value_1", "value_1", "value_1", "value_2", "value_2"]
self.assertListEqual(actual_properties_in_electrodes_table, expected_properties_in_electrodes_table)
def test_add_electrodes_addition_to_nwbfile(self):
"""
Keep the old logic of not allowing integer channel_ids to match electrodes.table.ids
"""
self.nwbfile.add_electrode_column("channel_name", description="channel_name")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=0, channel_name="0")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=1, channel_name="1")
# The self.base_recording channel_ids are [0, 1, 2, 3], so only '3' and '4' should be added
add_electrodes_to_nwbfile(recording=self.base_recording, nwbfile=self.nwbfile)
self.assertEqual(len(self.nwbfile.electrodes), len(self.base_recording.channel_ids))
def test_new_property_addition(self):
"""Add a property only available in a second recording."""
self.recording_2.set_property(key="added_property", values=["added_value"] * self.num_channels)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
actual_properties_in_electrodes_table = list(self.nwbfile.electrodes["added_property"].data)
expected_properties_in_electrodes_table = ["", "", "added_value", "added_value", "added_value", "added_value"]
self.assertListEqual(actual_properties_in_electrodes_table, expected_properties_in_electrodes_table)
def test_manual_row_adition_before_add_electrodes_function_to_nwbfile(self):
"""Add some rows to the electrode tables before using the add_electrodes_to_nwbfile function"""
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=123)
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=124)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
expected_ids = [123, 124, 2, 3, 4, 5]
expected_names = ["123", "124", "a", "b", "c", "d"]
self.assertListEqual(list(self.nwbfile.electrodes.id.data), expected_ids)
self.assertListEqual(list(self.nwbfile.electrodes["channel_name"].data), expected_names)
def test_manual_row_adition_after_add_electrodes_function_to_nwbfile(self):
"""Add some rows to the electrode table after using the add_electrodes_to_nwbfile function"""
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
# Since we're not using a probe, rel_x and rel_y columns won't exist
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=123, channel_name="123")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=124, channel_name="124")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=None, channel_name="6") # automatic ID set
expected_ids = [0, 1, 2, 3, 123, 124, 6]
expected_names = ["a", "b", "c", "d", "123", "124", "6"]
self.assertListEqual(list(self.nwbfile.electrodes.id.data), expected_ids)
self.assertListEqual(list(self.nwbfile.electrodes["channel_name"].data), expected_names)
def test_manual_row_adition_before_add_electrodes_function_optional_columns_to_nwbfile(self):
"""Add some rows including optional columns to the electrode tables before using the add_electrodes_to_nwbfile function."""
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=123, x=0.0, y=1.0, z=2.0)
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=124, x=1.0, y=2.0, z=3.0)
# recording_1 does not have x, y, z positions
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
expected_ids = [123, 124, 2, 3, 4, 5]
expected_x = [0, 1, np.nan, np.nan, np.nan, np.nan]
expected_y = [1, 2, np.nan, np.nan, np.nan, np.nan]
expected_z = [2, 3, np.nan, np.nan, np.nan, np.nan]
self.assertListEqual(list(self.nwbfile.electrodes.id.data), expected_ids)
self.assertListEqual(list(self.nwbfile.electrodes["x"].data), expected_x)
self.assertListEqual(list(self.nwbfile.electrodes["y"].data), expected_y)
self.assertListEqual(list(self.nwbfile.electrodes["z"].data), expected_z)
def test_no_new_electrodes_with_custom_property_without_default(self):
"""
Test that add_electrodes_to_nwbfile doesn't fail when:
- Electrode table has a custom property without a sensible default
- All channels from the recording already exist in the table
- No null values should be computed since no new rows are added
This is a regression test for https://github.com/catalystneuro/neuroconv/issues/1629
"""
# Add channel_name column and an integer property
# We use an integer property because integers do not have a clear default value,
# so if we were adding new rows, we would need to specify a null value for this property
self.nwbfile.add_electrode_column("channel_name", description="channel name")
self.nwbfile.add_electrode_column("custom_int_property", description="integer property without default")
# Add all electrodes from recording_1
for i, channel_id in enumerate(self.recording_1.channel_ids):
self.nwbfile.add_electrode(
**self.common_electrode_row_kwargs, id=i, channel_name=channel_id, custom_int_property=i * 10
)
# This should not raise an error even though custom_int_property has no clear default
# because no new rows need to be added
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
# Verify no additional electrodes were added
self.assertEqual(len(self.nwbfile.electrodes), len(self.recording_1.channel_ids))
def test_row_matching_by_channel_name_with_existing_property(self):
"""
Adding new electrodes to an already existing electrode table should match
properties and information by channel name.
"""
self.nwbfile.add_electrode_column(name="channel_name", description="a string reference for the channel")
self.nwbfile.add_electrode_column(name="property", description="existing property")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=20, channel_name="c", property="value_c")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=21, channel_name="d", property="value_d")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=22, channel_name="f", property="value_f")
property_values = ["value_a", "value_b", "x", "y"]
self.recording_1.set_property(key="property", values=property_values)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
# Remaining ids are filled positionally.
expected_ids = [20, 21, 22, 3, 4]
# Properties are matched by channel name.
expected_names = ["c", "d", "f", "a", "b"]
expected_property_values = ["value_c", "value_d", "value_f", "value_a", "value_b"]
self.assertListEqual(list(self.nwbfile.electrodes.id.data), expected_ids)
self.assertListEqual(list(self.nwbfile.electrodes["channel_name"].data), expected_names)
self.assertListEqual(list(self.nwbfile.electrodes["property"].data), expected_property_values)
def test_adding_new_property_with_identifical_channels_but_different_groups(self):
recording1 = generate_recording(num_channels=3)
recording1 = recording1.rename_channels(new_channel_ids=["a", "b", "c"])
recording1.set_property(key="group_name", values=["group1"] * 3)
recording2 = generate_recording(num_channels=3)
recording2 = recording2.rename_channels(new_channel_ids=["a", "b", "c"])
recording2.set_property(key="group_name", values=["group2"] * 3)
recording2.set_property(key="added_property", values=["value"] * 3)
add_electrodes_to_nwbfile(recording=recording1, nwbfile=self.nwbfile)
add_electrodes_to_nwbfile(recording=recording2, nwbfile=self.nwbfile)
expected_property = ["", "", "", "value", "value", "value"]
property = self.nwbfile.electrodes["added_property"].data
assert np.array_equal(property, expected_property)
def test_row_matching_by_channel_name_with_new_property(self):
"""
Adding new electrodes to an already existing electrode table should match
properties and information by channel name.
"""
self.nwbfile.add_electrode_column(name="channel_name", description="a string reference for the channel")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=20, channel_name="c")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=21, channel_name="d")
self.nwbfile.add_electrode(**self.common_electrode_row_kwargs, id=22, channel_name="f")
property_values = ["value_a", "value_b", "value_c", "value_d"]
self.recording_1.set_property(key="property", values=property_values)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
# Remaining ids are filled positionally.
expected_ids = [20, 21, 22, 3, 4]
# Properties are matched by channel name.
expected_names = ["c", "d", "f", "a", "b"]
expected_property_values = ["value_c", "value_d", "", "value_a", "value_b"]
self.assertListEqual(list(self.nwbfile.electrodes.id.data), expected_ids)
self.assertListEqual(list(self.nwbfile.electrodes["channel_name"].data), expected_names)
self.assertListEqual(list(self.nwbfile.electrodes["property"].data), expected_property_values)
def test_adding_ragged_array_properties(self):
ragged_array_values1 = [[1, 2], [3, 4], [5, 6], [7, 8]]
self.recording_1.set_property(key="ragged_property", values=ragged_array_values1)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
written_values = self.nwbfile.electrodes.to_dataframe()["ragged_property"].to_list()
np.testing.assert_array_equal(written_values, ragged_array_values1)
# Add a new recording that contains more properties for the ragged array
ragged_array_values2 = [[5, 6], [7, 8], [9, 10], [11, 12]]
self.recording_2.set_property(key="ragged_property", values=ragged_array_values2)
second_ragged_array_values = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"], ["j", "k", "l"]]
self.recording_2.set_property(key="ragged_property2", values=second_ragged_array_values)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
written_values = self.nwbfile.electrodes.to_dataframe()["ragged_property"].to_list()
expected_values = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]
np.testing.assert_array_equal(written_values, expected_values)
written_values = self.nwbfile.electrodes.to_dataframe()["ragged_property2"].to_list()
values_appended_to_table = [[], []]
expected_values = values_appended_to_table + second_ragged_array_values
# We need a for loop because this is a non-homogenous ragged array
for i, value in enumerate(written_values):
np.testing.assert_array_equal(value, expected_values[i])
def test_adding_doubled_ragged_arrays(self):
# Simple test for a double ragged array
doubled_nested_array1 = [
[[1, 2], [3, 4]],
[[5, 6], [7, 8]],
[[9, 10], [11, 12]],
[[13, 14], [15, 16]],
]
self.recording_1.set_property(key="double_ragged_property", values=doubled_nested_array1)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile)
written_values = self.nwbfile.electrodes.to_dataframe()["double_ragged_property"].to_list()
np.testing.assert_array_equal(written_values, doubled_nested_array1)
# Add a new recording that contains a continuation of the previous double ragged array
# There is overlapping in the channel names
doubled_nested_array2 = [
[[9, 10], [11, 12]],
[[13, 14], [15, 16]],
[[17, 18], [19, 20]],
[[21, 22], [23, 24]],
]
self.recording_2.set_property(key="double_ragged_property", values=doubled_nested_array2)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
written_values = self.nwbfile.electrodes.to_dataframe()["double_ragged_property"].to_list()
# Note this adds a combination of both arrays
expected_values = [
[[1, 2], [3, 4]],
[[5, 6], [7, 8]],
[[9, 10], [11, 12]],
[[13, 14], [15, 16]],
[[17, 18], [19, 20]],
[[21, 22], [23, 24]],
]
np.testing.assert_array_equal(written_values, expected_values)
second_doubled_nested_array = [
[["a", "b", "c"], ["d", "e", "f"]],
[["g", "h", "i"], ["j", "k", "l"]],
[["m", "n", "o"], ["p", "q", "r"]],
[["s", "t", "u"], ["v", "w", "x"]],
]
# We add another property to recording 2 which is not in recording 1
self.recording_2.set_property(key="double_ragged_property2", values=second_doubled_nested_array)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile)
written_values = self.nwbfile.electrodes.to_dataframe()["double_ragged_property2"].to_list()
values_appended_to_table = [
[],
[],
]
expected_values = values_appended_to_table + second_doubled_nested_array
# We need a for loop because this is a non-homogenous ragged array
for i, value in enumerate(written_values):
np.testing.assert_array_equal(value, expected_values[i])
def test_property_metadata_mismatch(self):
"""
Adding recordings that do not contain all properties described in
metadata should not error.
"""
self.recording_1.set_property(key="common_property", values=["value_1"] * self.num_channels)
self.recording_2.set_property(key="common_property", values=["value_2"] * self.num_channels)
self.recording_1.set_property(key="property_1", values=[f"value_{n+1}" for n in range(self.num_channels)])
self.recording_2.set_property(key="property_2", values=[f"value_{n+1}" for n in range(self.num_channels)])
metadata = dict(
Ecephys=dict(
Electrodes=[
dict(name="common_property", description="no description."),
dict(name="property_1", description="no description."),
dict(name="property_2", description="no description."),
]
)
)
add_electrodes_to_nwbfile(recording=self.recording_1, nwbfile=self.nwbfile, metadata=metadata)
add_electrodes_to_nwbfile(recording=self.recording_2, nwbfile=self.nwbfile, metadata=metadata)
actual_common_property_values = list(self.nwbfile.electrodes["common_property"].data)
expected_common_property_values = ["value_1", "value_1", "value_1", "value_1", "value_2", "value_2"]
self.assertListEqual(actual_common_property_values, expected_common_property_values)
actual_property_1_values = list(self.nwbfile.electrodes["property_1"].data)
expected_property_1_values = ["value_1", "value_2", "value_3", "value_4", "", ""]
self.assertListEqual(actual_property_1_values, expected_property_1_values)
actual_property_2_values = list(self.nwbfile.electrodes["property_2"].data)
expected_property_2_values = ["", "", "value_1", "value_2", "value_3", "value_4"]
self.assertListEqual(actual_property_2_values, expected_property_2_values)
def test_missing_int_values(self):
recording1 = generate_recording(num_channels=2, durations=[1.0])
recording1 = recording1.rename_channels(new_channel_ids=["a", "b"])
recording1.set_property(key="complete_int_property", values=[1, 2])
add_electrodes_to_nwbfile(recording=recording1, nwbfile=self.nwbfile)
expected_property = np.asarray([1, 2])
extracted_property = self.nwbfile.electrodes["complete_int_property"].data
assert np.array_equal(extracted_property, expected_property)
recording2 = generate_recording(num_channels=2, durations=[1.0])
recording2 = recording2.rename_channels(new_channel_ids=["c", "d"])
recording2.set_property(key="incomplete_int_property", values=[10, 11])
with self.assertRaises(ValueError):
add_electrodes_to_nwbfile(recording=recording2, nwbfile=self.nwbfile)
null_values_for_properties = {"complete_int_property": -1, "incomplete_int_property": -3}
add_electrodes_to_nwbfile(
recording=recording2, nwbfile=self.nwbfile, null_values_for_properties=null_values_for_properties
)
expected_complete_property = np.asarray([1, 2, -1, -1])
expected_incomplete_property = np.asarray([-3, -3, 10, 11])
extracted_complete_property = self.nwbfile.electrodes["complete_int_property"].data
extracted_incomplete_property = self.nwbfile.electrodes["incomplete_int_property"].data
assert np.array_equal(extracted_complete_property, expected_complete_property)
assert np.array_equal(extracted_incomplete_property, expected_incomplete_property)
def test_missing_bool_values(self):
recording1 = generate_recording(num_channels=2)
recording1 = recording1.rename_channels(new_channel_ids=["a", "b"])
recording1.set_property(key="complete_bool_property", values=[True, False])
add_electrodes_to_nwbfile(recording=recording1, nwbfile=self.nwbfile)