Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/Devices/Neuropixels1e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ int Neuropixels1e::configureDevice()

LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());

settings[0]->connected = probeMetadata.getProbeSerialNumber() != 0;

return ONI_ESUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Devices/Neuropixels1f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ int Neuropixels1f::configureDevice()

LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());

settings[0]->connected = probeMetadata.getProbeSerialNumber() != 0;

// Enable device streaming
rc = deviceContext->writeRegister (deviceIdx, 0x8000, 1);
if (rc != ONI_ESUCCESS)
Expand Down
30 changes: 17 additions & 13 deletions Source/Devices/Neuropixels2e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,22 @@ int Neuropixels2e::configureDevice()
LOGD ("Probe A SN: ", probeMetadata[0].getProbeSerialNumber());
LOGD ("Probe B SN: ", probeMetadata[1].getProbeSerialNumber());

if (probeMetadata[0].getProbeSerialNumber() == 0 && probeMetadata[1].getProbeSerialNumber() == 0)
{
m_numProbes = 0;
throw error_str ("No probes were found connected at address " + std::to_string (getDeviceIdx()));
}
else if (probeMetadata[0].getProbeSerialNumber() != 0 && probeMetadata[1].getProbeSerialNumber() != 0)
m_numProbes = 0;

for(int i = 0; i < NumberOfProbes; i++)
{
m_numProbes = 2;
if (probeMetadata[i].getProbeSerialNumber() != 0)
{
settings[i]->connected = true;
m_numProbes++;
}
else
settings[i]->connected = false;
}
else

if (m_numProbes == 0)
{
m_numProbes = 1;
throw error_str ("No probes were found connected at address " + std::to_string (getDeviceIdx()));
}

streamInfos.clear();
Expand All @@ -342,9 +346,9 @@ int Neuropixels2e::configureDevice()

