@@ -42,6 +42,18 @@ public int BufferSize
4242 set => bufferSize = ( int ) ( Math . Ceiling ( ( double ) value / NeuropixelsV1 . FramesPerRoundRobin ) * NeuropixelsV1 . FramesPerRoundRobin ) ;
4343 }
4444
45+ /// <summary>
46+ /// Gets or sets a boolean value that controls if the channels are ordered by depth.
47+ /// </summary>
48+ /// <remarks>
49+ /// If <see cref="OrderByDepth"/> is false, then channels are ordered from 0 to 383.
50+ /// If <see cref="OrderByDepth"/> is true, then channels are ordered based on the depth
51+ /// of the electrodes.
52+ /// </remarks>
53+ [ Description ( "Determines if the channels are returned ordered by depth." ) ]
54+ [ Category ( DeviceFactory . ConfigurationCategory ) ]
55+ public bool OrderByDepth { get ; set ; } = false ;
56+
4557 /// <summary>
4658 /// Generates a sequence of <see cref="NeuropixelsV1DataFrame"/> objects.
4759 /// </summary>
@@ -50,24 +62,27 @@ public unsafe override IObservable<NeuropixelsV1DataFrame> Generate()
5062 {
5163 var spikeBufferSize = BufferSize ;
5264 var lfpBufferSize = spikeBufferSize / NeuropixelsV1 . FramesPerRoundRobin ;
53-
5465 var bufferSize = BufferSize ;
66+ var orderByDepth = OrderByDepth ;
67+
5568 return DeviceManager . GetDevice ( DeviceName ) . SelectMany (
5669 deviceInfo => Observable . Create < NeuropixelsV1DataFrame > ( observer =>
5770 {
5871 var sampleIndex = 0 ;
59- var device = deviceInfo . GetDeviceContext ( typeof ( NeuropixelsV1f ) ) ;
72+ var info = ( NeuropixelsV1fDeviceInfo ) deviceInfo ;
73+ var device = info . GetDeviceContext ( typeof ( NeuropixelsV1f ) ) ;
6074 var spikeBuffer = new ushort [ NeuropixelsV1 . ChannelCount , spikeBufferSize ] ;
6175 var lfpBuffer = new ushort [ NeuropixelsV1 . ChannelCount , lfpBufferSize ] ;
6276 var frameCountBuffer = new int [ spikeBufferSize * NeuropixelsV1 . FramesPerSuperFrame ] ;
6377 var hubClockBuffer = new ulong [ spikeBufferSize ] ;
6478 var clockBuffer = new ulong [ spikeBufferSize ] ;
79+ int [ , ] channelOrder = orderByDepth ? Neuropixels . OrderChannelsByDepth ( info . ProbeConfiguration . ChannelMap , RawToChannel ) : RawToChannel ;
6580
6681 var frameObserver = Observer . Create < oni . Frame > (
6782 frame =>
6883 {
6984 var payload = ( NeuropixelsV1fPayload * ) frame . Data . ToPointer ( ) ;
70- NeuropixelsV1fDataFrame . CopyAmplifierBuffer ( payload ->AmplifierData , frameCountBuffer , spikeBuffer , lfpBuffer , sampleIndex ) ;
85+ NeuropixelsV1fDataFrame . CopyAmplifierBuffer ( payload ->AmplifierData , frameCountBuffer , spikeBuffer , lfpBuffer , sampleIndex , channelOrder ) ;
7186 hubClockBuffer [ sampleIndex ] = payload ->HubClock ;
7287 clockBuffer [ sampleIndex ] = frame . Clock ;
7388
@@ -89,5 +104,43 @@ public unsafe override IObservable<NeuropixelsV1DataFrame> Generate()
89104 . SubscribeSafe ( frameObserver ) ;
90105 } ) ) ;
91106 }
107+
108+ // ADC to channel
109+ // First dimension: ADC index
110+ // Second dimension: frame index within super frame
111+ // Output: channel number
112+ static readonly int [ , ] RawToChannel = {
113+ { 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 } ,
114+ { 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 , 19 , 21 , 23 } ,
115+ { 24 , 26 , 28 , 30 , 32 , 34 , 36 , 38 , 40 , 42 , 44 , 46 } ,
116+ { 25 , 27 , 29 , 31 , 33 , 35 , 37 , 39 , 41 , 43 , 45 , 47 } ,
117+ { 48 , 50 , 52 , 54 , 56 , 58 , 60 , 62 , 64 , 66 , 68 , 70 } ,
118+ { 49 , 51 , 53 , 55 , 57 , 59 , 61 , 63 , 65 , 67 , 69 , 71 } ,
119+ { 72 , 74 , 76 , 78 , 80 , 82 , 84 , 86 , 88 , 90 , 92 , 94 } ,
120+ { 73 , 75 , 77 , 79 , 81 , 83 , 85 , 87 , 89 , 91 , 93 , 95 } ,
121+ { 96 , 98 , 100 , 102 , 104 , 106 , 108 , 110 , 112 , 114 , 116 , 118 } ,
122+ { 97 , 99 , 101 , 103 , 105 , 107 , 109 , 111 , 113 , 115 , 117 , 119 } ,
123+ { 120 , 122 , 124 , 126 , 128 , 130 , 132 , 134 , 136 , 138 , 140 , 142 } ,
124+ { 121 , 123 , 125 , 127 , 129 , 131 , 133 , 135 , 137 , 139 , 141 , 143 } ,
125+ { 144 , 146 , 148 , 150 , 152 , 154 , 156 , 158 , 160 , 162 , 164 , 166 } ,
126+ { 145 , 147 , 149 , 151 , 153 , 155 , 157 , 159 , 161 , 163 , 165 , 167 } ,
127+ { 168 , 170 , 172 , 174 , 176 , 178 , 180 , 182 , 184 , 186 , 188 , 190 } ,
128+ { 169 , 171 , 173 , 175 , 177 , 179 , 181 , 183 , 185 , 187 , 189 , 191 } ,
129+ { 192 , 194 , 196 , 198 , 200 , 202 , 204 , 206 , 208 , 210 , 212 , 214 } ,
130+ { 193 , 195 , 197 , 199 , 201 , 203 , 205 , 207 , 209 , 211 , 213 , 215 } ,
131+ { 216 , 218 , 220 , 222 , 224 , 226 , 228 , 230 , 232 , 234 , 236 , 238 } ,
132+ { 217 , 219 , 221 , 223 , 225 , 227 , 229 , 231 , 233 , 235 , 237 , 239 } ,
133+ { 240 , 242 , 244 , 246 , 248 , 250 , 252 , 254 , 256 , 258 , 260 , 262 } ,
134+ { 241 , 243 , 245 , 247 , 249 , 251 , 253 , 255 , 257 , 259 , 261 , 263 } ,
135+ { 264 , 266 , 268 , 270 , 272 , 274 , 276 , 278 , 280 , 282 , 284 , 286 } ,
136+ { 265 , 267 , 269 , 271 , 273 , 275 , 277 , 279 , 281 , 283 , 285 , 287 } ,
137+ { 288 , 290 , 292 , 294 , 296 , 298 , 300 , 302 , 304 , 306 , 308 , 310 } ,
138+ { 289 , 291 , 293 , 295 , 297 , 299 , 301 , 303 , 305 , 307 , 309 , 311 } ,
139+ { 312 , 314 , 316 , 318 , 320 , 322 , 324 , 326 , 328 , 330 , 332 , 334 } ,
140+ { 313 , 315 , 317 , 319 , 321 , 323 , 325 , 327 , 329 , 331 , 333 , 335 } ,
141+ { 336 , 338 , 340 , 342 , 344 , 346 , 348 , 350 , 352 , 354 , 356 , 358 } ,
142+ { 337 , 339 , 341 , 343 , 345 , 347 , 349 , 351 , 353 , 355 , 357 , 359 } ,
143+ { 360 , 362 , 364 , 366 , 368 , 370 , 372 , 374 , 376 , 378 , 380 , 382 } ,
144+ { 361 , 363 , 365 , 367 , 369 , 371 , 373 , 375 , 377 , 379 , 381 , 383 } } ;
92145 }
93146}
0 commit comments