-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_exploration.py
More file actions
87 lines (66 loc) · 3.05 KB
/
data_exploration.py
File metadata and controls
87 lines (66 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import nibabel
import matplotlib.pyplot as plt
data_path = 'C:\\phd\\connectome_conv_net_tf2\\CNN\\'
subIDs = [100307, 101915, 103414, 103818, 106319]
def get_histogram(img_data):
hist, bins = np.histogram(img_data, bins=np.arange(img_data.min(), img_data.max(), .1))
stats = [np.median(img_data), np.percentile(img_data, 25), np.percentile(img_data, 75), np.percentile(img_data, 5),
np.percentile(img_data, 95)]
return hist, bins[:-1] + 0.05, stats
for subID in subIDs:
rest_img = nibabel.load(data_path + str(subID) + '_DR2_nosmoothing.nii.gz')
task_img = nibabel.load(data_path + str(subID) + '_motor1.nii.gz')
rest_hist, rest_bins, rest_stats = get_histogram(rest_img.get_fdata())
task_hist, task_bins, task_stats = get_histogram(task_img.get_fdata())
plt.figure(figsize=[20, 16])
plt.subplot(521)
plt.plot(task_bins, task_hist)
plt.title("50prc %.3f,25prc %.3f, 75prc %.3f, 5prc %.3f, 95prc %.3f" % tuple(task_stats))
plt.subplot(522)
plt.plot(rest_bins, rest_hist)
plt.title("50prc %.3f,25prc %.3f, 75prc %.5f, 5prc %.3f, 95prc %.3f" % tuple(rest_stats))
for i in range(8):
hist, bins, stats = get_histogram(rest_img.get_fdata()[:, :, :, i * 4])
plt.subplot(5, 2, 3 + i)
plt.plot(bins, hist)
plt.title("50prc %.3f,25prc %.3f, 75prc %.3f, 5prc %.3f, 95prc %.3f" % tuple(stats))
plt.savefig('%s_histograms.png' % subID)
plt.figure(figsize=[20, 20])
for i in range(4):
plt.subplot(4, 4, i + 1)
plt.imshow(rest_img.get_fdata()[:, :, 15 + i * 20, 10])
plt.subplot(4, 4, 4 + i + 1)
plt.imshow(rest_img.get_fdata()[:, :, 15 + i * 20, 20])
plt.subplot(4, 4, 8 + i + 1)
plt.imshow(rest_img.get_fdata()[:, :, 15 + i * 20, 30])
plt.subplot(4, 4, 12 + i + 1)
plt.imshow(task_img.get_fdata()[:, :, 15 + i * 20])
plt.savefig('%s_slices.png' % subID)
plt.figure(figsize=[20, 20])
for i in range(4):
plt.subplot(4, 4, i + 1)
plt.imshow(rest_img.get_fdata()[15 + i * 20, :, :, 10])
plt.subplot(4, 4, 4 + i + 1)
plt.imshow(rest_img.get_fdata()[15 + i * 20, :, :, 20])
plt.subplot(4, 4, 8 + i + 1)
plt.imshow(rest_img.get_fdata()[15 + i * 20, :, :, 30])
plt.subplot(4, 4, 12 + i + 1)
plt.imshow(task_img.get_fdata()[15 + i * 20, :, :, ])
plt.savefig('%s_slices2.png' % subID)
plt.figure(figsize=[20, 20])
for i in range(4):
plt.subplot(4, 4, i + 1)
plt.imshow(rest_img.get_fdata()[:, 15 + i * 20, :, 10])
plt.subplot(4, 4, 4 + i + 1)
plt.imshow(rest_img.get_fdata()[:, 15 + i * 20, :, 20])
plt.subplot(4, 4, 8 + i + 1)
plt.imshow(rest_img.get_fdata()[:, 15 + i * 20, :, 30])
plt.subplot(4, 4, 12 + i + 1)
plt.imshow(task_img.get_fdata()[:, 15 + i * 20, :, ])
plt.savefig('%s_slices3.png' % subID)