Re: How can I visualize signals from the csv file which generated using dataset.export_signals

75 views
Skip to first unread message
Message has been deleted

Jeff Zaremba

unread,
May 16, 2015, 10:55:56 PM5/16/15
to sima-...@googlegroups.com
Hi Yu,

ImagingDataset.export_signals() is designed to help people get the raw signals out of SIMA and out of Python, for analysis in some other software package. If you want to continue your analysis with Python you don't actually need to export signals to a csv, but can directly reference ImagingDataset.signals() as follow:

import matplotlib.pyplot as plt
import sima

path = '/path/to/sima/folder.sima'
extract_label = 'soma'

dataset = sima.ImagingDataset.load(path)

signals = dataset.signals()[extract_label]['raw']

# signals is now a list of numpy arrays, 1 array per sequence
len(signals) == len(dataset.sequences)
> True

# signals[0] is now an n_rois by n_frames array

# Plot the time series of the first ROI for the first sequence
plt.plot(signals[0][0, :])
plt.show()  # Might be unecessary, depends on how you have matplotlib set up

I also realized we haven't actually documented the csv export format very well, so I'll get that updated as well.

Let us know if this helps,

Jeff


Yu Peng

unread,
May 17, 2015, 1:41:29 PM5/17/15
to sima-...@googlegroups.com
Hi Jeff,
Thank you for your reply, yes I tried this method before but nothing showed on my plot.
I used HMM2D to correct motion and STICA to segment.
I am sure have no problem creating the imagingdataset so I did not attache the raw data here.
Attached is my python code for each stage, the data.sima is the imagingdataset from raw data which is generated by create.py
the corrected one and segmented one are large so I add a link here.corrected_data
Thank you very much
Yu
create.py
motioncorrection.py
segmentation.py
extract_green.py
visualize.py
0512-1data.sima.rar

Jeff Zaremba

unread,
May 19, 2015, 5:22:40 PM5/19/15
to sima-...@googlegroups.com
It looks like your data should be (1000, 1, 323, 431, 2) (frames, planes, rows, columns, channels), is that right?

In order to initialize a dataset from individual TIFF files, you'll want to use the 'TIFFs' sequence format instead of 'TIFF', which is for a (frame, plane, channel) interleaved TIFF stack.

In your specific example, this should work:

tiff_filenames = [[
    'TSeries-05122015-0947-051_Cycle00001_Ch{n1}_*.ome.tif'.format(n1=channel)
    for channel in range(3,5)]]

assert len(tiff_filenames) == 1  # planes
assert len(tiff_filenames) == 1000  # frames

sequences = [sima.Sequence.create('TIFFs', tiff_filenames)]

assert len(sequences) == 1  # 1 sequence (iteration/trial)
assert sequences[0].shape[0] == 1000  # frames
assert sequences[0].shape[1] == 1  # planes
assert sequences[0].shape[4] == 2  # channels

The rest of your scripts should work from this point.

Yu Peng

unread,
May 19, 2015, 5:43:53 PM5/19/15
to sima-...@googlegroups.com
Thank you Jeff, sorry I am new to imaging data analysis, I will have a try!

Jeff Zaremba

unread,
May 19, 2015, 5:58:54 PM5/19/15
to sima-...@googlegroups.com
No problem. We realized that the documentation is not particularly clear on the distinction between the difference Sequence formats, we'll try to improve that.

Let me know how it works.

Yu Peng

unread,
May 20, 2015, 12:09:27 AM5/20/15
to sima-...@googlegroups.com
I got an error when I used hmm2D for motion correction. Does this mean that I cannot apply hmm2D method?
Thank you very much!


Estimating model parameters.

Traceback (most recent call last):
  File "C:\Users\Yu\Desktop\motioncorrection.py", line 13, in <module>
    trim_criterion=0.95)
  File "G:\python264\lib\site-packages\sima\motion\motion.py", line 116, in correct
    displacements = self.estimate(sima.ImagingDataset(mc_sequences, None))
  File "G:\python264\lib\site-packages\sima\motion\motion.py", line 59, in estimate
    shifts = self._estimate(dataset)
  File "G:\python264\lib\site-packages\sima\motion\hmm.py", line 423, in _estimate
    raise Exception('Failed to estimate positive gains')
Exception: Failed to estimate positive gains

Patrick Kaifosh

unread,
May 20, 2015, 11:01:32 AM5/20/15
to sima-...@googlegroups.com
Most likely this results from an improperly formatted sequences. Can you please check that the sequences have the correct shape? Also, each time that you report a traceback, it's helpful to include the exact code that you ran to create that traceback. Thanks.
Reply all
Reply to author
Forward
0 new messages