Update GPR and SAR3D processing
This commit is contained in:
@@ -10,7 +10,7 @@ from python_app.models.json_fields import finite_number, json_object
|
||||
from python_app.models.run_config_schema import RunConfigModel
|
||||
|
||||
|
||||
def _decode_state(model: object, payload: dict[str, Any], context: str, *, check_constraints: bool = True) -> None:
|
||||
def _decode_state(model: object, payload: dict[str, Any], context: str) -> None:
|
||||
"""Read known fields recursively; unknown fields do not survive re-encoding."""
|
||||
if not is_dataclass(model) or isinstance(model, type):
|
||||
raise TypeError("GUI state must be a dataclass instance")
|
||||
@@ -19,14 +19,14 @@ def _decode_state(model: object, payload: dict[str, Any], context: str, *, check
|
||||
value = payload.get(member.name, default)
|
||||
name = f"{context}.{member.name}"
|
||||
if is_dataclass(default):
|
||||
_decode_state(default, json_object(payload.get(member.name), name), name, check_constraints=check_constraints)
|
||||
_decode_state(default, json_object(payload.get(member.name), name), name)
|
||||
continue
|
||||
if isinstance(default, float):
|
||||
value = finite_number(value, name)
|
||||
elif type(value) is not type(default):
|
||||
raise ValueError(f"{name} must be a JSON {type(default).__name__}")
|
||||
spec = member.metadata.get("setting")
|
||||
if check_constraints and isinstance(spec, Setting):
|
||||
if isinstance(spec, Setting):
|
||||
if spec.choices and value not in spec.choices:
|
||||
raise ValueError(f"{name} must be one of: {', '.join(spec.choices)}")
|
||||
if spec.minimum is not None:
|
||||
@@ -39,33 +39,16 @@ def _decode_state(model: object, payload: dict[str, Any], context: str, *, check
|
||||
|
||||
|
||||
def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
"""Read the pipeline config and optional GUI state, preserving old GPR profiles."""
|
||||
"""Read the pipeline config and optional GUI state; ignore unknown fields."""
|
||||
profile = GuiProfileModel(run_config=RunConfigModel.from_dict(payload))
|
||||
if payload.get("gui") is None:
|
||||
return profile
|
||||
gui_object = json_object(payload["gui"], "gui")
|
||||
processing = json_object(gui_object.get("processing"), "gui.processing")
|
||||
old_gpr = json_object(processing.get("gpr"), "gui.processing.gpr")
|
||||
gui = GuiStateModel()
|
||||
|
||||
# Older profiles kept both algorithms under gpr. Root mode and the short-lived
|
||||
# algorithm selector choose the legacy page; explicit legacy values win.
|
||||
root_gpr = payload.get("gpr")
|
||||
root_mode = root_gpr.get("mode") if isinstance(root_gpr, dict) else None
|
||||
algorithm_mode = {"legacy_point": "point", "legacy_extended": "extended"}.get(
|
||||
str(old_gpr.get("algorithm", "")))
|
||||
if root_mode in ("point", "extended"):
|
||||
gui.processing.legacy_gpr.mode = root_mode
|
||||
if algorithm_mode is not None:
|
||||
gui.processing.legacy_gpr.mode = algorithm_mode
|
||||
_decode_state(gui.processing.legacy_gpr, old_gpr, "gui.processing.gpr", check_constraints=False)
|
||||
_decode_state(gui, gui_object, "gui")
|
||||
if gui.version != 1:
|
||||
raise ValueError(f"Unsupported gui.version: {gui.version}")
|
||||
if gui.processing.selected_mode == "gpr" and (
|
||||
algorithm_mode is not None or root_mode in ("point", "extended")
|
||||
):
|
||||
gui.processing.selected_mode = "legacy_gpr"
|
||||
gui.preprocess_dialog.median_sweep_count = max(1, gui.preprocess_dialog.median_sweep_count)
|
||||
profile.gui = gui
|
||||
return profile
|
||||
|
||||
Reference in New Issue
Block a user