Skip to content

Commit

Permalink
add option for either loading calibration data from file or from config
Browse files Browse the repository at this point in the history
  • Loading branch information
rettigl committed Nov 22, 2024
1 parent 9214279 commit 2677069
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
24 changes: 13 additions & 11 deletions sed/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ def align_dld_sectors(
def calibrate_delay_axis(
self,
delay_range: Tuple[float, float] = None,
read_delay_ranges: bool = True,
datafile: str = None,
preview: bool = False,
verbose: bool = None,
Expand All @@ -1713,8 +1714,10 @@ def calibrate_delay_axis(
Args:
delay_range (Tuple[float, float], optional): The scanned delay range in
picoseconds. Defaults to None.
read_delay_ranges (bool, optional): Option whether to read the delay ranges from the
data. Defaults to True. If false, parameters in the config will be used.
datafile (str, optional): The file from which to read the delay ranges.
Defaults to None.
Defaults to the first file of the dataset.
preview (bool, optional): Option to preview the first elements of the data frame.
Defaults to False.
verbose (bool, optional): Option to print out diagnostic information.
Expand All @@ -1732,16 +1735,15 @@ def calibrate_delay_axis(
if verbose:
print("Adding delay column to dataframe:")

if delay_range is None and datafile is None:
if len(self.dc.calibration) == 0:
try:
datafile = self._files[0]
except IndexError:
print(
"No datafile available, specify either",
" 'datafile' or 'delay_range'",
)
raise
if read_delay_ranges:
try:
datafile = self._files[0]
except IndexError:
print(
"No datafile available, specify either",
" 'datafile' or 'delay_range'",
)
raise

df, metadata = self.dc.append_delay_axis(
self._dataframe,
Expand Down
13 changes: 10 additions & 3 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_delay_calibration_workflow() -> None:
verbose=True,
)
delay_range = (-500, 1500)
processor.calibrate_delay_axis(delay_range=delay_range, preview=False)
processor.calibrate_delay_axis(delay_range=delay_range)
# read from datafile
processor = SedProcessor(
folder=df_folder,
Expand All @@ -751,11 +751,18 @@ def test_delay_calibration_workflow() -> None:
processor.add_delay_offset(constant=1)
with pytest.raises(NotImplementedError):
processor.calibrate_delay_axis()
with pytest.raises(NotImplementedError):
processor.calibrate_delay_axis(
p1_key="@trARPES:DelayStage:p1",
p2_key="@trARPES:DelayStage:p2",
t0_key="@trARPES:DelayStage:t0",
read_delay_ranges=False,
)
processor.calibrate_delay_axis(
p1_key="@trARPES:DelayStage:p1",
p2_key="@trARPES:DelayStage:p2",
t0_key="@trARPES:DelayStage:t0",
preview=True,
read_delay_ranges=True,
)
assert "delay" in processor.dataframe.columns
creation_date_calibration = processor.dc.calibration["creation_date"]
Expand All @@ -776,7 +783,7 @@ def test_delay_calibration_workflow() -> None:
system_config={},
verbose=True,
)
processor.calibrate_delay_axis()
processor.calibrate_delay_axis(read_delay_ranges=False)
assert "delay" in processor.dataframe.columns
assert (
processor.attributes.metadata["delay_calibration"]["calibration"]["creation_date"]
Expand Down

0 comments on commit 2677069

Please sign in to comment.