Skip to content

Commit ae53d74

Browse files
committed
Extract duplicate darks/flats dict-to-config code to separate function
1 parent ae5a26d commit ae53d74

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

httomo/transform_loader_params.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -435,51 +435,39 @@ def parse_config(input_file: Path, config: Dict[str, Any]) -> Tuple[
435435
angles_config = parse_angles(config["rotation_angles"])
436436

437437
data_config = DataConfig(in_file=input_file, data_path=str(data_path))
438-
439-
darks_value: Optional[PartialDarksFlatsParam | Literal["ignore"]] = config.get(
440-
"darks", None
438+
darks_config = _darks_flats_dict_to_config(
439+
config.get("darks", None), data_config, image_key_path
440+
)
441+
flats_config = _darks_flats_dict_to_config(
442+
config.get("flats", None), data_config, image_key_path
441443
)
442-
darks_config: Optional[DarksFlatsFileConfig]
443-
match darks_value:
444-
case "ignore":
445-
darks_config = None
446-
case None:
447-
darks_config = parse_darks_flats(data_config, image_key_path, None)
448-
case _:
449-
darks_config = parse_darks_flats(
450-
data_config,
451-
image_key_path,
452-
DarksFlatsParam(
453-
file=darks_value["file"],
454-
data_path=darks_value["data_path"],
455-
image_key_path=darks_value.get("image_key_path", None),
456-
),
457-
)
458444

459-
flats_value: Optional[PartialDarksFlatsParam | Literal["ignore"]] = config.get(
460-
"flats", None
445+
return (
446+
data_config,
447+
image_key_path,
448+
angles_config,
449+
darks_config,
450+
flats_config,
461451
)
462-
flats_config: Optional[DarksFlatsFileConfig]
463-
match flats_value:
452+
453+
454+
def _darks_flats_dict_to_config(
455+
value: Optional[PartialDarksFlatsParam | Literal["ignore"]],
456+
data_config: DataConfig,
457+
image_key_path: Optional[str],
458+
) -> Optional[DarksFlatsFileConfig]:
459+
match value:
464460
case "ignore":
465-
flats_config = None
461+
return None
466462
case None:
467-
flats_config = parse_darks_flats(data_config, image_key_path, None)
463+
return parse_darks_flats(data_config, image_key_path, None)
468464
case _:
469-
flats_config = parse_darks_flats(
465+
return parse_darks_flats(
470466
data_config,
471467
image_key_path,
472468
DarksFlatsParam(
473-
file=flats_value["file"],
474-
data_path=flats_value["data_path"],
475-
image_key_path=flats_value.get("image_key_path", None),
469+
file=value["file"],
470+
data_path=value["data_path"],
471+
image_key_path=value.get("image_key_path", None),
476472
),
477473
)
478-
479-
return (
480-
data_config,
481-
image_key_path,
482-
angles_config,
483-
darks_config,
484-
flats_config,
485-
)

0 commit comments

Comments
 (0)