Review fixes for PR #65: map_channel_to_electrode, LFP boundaries, STTC, ImpedanceMeasurements#67
Closed
MilagrosMarin wants to merge 4 commits into
Closed
Review fixes for PR #65: map_channel_to_electrode, LFP boundaries, STTC, ImpedanceMeasurements#67MilagrosMarin wants to merge 4 commits into
MilagrosMarin wants to merge 4 commits into
Conversation
1) map channel to electrode function 2) Fix bug in trace extraction (currently doesn't account for file boundaries 3) Add impedance measurement tables 4) Add STTC tables
…ies, STTC, ImpedanceMeasurements) - Move neo/quantities/elephant imports to lazy imports inside STTC.make() to avoid breaking the module in environments without these packages - Fix map_channel_to_electrode: restrict ElectrodeConfig.Electrode fetch by probe_type (was unrestricted), add conflict detection across multiple configs, and deduplicate consistent mappings safely - Fix LFP boundary trimming: replace elif with two independent if blocks so single-file sessions correctly trim both start and end boundaries - Replace # REMOVE LATER comment in STTC.make() with proper explanation - Fix ImpedanceMeasurements.make(): move EphysSessionProbe existence check before the fetch to prevent KeyError on empty result Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_to_electrode - Add explicit check when no ElectrodeConfig rows exist for the probe_type to prevent np.column_stack from crashing on empty arrays - Replace np.empty with np.full(..., -1) so unset lookup positions return a detectable sentinel value (-1) rather than uninitialized memory Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
Recreating with correct base targeting judewerth:main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR proposes fixes to be incorporated into PR #65 (Changes to Ephys Schema by @judewerth) before it merges to main. The diff shows only the review corrections on top of Jude's changes.
Fixes Applied
A — Lazy imports for
neo,quantities,elephantimport neo,import quantities as pq, andfrom elephant.spike_train_correlation import spike_time_tiling_coefficientmoved from module level to lazy imports insideSTTC.make().Why: These are optional heavy dependencies used only by
STTC.make(). Importing at module level causesephys_no_curationto fail entirely on any environment without these packages (HPC nodes, minimal containers, dev machines not running spike sorting) — breaking LFP, frame analysis, and everything else that depends on this module. Follows the same lazy-import pattern applied tospikeinterfacein the workflow repo.B —
map_channel_to_electrode: restricted fetch + conflict detection + edge case guardsAlso replaced
np.empty(num_electrodes, dtype=int)withnp.full(num_electrodes, -1, dtype=int).Why:
probe_type. Silently wrong the moment a second probe type is added.probe_typeis already inElectrodeConfig.Electrode's PK (via-> ProbeType.Electrode), so no join throughElectrodeConfigis needed.np.uniquededuplication handles multiple configs for the same probe type that share the same mapping. Conflicting mappings raise aValueErrorexplicitly.ElectrodeConfigexists yet, the fetch returns empty arrays andnp.column_stackwould crash with a cryptic message. Added explicit check first.np.empty→np.full(..., -1):np.emptyproduces uninitialized memory for indices not covered by the config. Sentinel value-1makes uncovered positions detectable rather than silently returning garbage.Non-blocking suggestion for @judewerth: The return variable
electrode_idsand the docstringReturns: electrodes (array-like)...are misleading whenelectrode_to_channel=True— in that direction the function returns channel indices, not electrode indices. Worth updating in a follow-up.C — LFP boundary trimming:
elifbug for single-file sessionsWhy: When a session lives entirely within one
.rhdfile,file_paths[0] == file_paths[-1]. Theelifmeans only the start boundary is trimmed — sessions in a single file silently include LFP data beyondend_time.D —
# REMOVE LATERcomment inSTTC.make()Replaced with:
# clip spike times to session duration to guard against edge-case spikes beyond end_time. The line itself is necessary — without it,neo.SpikeTrainraises when spike times exceedt_stop.E —
ImpedanceMeasurements.make(): existence check before fetchMoved
if not (EphysSessionProbe & key)beforefetch("port_id"). Previously a missingEphysSessionProbewould causeport_id.pop()to raiseKeyErrorinstead of the intendedValueError.Test plan
from element_array_ephys.ephys_no_curation import map_channel_to_electrode, get_probe_typesucceeds withoutneo/elephantinstalledmap_channel_to_electrodereturns correct electrode indices for a known session.rhdfile produces the correct durationSTTC.make()runs end-to-end for a spike-sorted session🤖 Generated with Claude Code