yves-weissenberger / twoptb

Python toolbox for analysing data from two photon imaging experiments
0 stars 1 forks source link

saving ROI dict to mat file #19

Open samupicard opened 6 years ago

samupicard commented 6 years ago

The routine I wrote for saving python dictionaries as .mat data structures doesn't work anymore since I've started doing automatic ROI detection.

I suspect that it might have something to do with the format in which the variables are saved when extracting traces. When the ROIs are drawn by hand, the traces are saved as a list, whereas when they're drawn automatically they're saved as a numpy array (at least that's what the command prompt shows).

E.g. when pressing 'Extract trace' in the PyQtGraph ROI Drawer: ... extracting trace 101
<type 'numpy.ndarray'>
extracting trace 102
<type 'list'>
...

I'm not sure whether this is something that can be changed, but if so it'd be great to see whether it solves my problem too!

yves-weissenberger commented 6 years ago

Since that code isn't part of the main pipeline (... ;) ) its hard to say. If you want to go in manually with any numpy array you can convert it to a list by simply calling the tolist() function i.e.

a = np.array([1,2,3,4]).tolist()
type(a)

returns list. This is all I can say without seeing the code. Does that help?

samupicard commented 6 years ago

Thanks! I'll give it a shot and will get back to you

Just to be clear, what i copy-pasted does come from the main pipeline: traces seem to be extracted as lists or as arrays depending on whether the ROIs were manual or automatic. Which is why i thought it was worth flagging it up :)

samupicard commented 6 years ago

Actually I just saw that you added this to the PyQtGraph_ROI_Drawer code on line 673-678... wouldn't that make sure all traces are always saves as lists anyway?

            for i in range(self.nROIs):
                print type(self.ROI_attrs['centres'][i])
                if type(self.ROI_attrs['centres'][i])!=type(None):
                    print 'extracting trace %s' %i
                    self._extract_trace(i)
            self.ROI_attrs['traces'] = self.ROI_attrs['traces'].tolist()
samupicard commented 6 years ago

I think I found the issue: the 'patches' field in the ROI dictionary is nan when the ROI was automatically drawn while it's a two-dimensional array when the ROI is manually drawn..?