Skip to content

Scale IV curve current range to rheobase - #104

Merged
ilkilic merged 5 commits into
mainfrom
fix-iv-curve-current-range-scaling
Nov 6, 2026
Merged

ilkilic merged 5 commits into
mainfrom
fix-iv-curve-current-range-scaling

Conversation

@ilkilic

@ilkilic ilkilic commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

compute_plot_iv_curve built its sweep as np.linspace(rheobase - 2, rheobase - 0.1, nb_bins). The - 2 is an absolute nA offset that assumes a rheobase near 1 nA; for cells with a much smaller rheobase it injects large hyperpolarizing currents, far more negative than the cell's subthreshold range, and produces nonphysical steady-state voltages, while the positive-slope check still passes (so it is silent).

This scales the sweep to the cell's rheobase, hardens the guards, and lets callers override the bounds for a fixed absolute sweep.

Changes

  • Default sweep is now np.linspace(-rheobase, 0.9 * rheobase, nb_bins), so it runs from -rheobase up to just below threshold and includes positive subthreshold currents.
  • New optional min_amp/max_amp (nA). When unset they default to the rheobase-scaled range; when set they define a fixed absolute sweep and rheobase is neither computed nor required.
  • Guards: reject nb_bins < 2, reject a non-finite or non-positive rheobase (NaN included), and reject bounds that are non-finite or have min_amp >= max_amp.
  • iv_test now passes explicit bounds (-rheobase, 0.9 * rheobase) rather than relying on the library default, so the validation range is pinned in the validation code and will not move if the default changes. It also catches the range ValueError and marks the IV test failed, so a model with rheobase <= 0 fails that test instead of aborting the whole run_validations call.
  • nb_bins still controls resolution.

Behavior change (breaking: default output)

  • The default injected current range for a given rheobase changed. Old: [rheobase - 2, rheobase - 0.1] nA. New: [-rheobase, 0.9 * rheobase] nA. For a rheobase near 1 nA these are similar; for smaller rheobase (the platform median is ~0.1 nA, where the old range was all hyperpolarizing) the new range stays physiological. IV figures produced with default settings, including the platform validation figures, will differ from before. To reproduce the old window, pass min_amp=rheobase - 2, max_amp=rheobase - 0.1.

Tests

  • Range scales for small and large rheobase.
  • Non-finite/non-positive rheobase and degenerate nb_bins are rejected.
  • Explicit min_amp/max_amp set the sweep directly and skip rheobase; inverted bounds are rejected.
  • iv_test returns a failed result (not an exception) when the range cannot be built.

compute_plot_iv_curve hardcoded the current sweep as
linspace(rheobase - 2, rheobase - 0.1), an absolute -2 nA offset that
implicitly assumes a rheobase on the order of 1 nA. For cells with a much
smaller rheobase this injects currents orders of magnitude above rheobase
and yields nonphysical steady-state voltages, while the positive-slope
check still passes, so the issue is silent.

Scale the sweep to the cell's rheobase instead. The range is unchanged for
a rheobase near 1 nA, so existing callers are unaffected. Add a regression
test asserting the sweep scales with rheobase.
@ilkilic
ilkilic requested a review from darshanmandge October 28, 2026 12:39
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bluecellulab/analysis/analysis.py 96.24% <100.00%> (+0.13%) ⬆️
bluecellulab/validation/validation.py 100.00% <100.00%> (ø)
tests/test_analysis/test_analysis.py 98.92% <100.00%> (+0.15%) ⬆️
tests/test_validation/test_validation.py 100.00% <100.00%> (ø)

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@darshanmandge darshanmandge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will change the IV curves generated with default parameters. Let's think before merging this.

Document in PR description that the behavior change: the sweep is now ~-rheobase to 0.9*rheobase (was rheobase-2 to rheobase-0.1).

Comment thread bluecellulab/analysis/analysis.py Resolved
Comment thread tests/test_analysis/test_analysis.py Resolved
Replace the rheobase-scaled sweep with an explicit -rheobase to 0.9*rheobase
linspace, removing the abs() form that was only correct for positive rheobase
and masked a sign trap. At rheobase = 1 nA this matches the previous endpoints
exactly, so cells near 1 nA are unaffected.

Add two guards that fail loudly instead of producing silent garbage:
- nb_bins < 2 cannot span a range (checked before the rheobase search).
- rheobase must be finite and positive; a bare <= 0 check let NaN through
  (nan <= 0 is False) into an all-NaN sweep.

Tests assert exact sweep endpoints for a small and a large rheobase (so a
reintroduced fixed offset is caught), assert the sweep is ascending, and
cover the rheobase and nb_bins rejection paths.

@darshanmandge darshanmandge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @ilkilic. LGTM now.

Highlighting this from the PR description in case we need to come back:

The default injected current range for a given rheobase changed. Old: [rheobase - 2, rheobase - 0.1] nA. New: [-rheobase, 0.9 * rheobase] nA.

@ilkilic
ilkilic merged commit 0927dbd into main Nov 6, 2026
9 checks passed
@ilkilic
ilkilic deleted the fix-iv-curve-current-range-scaling branch November 6, 2026 17:02
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.

2 participants