Skip to content
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

Find centre of rotation #24

Closed
wants to merge 60 commits into from
Closed

Conversation

lauraporta
Copy link
Member

@lauraporta lauraporta commented Sep 19, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
See #12

What does this PR do?

Creates methods and pipeline to find the centre of rotation in the incremental dataset.

⚠️ It does not fix the wobbling issues. The pipeline works well with simulated data but worsens the real datasets.

Pipeline

Find the centre

Find the centre of rotation using the incremental rotations datasets, in which the sample was rotated at discrete angles with 10deg intervals. Centre of rotation is found by fitting an ellipse to the brightest ROI location at each of the 10deg configurations.
New methods include:

  • find_center_of_rotation
  • get_coords_of_largest_blob
  • plot_blob_detection
  • fit_ellipse_to_points
  • plot_ellipse_fit_and_centers

ellipse_fit

max_projection_with_center

Use the new centre

In order to use the new centre of rotation, the derotate_an_image_array_line_by_line needed to be totally rewritten. I am discarding the usage of scipy.ndimage.rotate and using classic linear algebra to rotate the matrices. With this new implementation the derotation is so much faster! 🚀

How has this PR been tested?

The performance of the de-rotation when the centre of rotation is shifted has been tested with simulated data generated by the class Rotator.

I created a stepwise array of angles to imitate the incremental rotation dataset, and a sinusoidal array as the main experimental session dataset.
rotation_angles

I then rotated a sample image that has two blobs that imitate two ROIs (one brighter than the other).
test_image

Ellipse fit works well with a shifted centre:
ellipse_fit

And derotation works smothly. This is the proof that in principle my derotation with shifted centres works.

I added tests to cover this new functionality and the pipeline.

Is this a breaking change?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@lauraporta lauraporta linked an issue Sep 19, 2024 that may be closed by this pull request
… feature - also make separate module for hooks
@lauraporta lauraporta changed the base branch from feature/rotator to main October 3, 2024 15:20
@lauraporta lauraporta marked this pull request as ready for review October 3, 2024 15:24
@lauraporta lauraporta marked this pull request as draft October 3, 2024 15:24
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 65.42553% with 65 lines in your changes missing coverage. Please review.

Project coverage is 44.33%. Comparing base (3e797a4) to head (3f631bf).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...tation/analysis/incremental_derotation_pipeline.py 51.48% 49 Missing ⚠️
derotation/analysis/full_derotation_pipeline.py 26.31% 14 Missing ⚠️
derotation/derotate_by_line.py 93.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #24       +/-   ##
===========================================
+ Coverage   20.39%   44.33%   +23.94%     
===========================================
  Files          12        6        -6     
  Lines         760      636      -124     
===========================================
+ Hits          155      282      +127     
+ Misses        605      354      -251     

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

@lauraporta lauraporta marked this pull request as ready for review October 4, 2024 10:37
@lauraporta
Copy link
Member Author

lauraporta commented Oct 24, 2024

Improve tests, suggestions from @JoeZiminski in #25 :

  • explain better the strategy of regression tests. Comments 1, 2
  • path of the pre-computed images. Comments 3
  • naming of the images. Comments 4
  • expand tests on Rotator constructor. Comments 5
  • move fixtures to conftest.py. Comments 6
  • more notes on why did I made certain choices. Comments 7

@lauraporta lauraporta changed the base branch from main to dev October 24, 2024 16:03
@lauraporta lauraporta changed the base branch from dev to main October 24, 2024 16:04
@lauraporta
Copy link
Member Author

Two dot diff with current state of main

1,674 additions and 318 deletions

@lauraporta lauraporta changed the base branch from main to feature/rotator November 15, 2024 13:46
@lauraporta lauraporta changed the base branch from feature/rotator to main November 15, 2024 13:52
@lauraporta
Copy link
Member Author

Easier to solve conflicts through a new branch and new PR -> #30

@lauraporta lauraporta closed this Nov 15, 2024
@lauraporta lauraporta deleted the feature/finding-centre-of-rotation branch November 15, 2024 23:13
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.

Find optimal centre of rotations
1 participant