Beispiel #1
0
    def save_grid_view(self):
        """
        Saves grid view in png file
        :return: None
        """
        file_types = "PNG (*.png)"
        filename = str(
            QtImport.QFileDialog.getSaveFileName(
                self,
                "Choose a filename to save under",
                os.path.expanduser("~"),
                file_types,
            )
        )

        filename += ".png"
        image = QtImport.QImage(
            self.grid_graphics_view.scene().sceneRect().size().toSize(),
            QtImport.QImage.Format_ARGB32,
        )
        image.fill(QtImport.Qt.white)
        image_painter = QtImport.QPainter(image)
        self.grid_graphics_view.render(image_painter)
        image_painter.end()
        image.save(filename)
    def display_image(self, index):
        if self.image_reading_thread is None:
            return

        # osc_seq = self.config_dict["collect"]["oscillation_sequence"][0]
        # angle = osc_seq["start"] + index * osc_seq["range"]
        # self.motor_positions["phi"] = angle
        # HWR.beamline.diffractometer.set_static_positions(self.motor_positions)
        # self.graphics_omega_reference_item.set_phi_position(angle)
        self.current_image_index = index

        raw_image = self.image_reading_thread.get_raw_image(index)

        if self.ff_apply:
            if self.ff_corrected_list[index] is None:
                corrected_im_min_max = (
                    self.image_reading_thread.get_corrected_im_min_max())
                ff_image = self.image_reading_thread.get_ff_image(
                    index).astype(float)
                ff_corrected_image = np.divide(
                    raw_image.astype(float),
                    ff_image,
                    out=np.ones_like(raw_image.astype(float)),
                    where=ff_image != 0,
                )
                im = (255.0 * (ff_corrected_image - corrected_im_min_max[0]) /
                      (corrected_im_min_max[1] - corrected_im_min_max[0]))
                self.ff_corrected_list[index] = im.astype(np.uint16)
            else:
                im = self.ff_corrected_list[index]
        else:
            raw_im_min_max = self.image_reading_thread.get_raw_im_min_max()
            im = (255.0 * (raw_image - raw_im_min_max[0]) /
                  (raw_im_min_max[1] - raw_im_min_max[0]))

        if im is not None:
            self.qimage = QtImport.QImage(
                im.astype(np.uint8),
                im.shape[1],
                im.shape[0],
                im.shape[1],
                QtImport.QImage.Format_Indexed8,
            )
            self.graphics_camera_frame.setPixmap(
                self.qpixmap.fromImage(self.qimage))
            self.emit("imageLoaded", index)
Beispiel #3
0
    def display_image(self, index):
        """
        Displays image on the canvas
        :param index: int
        :return:
        """
        angle = self.collect_omega_start + index * self.image_count / 360.0
        if angle > 360:
            angle -= 360
        elif angle < 0:
            angle += 360

        self.graphics_omega_reference_item.set_phi_position(angle)
        self.current_image_index = index

        im = self.image_reading_thread.get_raw_image(index)

        if self.ff_apply and self.image_processing_thread:
            if self.ff_corrected_list[index] is None:
                im_min, im_max = self.image_processing_thread.get_im_min_max()
                im = self.image_reading_thread.get_raw_image(index).astype(float)
                ff_image = self.image_reading_thread.get_ff_image(index).astype(float)
                ff_corrected_image = np.divide(
                    im, ff_image, out=np.ones_like(im), where=ff_image != 0
                )
                im = 255.0 * (ff_corrected_image - im_min) / (im_max - im_min)
                self.ff_corrected_list[index] = im.astype(np.uint16)
            else:
                im = self.ff_corrected_list[index]

        # sx = ndimage.sobel(im, axis=0, mode='constant')
        # sy = ndimage.sobel(im, axis=1, mode='constant')
        # im = np.hypot(sx, sy)

        if im is not None:
            self.qimage = QtImport.QImage(
                im.astype(np.uint8),
                im.shape[1],
                im.shape[0],
                im.shape[1],
                QtImport.QImage.Format_Indexed8,
            )
            self.graphics_camera_frame.setPixmap(self.qpixmap.fromImage(self.qimage))
            self.emit("imageLoaded", index)
