Skip to content

Commit 6803be8

Browse files
committed
fix intan dtype
1 parent f1cfcf7 commit 6803be8

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

neo/rawio/intanrawio.py

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _parse_header(self):
141141
(
142142
self._global_info,
143143
self._ordered_channel_info,
144-
data_dtype,
144+
memmap_data_dtype,
145145
header_size,
146146
self._block_size,
147147
channel_number_dict,
@@ -167,7 +167,7 @@ def _parse_header(self):
167167
(
168168
self._global_info,
169169
self._ordered_channel_info,
170-
data_dtype,
170+
memmap_data_dtype,
171171
header_size,
172172
self._block_size,
173173
channel_number_dict,
@@ -176,12 +176,12 @@ def _parse_header(self):
176176
# memmap the raw data for each format type
177177
# if header-attached there is one giant memory-map
178178
if self.file_format == "header-attached":
179-
self._raw_data = np.memmap(self.filename, dtype=data_dtype, mode="r", offset=header_size)
179+
self._raw_data = np.memmap(self.filename, dtype=memmap_data_dtype, mode="r", offset=header_size)
180180

181181
# for 'one-file-per-signal' we have one memory map / neo stream
182182
elif self.file_format == "one-file-per-signal":
183183
self._raw_data = {}
184-
for stream_index, (stream_index_key, stream_datatype) in enumerate(data_dtype.items()):
184+
for stream_index, (stream_index_key, stream_datatype) in enumerate(memmap_data_dtype.items()):
185185
num_channels = channel_number_dict[stream_index_key]
186186
file_path = raw_file_paths_dict[stream_index_key]
187187
size_in_bytes = file_path.stat().st_size
@@ -195,7 +195,7 @@ def _parse_header(self):
195195
# for one-file-per-channel we have one memory map / channel stored as a list / neo stream
196196
elif self.file_format == "one-file-per-channel":
197197
self._raw_data = {}
198-
for stream_index, (stream_index_key, stream_datatype) in enumerate(data_dtype.items()):
198+
for stream_index, (stream_index_key, stream_datatype) in enumerate(memmap_data_dtype.items()):
199199
self._raw_data[stream_index] = []
200200
num_channels = channel_number_dict[stream_index_key]
201201
for channel_index in range(num_channels):
@@ -487,7 +487,8 @@ def _get_analogsignal_chunk_one_file_per_signal(self, i_start, i_stop, stream_in
487487

488488
def _demultiplex_digital_data(self, raw_digital_data, channel_ids, i_start, i_stop):
489489

490-
output = np.zeros((i_stop - i_start, len(channel_ids)), dtype=np.uint8)
490+
dtype = np.uint16 # We fix this to match the memmap dtype
491+
output = np.zeros((i_stop - i_start, len(channel_ids)), dtype=dtype)
491492

492493
for channel_index, channel_id in enumerate(channel_ids):
493494
native_order = self.native_channel_order[channel_id]
@@ -698,9 +699,9 @@ def read_rhs(filename, file_format: str):
698699
# force them to be the last stream_id.
699700
stream_id_to_channel_info_list = {k: [] for k in [0, 3, 4, 5, 6]}
700701
if not file_format == "header-attached":
701-
# data_dtype for rhs is complicated. There is not 1, 2 (supply and aux),
702+
# memmap_data_dtype for rhs is complicated. There is not 1, 2 (supply and aux),
702703
# but there are dc-amp (10) and stim (11). we make timestamps (15)
703-
data_dtype = {k: [] for k in [0, 3, 4, 5, 6, 10, 11, 15]}
704+
memmap_data_dtype = {k: [] for k in [0, 3, 4, 5, 6, 10, 11, 15]}
704705
for g in range(global_info["nb_signal_group"]):
705706
group_info = read_variable_header(f, rhs_signal_group_header)
706707

@@ -726,9 +727,9 @@ def read_rhs(filename, file_format: str):
726727
# construct dtype by re-ordering channels by types
727728
ordered_channel_info = []
728729
if file_format == "header-attached":
729-
data_dtype = [("timestamp", "int32", BLOCK_SIZE)]
730+
memmap_data_dtype = [("timestamp", "int32", BLOCK_SIZE)]
730731
else:
731-
data_dtype[15] = "int32"
732+
memmap_data_dtype[15] = "int32"
732733
channel_number_dict[15] = 1
733734

734735
# 0: RHS2000 amplifier channel.
@@ -747,9 +748,9 @@ def read_rhs(filename, file_format: str):
747748
ordered_channel_info.append(chan_info)
748749
if file_format == "header-attached":
749750
name = chan_info["native_channel_name"]
750-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
751+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
751752
else:
752-
data_dtype[0] = "int16"
753+
memmap_data_dtype[0] = "int16"
753754

754755
if bool(global_info["dc_amplifier_data_saved"]):
755756
# if we have dc amp we need to grab the correct number of channels
@@ -767,9 +768,9 @@ def read_rhs(filename, file_format: str):
767768
chan_info_dc["dtype"] = "uint16"
768769
ordered_channel_info.append(chan_info_dc)
769770
if file_format == "header-attached":
770-
data_dtype += [(name + "_DC", "uint16", BLOCK_SIZE)]
771+
memmap_data_dtype += [(name + "_DC", "uint16", BLOCK_SIZE)]
771772
else:
772-
data_dtype[10] = "uint16"
773+
memmap_data_dtype[10] = "uint16"
773774

774775
# I can't seem to get stim files to generate for one-file-per-channel
775776
# so let's skip for now and can be given on request
@@ -790,9 +791,9 @@ def read_rhs(filename, file_format: str):
790791
chan_info_stim["dtype"] = "uint16"
791792
ordered_channel_info.append(chan_info_stim)
792793
if file_format == "header-attached":
793-
data_dtype += [(name + "_STIM", "uint16", BLOCK_SIZE)]
794+
memmap_data_dtype += [(name + "_STIM", "uint16", BLOCK_SIZE)]
794795
else:
795-
data_dtype[11] = "uint16"
796+
memmap_data_dtype[11] = "uint16"
796797
else:
797798
warnings.warn("Stim not implemented for `one-file-per-channel` due to lack of test files")
798799

@@ -812,9 +813,9 @@ def read_rhs(filename, file_format: str):
812813
ordered_channel_info.append(chan_info)
813814
if file_format == "header-attached":
814815
name = chan_info["native_channel_name"]
815-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
816+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
816817
else:
817-
data_dtype[stream_id] = "uint16"
818+
memmap_data_dtype[stream_id] = "uint16"
818819

819820
# 5: Digital input channel.
820821
# 6: Digital output channel.
@@ -828,13 +829,16 @@ def read_rhs(filename, file_format: str):
828829
chan_info["offset"] = 0.0
829830
chan_info["dtype"] = "uint16"
830831
ordered_channel_info.append(chan_info)
831-
832+
833+
# Note that all the channels are packed in one buffer, so the data type only needs to be added once
832834
if len(stream_id_to_channel_info_list[stream_id]) > 0:
833835
if file_format == "header-attached":
834836
name = stream_id_to_stream_name_rhs[stream_id]
835-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
836-
elif file_format in ["one-file-per-signal", "one-file-per-channel"]:
837-
data_dtype[stream_id] = "uint16"
837+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
838+
elif file_format == "one-file-per-channel":
839+
memmap_data_dtype[stream_id] = "uint16"
840+
elif file_format == "one-file-per-signal":
841+
memmap_data_dtype[stream_id] = "uint16"
838842

839843
# per discussion with Intan developers before version 3 of their software the 'notch_filter_mode'
840844
# was a request for postprocessing to be done in one of their scripts. From version 3+ the notch
@@ -849,10 +853,10 @@ def read_rhs(filename, file_format: str):
849853

850854
if not file_format == "header-attached":
851855
# filter out dtypes without any values
852-
data_dtype = {k: v for (k, v) in data_dtype.items() if len(v) > 0}
856+
memmap_data_dtype = {k: v for (k, v) in memmap_data_dtype.items() if len(v) > 0}
853857
channel_number_dict = {k: v for (k, v) in channel_number_dict.items() if v > 0}
854858

855-
return global_info, ordered_channel_info, data_dtype, header_size, BLOCK_SIZE, channel_number_dict
859+
return global_info, ordered_channel_info, memmap_data_dtype, header_size, BLOCK_SIZE, channel_number_dict
856860

857861

858862
###############
@@ -974,7 +978,7 @@ def read_rhd(filename, file_format: str):
974978
# read channel group and channel header
975979
stream_id_to_channel_info_list = {k: [] for k in [0, 1, 2, 3, 4, 5]}
976980
if not file_format == "header-attached":
977-
data_dtype = {k: [] for k in range(7)} # 5 streams + 6 for timestamps for not header attached
981+
memmap_data_dtype = {k: [] for k in range(7)} # 5 streams + 6 for timestamps for not header attached
978982
for g in range(global_info["nb_signal_group"]):
979983
group_info = read_variable_header(f, rhd_signal_group_header)
980984

@@ -1000,15 +1004,15 @@ def read_rhd(filename, file_format: str):
10001004

10011005
if version >= Version("1.2"):
10021006
if file_format == "header-attached":
1003-
data_dtype = [("timestamp", "int32", BLOCK_SIZE)]
1007+
memmap_data_dtype = [("timestamp", "int32", BLOCK_SIZE)]
10041008
else:
1005-
data_dtype[6] = "int32"
1009+
memmap_data_dtype[6] = "int32"
10061010
channel_number_dict[6] = 1
10071011
else:
10081012
if file_format == "header-attached":
1009-
data_dtype = [("timestamp", "uint32", BLOCK_SIZE)]
1013+
memmap_data_dtype = [("timestamp", "uint32", BLOCK_SIZE)]
10101014
else:
1011-
data_dtype[6] = "uint32"
1015+
memmap_data_dtype[6] = "uint32"
10121016
channel_number_dict[6] = 1
10131017

10141018
# 0: RHD2000 amplifier channel
@@ -1026,9 +1030,9 @@ def read_rhd(filename, file_format: str):
10261030

10271031
if file_format == "header-attached":
10281032
name = chan_info["native_channel_name"]
1029-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
1033+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
10301034
else:
1031-
data_dtype[0] = "int16"
1035+
memmap_data_dtype[0] = "int16"
10321036

10331037
# 1: RHD2000 auxiliary input channel
10341038
for chan_info in stream_id_to_channel_info_list[1]:
@@ -1040,9 +1044,9 @@ def read_rhd(filename, file_format: str):
10401044
ordered_channel_info.append(chan_info)
10411045
if file_format == "header-attached":
10421046
name = chan_info["native_channel_name"]
1043-
data_dtype += [(name, "uint16", BLOCK_SIZE // 4)]
1047+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE // 4)]
10441048
else:
1045-
data_dtype[1] = "uint16"
1049+
memmap_data_dtype[1] = "uint16"
10461050

10471051
# 2: RHD2000 supply voltage channel
10481052
for chan_info in stream_id_to_channel_info_list[2]:
@@ -1054,9 +1058,9 @@ def read_rhd(filename, file_format: str):
10541058
ordered_channel_info.append(chan_info)
10551059
if file_format == "header-attached":
10561060
name = chan_info["native_channel_name"]
1057-
data_dtype += [(name, "uint16")]
1061+
memmap_data_dtype += [(name, "uint16")]
10581062
else:
1059-
data_dtype[2] = "uint16"
1063+
memmap_data_dtype[2] = "uint16"
10601064

10611065
# temperature is not an official channel in the header
10621066
for i in range(global_info["num_temp_sensor_channels"]):
@@ -1068,7 +1072,7 @@ def read_rhd(filename, file_format: str):
10681072
chan_info["offset"] = 0.0
10691073
chan_info["dtype"] = "int16"
10701074
ordered_channel_info.append(chan_info)
1071-
data_dtype += [(name, "int16")]
1075+
memmap_data_dtype += [(name, "int16")]
10721076

10731077
# 3: USB board ADC input channel
10741078
for chan_info in stream_id_to_channel_info_list[3]:
@@ -1087,9 +1091,9 @@ def read_rhd(filename, file_format: str):
10871091
ordered_channel_info.append(chan_info)
10881092
if file_format == "header-attached":
10891093
name = chan_info["native_channel_name"]
1090-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
1094+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
10911095
else:
1092-
data_dtype[3] = "uint16"
1096+
memmap_data_dtype[3] = "uint16"
10931097

10941098
# 4: USB board digital input channel
10951099
# 5: USB board digital output channel
@@ -1108,9 +1112,11 @@ def read_rhd(filename, file_format: str):
11081112
if len(stream_id_to_channel_info_list[stream_id]) > 0:
11091113
if file_format == "header-attached":
11101114
name = stream_id_to_stream_name_rhd[stream_id]
1111-
data_dtype += [(name, "uint16", BLOCK_SIZE)]
1112-
elif file_format in ["one-file-per-signal", "one-file-per-channel"]:
1113-
data_dtype[stream_id] = "uint16"
1115+
memmap_data_dtype += [(name, "uint16", BLOCK_SIZE)]
1116+
elif file_format == "one-file-per-channel":
1117+
memmap_data_dtype[stream_id] = "uint16"
1118+
elif file_format == "one-file-per-signal":
1119+
memmap_data_dtype[stream_id] = "uint16"
11141120

11151121
# per discussion with Intan developers before version 3 of their software the 'notch_filter_mode'
11161122
# was a request for postprocessing to be done in one of their scripts. From version 3+ the notch
@@ -1125,10 +1131,10 @@ def read_rhd(filename, file_format: str):
11251131

11261132
if not file_format == "header-attached":
11271133
# filter out dtypes without any values
1128-
data_dtype = {k: v for (k, v) in data_dtype.items() if len(v) > 0}
1134+
memmap_data_dtype = {k: v for (k, v) in memmap_data_dtype.items() if len(v) > 0}
11291135
channel_number_dict = {k: v for (k, v) in channel_number_dict.items() if v > 0}
11301136

1131-
return global_info, ordered_channel_info, data_dtype, header_size, BLOCK_SIZE, channel_number_dict
1137+
return global_info, ordered_channel_info, memmap_data_dtype, header_size, BLOCK_SIZE, channel_number_dict
11321138

11331139

11341140
##########################################################################

0 commit comments

Comments
 (0)