Skip to content

Commit c96a978

Browse files
add param constrains and target constraints for #360
1 parent 52e2b87 commit c96a978

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/openlifu/plan/param_constraint.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ def get_status(self, value: float) -> str:
7878

7979
def get_status_symbol(self, value: float) -> str:
8080
return PARAM_STATUS_SYMBOLS[self.get_status(value)]
81+
82+
def get_table(self):
83+
"""Convert the parameter constraint to a table format."""
84+
import pandas as pd
85+
records = []
86+
if self.operator in ['<', '<=', '>', '>='] or self.operator in ['within', 'inside', 'outside', 'outside_inclusive']:
87+
value_template = f"value {self.operator} {{value}}"
88+
else:
89+
raise ValueError(f"Unsupported operator: {self.operator}")
90+
if self.warning_value is not None:
91+
records.append({"Name": "Warn if not", "Value": value_template.format(value=self.warning_value), "Unit": ""})
92+
if self.error_value is not None:
93+
records.append({"Name": "Error if not", "Value": value_template.format(value=self.error_value), "Unit": ""})
94+
return pd.DataFrame.from_records(records)

src/openlifu/plan/protocol.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ def _append_subtable(category_name, sub_df):
193193
table = _append_subtable("Apodization Method", self.apod_method.get_table())
194194
table = _append_subtable("Segmentation Method", self.seg_method.get_table())
195195
table = _append_subtable("Simulation Setup", self.sim_setup.get_table())
196-
196+
for tc in self.target_constraints:
197+
table = _append_subtable("Target Constraints", tc.to_table())
198+
for param_id, param_constraint in self.param_constraints.items():
199+
tp = param_constraint.get_table()
200+
tp["Value"] = tp["Value"].str.replace("value", param_id)
201+
table = _append_subtable("Parameter Constraints", tp)
197202
return table
198203

199204

src/openlifu/plan/target_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ def to_table(self):
6464
"""
6565
import pandas as pd
6666
records = [
67-
{"Name": self.name, "Value": f"{self.min} - {self.max}", "Unit": self.units},
67+
{"Name": self.name, "Value": f"({self.min},{self.max})", "Unit": self.units},
6868
]
6969
return pd.DataFrame.from_records(records)

0 commit comments

Comments
 (0)