Skip to content

Commit b8826e0

Browse files
peterhollenderarhowe00
authored andcommitted
Added focus_index to analysis.to_table
1 parent 2547866 commit b8826e0

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

notebooks/test_solution_analysis.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from openlifu.bf import Pulse, Sequence, apod_methods, focal_patterns
1717
from openlifu.geo import Point
1818
from openlifu.plan import Protocol
19+
from openlifu.plan.param_constraint import ParameterConstraint
1920
from openlifu.sim import SimSetup
2021
from openlifu.xdc import Transducer
2122

@@ -38,22 +39,17 @@
3839

3940
target = Point(position=(0,0,50), units="mm", radius=2)
4041
trans = Transducer.gen_matrix_array(nx=8, ny=8, pitch=4, kerf=0.5, id="m3", name="openlifu", impulse_response=1e6/10)
42+
# -
43+
4144
solution, sim_res, scaled_analysis = protocol.calc_solution(
4245
target=target,
4346
transducer=trans,
4447
simulate=True,
4548
scale=True)
46-
# -
47-
48-
solution.analyze(transducer=trans).to_dict()
49-
50-
from openlifu.plan.param_constraint import ParameterConstraint
5149

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

55-
solution
56-
5753
protocol = Protocol.from_file('../tests/resources/example_db/protocols/example_protocol/example_protocol.json')
5854
solution, sim_res, analysis = protocol.calc_solution(
5955
target=target,

src/openlifu/plan/solution_analysis.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SolutionAnalysis(DictMixin):
5555
global_ispta_mWcm2: float | None = None
5656
param_constraints: Dict[str, ParameterConstraint] = field(default_factory=dict)
5757

58-
def to_table(self, constraints:Dict[str,ParameterConstraint]|None=None) -> pd.DataFrame:
58+
def to_table(self, constraints:Dict[str,ParameterConstraint]|None=None, focus_index=None) -> pd.DataFrame:
5959
records = []
6060
if constraints is None:
6161
constraints = self.param_constraints
@@ -64,28 +64,38 @@ def to_table(self, constraints:Dict[str,ParameterConstraint]|None=None) -> pd.Da
6464
raise ValueError(f"Unknown parameter constraint for '{p}'. Must be one of: {list(PARAM_FORMATS.keys())}")
6565
for param, fmt in PARAM_FORMATS.items():
6666
if fmt[0] is None:
67-
pval = self.__dict__[param]
67+
value_by_focus = None
68+
agg_value = self.__dict__[param]
6869
elif fmt[0] == "max":
69-
pval = max(self.__dict__[param])
70+
value_by_focus = self.__dict__[param]
71+
agg_value = max(value_by_focus)
7072
elif fmt[0] == "mean":
71-
pval = np.mean(self.__dict__[param])
72-
if pval is not None:
73+
value_by_focus = self.__dict__[param]
74+
agg_value = np.mean(value_by_focus)
75+
if agg_value is not None:
7376
record = {"id": param,
7477
"Param": fmt[3],
7578
"Value" : "",
7679
"Units" : fmt[2],
7780
"Status": "",
78-
"_value" : pval,
81+
"_value" : agg_value,
82+
"_value_by_focus": value_by_focus,
7983
"_warning": False,
8084
"_error": False}
81-
if np.isnan(pval):
85+
if np.isnan(agg_value):
8286
record["Value"] = "NaN"
8387
else:
84-
record["Value"] = f"{pval:{fmt[1]}}"
88+
if focus_index is None:
89+
record["Value"] = f"{agg_value:{fmt[1]}}"
90+
elif value_by_focus is None:
91+
record["Value"] = "N/A"
92+
else:
93+
value = value_by_focus[focus_index]
94+
record["Value"] = f"{value:{fmt[1]}}"
8595
if param in constraints:
86-
record['_warning'] = constraints[param].is_warning(pval)
87-
record['_error'] = constraints[param].is_error(pval)
88-
record["Status"] = PARAM_STATUS_SYMBOLS[constraints[param].get_status(pval)]
96+
record['_warning'] = constraints[param].is_warning(agg_value)
97+
record['_error'] = constraints[param].is_error(agg_value)
98+
record["Status"] = PARAM_STATUS_SYMBOLS[constraints[param].get_status(agg_value)]
8999
records.append(record)
90100
return pd.DataFrame.from_records(records)
91101

0 commit comments

Comments
 (0)