-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesndtconverter.py
More file actions
145 lines (102 loc) · 2.94 KB
/
esndtconverter.py
File metadata and controls
145 lines (102 loc) · 2.94 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os.path
import os
import numpy as np
import pickle
import SegAnalysis as sa
from scipy.io import savemat
from functools import reduce
def ReadEsndtFile(fld,ds=1,navg=None):
#fld = 'c:\\temp2\\ascanExtractTest\\I40'
files = [f for f in os.listdir(fld) if ' pos ' in f]
d = {}
for fn in files:
# pos = int(abs(np.floor(float(fn.split(' pos ')[-1].split('$')[0]))))
pos = abs(float(fn.split(' pos ')[-1].split('$')[0]))
d[pos] = ReadEsndtSlice(os.path.join(fld,fn),ds)
k = list(d.keys())
k.sort()
d = [ d[kk] for kk in k]
L = len(d)
if type(navg) is int:
d = [reduce(lambda x,y:x+y,d[i:min([i+navg,L])])/navg for i in range(0,L,navg)]
return d
def ReadEsndtSlice(fn,ds=1):
#fn = 'c:\\temp2\\ascanExtractTest\\I40\\I40 pos 5$32,6501'
numElem, ascanLen = [int(x) for x in os.path.basename(fn).split('$')[-1].split(',',1)]
a = np.fromfile(fn, dtype='int16')
ascans = a.reshape((numElem,numElem,ascanLen))
ascans = ascans[:,:,0::ds]
return ascans
def Esndt2Pickle(infldr,fsamp,outfl='same',navg = None, ds=1):
a = ReadEsndtFile(infldr,ds,navg)
if outfl is 'same':
outfl = infldr+'/'+infldr.split('/')[-1]+'.p'
d = {'AScans':a,'SamplingFrequency':fsamp}
pickle.dump(d,open(outfl,'wb'))
def Esndt2Mat(infldr,outfl=None):
a = np.array(ReadEsndtFile(infldr))
if a.shape[0]==1:
a = a[0,:,:,:]
if outfl is None:
outfl = infldr+'/'+infldr.split('/')[-1]+'.mat'
savemat(outfl,{'AScans':a})
def Pickle2BinaryFolder(infl,outdir):
a = pickle.load(open(infl,'rb'))['AScans']
for i in range(len(a)):
a[i].tofile(outdir+str(i)+'.txt')
# d = ReadEsndtFile('c:\\temp2\\ascanExtractTest\\I40')
# ascan = d[5][10][20] # ascan at position 5 for tx element number 11, rx element number 21
# pth = 'C:/Users/jlesage/Documents/RepeatabilityStudy/'
# f = os.listdir(pth)
#
# # f = [f[0]]
#
# F = sa.FMC(25.)
#
# for ff in f:
#
# d = ReadEsndtFile(pth+ff)
#
# for i in range(len(d)):
#
# F.LoadAScans(d[i],'array')
#
# F.Calibrate()
#
# a = F.AScans.astype(np.int16).copy()
# #
# a.tofile(open(pth+'/'+ff+'/'+str(i)+'.txt','wb'))
#
#
#
#
# # f = [ff for ff in f if os.path.isdir(pth+ff)]
# # #
# # print(f)
#
# # for ff in f:
# #
# # # d = ReadEsndtFile(pth+ff)
# #
# # fn = os.listdir(pth+'/'+ff)[0]
# #
# # d = ReadEsndtSlice(pth+'/'+ff+'/'+fn)
# #
# # F = sa.FMC(50.,wedgeid='Black')
# #
# # F.LoadAScans(d,'array')
# #
# # F.Calibrate(BPParams=(1.,14.,3.),Offset=0.5)
# #
# # # a = F.AScans.astype(np.int16)
# #
# # F.AScans.tofile(open(pth+'/'+ff[1::]+'.txt','wb'))
#
#
#
#
#
#
#
# # print(ff)
# # pickle.dump(d,open('C:/Users/jlesage/Dropbox/Eclipse/Controlled/L/'+ff+'.p','wb'))