From 2ccba6b23af62098d5def29c00116f34fd43a1c5 Mon Sep 17 00:00:00 2001 From: gadorlhiac Date: Fri, 5 Apr 2024 08:27:45 -0700 Subject: [PATCH] ENH Add input/output file validators to MergePartialator --- lute/io/models/sfx_merge.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lute/io/models/sfx_merge.py b/lute/io/models/sfx_merge.py index 9f6509e9..0fdbad4a 100644 --- a/lute/io/models/sfx_merge.py +++ b/lute/io/models/sfx_merge.py @@ -48,7 +48,7 @@ class Config(BaseBinaryParameters.Config): "", description="Path to input stream.", flag_type="-", rename_param="i" ) out_file: str = Field( - "partialator.hkl", + "", description="Path to output file.", flag_type="-", rename_param="o", @@ -185,6 +185,29 @@ class Config(BaseBinaryParameters.Config): rename_param="harvest-file", ) + @validator("in_file", always=True) + def validate_in_file(cls, in_file: str, values: Dict[str, Any]) -> str: + if in_file == "": + stream_file: Optional[str] = read_latest_db_entry( + f"{values['lute_config'].work_dir}", + "ConcatenateStreamFiles", + "out_file", + ) + if stream_file: + return stream_file + return in_file + + @validator("out_file", always=True) + def validate_out_file(cls, out_file: str, values: Dict[str, Any]) -> str: + if out_file == "": + in_file: str = values["in_file"] + if in_file: + tag: str = in_file.split(".")[0] + return f"{tag}.hkl" + else: + return "partialator.hkl" + return out_file + class CompareHKLParameters(BaseBinaryParameters): """Parameters for CrystFEL's `compare_hkl` for calculating figures of merit.