-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_fsa_convex_transducer_transabdominal_imaging.py
347 lines (305 loc) · 10.1 KB
/
ex_fsa_convex_transducer_transabdominal_imaging.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
from pathlib import Path
import numpy as np
import fullwave_simulation
from fullwave_simulation.conditions import FSAInitialCondition
from fullwave_simulation.constants import Constant
from fullwave_simulation.domains import (
AbdominalWall,
Background,
DomainOrganizer,
PhatomLateral,
Scatterer,
WaterGel,
)
from fullwave_simulation.solvers import FullwaveSolver
from fullwave_simulation.transducers import (
C52VTransducer,
ConvexTxWaveTransmitter,
SignalReceiver,
)
from fullwave_simulation.utils import MapViewer
class FSASimulationParams(Constant):
# 64 sequential txrx events
nevents = 128
# element_pitch
element_pitch = 0.000508 # [m]
# Basic variables / parameters
freq_div = 1
c0 = 1540 # [m/s]
# frequency [MHz]
# not realistic radio frequency.
f0 = 3.7e6 / freq_div # [Hz]
omega0 = 2 * np.pi * f0
lambda_ = c0 / f0
# Simulation grid varables
# width of simulation field (m). lateral dimension.
wX = 6e-2 # [m]
# depth of simulation field (m)
wY = 9e-2 # [m]
# duration of simulation (s).
# the time how much you want to simulate the propagation (sec)
dur = wY * 2.3 / c0 # [sec]
# Courant-Friedrichs-Levi condition
cfl = 0.4
# pressure in Pa. 100kpa.
# 2.5Mpa is normal but not in this simulation.
p0 = 1e5 # [Pa]
# emission parameters
num_cycles = 2
# exponential drop-off of envelope
drop_off = 1
# --- aliases ---
width = wX
depth = wY
modT = 7
ncycles = num_cycles
# define fnumber
fnumber = 1.5
# fnumber = focal_depth / width
# whether the transmit sequence is Fully synthetic aperture (FSA)
is_fsa = True
# is_fsa = False self.bw = self.simulation_params.tx_bw
tx_bw = 0.7
class MaterialProperties(Constant):
fat = {
"b_over_a": 9.6,
"alpha": 0.48,
"ppower": 1.1,
"c0": 1478,
"rho0": 950,
}
fat["beta"] = 1 + fat["b_over_a"] / 2
liver = {
"b_over_a": 7.6,
"alpha": 0.5,
"ppower": 1.1,
"c0": 1570,
"rho0": 1064,
}
liver["beta"] = 1 + liver["b_over_a"] / 2
muscle = {
"b_over_a": 9,
"alpha": 1.09,
"ppower": 1.0,
"c0": 1547,
"rho0": 1050,
}
muscle["beta"] = 1 + muscle["b_over_a"] / 2
water = {
"b_over_a": 5,
"alpha": 0.005,
"ppower": 2.0,
"c0": 1480,
"rho0": 1000,
}
water["beta"] = 1 + water["b_over_a"] / 2
skin = {
"b_over_a": 8,
"alpha": 2.1,
"ppower": 1,
"c0": 1498,
"rho0": 1000,
}
skin["beta"] = 1 + skin["b_over_a"] / 2
tissue = {
"b_over_a": 9,
"alpha": 0.5,
"ppower": 1,
"c0": 1540,
"rho0": 1000,
}
tissue["beta"] = 1 + tissue["b_over_a"] / 2
connective = {
"b_over_a": 8,
"alpha": 1.57,
"ppower": 1,
"c0": 1613,
"rho0": 1120,
}
connective["beta"] = 1 + connective["b_over_a"] / 2
blood = {
"b_over_a": 5,
"alpha": 0.005,
"ppower": 2.0,
"c0": 1520,
"rho0": 1000,
}
blood["beta"] = 1 + blood["b_over_a"] / 2
lung_fluid = {
"b_over_a": 5,
"alpha": 0.005,
"ppower": 2.0,
"c0": 1440,
"rho0": 1000,
}
lung_fluid["beta"] = 1 + lung_fluid["b_over_a"] / 2
transducer = connective
c0 = 1540
rho0 = 1000
a0 = 0.5
beta0 = 0
def main():
# Define your work directory and make the directory.
home_dir = Path(fullwave_simulation.__file__).parent.parent
work_dir = home_dir / "outputs" / "exp_dir_20240603_test"
work_dir.mkdir(
exist_ok=True,
parents=True,
)
# Set the parameters with fullwave_simulation.constants classes.
simulation_params = FSASimulationParams()
material_properties = MaterialProperties()
# Define the transducer properties using class in `fullwave_simulation.transducers`.
# C52V is available at the moment. More options will be available such as a L7-4 and L12-5 (linear transducer).
c52v_transducer = C52VTransducer(
simulation_params=simulation_params,
material_properties=material_properties,
rho0=material_properties.transducer["rho0"],
c0=material_properties.transducer["c0"],
a0=material_properties.transducer["alpha"],
beta0=material_properties.transducer["beta"],
element_pitch=FSASimulationParams.element_pitch,
)
# Define the simulation domains using fullwave_simulation.domains classes.
# Each domain has its own material properties like density, sound speed, attenuation, etc.
# If you need to make a new simulational maps or domains such as abdmonial wall, lung, or liver,
# you will write a class refer to these classes.
background_domain_properties = "liver"
map_viewer = MapViewer(save_dir=work_dir / "input_maps")
# In this example, background with scatter, abdominal wall, and phantom were defined.
# First, download the abdominal wall data and put them to `fullwave_simulation/domains/data`
# https://drive.google.com/file/d/1KMSlqcgXSzd9NGU2fauO9OJ6s8PPrA5P/view?usp=sharing
background = Background(
num_x=c52v_transducer.num_x,
num_y=c52v_transducer.num_y,
material_properties=material_properties,
simulation_params=simulation_params,
background_domain_properties=background_domain_properties,
)
scatterer = Scatterer(
num_x=c52v_transducer.num_x,
num_y=c52v_transducer.num_y,
material_properties=material_properties,
simulation_params=simulation_params,
transducer=c52v_transducer,
num_scatter=18,
)
csr = 0.035
background.rho_map = background.rho_map - scatterer.rho_map * csr
phantom = PhatomLateral(
num_x=c52v_transducer.num_x,
num_y=c52v_transducer.num_y,
material_properties=material_properties,
simulation_params=simulation_params,
dX=c52v_transducer.dX,
dY=c52v_transducer.dY,
base_circle_depth_in_meter=0.04,
lat_phantom_in_meter=simulation_params.wX,
depth_phantom_in_meter=simulation_params.wY,
background_domain_properties=background_domain_properties,
)
abdominal_wall = AbdominalWall(
num_x=c52v_transducer.num_x,
num_y=c52v_transducer.num_y,
crop_depth=0.8e-2,
start_depth=0.0,
dY=c52v_transducer.dY,
dX=c52v_transducer.dX,
transducer=c52v_transducer,
abdominal_wall_mat_path=Path(
"fullwave_simulation/domains/data/abdominal_wall/i2365f_etfw1.mat"
),
material_properties=material_properties,
simulation_params=simulation_params,
apply_tissue_deformation=True,
apply_tissue_compression=True,
use_smoothing=True,
skip_i0=False,
use_center_region=True,
background_domain_properties=background_domain_properties,
ppw=c52v_transducer.ppw,
sequence_type="fsa",
)
# Next, register each domain classes into DomainOrganizer and construct a integrated domain.
# The order of the domains is important.
# The domain map will be constructed in a bottom-up fashion with DomainOrganizer like a sticker using the registered domains.
domain_organizer = DomainOrganizer(
material_properties=material_properties,
background_domain_properties=background_domain_properties,
ignore_non_linearity=True,
)
domain_organizer.register_domains(
[
background,
phantom,
abdominal_wall,
c52v_transducer.convex_transmitter_map,
],
)
domain_organizer.construct_domain()
# you can view the constructed domain maps using MapViewer.
for map_type in [
"rho_map",
"beta_map",
"c_map",
"a_map",
"geometry",
]:
map_viewer.view_map(
# np.flip(domain_organizer.constructed_domain_dict[map_type].T, 1),
map_data=domain_organizer.constructed_domain_dict[map_type].T,
title=map_type,
save_name_base=map_type,
extent=[
-simulation_params.wX / 2 * 1e3,
simulation_params.wX / 2 * 1e3,
simulation_params.wY * 1e3,
0,
],
)
# Now, define the wave transmitter and signal receiver.
# WaveTransmitter is used to calculate the transmission pulse.
# SignalReceiver does not have an effect at the moment.
wave_transmitter = ConvexTxWaveTransmitter(
transducer=c52v_transducer,
simulation_params=simulation_params,
material_properties=material_properties,
is_fsa=simulation_params.is_fsa,
)
# signal_receiver is a dummy for now.
signal_receiver = SignalReceiver(
transducer=c52v_transducer,
simulation_params=simulation_params,
material_properties=material_properties,
)
# Define the initial condition.
# InitialCondition class is used to generate the icmat,
# which is the initial pressure in time space,
# for each event based on the transmission pulse (icvec).
# icvec will be generated by the WaveTransmitter.
initial_condition = FSAInitialCondition(
# is_fsa=simulation_params.is_fsa,
transducer=c52v_transducer,
wave_transmitter=wave_transmitter,
)
# Finally, pass the above defined parameters to the solver and run the simulation.
# genout_list contains numpy array version of the genout,
# which is a Fullwave2's output file.
# Each outputs will be exported in the work directory defined in a first step.
fw_solver = FullwaveSolver(
work_dir=work_dir,
#
simulation_params=simulation_params,
#
domain_organizer=domain_organizer,
transducer=c52v_transducer,
wave_transmitter=wave_transmitter,
signal_receiver=signal_receiver,
#
initial_condition=initial_condition,
on_memory=False,
)
genout_list = fw_solver.run()
print()
if __name__ == "__main__":
main()