Skip to content

Commit

Permalink
test tof_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
steinnymir committed Nov 1, 2023
1 parent b8911ea commit 2538e28
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 0 additions & 2 deletions sed/calibrator/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,6 @@ def append_tof_ns_axis(
) -> Tuple[Union[pd.DataFrame, dask.dataframe.DataFrame], dict]:
"""Converts the time-of-flight time from steps to time in ns.
# TODO: needs tests
Args:
df (Union[pd.DataFrame, dask.dataframe.DataFrame]): Dataframe to convert.
tof_column (str, optional): Name of the column containing the
Expand Down
30 changes: 30 additions & 0 deletions tests/calibrator/test_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,36 @@ def test_append_energy_axis_raises():
)


def test_append_tof_ns_axis():
"""Function to test if the tof_ns calibration is correctly applied.
TODO: add further tests once the discussion about units is done.
"""
cfg = {
"dataframe": {
"tof_column": "t",
"tof_ns_column": "t_ns",
"tof_binning": 1,
"tof_binwidth": 1e-9,
},
}
config = parse_config(config=cfg, folder_config={}, user_config={}, system_config={})
loader = get_loader(loader_name="mpes", config=config)

# from kwds
df, _ = loader.read_dataframe(folders=df_folder, collect_metadata=False)
ec = EnergyCalibrator(config=config, loader=loader)
df, _ = ec.append_tof_ns_axis(df, binwidth=2e-9, binning=1)
assert config["dataframe"]["tof_ns_column"] in df.columns
np.testing.assert_allclose(df[ec.tof_column], df[ec.tof_ns_column] / 4)

# from config
df, _ = loader.read_dataframe(folders=df_folder, collect_metadata=False)
ec = EnergyCalibrator(config=config, loader=loader)
df, _ = ec.append_tof_ns_axis(df)
assert config["dataframe"]["tof_ns_column"] in df.columns
np.testing.assert_allclose(df[ec.tof_column], df[ec.tof_ns_column] / 2)


amplitude = 2.5 # pylint: disable=invalid-name
center = (730, 730)
sample = np.array(
Expand Down

0 comments on commit 2538e28

Please sign in to comment.