Skip to content

Commit 2547866

Browse files
peterhollenderarhowe00
authored andcommitted
fixed unit tests for required dims
1 parent 43c6bb8 commit 2547866

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

notebooks/test_solution_analysis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
# +
2323
f0 = 400e3
2424
pulse = Pulse(frequency=f0, duration=10/f0, amplitude=1)
25-
sequence = Sequence(pulse_interval=0.1, pulse_count=10, pulse_train_interval=0, pulse_train_count=1)
25+
sequence = Sequence(pulse_interval=0.1, pulse_count=9, pulse_train_interval=0, pulse_train_count=1)
2626
focal_pattern = focal_patterns.SinglePoint(target_pressure=1.2e6)
27+
focal_pattern = focal_patterns.Wheel(center=False, spoke_radius=5, num_spokes=3, target_pressure=1.2e6)
2728
apod_method = apod_methods.MaxAngle(30)
2829
sim_setup = SimSetup(x_extent=[-30,30], y_extent=[-30,30], z_extent=[-4,70])
2930
protocol = Protocol(
@@ -44,11 +45,15 @@
4445
scale=True)
4546
# -
4647

48+
solution.analyze(transducer=trans).to_dict()
49+
4750
from openlifu.plan.param_constraint import ParameterConstraint
4851

4952
pc = {"MI":ParameterConstraint('<', 1.8, 1.85), "TIC":ParameterConstraint('<', 2.0), 'global_isppa_Wcm2':ParameterConstraint('within', error_value=(49, 190))}
5053
scaled_analysis.to_table(constraints=pc).set_index('Param')[['Value', 'Units', 'Status']]
5154

55+
solution
56+
5257
protocol = Protocol.from_file('../tests/resources/example_db/protocols/example_protocol/example_protocol.json')
5358
solution, sim_res, analysis = protocol.calc_solution(
5459
target=target,

src/openlifu/bf/focal_patterns/wheel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class Wheel(FocalPattern):
1717
:ivar center: Whether to include the center point of the wheel pattern
1818
:ivar num_spokes: Number of spokes in the wheel pattern
1919
:ivar spoke_radius: Radius of the spokes in the wheel pattern
20-
:ivar units: Units of the wheel pattern parameters
20+
:ivar spoke_units: Units of the wheel pattern parameters
2121
"""
2222
center: bool = True
2323
num_spokes: int = 4
2424
spoke_radius: float = 1.0 # mm
25-
units: str = "mm"
25+
spoke_units: str = "mm"
2626

2727
def get_targets(self, target: Point):
2828
"""
@@ -45,7 +45,7 @@ def get_targets(self, target: Point):
4545
spoke = Point(id=f"{target.id}_{np.rad2deg(theta):.0f}deg",
4646
name=f"{target.name} ({np.rad2deg(theta):.0f}°)",
4747
position=position,
48-
units=self.units,
48+
units=self.spoke_units,
4949
radius=target.radius)
5050
targets.append(spoke)
5151
return targets

src/openlifu/plan/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def to_dict(self):
110110
"delay_method": self.delay_method.to_dict(),
111111
"apod_method": self.apod_method.to_dict(),
112112
"seg_method": self.seg_method.to_dict(),
113-
"param_constraints": self.param_constraints,
113+
"param_constraints": {id: pc.to_dict() for id, pc in self.param_constraints.items()},
114114
"target_constraints": self.target_constraints,
115115
"virtual_fit_options": self.virtual_fit_options.to_dict(),
116116
"analysis_options": self.analysis_options,

src/openlifu/plan/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def analyze(self,
216216
solution_analysis.p0_MPa += [1e-6*np.max(p0_Pa)]
217217
solution_analysis.TIC = np.mean(TIC)
218218
solution_analysis.power_W = np.mean(power_W)
219-
solution_analysis.MI = (solution_analysis.mainlobe_pnp_MPa/np.sqrt(self.pulse.frequency*1e-6)).item()
219+
solution_analysis.MI = (np.max(solution_analysis.mainlobe_pnp_MPa)/np.sqrt(self.pulse.frequency*1e-6))
220220
solution_analysis.global_ispta_mWcm2 = float((ita_mWcm2*z_mask).max())
221221
solution_analysis.param_constraints = param_constraints
222222
return solution_analysis

src/openlifu/plan/solution_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"p0_MPa": ["max", "0.3f", "MPa", "Emitted Pressure"],
3232
"power_W": [None, "0.3f", "W", "Emitted Power"],
3333
"TIC": [None, "0.3f", "", "TIC"],
34-
"MI": ["max", "0.3f", "", "MI"]}
34+
"MI": [None, "0.3f", "", "MI"]}
3535

3636
@dataclass
3737
class SolutionAnalysis(DictMixin):

tests/test_protocol.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ def test_calc_solution_use_gpu(
104104
"""Test that the correct value of use_gpu is passed to the simulation runner"""
105105
example_simulation_output = xa.Dataset(
106106
{
107-
'p_min': xa.DataArray(data=np.empty((3, 2, 3)), dims=["x", "y", "z"], attrs={'units': "Pa"}),
108-
'p_max': xa.DataArray(data=np.empty((3, 2, 3)),dims=["x", "y", "z"],attrs={'units': "Pa"}),
109-
'intensity': xa.DataArray(data=np.empty((3, 2, 3)),dims=["x", "y", "z"],attrs={'units': "W/cm^2"}),
107+
'p_min': xa.DataArray(data=np.empty((3, 2, 3)), dims=["lat", "ele", "ax"], attrs={'units': "Pa"}),
108+
'p_max': xa.DataArray(data=np.empty((3, 2, 3)),dims=["lat", "ele", "ax"],attrs={'units': "Pa"}),
109+
'intensity': xa.DataArray(data=np.empty((3, 2, 3)),dims=["lat", "ele", "ax"],attrs={'units': "W/cm^2"}),
110110
},
111111
coords={
112-
'x': xa.DataArray(dims=["x"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
113-
'y': xa.DataArray(dims=["y"], data=np.linspace(0, 1, 2), attrs={'units': "m"}),
114-
'z': xa.DataArray(dims=["z"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
112+
'lat': xa.DataArray(dims=["lat"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
113+
'ele': xa.DataArray(dims=["ele"], data=np.linspace(0, 1, 2), attrs={'units': "m"}),
114+
'ax': xa.DataArray(dims=["ax"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
115115
},
116116
)
117117
mocker.patch(

tests/test_solution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def example_solution() -> Solution:
7171
)
7272
},
7373
coords={
74-
'x': xa.DataArray(dims=["x"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
75-
'y': xa.DataArray(dims=["y"], data=np.linspace(0, 1, 2), attrs={'units': "m"}),
76-
'z': xa.DataArray(dims=["z"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
74+
'lat': xa.DataArray(dims=["lat"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
75+
'ele': xa.DataArray(dims=["ele"], data=np.linspace(0, 1, 2), attrs={'units': "m"}),
76+
'ax': xa.DataArray(dims=["ax"], data=np.linspace(0, 1, 3), attrs={'units': "m"}),
7777
'focal_point_index': [0]
7878
}
7979
)

0 commit comments

Comments
 (0)