feat: compute and plot normalised g-V curve with Boltzmann fit (#177)#207
Merged
Conversation
Adds GVPoint, BoltzmannFit, GVAnalysisResult dataclasses and compute_gv() / boltzmann() functions to patch_sim.analysis. Exports them from both the analysis subpackage and top-level patch_sim namespace.
16 tests covering boltzmann(), compute_gv() unit behaviour (chord conductance, normalisation, driving-force filtering, Boltzmann fit recovery), edge cases (empty input, <2 valid points), and an integration test against a real HH multi-sweep simulation.
Refactors _compute_iv_data() to return the raw IVAnalysisResult alongside the serialised dict. Adds _compute_gv_data() which calls compute_gv() and pre-computes the Boltzmann fit curve. The neuron's Na+ reversal potential (core_channels[0]) is used as E_rev. gv_data is stored in AnalysisState and cleared in all non-voltage-clamp paths.
- AnalysisState gets gv_data, has_gv_data, and gv_figure - build_gv_figure() renders G/Gmax scatter + Boltzmann fit curve with V_half and k annotation - _iv_curve_tab() embeds the g-V plot below the I-V plot in a scroll_area when g-V data is available
- Replace Union[float, np.ndarray] with float | np.ndarray in boltzmann() - Fix __all__ ordering in analysis/__init__.py (boltzmann/compute_gv now sorted alphabetically among function names) - Add explanatory comment on _null_fit sentinel in compute_gv() - Replace hardcoded core_channels[0] with an explicit Na+ channel lookup via NernstSpec/IonSpecies.SODIUM in simulation.py and integration test
JCorson
commented
Apr 13, 2026
Instead of silently falling back to core_channels[0] (which could be
any channel), set gv_data to {} so the plot stays empty rather than
showing a g-V curve computed against an arbitrary reversal potential.
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.
Summary
patch_sim/analysis/gv_curve.pywithcompute_gv()andboltzmann()— computes chord conductance G = I / (V − E_rev), normalises to G/Gmax, and fits a two-parameter Boltzmann sigmoid viascipy.optimize.curve_fitcore_channels[0].reversal_potential(neuron)) intorun_simulation()so g-V is computed automatically after every voltage-clamp multi-sweep runbuild_gv_figure()(green scatter + dashed Boltzmann fit curve + V½/k annotation) and embeds it below the existing I-V plot in a scrollable container in the I-V Curve analysis tabboltzmann()properties,compute_gv()unit behaviour (chord conductance, normalisation, driving-force filtering, Boltzmann parameter recovery, edge cases), and an HH integration testTest plan
uv run --frozen --group ui -m pytest)ruff check .andruff format --check .passty checkpassesCloses #177