@@ -562,4 +562,64 @@ static class NeuropixelsV1
562562 return baseConfigs;
563563 }
564564};
565+
566+ static class NeuropixelsHelpers
567+ {
568+ public:
569+ /* * Set all channel metadata, starting with the last (most recently added) channel and working backwards over all selected electrodes */
570+ static void setChannelMetadata (OwnedArray<ContinuousChannel>* continuousChannels, const std::vector<std::unique_ptr<ProbeSettings>>& probeSettings)
571+ {
572+ ContinuousChannel** channels = continuousChannels->end ();
573+ channels--;
574+
575+ for (auto it = probeSettings.rbegin (); it != probeSettings.rend (); it++)
576+ {
577+ ProbeSettings* probeSetting = it->get ();
578+
579+ for (int i = probeSetting->numberOfChannels - 1 ; i >= 0 ; i--)
580+ {
581+ auto channel = *channels--;
582+
583+ int globalIndex = probeSetting->selectedElectrode [i];
584+ int shankIndex = probeSetting->electrodeMetadata [globalIndex].shank ;
585+
586+ float xpos = probeSetting->electrodeMetadata [globalIndex].xpos ;
587+ float ypos = probeSetting->electrodeMetadata [globalIndex].ypos ;
588+
589+ // NB: Depth must be a unique value for compatibility with legacy LFP viewer channel sorting algorithm
590+ float depth = ypos + (float )shankIndex * 10000 .0f + xpos * 0 .001f ;
591+
592+ channel->position .x = xpos;
593+ channel->position .y = depth;
594+
595+ channel->group .name = " Shank " + String (shankIndex + 1 );
596+ channel->group .number = shankIndex;
597+
598+ // NB: Add real Y position as a metadata descriptor
599+ MetadataDescriptor yposDescriptor (MetadataDescriptor::MetadataType::FLOAT,
600+ 1 ,
601+ " ypos" ,
602+ " Channel y-position (relative to shank tip)" ,
603+ " channel.ypos" );
604+
605+ MetadataValue yposValue (MetadataDescriptor::MetadataType::FLOAT, 1 );
606+ yposValue.setValue (ypos);
607+
608+ channel->addMetadata (yposDescriptor, yposValue);
609+
610+ // NB: Add electrode index as metadata
611+ MetadataDescriptor selectedElectrodeDescriptor (MetadataDescriptor::MetadataType::UINT16,
612+ 1 ,
613+ " electrode_index" ,
614+ " Electrode index for this channel" ,
615+ " neuropixels.electrode_index" );
616+
617+ MetadataValue selectedElectrodeValue (MetadataDescriptor::MetadataType::UINT16, 1 );
618+ selectedElectrodeValue.setValue ((uint16) globalIndex);
619+
620+ channel->addMetadata (selectedElectrodeDescriptor, selectedElectrodeValue);
621+ }
622+ }
623+ }
624+ };
565625} // namespace OnixSourcePlugin
0 commit comments