@@ -362,17 +362,25 @@ def _read_kmod_results(paths: Sequence[Path | str], beam: int
362362 # sort into bpm and betastar --
363363 bpm_results = _filter_bpm_results (all_dfs , beam = beam )
364364 betastar_results = _filter_betastar_results (all_dfs )
365-
365+ LOG .debug (
366+ f"Found { len (bpm_results )} BPM results and { len (betastar_results )} betastar results for beam { beam } ."
367+ )
366368 return bpm_results , betastar_results
367369
368370
371+ def _is_bpm_df (df : tfs .TfsDataFrame , beam : int ) -> bool :
372+ """ Check if the given df is a BPM results file for the given beam. """
373+ # bpm files must have a beta column
374+ if f"{ BETA } X" not in df .columns :
375+ return False
376+
377+ # They should also have at least one element (e.g. the BPM) matching the beam
378+ elements = df .index if NAME not in df .columns else df [NAME ]
379+ return elements .str .match (fr".*\.B{ beam } $" , flags = re .IGNORECASE ).any ()
380+
381+
369382def _filter_bpm_results (dfs : Sequence [tfs .TfsDataFrame ], beam : int ) -> list [tfs .TfsDataFrame ]:
370- bpm_dfs = [df for df in dfs if f"{ BETA } X" in df .columns ]
371- bpm_dfs = [df for df in bpm_dfs if (
372- NAME not in df .columns or all (df [NAME ].str .match (fr"(.*\.B{ beam } $|IP\d$)" , flags = re .IGNORECASE ))
373- )
374- ]
375- return bpm_dfs
383+ return [df for df in dfs if _is_bpm_df (df , beam )]
376384
377385
378386def _filter_betastar_results (dfs : Sequence [tfs .TfsDataFrame ]) -> list [tfs .TfsDataFrame ]:
@@ -386,8 +394,9 @@ def _write_output(dfs: dict[str, tfs.TfsDataFrame], output_dir: Path):
386394 df = dfs .get (f"{ id_ } { plane } " )
387395 if df is None :
388396 continue
389-
390- tfs .write (output_dir / f"{ filename } { plane .lower ()} { EXT } " , df , save_index = NAME )
397+ outfile = output_dir / f"{ filename } { plane .lower ()} { EXT } "
398+ LOG .info (f"Writing output file { outfile } " )
399+ tfs .write (outfile , df , save_index = NAME )
391400
392401
393402# Script Mode ------------------------------------------------------------------
0 commit comments