| 56 | | data_dict['version'] = struct.unpack('<i',bin_file.read(4))[0] |
| 57 | | data_dict['comment'] = bin_file.read(256).replace('\x00','') |
| 58 | | data_dict['freq'] = float(struct.unpack('<d', bin_file.read(8))[0]) |
| 59 | | data_dict['tbeg'] = struct.unpack('<i', bin_file.read(4))[0]/data_dict['freq'] |
| 60 | | data_dict['tend'] = struct.unpack('<i', bin_file.read(4))[0]/data_dict['freq'] |
| | 59 | output_dict['version'] = struct.unpack('<i',bin_file.read(4))[0] |
| | 60 | output_dict['comment'] = bin_file.read(256).replace('\x00','') |
| | 61 | output_dict['freq'] = float(struct.unpack('<d', bin_file.read(8))[0]) |
| | 62 | output_dict['tbeg'] = struct.unpack('<i', bin_file.read(4))[0]/output_dict['freq']*1000 |
| | 63 | output_dict['tend'] = struct.unpack('<i', bin_file.read(4))[0]/output_dict['freq']*1000 |
| 70 | | data_dict["neurons"] = SpikeList(spikes, id_list, interval=(data_dict['tbeg'], data_dict['tend'])) |
| 71 | | data_dict["events"] = SpikeList(spikes, id_list, interval=(data_dict['tbeg'], data_dict['tend'])) |
| 72 | | data_dict["intervals"] = None |
| 73 | | data_dict["waves"] = {} |
| 74 | | data_dict["popvectors"] = {} |
| 75 | | data_dict["contvars"] = {} |
| 76 | | data_dict["markers"] = {} |
| | 73 | output_dict["neurons"] = {} |
| | 74 | output_dict["events"] = {} |
| | 75 | output_dict["intervals"] = None |
| | 76 | output_dict["waves"] = {} |
| | 77 | output_dict["popvectors"] = {} |
| | 78 | output_dict["contvars"] = {} |
| | 79 | output_dict["markers"] = {} |
| 82 | | header['varVersion'] = struct.unpack('<i', bin_file.read(4))[0] |
| 83 | | header['name'] = bin_file.read(64).replace('\x00','') |
| 84 | | header['offset'] = struct.unpack('<i', bin_file.read(4))[0] |
| 85 | | header['n'] = struct.unpack('<i', bin_file.read(4))[0] |
| 86 | | header['WireNumber'] = struct.unpack('<i', bin_file.read(4))[0] |
| 87 | | header['UnitNumber'] = struct.unpack('<i', bin_file.read(4))[0] |
| 88 | | header['Gain'] = struct.unpack('<i', bin_file.read(4))[0] |
| 89 | | header['Filter'] = struct.unpack('<i', bin_file.read(4))[0] |
| 90 | | header['XPos'] = struct.unpack('<d', bin_file.read(8))[0] |
| 91 | | header['YPos'] = struct.unpack('<d', bin_file.read(8))[0] |
| 92 | | header['WFrequency'] = struct.unpack('<d', bin_file.read(8))[0] # wf sampling fr. |
| 93 | | header['ADtoMV'] = struct.unpack('<d', bin_file.read(8))[0] # coeff to convert from AD values to Millivolts. |
| 94 | | header['NPointsWave'] = struct.unpack('<i', bin_file.read(4))[0] # number of points in each wave |
| 95 | | header['NMarkers'] = struct.unpack('<i', bin_file.read(4))[0] # how many values are associated with each marker |
| 96 | | header['MarkerLength'] = struct.unpack('<i', bin_file.read(4))[0] # how many characters are in each marker value |
| 97 | | header['MVOffset'] = struct.unpack('<d', bin_file.read(8))[0] # coeff to shift AD values in Millivolts: mv = raw*ADtoMV+MVOffset |
| 98 | | return header |
| | 85 | data['varVersion'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 86 | data['name'] = bin_file.read(64).replace('\x00','') |
| | 87 | data['offset'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 88 | data['n'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 89 | data['WireNumber'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 90 | data['UnitNumber'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 91 | data['Gain'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 92 | data['Filter'] = struct.unpack('<i', bin_file.read(4))[0] |
| | 93 | data['XPos'] = struct.unpack('<d', bin_file.read(8))[0] |
| | 94 | data['YPos'] = struct.unpack('<d', bin_file.read(8))[0] |
| | 95 | data['WFrequency'] = struct.unpack('<d', bin_file.read(8))[0] # wf sampling fr. |
| | 96 | data['ADtoMV'] = struct.unpack('<d', bin_file.read(8))[0] # coeff to convert from AD values to Millivolts. |
| | 97 | data['NPointsWave'] = struct.unpack('<i', bin_file.read(4))[0] # number of points in each wave |
| | 98 | data['NMarkers'] = struct.unpack('<i', bin_file.read(4))[0] # how many values are associated with each marker |
| | 99 | data['MarkerLength'] = struct.unpack('<i', bin_file.read(4))[0] # how many characters are in each marker value |
| | 100 | data['MVOffset'] = struct.unpack('<d', bin_file.read(8))[0] # coeff to shift AD values in Millivolts: mv = raw*ADtoMV+MVOffset |
| | 101 | return data |
| 100 | | def build_neuron(bin_file, data_dict, header, filePosition) : |
| 101 | | bin_file.seek(header['offset'],0) |
| 102 | | spikes = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| 103 | | current_ST = SpikeTrain(spikes, interval=(data_dict['tbeg'], data_dict['tend'])) |
| 104 | | data_dict["neurons"].append(header['name'], current_ST) |
| | 103 | def build_neuron(bin_file, output_dict, data, filePosition) : |
| | 104 | bin_file.seek(data['offset'],0) |
| | 105 | spikes = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 106 | current_ST = SpikeTrain(spikes, interval = Interval([[output_dict['tbeg'],output_dict['tend']]])) |
| | 107 | output_dict["neurons"][data['name']] = current_ST |
| 107 | | def build_event(bin_file, data_dict, header, filePosition) : |
| 108 | | bin_file.seek(header['offset'],0) |
| 109 | | spikes = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| 110 | | current_ET = SpikeTrain(spikes, interval=(data_dict['tbeg'], data_dict['tend'])) |
| 111 | | data_dict["events"].append(header['name'],current_ET) |
| | 110 | def build_event(bin_file, output_dict, data, filePosition) : |
| | 111 | bin_file.seek(data['offset'],0) |
| | 112 | spikes = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 113 | current_ET = SpikeTrain(spikes, interval = Interval([[output_dict['tbeg'],output_dict['tend']]])) |
| | 114 | output_dict["events"][data['name']] = current_ET |
| 114 | | def build_interval(bin_file, data_dict, header, filePosition) : |
| 115 | | bin_file.seek(header['offset'],0) |
| 116 | | start_times = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| 117 | | stop_times = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| | 117 | def build_interval(bin_file, output_dict, data, filePosition) : |
| | 118 | bin_file.seek(data['offset'],0) |
| | 119 | start_times = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 120 | stop_times = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| 125 | | def build_waves(bin_file, data_dict, header, filePosition) : |
| 126 | | bin_file.seek(header['offset'],0) |
| 127 | | data_dict['waves'][header['name']]['NPointsWave'] = data_dict['NPointsWave'] |
| 128 | | data_dict['waves'][header['name']]['WFrequency'] = WFrequency |
| 129 | | data = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| 130 | | data_dict['waves'][header['name']]['timestamps'] = SpikeTrain(data) |
| 131 | | data = np.fromstring(bin_file.read(header['n']*header['NPointsWave']*2), np.int16) |
| 132 | | data_dict['waves'][header['name']]['waveforms'] = np.reshape(data*header['ADtoMV'] + header['MVOffset'], (header['n'],header['NPointsWave'])) |
| | 127 | def build_waves(bin_file, output_dict, data, filePosition) : |
| | 128 | bin_file.seek(data['offset'],0) |
| | 129 | output_dict['waves'][data['name']]['NPointsWave'] = output_dict['NPointsWave'] |
| | 130 | output_dict['waves'][data['name']]['WFrequency'] = WFrequency |
| | 131 | data = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 132 | output_dict['waves'][data['name']]['timestamps'] = SpikeTrain(data) |
| | 133 | data = np.fromstring(bin_file.read(data['n']*data['NPointsWave']*2), np.int16) |
| | 134 | output_dict['waves'][data['name']]['waveforms'] = np.reshape(data*data['ADtoMV'] + data['MVOffset'], (data['n'],data['NPointsWave'])) |
| 135 | | def build_popvectors(bin_file, data_dict, header, filePosition) : |
| 136 | | bin_file.seek(header['offset'],0) |
| 137 | | data_dict['popvectors'][name]['weights'] = np.fromstring(bin_file.read(header['n']*8), np.double) |
| | 137 | def build_popvectors(bin_file, output_dict, data, filePosition) : |
| | 138 | bin_file.seek(data['offset'],0) |
| | 139 | output_dict['popvectors'][name]['weights'] = np.fromstring(bin_file.read(data['n']*8), np.double) |
| 140 | | def build_analog(bin_file, data_dict, header, filePosition) : |
| 141 | | bin_file.seek(header['offset'],0) |
| 142 | | timestamps = np.fromstring(bin_file.read(header['n']*4), np.int32)/data_dict['freq'] |
| 143 | | fragmentStarts = np.fromstring(bin_file.read(header['n']*4), np.int32) |
| 144 | | t0 = timestamps[0] - fragmentStarts[0]/float(header['WFrequency']) |
| 145 | | data_dict['contvars'][header['name']] = AnalogSignal(np.fromstring(bin_file.read(header['NPointsWave']*2), np.int16)*header['ADtoMV'] + header['MVOffset'], 1/float(header['WFrequency']), t_start=t0); |
| | 142 | def build_analog(bin_file, output_dict, data, filePosition) : |
| | 143 | bin_file.seek(data['offset'],0) |
| | 144 | timestamps = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 145 | fragmentStarts = np.fromstring(bin_file.read(data['n']*4), np.int32) |
| | 146 | t0 = timestamps[0] - fragmentStarts[0]/float(data['WFrequency'])*1000. |
| | 147 | output_dict['contvars'][data['name']] = AnalogSignal(np.fromstring(bin_file.read(data['NPointsWave']*2), np.int16)*data['ADtoMV'] + data['MVOffset'], 1/float(data['WFrequency']), t_start=t0); |
| 148 | | def build_markers(bin_file, data_dict, header, filePosition) : |
| 149 | | bin_file.seek(header['offset'],0) |
| 150 | | data_dict['markers'][header['name']] = dict() |
| 151 | | data_dict['markers'][header['name']]['timestamps'] = np.fromstring(bin_file.read(header['n']*4), np.int32) |
| 152 | | data_dict['markers'][header['name']]['values'] = [dict()]*header['NMarkers'] |
| 153 | | for j in range(header['NMarkers']) : |
| 154 | | data_dict['markers'][header['name']]['values'][j]['name'] = bin_file.read(64).replace('\x00','') |
| 155 | | data_dict['markers'][header['name']]['values'][j]['strings'] = ['']*header['n'] |
| 156 | | for p in range(header['n']) : |
| 157 | | data_dict['markers'][header['name']]['values'][j]['strings'][p] = bin_file.read(header['MarkerLength']).replace('\x00','') |
| | 150 | def build_markers(bin_file, output_dict, data, filePosition) : |
| | 151 | bin_file.seek(data['offset'],0) |
| | 152 | output_dict['markers'][data['name']] = dict() |
| | 153 | output_dict['markers'][data['name']]['timestamps'] = np.fromstring(bin_file.read(data['n']*4), np.int32)/output_dict['freq']*1000 |
| | 154 | output_dict['markers'][data['name']]['values'] = [dict()]*data['NMarkers'] |
| | 155 | for j in range(data['NMarkers']) : |
| | 156 | output_dict['markers'][data['name']]['values'][j]['name'] = bin_file.read(64).replace('\x00','') |
| | 157 | output_dict['markers'][data['name']]['values'][j]['strings'] = ['']*data['n'] |
| | 158 | for p in range(data['n']) : |
| | 159 | output_dict['markers'][data['name']]['values'][j]['strings'][p] = bin_file.read(data['MarkerLength']).replace('\x00','') |