def setup(self):
        """Perform necessary initialisation."""
        self.MasterNode.disable_hv()  # In case already setup and LV is enabled
        self.MasterNode.initialise_lv()
        self.MasterNode.set_hv_bias(120)
        # self.MasterNode.enable_hv()

        node_threads = []
        for node in self.Nodes:
            node_threads.append(util.spawn_thread(node.setup))
        util.wait_for_threads(node_threads)
    def unmask_pixels(self, node=None, chips=None):
        """Reset pixelmask for the given chips.

        Args:
            node(int): Node to unmask - If None, all nodes included
            chips(list(int)): List of chips to include in equalisation - If
                None, all chips included

        """
        nodes, chips = self._validate(node, chips)

        node_threads = []
        for node in nodes:
            node_threads.append(util.spawn_thread(node.unmask_pixels, chips))
        util.wait_for_threads(node_threads)
    def optimise_gnd_fbk_cas(self, node_id=None, chips=None):
        """Optimise GND, FBK and CAS for the given node and chips.

        Args:
            node_id(int): Node to optimise - If None, all nodes included
            chips(list(int)): List of chips to include in optimisation - If
                None, all chips included

        """
        nodes, chips = self._validate(node_id, chips)

        node_threads = []
        for node in nodes:
            node_threads.append(
                util.spawn_thread(node.optimise_gnd_fbk_cas, chips))
        util.wait_for_threads(node_threads)
    def test_wait_for_threads(self):
        mocks = [MagicMock(), MagicMock(), MagicMock(), MagicMock()]

        response = util.wait_for_threads(mocks)

        for idx, mock in enumerate(mocks):
            mock.join.assert_called_once_with()
            self.assertEqual(mock.join.return_value, response[idx])
    def full_calibration(self, node_id=None):
        """Perform the full calibration process.

        Args:
            node_id(int): Node to optimise - If None, all nodes included

        """
        nodes, _ = self._validate(node_id)

        node_threads = []
        for node_ in nodes:
            node_threads.append(
                util.spawn_thread(self._try_node_full_calibration, node_))
        util.wait_for_threads(node_threads)

        while self.errors:
            error = self.errors.pop()
            self.logger.info(error[0], *error[1])
    def threshold_equalization(self, node_id=None, chips=None):
        """Calibrate discriminator equalization for given chips in detector.

        Args:
            node_id(int): Node to equalise - If None, all nodes included
            chips(list(int)): List of chips to include in equalisation - If
                None, all chips included

        """
        nodes, chips = self._validate(node_id, chips)

        node_threads = []
        for node_ in nodes:
            node_threads.append(
                util.spawn_thread(self._try_node_threshold_equalization, node_,
                                  chips))
        util.wait_for_threads(node_threads)

        while self.errors:
            error = self.errors.pop()
            self.logger.info(error[0], *error[1])
    def acquire_tp_image(self, tp_mask):
        """Load the given test pulse mask and capture a tp image.

        Args:
            tp_mask(str): Mask file in config directory

        """
        node_threads = []
        for node in self.Nodes:
            node_threads.append(
                util.spawn_thread(node.acquire_tp_image, tp_mask))

        images = util.wait_for_threads(node_threads)

        detector_image = self._combine_images(images)

        plot_name = util.tag_plot_name("TPImage", "Detector")
        self.dawn.plot_image(detector_image, plot_name)
    def expose(self, exposure_time):
        """Acquire single image.

        Args:
            exposure_time(int): Acquire time for image

        Returns:
            numpy.array: Image data

        """
        node_threads = []
        for node in self.Nodes:
            node_threads.append(util.spawn_thread(node.expose, exposure_time))

        images = util.wait_for_threads(node_threads)

        detector_image = self._combine_images(images)

        plot_name = util.tag_plot_name("Image", "Detector")
        self.dawn.plot_image(detector_image, plot_name)
 def load_config(self):
     """Load detector configuration files and default thresholds."""
     node_threads = []
     for node in self.Nodes:
         node_threads.append(util.spawn_thread(node.load_config))
     util.wait_for_threads(node_threads)