Beispiel #4
0
    def init(self):
        AbstractCollect.init(self)
        self.ready_event = gevent.event.Event()
        self.image_dimension = (2048, 2048)
        self.reference_distance = self.getProperty("reference_distance")
        self.reference_angle = self.getProperty("reference_angle")

        QtGraphicsManager.init(self)

        self.disconnect(HWR.beamline.sample_view.camera, "imageReceived",
                        self.camera_image_received)

        self.disconnect(
            HWR.beamline.diffractometer,
            "minidiffStateChanged",
            self.diffractometer_state_changed,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "centringStarted",
            self.diffractometer_centring_started,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "centringAccepted",
            self.create_centring_point,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "centringSuccessful",
            self.diffractometer_centring_successful,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "centringFailed",
            self.diffractometer_centring_failed,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "pixelsPerMmChanged",
            self.diffractometer_pixels_per_mm_changed,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "omegaReferenceChanged",
            self.diffractometer_omega_reference_changed,
        )
        self.disconnect(
            HWR.beamline.diffractometer,
            "minidiffPhaseChanged",
            self.diffractometer_phase_changed,
        )

        self.diffractometer_pixels_per_mm_changed((20., 20.))
        self.graphics_manager_hwobj = self.getObjectByRole("graphics_manager")

        self.graphics_scale_item.set_start_position(
            20, self.image_dimension[1] - 20)

        self.graphics_scale_item.set_custom_pen_color(Colors.BLUE)
        self.graphics_omega_reference_item.set_custom_pen_color(
            Colors.DARK_BLUE)
        self.graphics_measure_distance_item.set_custom_pen_color(
            Colors.DARK_BLUE)
        self.graphics_beam_item.hide()

        self.graphics_view.scene().measureItemChanged.connect(
            self.measure_item_changed)
        self.graphics_view.scene().setSceneRect(0, 0, self.image_dimension[0],
                                                self.image_dimension[1])

        self.qimage = QtImport.QImage()
        self.qpixmap = QtImport.QPixmap()

        self.chan_frame = self.get_channel_object("chanFrame")
        self.chan_frame.connectSignal("update", self.frame_changed)

        self.chan_ff_ssim = self.get_channel_object("chanFFSSIM")
        self.chan_ff_ssim.connectSignal("update", self.ff_ssim_changed)

        self.chan_collect_status = self.get_channel_object("collectStatus")
        #self._actual_collect_status = self.chan_collect_status.getValue()
        self.chan_collect_status.connectSignal("update",
                                               self.collect_status_update)

        self.chan_collect_frame = self.get_channel_object("chanFrameCount")
        self.chan_collect_frame.connectSignal("update",
                                              self.collect_frame_update)

        self.chan_collect_error = self.get_channel_object("collectError")
        self.chan_collect_error.connectSignal("update",
                                              self.collect_error_update)

        self.chan_camera_warning = self.get_channel_object("cameraWarning")
        self.chan_camera_warning.connectSignal("update",
                                               self.camera_warning_update)

        self.chan_camera_error = self.get_channel_object("cameraError")
        self.chan_camera_error.connectSignal("update",
                                             self.camera_error_update)

        self.cmd_collect_detector = self.get_command_object("collectDetector")
        self.cmd_collect_directory = self.get_command_object(
            "collectDirectory")
        self.cmd_collect_exposure_time = self.get_command_object(
            "collectExposureTime")
        self.cmd_collect_in_queue = self.get_command_object("collectInQueue")
        self.cmd_collect_num_images = self.get_command_object(
            "collectNumImages")
        self.cmd_collect_range = self.get_command_object("collectRange")
        self.cmd_collect_scan_type = self.get_command_object("collectScanType")
        self.cmd_collect_shutter = self.get_command_object("collectShutter")
        self.cmd_collect_shutterless = self.get_command_object(
            "collectShutterless")
        self.cmd_collect_start_angle = self.get_command_object(
            "collectStartAngle")
        self.cmd_collect_template = self.get_command_object("collectTemplate")

        self.cmd_collect_ff_num_images = self.get_command_object(
            "collectFFNumImages")
        self.cmd_collect_ff_offset = self.get_command_object("collectFFOffset")
        self.cmd_collect_ff_pre = self.get_command_object("collectFFPre")
        self.cmd_collect_ff_post = self.get_command_object("collectFFPost")

        self.cmd_camera_trigger = self.get_command_object("cameraTrigger")
        self.cmd_camera_live_view = self.get_command_object("cameraLiveView")
        self.cmd_camera_write_data = self.get_command_object("cameraWriteData")
        self.cmd_camera_ff_ssim = self.get_command_object("cameraFFSSIM")

        self.cmd_collect_start = self.get_command_object("collectStart")
        self.cmd_collect_abort = self.get_command_object("collectAbort")

        self.beam_focusing_hwobj = self.getObjectByRole("beam_focusing")