@@ -287,6 +287,7 @@ struct ProbeSettings
287287 lfpGainIndex = newSettings->lfpGainIndex ;
288288 referenceIndex = newSettings->referenceIndex ;
289289 apFilterState = newSettings->apFilterState ;
290+ connected = newSettings->connected ;
290291
291292 selectedBank = newSettings->selectedBank ;
292293 selectedShank = newSettings->selectedShank ;
@@ -344,6 +345,7 @@ struct ProbeSettings
344345 int lfpGainIndex = 0 ;
345346 int referenceIndex = 0 ;
346347 bool apFilterState = false ;
348+ bool connected = false ;
347349
348350 std::vector<Bank> selectedBank;
349351 std::vector<int > selectedShank;
@@ -562,4 +564,67 @@ static class NeuropixelsV1
562564 return baseConfigs;
563565 }
564566};
567+
568+ static class NeuropixelsHelpers
569+ {
570+ public:
571+ /* * Set all channel metadata, starting with the last (most recently added) channel and working backwards over all selected electrodes */
572+ static void setChannelMetadata (OwnedArray<ContinuousChannel>* continuousChannels, const std::vector<std::unique_ptr<ProbeSettings>>& probeSettings)
573+ {
574+ ContinuousChannel** channels = continuousChannels->end ();
575+ channels--;
576+
577+ for (auto it = probeSettings.rbegin (); it != probeSettings.rend (); it++)
578+ {
579+ ProbeSettings* probeSetting = it->get ();
580+
581+ if (! probeSetting->connected )
582+ continue ;
583+
584+ for (int i = probeSetting->numberOfChannels - 1 ; i >= 0 ; i--)
585+ {
586+ auto channel = *channels--;
587+
588+ int globalIndex = probeSetting->selectedElectrode [i];
589+ int shankIndex = probeSetting->electrodeMetadata [globalIndex].shank ;
590+
591+ float xpos = probeSetting->electrodeMetadata [globalIndex].xpos ;
592+ float ypos = probeSetting->electrodeMetadata [globalIndex].ypos ;
593+
594+ // NB: Depth must be a unique value for compatibility with legacy LFP viewer channel sorting algorithm
595+ float depth = ypos + (float )shankIndex * 10000 .0f + xpos * 0 .001f ;
596+
597+ channel->position .x = xpos;
598+ channel->position .y = depth;
599+
600+ channel->group .name = " Shank " + String (shankIndex + 1 );
601+ channel->group .number = shankIndex;
602+
603+ // NB: Add real Y position as a metadata descriptor
604+ MetadataDescriptor yposDescriptor (MetadataDescriptor::MetadataType::FLOAT,
605+ 1 ,
606+ " ypos" ,
607+ " Channel y-position (relative to shank tip)" ,
608+ " channel.ypos" );
609+
610+ MetadataValue yposValue (MetadataDescriptor::MetadataType::FLOAT, 1 );
611+ yposValue.setValue (ypos);
612+
613+ channel->addMetadata (yposDescriptor, yposValue);
614+
615+ // NB: Add electrode index as metadata
616+ MetadataDescriptor selectedElectrodeDescriptor (MetadataDescriptor::MetadataType::UINT16,
617+ 1 ,
618+ " electrode_index" ,
619+ " Electrode index for this channel" ,
620+ " neuropixels.electrode_index" );
621+
622+ MetadataValue selectedElectrodeValue (MetadataDescriptor::MetadataType::UINT16, 1 );
623+ selectedElectrodeValue.setValue ((uint16) globalIndex);
624+
625+ channel->addMetadata (selectedElectrodeDescriptor, selectedElectrodeValue);
626+ }
627+ }
628+ }
629+ };
565630} // namespace OnixSourcePlugin
0 commit comments