Skip to content

Match T4/T5 tuning metrics to ground truth by cell type - #28

Open
marisbasha wants to merge 1 commit into
TuragaLab:mainfrom
marisbasha:fix/tuning-metrics-cell-type
Open

marisbasha wants to merge 1 commit into
TuragaLab:mainfrom
marisbasha:fix/tuning-metrics-cell-type

Conversation

@marisbasha

Copy link
Copy Markdown

Summary

correlation_to_known_tuning_curves and angular_distance_to_known compare each T4/T5 cell with the known tuning by position rather than by cell type. time_window also fails on a floating point comparison for some edge offsets.

Changes

Tuning curve correlation

The selected T4/T5 cells were correlated with the known tuning curves in the fixed order T4a..T5d. The data keeps its own neuron order, so any other order (a custom connectome, a cell_index subset, isel or sortby) correlated a cell with another type's curve. The ground truth is now built in the order of the selected cells. With the default connectome the result is unchanged.

Preferred direction distance

angular_distance_to_known zipped the selected cells with a fixed list of four angles, with the same assumption. It now looks up each cell type in groundtruth_utils.preferred_directions, which holds the same angles.

time_window assertion

time_window asserts abs(end_in_columns) >= abs(to_column). With the default to_degree of peak_responses, (offsets[1] - 1) * 2.25, both sides are equal in exact arithmetic but can differ in the last bit. So peak_responses, direction_selectivity_index and preferred_direction raised a bare AssertionError for edge offsets ending at 12, 16 or 19, such as (-10, 12), (-11, 12) or (-12, 16). The default offsets (-10, 11) are not affected. The difference is at most 9e-16, and the comparison now allows 1e-9.

Testing

New tests/test_moving_bar_responses.py builds a synthetic moving-edge dataset in which the eight central T4/T5 cells respond with their published tuning curves. Both metrics are checked on the original neuron order and with T4a and T4b swapped, and peak_responses is run for the three offsets above. All five tests fail on main (correlation -0.4 instead of 1 for the swapped cells, angular distances near pi, AssertionError) and pass with the change.

I also scored the moving edge responses of the pretrained model flow/0000/000. With the default neuron order, correlation_to_known_tuning_curves, angular_distance_to_known and direction_selectivity_index are bit-identical to main. With the neuron order reversed, the branch gives the same value for each cell type. Main returns the correlations without the cell_type coordinate, each against another type's curve: for T4a at ON edges, -0.24 instead of 0.95.

Full suite (-m "not require_download and not require_large_download and not gpu", test_examples.py and test_sintel.py excluded): 196 passed, 12 skipped on main; 201 passed, 12 skipped on the branch. require_download tests against the pretrained models: 21 passed on both. tests/test_sintel.py, run offline with the mock data: 14 passed on both. ruff check and ruff format (0.5.5) are clean on the changed files.

Tuning curve correlation: correlation_to_known_tuning_curves paired the
selected T4/T5 cells with the known tuning curves by position, assuming the
data lists them as T4a..T5d. Any other neuron order (a custom connectome, a
cell_index subset, isel or sortby) correlated cells with another type's curve.
The ground truth is now built in the order of the selected cells.

Preferred direction distance: angular_distance_to_known zipped the selected
cells with a fixed list of four angles, with the same assumption. It now looks
up each cell type in groundtruth_utils.preferred_directions, which holds the
same angles.

Time window: time_window asserted abs(end_in_columns) >= abs(to_column) on two
values that are equal for the default to_column but can differ in the last bit.
peak_responses, direction_selectivity_index and preferred_direction raised a
bare AssertionError for edge offsets such as (-10, 12) or (-12, 16). The
comparison now allows for rounding.

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The targeted fixes are consistent with existing data structures and are adequately covered by regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Aligns T4/T5 tuning metrics with cell-type coordinates and tolerates harmless floating-point error in time-window bounds.

Changes:

  • Builds ground-truth curves in selected neuron order.
  • Looks up preferred directions by cell type.
  • Adds regression tests for reordered neurons and edge offsets.
File Description
flyvis/​analysis/​moving_bar_responses.py Fixes metric alignment and time-window tolerance.
tests/​test_moving_bar_responses.py Adds synthetic regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.93%. Comparing base (92b3845) to head (e93f038).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   38.68%   39.93%   +1.24%     
==========================================
  Files          75       75              
  Lines        9738     9739       +1     
==========================================
+ Hits         3767     3889     +122     
+ Misses       5971     5850     -121     
Flag Coverage Δ
unittests 39.93% <100.00%> (+1.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

This branch has not been deployed

No deployments
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