Skip to content

Commit d05e245

Browse files
committed
Fix bug in dig-in handling for traditional file format
1 parent 05daca5 commit d05e245

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

blech_clust.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@ def generate_processing_scripts(dir_name, blech_clust_dir, electrode_layout_fram
301301
electrodes_list = file_lists[file_type[0]]['electrodes']
302302
dig_in_file_list = file_lists[file_type[0]]['dig_in']
303303

304+
if file_type == ['one file per channel']:
305+
print("\tOne file per CHANNEL Detected")
306+
# Read dig-in data
307+
# Pull out the digital input channels used,
308+
# and convert them to integers
309+
dig_in_int = [x.split('-')[-1].split('.')[0] for x in dig_in_file_list]
310+
dig_in_int = sorted([(x) for x in dig_in_int])
311+
elif file_type == ['one file per signal type']:
312+
print("\tOne file per SIGNAL Detected")
313+
dig_in_int = np.arange(info_dict['dig_ins']['count'])
314+
304315
# Use info file for port list calculation
305316
info_file = np.fromfile(dir_name + '/info.rhd', dtype=np.dtype('float32'))
306317
sampling_rate = int(info_file[2])
@@ -310,20 +321,22 @@ def generate_processing_scripts(dir_name, blech_clust_dir, electrode_layout_fram
310321
num_recorded_samples = len(np.fromfile(
311322
dir_name + '/' + 'time.dat', dtype=np.dtype('float32')))
312323
total_recording_time = num_recorded_samples/sampling_rate # In seconds
324+
ports = info_dict['ports']
313325

314326
check_str = f'Amplifier files: {electrodes_list} \nSampling rate: {sampling_rate} Hz'\
315-
f'\nDigital input files: {dig_in_file_list} \n ---------- \n \n'
327+
f'\nDigital input files: {dig_in_file_list} \n Ports : {ports} \n---------- \n \n'
316328
print(check_str)
317-
ports = info_dict['ports']
318329

319330
if file_type[0] == 'traditional':
331+
print('Tranditional INTAN file format detected')
320332
rhd_file_list = file_lists[file_type[0]]['rhd']
321333
with open(rhd_file_list[0], 'rb') as f:
322334
header = read_header(f)
323335
# temp_file, data_present = importrhdutilities.load_file(file_list[0])
324336
amp_channel_ports = [x['port_prefix'] for x in header['amplifier_channels']]
325337
amp_channel_names = [x['native_channel_name'] for x in header['amplifier_channels']]
326338
dig_in_channels = [x['native_channel_name'] for x in header['board_dig_in_channels']]
339+
dig_in_int = sorted([x.split('-')[-1].split('.')[0] for x in dig_in_channels])
327340
sampling_rate = int(header['sample_rate'])
328341
ports = np.unique(amp_channel_ports)
329342

@@ -335,27 +348,6 @@ def generate_processing_scripts(dir_name, blech_clust_dir, electrode_layout_fram
335348
"""
336349
print(check_str)
337350

338-
339-
340-
if file_type == ['one file per channel']:
341-
print("\tOne file per CHANNEL Detected")
342-
# Read dig-in data
343-
# Pull out the digital input channels used,
344-
# and convert them to integers
345-
dig_in_int = [x.split('-')[-1].split('.')[0] for x in dig_in_file_list]
346-
dig_in_int = sorted([(x) for x in dig_in_int])
347-
elif file_type == ['one file per signal type']:
348-
print("\tOne file per SIGNAL Detected")
349-
dig_in_int = np.arange(info_dict['dig_ins']['count'])
350-
elif file_type == ['traditional']:
351-
print('Tranditional INTAN file format detected')
352-
dig_in_int = sorted([x.split('-')[-1].split('.')[0] for x in dig_in_channels])
353-
354-
check_str = f'ports used: {ports} \n sampling rate: {sampling_rate} Hz'\
355-
f'\n digital inputs on intan board: {dig_in_int}'
356-
357-
print(check_str)
358-
359351
all_car_group_vals = []
360352
for region_name, region_elecs in info_dict['electrode_layout'].items():
361353
if not region_name == 'emg':

utils/read_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def read_traditional_intan(
7070
dig_in_channels = [x['native_channel_name'] for x in this_file_data['board_dig_in_channels']]
7171
# for i, this_dig_in in enumerate(this_file_data['board_dig_in_data']):
7272
for i, this_dig in enumerate(dig_in_channels):
73-
this_dig_in_int = int(this_dig.split('-')[-1].split('.')[0])
73+
this_dig_in_int = this_dig.split('-')[-1].split('.')[0]
7474
if this_dig_in_int not in dig_in_int:
7575
continue
7676
array_name = f'dig_in_{this_dig_in_int}'

0 commit comments

Comments
 (0)