Skip to content

Commit

Permalink
UHD electrode selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed May 29, 2024
1 parent 7de77da commit 3be73fc
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 128 deletions.
44 changes: 36 additions & 8 deletions Source/NeuropixThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ void NeuropixThread::updateSettings(OwnedArray<ContinuousChannel>* continuousCha
OwnedArray<DeviceInfo>* devices,
OwnedArray<ConfigurationObject>* configurationObjects)
{
LOGD("NeuropixThread::updateSettings()");

if (sourceStreams.size() == 0) // initialize data streams
{
Expand Down Expand Up @@ -1109,18 +1110,45 @@ void NeuropixThread::updateSettings(OwnedArray<ContinuousChannel>* continuousCha

if (type == ContinuousChannel::Type::ELECTRODE)
{
int chIndex = info.probe->settings.selectedChannel.indexOf(ch);
float depth = 0.0f;
int chIndex = 0;

Array<Bank> availableBanks = info.probe->settings.availableBanks;
if (info.probe->type != ProbeType::UHD2)
{
chIndex = info.probe->settings.selectedChannel.indexOf(ch);

Array<Bank> availableBanks = info.probe->settings.availableBanks;

int selectedBank = availableBanks.indexOf(info.probe->settings.selectedBank[chIndex]);
int selectedBank = availableBanks.indexOf(info.probe->settings.selectedBank[chIndex]);

int selectedElectrode = info.probe->settings.selectedElectrode[chIndex];
int shank = info.probe->settings.selectedShank[chIndex];
int selectedElectrode = info.probe->settings.selectedElectrode[chIndex];
int shank = info.probe->settings.selectedShank[chIndex];

float depth = float(info.probe->electrodeMetadata[selectedElectrode].ypos)
+ shank * 10000.0f
+ info.probe->electrodeMetadata[selectedElectrode].column_index * 0.0001f;
depth = float(info.probe->electrodeMetadata[selectedElectrode].ypos)
+ shank * 10000.0f
+ info.probe->electrodeMetadata[selectedElectrode].xpos * 0.001f;
}
else {

for (int i = 0; i < info.probe->electrodeMetadata.size(); i++)
{
if (info.probe->electrodeMetadata[i].channel == ch && info.probe->electrodeMetadata[i].status == ElectrodeStatus::CONNECTED)
{
chIndex = i;
break;
}
}

depth = float(info.probe->electrodeMetadata[chIndex].ypos)
+ info.probe->electrodeMetadata[chIndex].xpos * 0.001f;

if (false)
std::cout << "Channel: " << ch << " chIndex: " << chIndex <<
" ypos: " << info.probe->electrodeMetadata[chIndex].ypos <<
" xpos: " << info.probe->electrodeMetadata[chIndex].xpos <<
" depth: " << depth << std::endl;

}

continuousChannels->getLast()->position.y = depth;

Expand Down
6 changes: 5 additions & 1 deletion Source/Probes/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,11 @@ void Geometry::UHDActive(Array<ElectrodeMetadata>& electrodeMetadata,
metadata.ypos = (i - (i % numColumns)) * siteSpacing / numColumns;
metadata.site_width = siteSpacing - 1;

metadata.channel = channel_order[i];
metadata.channel = channel_order[(i / numColumns) * numColumns + metadata.column_index];

//if (i < 384)
// std::cout << "Electrode: " << i << ", Channel: " << metadata.channel << std::endl;

metadata.bank = Bank::A;
if (i < 384)
metadata.status = ElectrodeStatus::CONNECTED;
Expand Down
62 changes: 34 additions & 28 deletions Source/Probes/Neuropixels2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ Neuropixels2::Neuropixels2(Basestation* bs, Headstage* hs, Flex* fl, int dock) :

if (probeMetadata.shank_count == 1)
{
settings.availableReferences.add("Ext");
settings.availableReferences.add("Tip");
availableReferences.add("Ext");
availableReferences.add("Tip");

settings.availableElectrodeConfigurations.add("Bank A");
settings.availableElectrodeConfigurations.add("Bank B");
settings.availableElectrodeConfigurations.add("Bank C");
settings.availableElectrodeConfigurations.add("Bank D");
}
else {
settings.availableReferences.add("Ext");
settings.availableReferences.add("1: Tip");
settings.availableReferences.add("2: Tip");
settings.availableReferences.add("3: Tip");
settings.availableReferences.add("4: Tip");
availableReferences.add("Ext");
availableReferences.add("1: Tip");
availableReferences.add("2: Tip");
availableReferences.add("3: Tip");
availableReferences.add("4: Tip");

settings.availableElectrodeConfigurations.add("Shank 1 Bank A");
settings.availableElectrodeConfigurations.add("Shank 1 Bank B");
Expand Down Expand Up @@ -124,8 +124,12 @@ Neuropixels2::Neuropixels2(Basestation* bs, Headstage* hs, Flex* fl, int dock) :
info.part_number.equalsIgnoreCase("NP2003") ||
info.part_number.equalsIgnoreCase("NP2004"))
{
settings.availableReferences.add("Ground");
}
availableReferences.add("Ground");

bitScaling = 4096;
}

settings.availableReferences = availableReferences;

open();
}
Expand Down Expand Up @@ -566,35 +570,37 @@ void Neuropixels2::setAllReferences()
int refElectrodeBank = 0;
int shank = 0;

switch (settings.referenceIndex)
{
case 0:
String selectedRef = availableReferences[settings.referenceIndex];

if (selectedRef.equalsIgnoreCase("Ext"))
refId = Neuropixels::EXT_REF;
break;
case 1:
else if (selectedRef.equalsIgnoreCase("Tip"))
refId = Neuropixels::TIP_REF;
else if (selectedRef.equalsIgnoreCase("Ground"))
refId = Neuropixels::GND_REF;
else if (selectedRef.equalsIgnoreCase("1: Tip"))
{
refId = Neuropixels::TIP_REF;
shank = 0;
break;
case 2:
}
else if (selectedRef.equalsIgnoreCase("2: Tip"))
{
refId = Neuropixels::TIP_REF;
shank = 1;
break;
case 3:
}
else if (selectedRef.equalsIgnoreCase("3: Tip"))
{
refId = Neuropixels::TIP_REF;
shank = 2;
break;
case 4:
}
else if (selectedRef.equalsIgnoreCase("4: Tip"))
{
refId = Neuropixels::TIP_REF;
shank = 3;
break;
case 5:
refId = Neuropixels::GND_REF;
break;

default:
refId = Neuropixels::EXT_REF;
}

LOGC("Setting reference for slot: ", basestation->slot, " port: ", headstage->port, " dock: ", dock, " to ", refId);

for (int channel = 0; channel < channel_count; channel++)
Neuropixels::setReference(basestation->slot,
headstage->port,
Expand Down Expand Up @@ -688,7 +694,7 @@ void Neuropixels2::run()
for (int j = 0; j < 384; j++)
{
apSamples[j + packetNum * SKIP] =
float(data[packetNum * 384 + j]) * 1.0f / 16384.0f * 1000000.0f / 80.0f; // convert to microvolts
float(data[packetNum * 384 + j]) * 1.0f / bitScaling * 1000000.0f / 80.0f; // convert to microvolts

apView->addSample(apSamples[j + packetNum * SKIP], j);

Expand Down
4 changes: 4 additions & 0 deletions Source/Probes/Neuropixels2.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class Neuropixels2 : public Probe

Neuropixels::PacketInfo packetInfo[MAXPACKETS];

Array<String> availableReferences;

float bitScaling = 16384.0f;

};


Expand Down
5 changes: 5 additions & 0 deletions Source/Probes/Neuropixels_UHD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ Array<int> Neuropixels_UHD::selectElectrodeConfiguration(String electrodeConfigu
if (index == -1)
return defaultReturnValue;

settings.selectedElectrode.clear();

for (int i = 0; i < 384; i++)
settings.selectedElectrode.add(electrodeConfigurations[index]->getUnchecked(i));

if (index < banksPerProbe || index > 17)
{
LOGC("Selecting column pattern: ALL");
Expand Down
175 changes: 92 additions & 83 deletions Source/Probes/SimulatedProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,91 +670,100 @@ Array<int> SimulatedProbe::selectElectrodeConfiguration(String config)
}
}
}
else if (config.equalsIgnoreCase("8 x 48: Bank 0"))
{
return *electrodeConfigurationsUHD[0];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 1"))
{
return *electrodeConfigurationsUHD[1];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 2"))
{
return *electrodeConfigurationsUHD[2];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 3"))
{
return *electrodeConfigurationsUHD[3];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 4"))
{
return *electrodeConfigurationsUHD[4];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 5"))
{
return *electrodeConfigurationsUHD[5];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 6"))
{
return *electrodeConfigurationsUHD[6];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 7"))
{
return *electrodeConfigurationsUHD[7];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 8"))
{
return *electrodeConfigurationsUHD[8];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 9"))
{
return *electrodeConfigurationsUHD[9];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 10"))
{
return *electrodeConfigurationsUHD[10];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 11"))
{
return *electrodeConfigurationsUHD[11];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 12"))
{
return *electrodeConfigurationsUHD[12];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 13"))
{
return *electrodeConfigurationsUHD[13];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 14"))
{
return *electrodeConfigurationsUHD[14];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 15"))
{
return *electrodeConfigurationsUHD[15];
}
else if (config.equalsIgnoreCase("1 x 384: Tip Half"))
{
return *electrodeConfigurationsUHD[16];
}
else if (config.equalsIgnoreCase("1 x 384: Base Half"))
{
return *electrodeConfigurationsUHD[17];
}
else if (config.equalsIgnoreCase("2 x 192"))
{
return *electrodeConfigurationsUHD[18];
}
else if (config.equalsIgnoreCase("4 x 96"))
{
return *electrodeConfigurationsUHD[19];
}
else if (config.equalsIgnoreCase("2 x 2 x 96"))

if (type == ProbeType::UHD2)
{
return *electrodeConfigurationsUHD[20];

Array<int>* electrodeConfig;

if (config.equalsIgnoreCase("8 x 48: Bank 0"))
{
electrodeConfig = electrodeConfigurationsUHD[0];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 1"))
{
electrodeConfig = electrodeConfigurationsUHD[1];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 2"))
{
electrodeConfig = electrodeConfigurationsUHD[2];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 3"))
{
electrodeConfig = electrodeConfigurationsUHD[3];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 4"))
{
electrodeConfig = electrodeConfigurationsUHD[4];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 5"))
{
electrodeConfig = electrodeConfigurationsUHD[5];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 6"))
{
electrodeConfig = electrodeConfigurationsUHD[6];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 7"))
{
electrodeConfig = electrodeConfigurationsUHD[7];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 8"))
{
electrodeConfig = electrodeConfigurationsUHD[8];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 9"))
{
electrodeConfig = electrodeConfigurationsUHD[9];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 10"))
{
electrodeConfig = electrodeConfigurationsUHD[10];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 11"))
{
electrodeConfig = electrodeConfigurationsUHD[11];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 12"))
{
electrodeConfig = electrodeConfigurationsUHD[12];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 13"))
{
electrodeConfig = electrodeConfigurationsUHD[13];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 14"))
{
electrodeConfig = electrodeConfigurationsUHD[14];
}
else if (config.equalsIgnoreCase("8 x 48: Bank 15"))
{
electrodeConfig = electrodeConfigurationsUHD[15];
}
else if (config.equalsIgnoreCase("1 x 384: Tip Half"))
{
electrodeConfig = electrodeConfigurationsUHD[16];
}
else if (config.equalsIgnoreCase("1 x 384: Base Half"))
{
electrodeConfig = electrodeConfigurationsUHD[17];
}
else if (config.equalsIgnoreCase("2 x 192"))
{
electrodeConfig = electrodeConfigurationsUHD[18];
}
else if (config.equalsIgnoreCase("4 x 96"))
{
electrodeConfig = electrodeConfigurationsUHD[19];
}
else if (config.equalsIgnoreCase("2 x 2 x 96"))
{
electrodeConfig = electrodeConfigurationsUHD[20];
}

return *electrodeConfig;

}


return selection;
}
Expand Down
Loading

0 comments on commit 3be73fc

Please sign in to comment.