-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_viewer.py
114 lines (90 loc) · 3.16 KB
/
data_viewer.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from optipropapy import optipropapy_functions as opp
from threading import Thread
from datetime import date
def main():
est_viewer()
#gen_viewer()
print('done')
def gen_viewer():
samples = 4
# variables to access data
base_data_dir = Path('/opt', 'data', 'gen_data')
data_dir = base_data_dir / 'raw'
sub_dir = 'train'
# get all sub-directories and randomize in the same way as the est script
dirs = os.listdir(data_dir / sub_dir)
n = 0
sz = 100
frames = 32
files = []
truth = []
for dd in dirs:
if '0' not in dd:
n = n + np.size(os.listdir(data_dir / sub_dir / dd))
for ff in os.listdir(data_dir / sub_dir / dd):
files.append(data_dir / sub_dir / dd / ff)
truth.append(dd)
temp = list(zip(files, truth))
np.random.shuffle(temp)
files, truth = zip(*temp)
data = np.zeros((samples, frames, sz, sz))
for ii in range(samples):
data[ii, :, :, :] = np.load(files[ii])
fig, ax = plt.subplots(1, 1)
ax.imshow(data[ii, 0, :, :])
plt.suptitle(f'Truth: {truth[ii]}')
plt.show()
print('done')
def est_viewer():
instance = '2022-06-06_225'
samples = 12
# variables to access data
base_data_dir = Path('gen_data')
load_dir = 'data_ests'
# load processed data
obj_fn = instance + '_objEst.npy'
truth_fn = instance + '_truth.npy'
otf_fn = instance + '_otfEst.npy'
obj_est = np.load(base_data_dir / load_dir / obj_fn)
truth = np.load(base_data_dir / load_dir / truth_fn)
truth = truth.astype('float')
otf_est = np.load(base_data_dir / load_dir / otf_fn)
# show data from 1 -> # samples
if np.size(truth) < samples: samples = np.size(truth)
for ii in range(samples):
fig, ax = plt.subplots(1, 2)
ax[0].imshow(np.fft.fftshift(obj_est[ii, :, :]))
ax[1].imshow(np.fft.fftshift(np.abs(otf_est[ii, :, :, 0])))
plt.suptitle(f'Truth: {truth[ii]}')
plt.show()
def old_functions():
name_data = 'light_prop_data_array.npy'
name_label = 'light_prop_label_array.npy'
if os.path.isfile(name_data):
n = 50
data_handle = np.load(name_data, allow_pickle=True)
label_handle = np.load(name_label, allow_pickle=True)
fig, ax = plt.subplots(2, 2)
ax[0, 0].imshow(data_handle[n * 4])
ax[0, 0].set_title('Objs: %i' % label_handle[n * 4])
ax[0, 0].axis('off')
ax[0, 1].imshow(data_handle[n * 4 + 1])
ax[0, 1].set_title('Objs: %i' % label_handle[n * 4 + 1])
ax[0, 1].axis('off')
ax[1, 0].imshow(data_handle[n * 4 + 2])
ax[1, 0].set_title('Objs: %i' % label_handle[n * 4 + 2])
ax[1, 0].axis('off')
ax[1, 1].imshow(data_handle[n * 4 + 3])
ax[1, 1].set_title('Objs: %i' % label_handle[n * 4 + 3])
ax[1, 1].axis('off')
fig.suptitle('Samples = %i, n = %i:%i' % (np.size(data_handle), n * 4, n * 4 + 3))
plt.tight_layout()
plt.show()
else:
print('no file exists')
if __name__ == '__main__':
main()