Skip to content

gotthard2lib

Gotthard2Ctrl

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
class Gotthard2Ctrl():
    def __init__(
        self,
        run_dc: extra_data.DataCollection,
        ctrl_src: str,
    ):
        """Read slow data.
        :param run_dir: EXtra-data RunDirectory DataCollection object.
        :param ctrl_src: Control source name for accessing slow data.
        """
        self.run_dc = run_dc
        self.ctrl_src = ctrl_src

    def get_bias_voltage(self):
        """Get bias voltage for gotthard2."""
        return self.run_dc[self.ctrl_src, "highVoltageMax"].as_single_value()

    def get_exposure_time(self):
        """Get exposure time for gotthard2."""
        return round(
            self.run_dc[self.ctrl_src, "exposureTime"].as_single_value(), 4)

    def get_exposure_period(self):
        """Get exposure period for gotthard2."""
        return round(
            self.run_dc[self.ctrl_src, "exposurePeriod"].as_single_value(), 4)

    def get_acquisition_rate(self):
        """Get acquisition rate for gotthard2."""
        try:
            return float(
                self.run_dc.get_run_value(self.ctrl_src, "acquisitionRate"))
        except extra_data.PropertyNameError:
            pass

    def get_single_photon(self):
        """Get single photon for gotthard2."""
        if "singlePhoton.value" in self.run_dc.keys_for_source(self.ctrl_src):
            return bool(
                self.run_dc[self.ctrl_src, "singlePhoton"].as_single_value())

    def get_det_type(self):
        """GH2 rxHostname is a vector of bytes objects.
        GH2 25um has two host names unlike 50um which has one.

        Returns:
            str: return if its a 25um or 50um detector.
        """

        hostname = self.run_dc.get_run_value(self.ctrl_src, "rxHostname")
        return "25um" if hostname[1].decode("utf-8") else "50um"

    def second_module_reversed(self):
        """Check if reverseSlaveReadOutMode is True."""
        return bool(
                self.run_dc[
                    self.ctrl_src, "reverseSlaveReadOutMode"].as_single_value())

__init__(run_dc, ctrl_src)

Read slow data. :param run_dir: EXtra-data RunDirectory DataCollection object. :param ctrl_src: Control source name for accessing slow data.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def __init__(
    self,
    run_dc: extra_data.DataCollection,
    ctrl_src: str,
):
    """Read slow data.
    :param run_dir: EXtra-data RunDirectory DataCollection object.
    :param ctrl_src: Control source name for accessing slow data.
    """
    self.run_dc = run_dc
    self.ctrl_src = ctrl_src

get_acquisition_rate()

Get acquisition rate for gotthard2.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_acquisition_rate(self):
    """Get acquisition rate for gotthard2."""
    try:
        return float(
            self.run_dc.get_run_value(self.ctrl_src, "acquisitionRate"))
    except extra_data.PropertyNameError:
        pass

get_bias_voltage()

Get bias voltage for gotthard2.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_bias_voltage(self):
    """Get bias voltage for gotthard2."""
    return self.run_dc[self.ctrl_src, "highVoltageMax"].as_single_value()

get_det_type()

GH2 rxHostname is a vector of bytes objects. GH2 25um has two host names unlike 50um which has one.

Returns:

Name Type Description
str

return if its a 25um or 50um detector.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_det_type(self):
    """GH2 rxHostname is a vector of bytes objects.
    GH2 25um has two host names unlike 50um which has one.

    Returns:
        str: return if its a 25um or 50um detector.
    """

    hostname = self.run_dc.get_run_value(self.ctrl_src, "rxHostname")
    return "25um" if hostname[1].decode("utf-8") else "50um"

get_exposure_period()

Get exposure period for gotthard2.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_exposure_period(self):
    """Get exposure period for gotthard2."""
    return round(
        self.run_dc[self.ctrl_src, "exposurePeriod"].as_single_value(), 4)

get_exposure_time()

Get exposure time for gotthard2.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_exposure_time(self):
    """Get exposure time for gotthard2."""
    return round(
        self.run_dc[self.ctrl_src, "exposureTime"].as_single_value(), 4)

get_single_photon()

Get single photon for gotthard2.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def get_single_photon(self):
    """Get single photon for gotthard2."""
    if "singlePhoton.value" in self.run_dc.keys_for_source(self.ctrl_src):
        return bool(
            self.run_dc[self.ctrl_src, "singlePhoton"].as_single_value())

second_module_reversed()

Check if reverseSlaveReadOutMode is True.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def second_module_reversed(self):
    """Check if reverseSlaveReadOutMode is True."""
    return bool(
            self.run_dc[
                self.ctrl_src, "reverseSlaveReadOutMode"].as_single_value())

sort_dark_runs_by_gain(raw_folder, runs, ctrl_src)

Sort the three dark runs based /RUN/.../settings/. The expected value options are [dynamicgain, fixgain1, fixgain2]

Parameters:

Name Type Description Default
raw_folder Union[str, Path]

The raw folder for the three runs to be sorted.

required
runs list

A list of three dark runs.

required
ctrl_src str

The CTRL source for checking settings dataset value.

required
Return

List: Ordered list of runs.

Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/gotthard2/gotthard2lib.py
def sort_dark_runs_by_gain(
    raw_folder: Union[str, Path],
    runs: List[int],
    ctrl_src: str,
):
    """Sort the three dark runs based /RUN/.../settings/.
    The expected value options are [dynamicgain, fixgain1, fixgain2]
    Args:
        raw_folder (Union[str, Path]): The raw folder for the three runs to be sorted.
        runs (list): A list of three dark runs.
        ctrl_src: The CTRL source for checking `settings` dataset value.
    Return:
        List: Ordered list of runs.
    """

    run_to_setting = dict()
    expected_settings = ["dynamicgain", "fixgain1", "fixgain2"]
    assert len(set(runs)) == 3, f"A list of {len(runs)} runs is provided, three different dark runs are expected."  # noqa

    for r in runs:
        run_to_setting[r] = extra_data.RunDirectory(
            Path(raw_folder) / f"r{r:04d}").get_run_value(
                ctrl_src, "settings")

    if len(set(run_to_setting.values())) < 3:
        raise ValueError(
            f"Incorrect gain settings for the provided dark runs: {run_to_setting}."
            f" The expected settings for these runs are {expected_settings}.")

    sorted_run_to_setting = dict(sorted(
        run_to_setting.items(),
        key=lambda x: expected_settings.index(x[1])))

    sorted_runs = list(sorted_run_to_setting.keys())
    if list(run_to_setting.values()) != expected_settings:
        warning(
            "Dark runs were incorrectly sorted and "
            f"have now been corrected to: {sorted_runs}.")

    return sorted_runs