Open QNeuron opened 6 years ago
OK actually I explored a little more, and found out that for the files that could not be converted, there are some NaN values in the 'patches' entry. So when trying to save, the function finds a NaN instead of an array, and fails.
The problem is that these nan values are replacing patches missing in the pickle file. On that particular file I expected 74 ROIs, and I have 17 nans and 57 actual patches. So, how can I correct that ? I already tried to run extract_traces.py again, but it did not help...
When are the patches generated ? And actually, what are they ? A chunk of the mean stack ?
Just saw this @QNeuron, and I had the same issue yesterday. It turns out that for the ROIs that were automatically selected (using 'run_classifier') the 'patches' entry is just a single NaN tuple (instead of the 30-by-30-ish 2D array that it would be if you'd drawn the ROI yourself.
As a work-around I've written this piece of code wherever I save to mat-file so any nan-values are always converted to a 2-by-2 array of nans. (You might have solved this issue already but I thought I'd post my workaround just in case it's still a problem)
for idx, val in enumerate(roiattrs['patches']): if np.any(np.isnan(val)): roiattrs['patches'][idx] = np.array([[np.nan,np.nan],[np.nan,np.nan]])
Thanks @samupicard . My workaround was to ignore the patches, I don't use them in my analysis anyway ^^.
But I am still wondering what should be the proper behaviour for the code ? Why would you expect NaNs when the ROIs are automatically sorted ?
Yep, it's not directly related to the toolbok, but I know you love the issue system better than emails :-)
So I am trying to convert the piclke files to mat files using the following instructions :
data = pickle.load(open(os.path.join(root,f), "rb" )) scipy.io.savemat(os.path.join(root,fnew), mdict={'data': data})
The problem is that for some of the ROI files the savemat fails, and I don't see any difference between .p files that works and .p files that don't. I have tried to change the .p files by adding a ROI and re-doing the trace extraction, but no luck.
Any help or idea would be appreciated, I am reaching the limits of my googling abilities here...
Content of the pickle file (same for files that can be converted or not): patches <type 'list'> masks <type 'list'> idxs <type 'list'> centres <type 'list'> corr_traces <type 'numpy.ndarray'> raw_traces <type 'numpy.ndarray'> dfF <type 'numpy.ndarray'> traces <type 'numpy.ndarray'> neuropil_traces <type 'numpy.ndarray'>
error message:
ValueError Traceback (most recent call last)