Beispiel #1
0
import matplotlib.pyplot as plt
# =============================================================================
# Parameters
wf = 1
scid = 'nsc'
wave_type = 'abp'
trial = 2
pwd = '/home/ov/data/stacked/selected/trial' + str(trial) + '/'
# =============================================================================
# Load waves:
waves = np.load(pwd + 'wf{}_{}.npy'.format(wf, scid))
plt.plot(waves[1000])
plt.show()
# =============================================================================
# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]

utils.plot_3d_mod(xs,
                  ys,
                  zs,
                  title='wf{} {}'.format(wf, scid),
                  s=5,
                  edge='navy',
                  xlabel='PC1',
                  ylabel='PC2',
                  zlabel='PC3',
                  add_info='PAT{} ({})'.format(wf, scid))
Beispiel #2
0
    pwd_mat1 = pwd + 'nfpat' + str(
        patient_nr) + '.icp.' + scid + 'seg.waves.mat'
    pwd_mat2 = pwd + 'nfpat' + str(
        patient_nr) + '.testicp.' + scid + 'seg.waves.mat'
    concatenated_waves = scipy.io.loadmat(pwd_mat1)['waves_mat']
    concatenated_waves = np.concatenate(
        (concatenated_waves, scipy.io.loadmat(pwd_mat2)['waves_mat']), axis=0)

# Normalization:
from sklearn.preprocessing import normalize
concatenated_waves = normalize(concatenated_waves, norm='max')

print(concatenated_waves.shape)

# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(concatenated_waves, 3, svd_solver='arpack')
print(fitted.shape)

xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]

utils.plot_3d(xs,
              ys,
              zs,
              title='NFPAT{} {} PCA projection'.format(patient_nr, scid),
              xlabel='PC1',
              ylabel='PC2',
              zlabel='PC3',
              s=1)
# =============================================================================
# Parameters
patient_nr = 10
scid = 'scp'
wave_type = 'abp'
pwd = '/home/ov/data/stacked/'
# =============================================================================
# Load waves:
#stacked_waves = np.load(pwd_stacked_out)
stacked_waves = utils.load_waves_by_pat_scid([patient_nr], scid, pwd)
waves = utils.acces_waves_by_type(None, stacked_waves, wave_type)
print('Stacked size: {}'.format(stacked_waves.shape))
print('Unstacked {} waves: {}'.format(wave_type, waves.shape))
# =============================================================================
# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]
"""
utils.plot_3d_mod(xs, ys, zs,
                    title='',
                    s=1,
                    edge = 'navy',
                    xlabel = 'PC1',
                    ylabel = 'PC2',
                    zlabel = 'PC3',
                    add_info = 'PAT{} ({})'.format(patient_nr, scid))
if input('Satisfied? (y|N)\n') != 'y':
    raise Exception('Not satisified :(')
import matplotlib
# =============================================================================
# Parameters:
scp_mean = 3
nsc_mean = 3
scid = 'scp+nsc'
pwd = '/home/ov/data/stacked/selected/trial2/'
# =============================================================================
# Load clusters:
clusters_nsc = np.load(pwd + 'nsc_clusters_hdbscan.npy', allow_pickle=True)
clusters_scp = np.load(pwd + 'scp_clusters_hdbscan.npy', allow_pickle=True)
print(clusters_scp[scp_mean].shape)
print(clusters_nsc[nsc_mean].shape)

fitted_scp = utils.pca_projections(clusters_scp[scp_mean],
                                   3,
                                   svd_solver='arpack')
fitted_nsc = utils.pca_projections(clusters_nsc[nsc_mean],
                                   3,
                                   svd_solver='arpack')

xs_list = []
ys_list = []
zs_list = []

xs_list.append(fitted_scp[:, 0])
xs_list.append(fitted_nsc[:, 0])
ys_list.append(fitted_scp[:, 1])
ys_list.append(fitted_nsc[:, 1])
zs_list.append(fitted_scp[:, 2])
zs_list.append(fitted_nsc[:, 2])