bool Neuropixels2e::updateSettings()
{
for (int i = 0; i < 2; i++)
for (int i = 0; i < NumberOfProbes; i++)
{
if (probeMetadata[i].getProbeSerialNumber() != 0)
if (settings[i]->connected)
{
if (! NeuropixelsProbeMetadata::validateProbeTypeAndPartNumber (settings[i]->probeType, probeMetadata[i]))
{
Expand Down Expand Up @@ -416,7 +420,7 @@ bool Neuropixels2e::updateSettings()

for (int i = 0; i < NumberOfProbes; i++)
{
if (probeMetadata[i].getProbeSerialNumber() != 0)
if (settings[i]->connected)
{
selectProbe (serializer.get(), i == 0 ? ProbeASelected : ProbeBSelected);
writeConfiguration (settings[i].get());
Expand Down Expand Up @@ -554,7 +558,7 @@ void Neuropixels2e::addSourceBuffers (OwnedArray<DataBuffer>& sourceBuffers)
if (m_numProbes == 1)
{
sourceBuffers.add (new DataBuffer (streamInfos.getFirst().getNumChannels(), (int) streamInfos.getFirst().getSampleRate() * bufferSizeInSeconds));
auto bufferIndex = probeMetadata[0].getProbeSerialNumber() != 0 ? 0 : 1;
auto bufferIndex = settings[0]->connected ? 0 : 1;
amplifierBuffer[bufferIndex] = sourceBuffers.getLast();
}
else
Expand Down
65 changes: 65 additions & 0 deletions Source/NeuropixelsComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ struct ProbeSettings
lfpGainIndex = newSettings->lfpGainIndex;
referenceIndex = newSettings->referenceIndex;
apFilterState = newSettings->apFilterState;
connected = newSettings->connected;

selectedBank = newSettings->selectedBank;
selectedShank = newSettings->selectedShank;
Expand Down Expand Up @@ -344,6 +345,7 @@ struct ProbeSettings
int lfpGainIndex = 0;
int referenceIndex = 0;
bool apFilterState = false;
bool connected = false;

std::vector<Bank> selectedBank;
std::vector<int> selectedShank;
Expand Down Expand Up @@ -562,4 +564,67 @@ static class NeuropixelsV1
return baseConfigs;
}
};

static class NeuropixelsHelpers
{
public:
/** Set all channel metadata, starting with the last (most recently added) channel and working backwards over all selected electrodes */
static void setChannelMetadata (OwnedArray<ContinuousChannel>* continuousChannels, const std::vector<std::unique_ptr<ProbeSettings>>& probeSettings)
{
ContinuousChannel** channels = continuousChannels->end();
channels--;

for (auto it = probeSettings.rbegin(); it != probeSettings.rend(); it++)
{
ProbeSettings* probeSetting = it->get();

if (! probeSetting->connected)
continue;

for (int i = probeSetting->numberOfChannels - 1; i >= 0; i--)
{
auto channel = *channels--;

int globalIndex = probeSetting->selectedElectrode[i];
int shankIndex = probeSetting->electrodeMetadata[globalIndex].shank;

float xpos = probeSetting->electrodeMetadata[globalIndex].xpos;
float ypos = probeSetting->electrodeMetadata[globalIndex].ypos;

// NB: Depth must be a unique value for compatibility with legacy LFP viewer channel sorting algorithm
float depth = ypos + (float)shankIndex * 10000.0f + xpos * 0.001f;

channel->position.x = xpos;
channel->position.y = depth;

channel->group.name = "Shank " + String (shankIndex + 1);
channel->group.number = shankIndex;

// NB: Add real Y position as a metadata descriptor
MetadataDescriptor yposDescriptor (MetadataDescriptor::MetadataType::FLOAT,
1,
"ypos",
"Channel y-position (relative to shank tip)",
"channel.ypos");

MetadataValue yposValue (MetadataDescriptor::MetadataType::FLOAT, 1);
yposValue.setValue (ypos);

channel->addMetadata (yposDescriptor, yposValue);

// NB: Add electrode index as metadata
MetadataDescriptor selectedElectrodeDescriptor (MetadataDescriptor::MetadataType::UINT16,
1,
"electrode_index",
"Electrode index for this channel",
"neuropixels.electrode_index");

MetadataValue selectedElectrodeValue (MetadataDescriptor::MetadataType::UINT16, 1);
selectedElectrodeValue.setValue ((uint16) globalIndex);

channel->addMetadata (selectedElectrodeDescriptor, selectedElectrodeValue);
}
}
}
};
} // namespace OnixSourcePlugin
6 changes: 6 additions & 0 deletions Source/OnixSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@ void OnixSource::updateSettings (OwnedArray<ContinuousChannel>* continuousChanne
deviceInfos->add (device);

addIndividualStreams (source->streamInfos, dataStreams, deviceInfos, continuousChannels);

NeuropixelsHelpers::setChannelMetadata (continuousChannels, std::static_pointer_cast<Neuropixels1f> (source)->settings);
}
else if (type == OnixDeviceType::BNO || type == OnixDeviceType::POLLEDBNO)
{
Expand Down Expand Up @@ -885,6 +887,8 @@ void OnixSource::updateSettings (OwnedArray<ContinuousChannel>* continuousChanne
deviceInfos->add (device);

addIndividualStreams (source->streamInfos, dataStreams, deviceInfos, continuousChannels);

NeuropixelsHelpers::setChannelMetadata (continuousChannels, std::static_pointer_cast<Neuropixels2e> (source)->settings);
}
else if (type == OnixDeviceType::MEMORYMONITOR)
{
Expand Down Expand Up @@ -979,6 +983,8 @@ void OnixSource::updateSettings (OwnedArray<ContinuousChannel>* continuousChanne
deviceInfos->add (device);

addIndividualStreams (source->streamInfos, dataStreams, deviceInfos, continuousChannels);

NeuropixelsHelpers::setChannelMetadata (continuousChannels, std::static_pointer_cast<Neuropixels1e> (source)->settings);
}
else if (type == OnixDeviceType::OUTPUTCLOCK)
{
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/NeuropixelsV1Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ void NeuropixelsV1Interface::selectElectrodes (std::vector<int> electrodes)
{
std::static_pointer_cast<Neuropixels1> (device)->settings[0]->selectElectrodes (electrodes);

CoreServices::updateSignalChain (editor);

repaint();
}

Expand Down
2 changes: 2 additions & 0 deletions Source/UI/NeuropixelsV2eProbeInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ void NeuropixelsV2eProbeInterface::selectElectrodes (std::vector<int> electrodes
{
std::static_pointer_cast<Neuropixels2e> (device)->settings[probeIndex]->selectElectrodes (electrodes);

CoreServices::updateSignalChain (editor);

repaint();
}

Expand Down