Match T4/T5 tuning metrics to ground truth by cell type - #28
Open
marisbasha wants to merge 1 commit into
Open
marisbasha wants to merge 1 commit into
marisbasha wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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
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.