-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple_mat_to_npy.py
21 lines (20 loc) · 1.03 KB
/
simple_mat_to_npy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import numpy as np
from scipy.io import loadmat
def simple_mat_to_npy(file_name):
'''Convert a .mat file generated by Sources2D_to_simple_mat containing CNMFe
data into a folder of .npy files. The A matrix is reshaped such that neuron
footprints can be visualised with imshow(A[0]) etc.
(c) Thomas Akam 2019. GPL-3 open source licence.
'''
data = loadmat(file_name)
folder_name = data['file_name'][0].split('.')[0] + '_npy'
os.mkdir(folder_name)
# Reshape A to be size [n_neurons, image_y_dim, image_x_dim]
A = data['A'].toarray().reshape([*np.flip(data['image_size'][0]),-1]).transpose()
# Convert A from sparse matrix to numpy array.
S = data['S'].toarray()
np.save(os.path.join(folder_name, 'A') , A , allow_pickle=False)
np.save(os.path.join(folder_name, 'S') , S , allow_pickle=False)
np.save(os.path.join(folder_name, 'C') , data['C'] , allow_pickle=False)
np.save(os.path.join(folder_name, 'C_raw'), data['C_raw'], allow_pickle=False)