Motion Correction Error Help

31 views
Skip to first unread message

Alisa Omelchenko

unread,
Nov 5, 2019, 5:24:26 PM11/5/19
to sima-users
Hello,

I am trying to use the SIMA package for my calcium imaging data. The data comes out as a tif image for each slice and time point (total 1320 images). There are 15 slices in each stack, and 88 time points so I used Matlab to combine the separated images into 88 stacks. 

When I try to do motion correction for a singular stack, I get an error. I am following the tutorial. Are my images not properly formatted or what would be the reason I would be receiving the error. I can send a stack created through the imread append function in Matlab through google drive since it's too big to attach here. Thank you very much for your help!

This is the code I am running:

sequences = [sima.Sequence.create('TIFF', 'stack1.tif')]
dataset = sima.ImagingDataset(sequences, 'stack1_TIFF.sima')

print("Running motion correction.")
mc_approach = sima.motion.HiddenMarkov2D(granularity='row', max_displacement=[20, 30], verbose=False)
corrected = mc_approach.correct(sequences, dataset, trim_criterion=0.95)
Running motion correction.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-65-7f654352bfd4> in <module>
     14 print("Running motion correction.")
     15 mc_approach = sima.motion.HiddenMarkov2D(granularity='row', max_displacement=[20, 30], verbose=False)
---> 16 dataset = mc_approach.correct(sequences, dataset, trim_criterion=0.95)

~/.local/lib/python3.6/site-packages/sima/motion/motion.py in correct(self, dataset, savedir, channel_names, info, correction_channels, trim_criterion)

~/.local/lib/python3.6/site-packages/sima/motion/motion.py in estimate(self, dataset)

~/.local/lib/python3.6/site-packages/sima/motion/hmm.py in _estimate(self, dataset)

~/.local/lib/python3.6/site-packages/sima/motion/hmm.py in _estimate_shifts(self, dataset)

~/.local/lib/python3.6/site-packages/sima/motion/motion.py in estimate(self, dataset)

~/.local/lib/python3.6/site-packages/sima/motion/frame_align.py in _estimate(self, dataset)

~/.local/lib/python3.6/site-packages/sima/motion/frame_align.py in _frame_alignment_base(dataset, max_displacement, method, n_processes)

~/.local/lib/python3.6/site-packages/sima/motion/frame_align.py in _align_frame(inputs)

~/.local/lib/python3.6/site-packages/sima/motion/frame_align.py in _update_reference(sums, counts, offset, displacement, image)

~/.local/lib/python3.6/site-packages/sima/motion/frame_align.py in _resize_array(array, displacement, frame_shape)

ValueError: operands could not be broadcast together with shapes (3,) (4,) 

Alisa Omelchenko

unread,
Nov 8, 2019, 10:34:21 AM11/8/19
to sima-users
Quick edit, the code used to use dataset instead of the corrected variable. I changed it because I thought it was confusing but forgot to rerun the error. 

Alisa Omelchenko

unread,
Nov 16, 2019, 1:00:36 PM11/16/19
to Jeff Zaremba, sima-users
Hey Jeff! 

Thank you for your quick reply! I changed the sequences to what you suggested and added a path to be saved, and I get the same error.

ValueError: operands could not be broadcast together with shapes (3,) (4,)

I’m not sure why.

This is the new code that I am running:

save_path = "stack1_corrected.tif"
sequences = [sima.Sequence.create('TIFF', 'stack1.tif', num_planes= 15)]
dataset = sima.ImagingDataset(sequences, 'stack1_TIFF.sima')

print("Running motion correction.")
mc_approach = sima.motion.HiddenMarkov2D(granularity='row', max_displacement=[20, 30], verbose=False)
corrected = mc_approach.correct(dataset, save_path, trim_criterion=0.95)


Do you have any other suggestions?

Thank you for your help!
Alisa

On Nov 11, 2019, at 12:07 AM, Jeff Zaremba <jzar...@pm.me> wrote:

Hi Alisa,

I'm not entirely sure what lead to that specific broadcast error, but i do have two suggestion that may help.

For interleaved TIFF data, you need to specify the number of planes in your data (see https://github.com/losonczylab/sima/blob/0b16818d9ba47fe4aae6d4aad1a9735d16da00dc/sima/sequence.py#L366) when you call sima.Sequence.create, so
sequences = [sima.Sequence.create('TIFF', 'stack1.tif', num_planes=15)]

Also, motion correction errored out before it tired to save, but the second argument to mc_approach.correct should be a path to save the corrected dataset to. That first ImagingDataset you create you don't really need, though it lets you see the raw data in the sima format.

Hope this helps!
Best,
Jeff



‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
--
You received this message because you are subscribed to the Google Groups "sima-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sima-users+...@googlegroups.com.


Reply all
Reply to author
Forward
0 new messages