8000 Adding quilt viewer to visualize how FOV is broken up into patches by EricThomson · Pull Request #1156 · flatironinstitute/CaImAn · GitHub
[go: up one dir, main page]

Skip to content

Adding quilt viewer to visualize how FOV is broken up into patches #1156

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 3 commits into from
Aug 25, 2023

Conversation

EricThomson
Copy link
Contributor
@EricThomson EricThomson commented Aug 19, 2023

Description

Adds functionality to visualize overlapping patches that split up field of view for motion correction and cnmf for parellelization. Useful when picking different spatial parameters (rf/stride/gSig/gSiz for 8000 cnmf, and strides/overlaps for motion correction).

Thanks to @kushalkolar (mesmerize) for idea of quilt name, as patches is already used for viewing spatial contours.

Fixes #1116

Type of change

  • New feature (non-breaking change which adds functionality)

Has your PR been tested?

I ran the tests there are no new errors introduced in dev branch. I have tested the plotting functionality fairly extensively, have not yet added new tests to caiman/tests

@EricThomson
Copy link
Contributor Author
EricThomson commented Aug 19, 2023

Note the natural names for these are patches: in the paper and code we talk about splitting the FOV into patches with stride and overlap. Unfortunately there are already a bunch of patch plotting functions that are for plotting contours of spatial components. Luckily mesmerize had a great name for it: quilt!

I have to admit I just recently turned the corner on type hinting because of @pgunn . A couple of notes: I went ahead and used Any for matplotlib graphics objects until support for mypy is a little more mature in matplotlib. E.g., see:

matplotlib/matplotlib#20504
matplotlib/matplotlib#24976

In particular, eventually we'll want to replace Any in rect_draw() to be clear that takes in plt.Axes, returns (plt.Axes, matplotlib.patches.Rectangle)

For array-like things numpy's ArrayLike is great, but currently throws an error when you try to specify types such as ArrayLike[int]. There should be support for this eventually (note those issues are worth reading for entertainment value alone):
beartype/beartype#42 (comment)
beartype/beartype#212

col_minmax: array-like
[col_min, col_max] -- int bounds for rect cols
color : string
rectangle color, default 'yellow'
Copy link
Member

Choose a reason for hiding this comment

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

Can we stick a link in here indicating what colours are valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I shouldn't have specified string there. Any Matplotlib color specification, e.g., rgb tuple or list, or string 'red' is fine (https://matplotlib.org/stable/tutorials/colors/colors.html). I should probably just put Any for this, and be more clear in docs.

rectangle color, default 'yellow'
alpha : float
rectangle alpha (0. to 1., where 1 is opaque), default 0.3
ax : pyplot.Axes object
Copy link
Member

Choose a reason for hiding this comment

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

Eventually we'll want to add proper typing for this, but no rush

"""
Plot patches on template image given stride and overlap parameters.

Given stride and overlap, plot overlapping patch blocks on template image.
Copy link
Member

Choose a reason for hiding this comment

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

Seems to have some redundancy between the 1-sentence and longer description; is this because some tool treats those as separate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is sort of silly. I can just combine them.

row x col summary image upon which to draw patches (e.g., correlation image)
stride (int) stride between patches in pixels
overlap (int) overlap between patches in pixels
color (str): color of patches, default 'white'
Copy link
Member

Choose a reason for hiding this comment

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

probably no need to mention default when it's visible in params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is debated all over the place. I've noticed in our code we have it in both places, so I've done this too. But it is a maintenance headache and is asking for trouble/inconsistencyes. Happy to stop doing it moving forward.

Copy link
Member

Choose a reason for hiding this comment

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

It's not really a big deal either way, it's just another thing to maintain if it changes in one place.

alpha: Optional[float]=0.3,
vmin: Optional[float]=0.0,
vmax: Optional[float]=0.6,
figsize: Optional[Tuple]=(6,6)) -> Any:
Copy link
Member

Choose a reason for hiding this comment

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

Is this Optional[Tuple[float,float]] or Optional[Tuple[int,int]]?

The default seems to disagree with the comment section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixing (it's float,float)

axes object upon which rectangle will be drawn, default None

Returns:
ax (Axes object)
Copy link
Member

Choose a reason for hiding this comment

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

If we don't want to specify types for these, can we say a little bit more about what we expect them to be? matplotlib.axes?

ax (Axes object)
rect (Rectangle object)
"""
from matplotlib.patches import Rectangle
Copy link
Member

Choose a reason for hiding this comment

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

Imports don't go in methods/functions; please move this to the head of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing

@pgunn pgunn merged commit 03ed18c into flatironinstitute:dev Aug 25, 2023
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
0