Skip to content

Propagate CaImAn quality metrics #1436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 29, 2025
Merged

Propagate CaImAn quality metrics #1436

merged 14 commits into from
Jul 29, 2025

Conversation

daphnedequatrebarbes
Copy link
Contributor

@daphnedequatrebarbes daphnedequatrebarbes commented Jul 14, 2025

Fix #1414 : propagate quality metrics and add multiplane stub files to testing.

@daphnedequatrebarbes daphnedequatrebarbes self-assigned this Jul 14, 2025
@h-mayorquin
Copy link
Collaborator

Hi, see comments on #1414 (comment) to see how to move forward with this. Feel free to reach me in slack for a call if things are not clear.

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

We discussed the following points on a meeting.

@@ -950,6 +980,12 @@ def _add_plane_segmentation(
data=is_id_rejected,
)

if include_quality_metrics and quality_metrics is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

default_descriptions = {"snr": "signal_to_noise_ratio_orwhatever", "other_property": "default_description}"

If your property is named like that then you used this description, otherwise, you use empty string or no description.

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

The CaImAn part is ready, we need the generic test now.

@@ -823,6 +843,7 @@ def add_plane_segmentation_to_nwbfile(
include_roi_acceptance=include_roi_acceptance,
mask_type=mask_type,
iterator_options=iterator_options,
quality_metrics=quality_metrics,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should call this segmentation_extractor_properties because it is not only quality metrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -950,6 +969,13 @@ def _add_plane_segmentation(
data=is_id_rejected,
)

# Always add quality metrics if they are available
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the default definitions should be here:

    quality_metrics_definitions = {
        "snr": "Signal-to-noise ratio for each component",
        "r_values": "Spatial correlation values for each component",
        "cnn_preds": "CNN classifier predictions for component quality",
    }

close to where they are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -536,6 +536,26 @@ def test_rejected_roi_ids(self, rejected_list, expected_rejected_roi_ids):
plane_segmentation_accepted_roi_ids = plane_segmentation["Accepted"].data
assert_array_equal(plane_segmentation_accepted_roi_ids, accepted_roi_ids)

def test_add_plane_segmentation_with_quality_metrics(self):
"""Test that available quality metrics in the segmentation extractor are added as columns to the PlaneSegmentation when available."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks fishy,
if & is intersection I think this test will always pass. or am I wrong?

Anyway, for these test here we have absolute control. Can you add some specific properties to the segmentation extractor here and test:

  1. that they are added
  2. their values match what we just added.

So just create a segmentation extractor, add properties with values that you control of various dtypes and check that they are written correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

LGTM

@daphnedequatrebarbes daphnedequatrebarbes marked this pull request as ready for review July 28, 2025 17:05
@h-mayorquin h-mayorquin merged commit 589501f into main Jul 29, 2025
30 of 32 checks passed
@h-mayorquin h-mayorquin deleted the add_caiman_interface branch July 29, 2025 16:43
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.06%. Comparing base (304691d) to head (91f52fe).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1436      +/-   ##
==========================================
+ Coverage   87.04%   87.06%   +0.01%     
==========================================
  Files         145      145              
  Lines        9681     9691      +10     
==========================================
+ Hits         8427     8437      +10     
  Misses       1254     1254              
Flag Coverage Δ
unittests 87.06% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...rfaces/ophys/basesegmentationextractorinterface.py 98.43% <ø> (ø)
...datainterfaces/ophys/caiman/caimandatainterface.py 100.00% <100.00%> (ø)
src/neuroconv/tools/roiextractors/roiextractors.py 91.52% <100.00%> (+0.20%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[Feature]: Propagate CaImAn quality metrics to PlaneSegmentation in NWB exports
2 participants