From 4fc3b529fed2d26d6ee3d1834cb424cd8445f017 Mon Sep 17 00:00:00 2001 From: rettigl Date: Sun, 7 Jan 2024 11:03:22 +0100 Subject: [PATCH] fix momentum correction (bin_ranges) when no image is loaded fix for missing lens voltages --- sed/calibrator/momentum.py | 2 +- sed/loader/mpes/loader.py | 2 +- tests/calibrator/test_energy.py | 2 +- tests/test_processor.py | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sed/calibrator/momentum.py b/sed/calibrator/momentum.py index e357e335..abea05a9 100644 --- a/sed/calibrator/momentum.py +++ b/sed/calibrator/momentum.py @@ -73,7 +73,7 @@ def __init__( self.slice: np.ndarray = None self.slice_corrected: np.ndarray = None self.slice_transformed: np.ndarray = None - self.bin_ranges: List[Tuple] = [] + self.bin_ranges: List[Tuple] = self._config["momentum"].get("bin_ranges", []) if data is not None: self.load_data(data=data, bin_ranges=bin_ranges) diff --git a/sed/loader/mpes/loader.py b/sed/loader/mpes/loader.py index faeb2d10..e1886c32 100644 --- a/sed/loader/mpes/loader.py +++ b/sed/loader/mpes/loader.py @@ -840,7 +840,7 @@ def gather_metadata( ].keys() lens_volts = np.array( - [metadata["file"][f"KTOF:Lens:{lens}:V"] for lens in lens_list], + [metadata["file"].get(f"KTOF:Lens:{lens}:V", np.NaN) for lens in lens_list], ) for mode, value in self._config["metadata"]["lens_mode_config"].items(): lens_volts_config = np.array([value[k] for k in lens_list]) diff --git a/tests/calibrator/test_energy.py b/tests/calibrator/test_energy.py index acfe0898..ebcb887e 100644 --- a/tests/calibrator/test_energy.py +++ b/tests/calibrator/test_energy.py @@ -631,7 +631,7 @@ def test_add_offsets_functionality(energy_scale: str) -> None: loader=get_loader("flash", config=config), ) t_df = dask.dataframe.from_pandas(df.copy(), npartitions=2) - res, meta = ec.add_offsets(t_df, **params) # type: ignore[arg-type] # pylint disable=unexpected-keyword-arg + res, meta = ec.add_offsets(t_df, **params) # type: ignore np.testing.assert_allclose(res["energy"].values, exp_vals.values) exp_meta = {} exp_meta["applied"] = True diff --git a/tests/test_processor.py b/tests/test_processor.py index ecd53ba7..f2a0356d 100644 --- a/tests/test_processor.py +++ b/tests/test_processor.py @@ -8,7 +8,6 @@ from importlib.util import find_spec from pathlib import Path from typing import Any -from typing import cast from typing import Dict from typing import List from typing import Tuple @@ -20,7 +19,6 @@ from sed import SedProcessor from sed.core.config import parse_config -from sed.loader.flash.loader import FlashLoader from sed.loader.loader_interface import get_loader # pylint: disable=duplicate-code @@ -335,11 +333,11 @@ def test_pose_adjustment() -> None: verbose=True, ) # pose adjustment w/o loaded image - processor.pose_adjustment(**adjust_params, use_correction=False, apply=True) # type: ignore[arg-type] + processor.pose_adjustment(**adjust_params, use_correction=False, apply=True) # type: ignore processor.bin_and_load_momentum_calibration(apply=True) # test pose adjustment - processor.pose_adjustment(**adjust_params, use_correction=False, apply=True) # type: ignore[arg-type] + processor.pose_adjustment(**adjust_params, use_correction=False, apply=True) # type: ignore processor = SedProcessor( folder=df_folder,