Skip to content

Spikeglx: use probe features from ProbeTable to infer Neuropixels type#1842

Open
alejoe91 wants to merge 5 commits into
NeuralEnsemble:masterfrom
alejoe91:spikeglx-probe-table
Open

Spikeglx: use probe features from ProbeTable to infer Neuropixels type#1842
alejoe91 wants to merge 5 commits into
NeuralEnsemble:masterfrom
alejoe91:spikeglx-probe-table

Conversation

@alejoe91
Copy link
Copy Markdown
Contributor

Following #1839, the SpikeGLX reader is updated to infer the 1.0/2.0 probe type from the datasheet field of the associated entry in the noe/resources/neuropixels_probe_features.json.

In case the datasheet is not 1.0/2.0, a warning is pronted and unitary gains are added.

@alejoe91 alejoe91 requested a review from h-mayorquin April 22, 2026 12:41
@samuelgarcia samuelgarcia added this to the 0.14.5 milestone Apr 22, 2026
Copy link
Copy Markdown
Contributor

@chrishalcrow chrishalcrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, and also allows the new NP2020 data to load successfully.
(I know my approval has little weight here - but I'm giving it anyway!!)

@alejoe91
Copy link
Copy Markdown
Contributor Author

alejoe91 commented May 8, 2026

This looks good to me, and also allows the new NP2020 data to load successfully. (I know my approval has little weight here - but I'm giving it anyway!!)

I'll take it!

Copy link
Copy Markdown
Contributor

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrishalcrow for testing this and sorry for taking so long @alejoe91. Actually, I was not sure if it was ready so I delayed it, sorry for assuming wrong. I have some requests regarding the handling of warnings vs error but otherwise LGTM.

Metacommentary:

After #1839 and #1842 we have our own copy of the json of the probe library. This is fine as long as both releases stay in lockstep with billkarsh's ProbeTable, but the cadence is controlled by two independent actions and two independent release cycles. A user with neo==X and probeinterface==Y where X and Y bracket a ProbeTable update might see diferences depending on versios. Honestly, it would be been simpler to just use probeinterface here rather than python-neo carrying its own copy. I do understand the French reason you probably decided against it though.

with open(neuropixels_probe_features_file, "r") as f:
probe_features = json.load(f)

if probe_part_number is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two outer if probe_part_number is not None: and if features is not None: wrappers can collapse if we mirror probeinterface's Phase3A remap and raise instead of warning. This also picks up the Phase3A case (imProbeOpt instead of imDatPrb_pn), which probeinterface handles here but #1842 currently drops to unitary gain.

Suggested change
if probe_part_number is not None:
probe_part_number = meta.get("imDatPrb_pn", None)
if probe_part_number is None and meta.get("imProbeOpt") is not None:
probe_part_number = "NP1010" # Phase3A remap, matches probeinterface
if probe_part_number is None:
raise ValueError("Could not determine probe part number from metadata.")
features = probe_features["neuropixels_probes"].get(probe_part_number)
if features is None:
raise ValueError(f"Probe part number {probe_part_number} not found in ProbeTable.")

This replaces the warn-and-unitary-gain fallbacks with hard failures. We were doing this on master already with NotImplementedError for unsupported probes, and silently scaled-wrong traces are harder to catch downstream.

gain_factor = float(meta["imAiRangeMax"]) / max_int
channel_gains = gain_factor * per_channel_gain * 1e6
else:
warn(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same argument applies inside the gain branch: I think we should raise an error Raising matches master's behaviour which I think is better than letting wrong gains silently propagate.

Suggested change
warn(
else:
raise NotImplementedError(
f"Probe {probe_part_number} has datasheet {datasheet!r}, "
f"which is not currently supported by the SpikeGLX gain calculation. \n"
"Please open an issue at python-neo repo"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will become easier with a logic like the one in:

SpikeInterface/probeinterface#434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants