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

Question/ issue: Does mesmerise-core work with 3D movies? #312

Open
rajlakshmi-sawale opened this issue Aug 22, 2024 · 29 comments
Open

Question/ issue: Does mesmerise-core work with 3D movies? #312

rajlakshmi-sawale opened this issue Aug 22, 2024 · 29 comments

Comments

@rajlakshmi-sawale
Copy link

Hi, does mesmerise-core work with 3D movies? I tried to run it with my xyzt data but the mcorr failed. Any help would be appreciated!
Thanks!

@rajlakshmi-sawale rajlakshmi-sawale changed the title Does mesmerise-core work with 3D movies? Question/ issue: Does mesmerise-core work with 3D movies? Aug 22, 2024
@ethanbb
Copy link
Collaborator

ethanbb commented Aug 22, 2024

Hi @rajlakshmi-sawale, is it failing at the local correlations step? If so, #300 is meant to address this, but it hasn't been merged yet.

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 22, 2024

OK I just merged that PR; can you try again after installing from the master branch? You will also need caiman version 1.11.2 or later.

@rajlakshmi-sawale
Copy link
Author

rajlakshmi-sawale commented Aug 22, 2024

Hi @ethanbb, Thanks for the quick reply!
I'm not sure where it is failing.. I have attached what I see.. Sorry, I might not be running it in the right way in the first place as I am very new to this.
image

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 22, 2024

Yup, that looks normal, it ran into an error while running but it didn't tell you exactly what it is.

What does it show if you run print(df.iloc[-1, :].outputs['traceback'])?

@rajlakshmi-sawale
Copy link
Author

This: image

@rajlakshmi-sawale
Copy link
Author

To run it on 3D data, do we have to specify any additional parameters?
The only thing I changed so far in the provided notebook for 2D data was in this section:

# We will start with one version of parameters mcorr_params1 =\ { 'main': # this key is necessary for specifying that these are the "main" params for the algorithm { 'max_shifts': [5, 5, 2], 'strides': [24, 24, 6], 'overlaps': [12, 12, 2], 'max_deviation_rigid': 3, 'border_nan': 'copy', 'pw_rigid': True, 'gSig_filt': None }, }

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 22, 2024

Oh ok you might need to use a different index than -1. If you just print the df you should be able to see which row corresponds to the failed run ("outputs" should be a dict with "success": False) and then you can use that index.

@rajlakshmi-sawale
Copy link
Author

rajlakshmi-sawale commented Aug 22, 2024

image

@kushalkolar
Copy link
Collaborator

The traceback in the output doesn't have to be accessed manually, you can call get_output() and it will print the traceback nicely:

df.iloc[i].mcorr.get_output()

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 22, 2024

Ah, I think you also have to set is3D to true in your params['main'].

@rajlakshmi-sawale
Copy link
Author

Hi, I re-installed it and got this error:
image

@kushalkolar
Copy link
Collaborator

Reload the dataframe from disk after running an item

@rajlakshmi-sawale
Copy link
Author

image

@kushalkolar
Copy link
Collaborator

The message says you're out of RAM. What are the dimensions of the movie? How many pixels do you have per neuron/ROI? What's your temporal sampling rate? Can you post a mean projectiom of some of the planes.

@rajlakshmi-sawale
Copy link
Author

It is 259,1024,28 with 1200 frames at 2 volumes per second. The neurons are approx 100-130 pixels.
MAX_avg

@kushalkolar
Copy link
Collaborator

kushalkolar commented Aug 27, 2024 via email

@rajlakshmi-sawale
Copy link
Author

128 GB

@kushalkolar
Copy link
Collaborator

kushalkolar commented Aug 27, 2024 via email

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 27, 2024

I agree, reduce number of processes by setting the MESMERIZE_N_PROCESSES environment variable. That way it will not try to process as many chunks at a time and will use less memory.

Also, maybe you already did this, but in movies.py the function to3DFromPixelxTime should look like this:

def to3DFromPixelxTime(self, shape, order='F') -> 'movie':
    """
    Transform 2D movie (pixels x time) into 3D or 4D
    """
    return to_3D(self,shape[::-1],order=order).T

If not, you need to update your version of caiman.

@rajlakshmi-sawale
Copy link
Author

Yes, the to3DFromPixelxTime function is as expected. After reducing the number of processes it gave this:
image

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 29, 2024

Oh interesting, I'm guessing I missed this because I only tried rigid 3d mcorr. Can take a look later today.

@ethanbb
Copy link
Collaborator

ethanbb commented Aug 29, 2024

Yeah, sorry, the 3D mcorr PR had a bug which wasn't caught since I didn't add tests for both the rigid and piecewise cases.

Can you change line 115 of mesmerize_core/algorithms/mcorr.py from
shifts += mc.z_shifts_els
to
shifts.append(mc.z_shifts_els)
and see if it works now? If so I'll make a follow-up PR.

@rajlakshmi-sawale
Copy link
Author

That worked! But now there seems to be some mismatch in dimensions for the visualisation..
image

@kushalkolar
Copy link
Collaborator

Thanks for hanging in there!
Mesmerize-viz is pinned to a much older fastplotlib that's quite limited, we don't have the resources right now to update mesmerize-viz. You'll have to get the latest release of fastplotlib and use the ImageWidget to view your results, it's just a few lines rather than a one-liner that mesviz provides. ImageWidget examples are here: https://github.com/fastplotlib/fastplotlib/blob/main/examples/notebooks/image_widget.ipynb

@rajlakshmi-sawale
Copy link
Author

Okay, thanks!

@rajlakshmi-sawale
Copy link
Author

Hi, the visualization worked. Thanks for creating this amazing tool! I am now trying to run the CNMF but got this error..
image
Any suggestions?

@ethanbb
Copy link
Collaborator

ethanbb commented Sep 3, 2024

Glad you're making progress! I believe this error is because you need to provide gSig as a 3-element list for 3D CNMF. The same is true for rf and stride in the patch group, if you're using patches. And finally you will have to disable the CNN by setting use_cnn in the quality group to False.

@rajlakshmi-sawale
Copy link
Author

rajlakshmi-sawale commented Sep 3, 2024

What about this?
image

@ethanbb
Copy link
Collaborator

ethanbb commented Sep 3, 2024

I'm not sure, I haven't run into that one - you should try debugging it. It looks like at least one of the patch runs is giving an S of None when that's not expected. You can try to see why that's happening by setting a conditional breakpoint somewhere in CNMF.fit, for example. My guess would be that some of your patches are invalid in some way (empty?) and that tweaking your patch settings may fix it (but this is still a bug in caiman, probably).

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

No branches or pull requests

3 participants