nel-lab / mesmerize-core

High level pandas-based API for batch analysis of Calcium Imaging data using CaImAn
Other
58 stars 15 forks source link

corr-pnr plot not accepting 'controllers' variable #282

Closed blogeman closed 6 months ago

blogeman commented 6 months ago

I'm getting an error when running the cnmfe.ipynb when trying to sync the threshold image widget with the corr-pnr plot: https://github.com/nel-lab/mesmerize-core/blob/74345ef336539b59b87a33025cb50302b876f6a4/notebooks/cnmfe.ipynb#L881

Specifically I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[36], line 18
     12 # sync the threshold image widget with the corr-pnr plot
     13 threshold_grid_plot_kwargs = {
     14     "controllers": [[iw_corr_pnr.gridplot["corr"].controller]*2]*2,
     15     "size": (650, 600)
     16 }
---> 18 iw_thres_movie = fpl.ImageWidget(
     19     mcorr_vids, 
     20     names=["over corr threshold", "over pnr threshold", "under corr threshold", "under pnr threshold"],
     21     # sync this with the corr-pnr plot
     22     grid_plot_kwargs=threshold_grid_plot_kwargs,
     23     cmap="gnuplot2"
     24 )
     26 # display threshold of the spatially filtered movie
     27 def spatial_filter(frame):

File [~\anaconda3\envs\GCAMP\lib\site-packages\fastplotlib\widgets\image.py:561](http://localhost:8888/lab/tree/~/anaconda3/envs/GCAMP/lib/site-packages/fastplotlib/widgets/image.py#line=560), in ImageWidget.__init__(self, data, dims_order, slider_dims, window_funcs, frame_apply, grid_shape, names, grid_plot_kwargs, histogram_widget, **kwargs)
    557 # update the default kwargs with any user-specified kwargs
    558 # user specified kwargs will overwrite the defaults
    559 grid_plot_kwargs_default.update(grid_plot_kwargs)
--> 561 self._gridplot: GridPlot = GridPlot(shape=grid_shape, **grid_plot_kwargs_default)
    563 for data_ix, (d, subplot) in enumerate(zip(self.data, self.gridplot)):
    564     if self._names is not None:

TypeError: GridPlot.__init__() got an unexpected keyword argument 'controllers'

Looking at the fastplotlib implementation of the Gridplot class it seems that it is not expecting to receive the variable 'controllers'. https://github.com/fastplotlib/fastplotlib/blob/5978e7d9f2727eb953a243780af92592dd6ad416/fastplotlib/layouts/_gridplot.py#L28

I tried substituting controllers with 'controller_types' and 'controller_ids' to check if these names changed with a version update and could be a simple swap but that resulted in errors as well. Commenting out the line allows the block to run but bottom portion of the plot is broken.

Any thoughts on whats going on here?

kushalkolar commented 6 months ago

See https://github.com/fastplotlib/fastplotlib/issues/425

For now I would just set the controller_ids to "sync", and manually set the controllers after creating the gridplots, something Iike:

gp[0, 0].controller = other_gp[0, 0].controller

I think that should work, if not you'll have to just use gridplots with independent controllers between them until the next release of fastplotlib.

blogeman commented 6 months ago

Thanks for looking into this @kushalkolar. I'm not very familiar with the construction of gridplots. Could you please provide a little more information about how to do this in the context of the cnmfe.ipynb notebook?

kushalkolar commented 6 months ago

Don't specify controllers and then do this after creating iw_thres_movie:

for subplot in iw_thres_movie.gridplot:
    subplot.controller = iw_corr_pnr.gridplot["corr"].controller

I think that should work

blogeman commented 6 months ago

That allows the code block to run but in the visualization the four panels generated from iw_thres_movie go black as soon as the play button is clicked. This is the same behavior as commenting out the line that defines the controllers. Not sure what to test since no error is generated but would be happy to attempt and implementations you might have.

kushalkolar commented 6 months ago

They're black because no pixels are above the corr and pnr thresholds when you create the plot :)

Change the corr and pnr thresholds (adjust the vmin using the histogram tool on the right of each Subplot) and reset the vmin vmax of the threshold plots

On Thu, Mar 7, 2024, 06:42 Brandon Logeman @.***> wrote:

That allows the code block to run but in the visualization the four panels generated from iw_thres_movie go black as soon as the play button is clicked. This is the same behavior as commenting out the line that defines the controllers. Not sure what to test since no error is generated but would be happy to attempt and implementations you might have.

— Reply to this email directly, view it on GitHub https://github.com/nel-lab/mesmerize-core/issues/282#issuecomment-1983332290, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACHXXRGK57OPF5AQRFH32F3YXBHATAVCNFSM6AAAAABEJLU4PCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBTGMZTEMRZGA . You are receiving this because you were mentioned.Message ID: @.***>

blogeman commented 6 months ago

Oh got it now, thanks.