Beispiel #1
0
behaviour = np.load(behaviour_dir + beh_file_name_1)
#c = np.linspace(0, 20, len(behaviour))
neural_activity_new = []
testing = []
reshape_behaviour = np.reshape(
    behaviour[:int(int(behaviour.shape[0] / re_sf) * re_sf)],
    (int(behaviour.shape[0] / re_sf), re_sf))
resample_beh1 = np.reshape(
    scipy.stats.mode(reshape_behaviour, axis=1)[0], reshape_behaviour.shape[0])
resample_timeline = timeline_1 / re_sf

#%%pca
cov_matrix1 = stats.cov_matrix(neural_activity=neural_activity1)
eigenvalues1, eigenvectors1 = stats.compute_PCA(corr_matrix=cov_matrix1)
proj1 = stats.PCA_projection(neural_activity=neural_activity1,
                             eigenvalues=eigenvalues1,
                             eigenvectors=eigenvectors1,
                             n_components=n_components)
#%% plot eigendecomposition
pca_descop_fig_path =  os.environ['PROJECT_DIR'] +'neural_analysis/data/process/figures/pca_eigendecomposition_mouse_'+\
f'{mouse}' +'_session_'+f'{session}_binsize_'+f'{re_sf}'+'.png'
figs.plot_pca_decomposition(eigenvalues = eigenvalues1, eigenvectors = eigenvectors1, n_components = n_components,\
                            title = task , path_save = pca_descop_fig_path)
#%% plot projection
pca_fig_path =  os.environ['PROJECT_DIR'] +'neural_analysis/data/process/figures/pca_mouse_'+\
f'{mouse}' +'_session_'+f'{session}_binsize_'+f'{re_sf}'+'.png'
figs.plot_pca_projection(projection=proj1, title=task, path_save=pca_fig_path)

#%%
## LOAD BEHAVIOUR
behaviour = np.load(behaviour_dir + beh_file_name_1)
c = np.linspace(0, 20, len(behaviour))
Beispiel #2
0
        if i%2 == 0:
            color = 'b'
        axes.plot(np.arange(0,min_time_step)/10,c_activity_trial[i], color = color)
    axes.set_xlabel('t [s]')
    axes.set_yticks([])
    axes.set_ylabel('trial')
    figure_name = figure_directory + 'trials/mouse_56165_session_1_cell' + f'{j}'+ '.png'
    figure.savefig(figure_name)


### do analysis corr, PCA and correlate with behaviour

neural_activity = activity[1:,:]
corr_matrix = stats.corr_matrix(neural_activity = neural_activity)
eigenvalues, eigenvectors = stats.compute_PCA(corr_matrix = corr_matrix)
proj2 = stats.PCA_projection(neural_activity=neural_activity, eigenvalues=eigenvalues,
                            eigenvectors=eigenvectors, n_components=6)


PROJECT_DIR = '/home/sebastian/Documents/Melisa/calcium_imaging_behaviour/'
directory = PROJECT_DIR + '/data/scoring_time_vector/'
file_name = 'mouse_56165_events_2.npy'
behaviour = np.load(directory + file_name)

elements2 = []
for i in range(6):
    elements2.append(proj2[:,np.where(behaviour == i)])


elements = elements1
fig1 = plt.figure()
axes = fig1.add_subplot(1, 2, 1, projection='3d')
Beispiel #3
0
                                                                                    re_sf=re_sf)

#%%
## load behavioural file, downsample it and separate different parts of the experiment
behaviour = np.load(behaviour_dir + beh_file_name)
# resample neural activity and behavioural vector
reshape_behaviour = np.reshape(behaviour[:int(int(behaviour.shape[0]/re_sf)*re_sf)],(int(behaviour.shape[0]/re_sf),re_sf))
resample_beh = np.reshape(scipy.stats.mode(reshape_behaviour,axis=1)[0],reshape_behaviour.shape[0])
resample_timeline = timeline/re_sf
color = np.linspace(0, 20, len(resample_beh))

#%%
## run pca analysis on covariance matrix
cov_matrix = stats.cov_matrix(neural_activity = neural_activity) ## compute covariance matrix
eigenvalues, eigenvectors = stats.compute_PCA(corr_matrix = cov_matrix) ## run eigenvalues and eigenvectors analysis
projection = stats.PCA_projection(neural_activity=neural_activity, eigenvalues=eigenvalues,
                            eigenvectors=eigenvectors, n_components=n_components) ## project to n_componets

#%% Separate trials
neural_activity_days = []
time_length = np.diff(resample_timeline)
for i in range(0,42,2):
    trial_matrix = resample_neural_activity_mean[:,int(resample_timeline[i]):int(resample_timeline[i]) + int(time_length[i])]
    neural_activity_days.append(trial_matrix)

neural_activity_resting_days = []
for i in range(1,42,2):
    trial_matrix = resample_neural_activity_mean[:,int(resample_timeline[i]):int(resample_timeline[i]) + int(time_length[i])]
    neural_activity_resting_days.append(trial_matrix)

#%%
eigenvectors_list_trials = []