Skip to content

Commit a5ae628

Browse files
peterhollenderarhowe00
authored andcommitted
Address comments (#230)
Addresses comments on [SlicerOpenLIFU PR#250 review](#250 (review))
1 parent f84411c commit a5ae628

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

src/openlifu/plan/param_constraint.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from dataclasses import dataclass
44
from typing import Annotated, Literal, Tuple
55

6-
from openlifu.util.dict_conversion import DictMixin
76
from openlifu.util.annotations import OpenLIFUFieldData
7+
from openlifu.util.dict_conversion import DictMixin
88

99
PARAM_STATUS_SYMBOLS = {
1010
"ok": "✅",
@@ -27,13 +27,10 @@ def __post_init__(self):
2727
if self.warning_value is None and self.error_value is None:
2828
raise ValueError("At least one of warning_value or error_value must be set")
2929
if self.operator in ['within','inside','outside','outside_inclusive']:
30-
if self.warning_value is not None:
31-
if not isinstance(self.warning_value, tuple) or len(self.warning_value) != 2 or (self.warning_value[0] >= self.warning_value[1]):
32-
raise ValueError("Warning value must be a sorted tuple of two numbers")
33-
34-
if self.error_value is not None:
35-
if not isinstance(self.error_value, tuple) or len(self.error_value) != 2 or not (self.error_value[0] >= self.error_value[1]):
36-
raise ValueError("Error value must be a sorted tuple of two numbers")
30+
if self.warning_value and (not isinstance(self.warning_value, tuple) or len(self.warning_value) != 2 or (self.warning_value[0] >= self.warning_value[1])):
31+
raise ValueError("Warning value must be a sorted tuple of two numbers")
32+
if self.error_value and (not isinstance(self.error_value, tuple) or len(self.error_value) != 2 or not (self.error_value[0] >= self.error_value[1])):
33+
raise ValueError("Error value must be a sorted tuple of two numbers")
3734
elif self.operator in ['<','<=','>','>=']:
3835
if self.warning_value is not None and not isinstance(self.warning_value, (int, float)):
3936
raise ValueError("Warning value must be a single value")

src/openlifu/plan/solution.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,19 @@ def num_foci(self) -> int:
9999
def analyze(self,
100100
transducer: Transducer,
101101
options: SolutionAnalysisOptions = SolutionAnalysisOptions(),
102-
param_constraints: Dict[str,ParameterConstraint] = {}) -> SolutionAnalysis:
102+
param_constraints: Dict[str,ParameterConstraint]|None = None) -> SolutionAnalysis:
103103
"""Analyzes the treatment solution.
104104
105105
Args:
106106
transducer: A Transducer item.
107107
options: A struct for solution analysis options.
108+
param_constraints: A dictionary of parameter constraints to apply to the analysis.
109+
The keys are the parameter names and the values are the ParameterConstraint objects.
108110
109111
Returns: A struct containing the results of the analysis.
110112
"""
113+
if param_constraints is None:
114+
param_constraints = {}
111115
solution_analysis = SolutionAnalysis()
112116

113117
if transducer.id != self.transducer_id:

src/openlifu/plan/solution_analysis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas as pd
99
import xarray as xa
1010

11+
from openlifu.plan.param_constraint import PARAM_STATUS_SYMBOLS, ParameterConstraint
1112
from openlifu.util.annotations import OpenLIFUFieldData
1213
from openlifu.util.dict_conversion import DictMixin
1314

@@ -109,6 +110,8 @@ def to_table(self, constraints:Dict[str,ParameterConstraint]|None=None, focus_in
109110
elif fmt[0] == "mean":
110111
value_by_focus = self.__dict__[param]
111112
agg_value = np.mean(value_by_focus)
113+
else:
114+
raise ValueError(f"Unknown aggregation method '{fmt[0]}' for parameter '{param}'.")
112115
if agg_value is not None:
113116
record = {"id": param,
114117
"Param": fmt[3],

src/openlifu/xdc/element.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,4 @@ def to_dict(self):
224224

225225
@staticmethod
226226
def from_dict(d):
227-
if isinstance(d, dict):
228-
return [Element(**d)]
229-
else:
230-
return [Element(**di) for di in d]
227+
return Element(**d)

src/openlifu/xdc/transducer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import logging
66
from dataclasses import dataclass, field
7-
from typing import Annotated, Any, Dict, List, Tuple
7+
from typing import Annotated, Any, Dict, List
88

99
import numpy as np
1010
import vtk
@@ -23,7 +23,7 @@ class Transducer:
2323
name: Annotated[str, OpenLIFUFieldData("Transducer name", "Human readable name for transducer")] = ""
2424
"""Human readable name for transducer"""
2525

26-
elements: Annotated[Tuple[Element], OpenLIFUFieldData("Elements", "Collection of transducer Elements")] = ()
26+
elements: Annotated[List[Element], OpenLIFUFieldData("Elements", "Collection of transducer Elements")] = field(default_factory=list)
2727
"""Collection of transducer Elements"""
2828

2929
frequency: Annotated[float, OpenLIFUFieldData("Frequency (Hz)", "Nominal array frequency (Hz)")] = 400.6e3
@@ -230,7 +230,7 @@ def from_file(filename):
230230
@staticmethod
231231
def from_dict(d, **kwargs):
232232
d = d.copy()
233-
d["elements"] = Element.from_dict(d["elements"])
233+
d["elements"] = [Element.from_dict(element) for element in d["elements"]]
234234
if "standoff_transform" in d:
235235
d["standoff_transform"] = np.array(d["standoff_transform"])
236236
return Transducer(**d, **kwargs)

0 commit comments

Comments
 (0)