def perform_match(self, parser_manager):
        """
        Perform image alignment and crystal matching returning a results object.
        :param .
        :return: ServiceResult object.
        """
        log = logging.getLogger(".".join([__name__, self.__class__.__name__]))
        log.addFilter(logconfig.ThreadContextFilter())
        extra = self._config_align.all_to_json()
        extra.update(self._config_crystal.all_to_json())
        log = logging.LoggerAdapter(log, extra)
        log.info("Matching Started")
        log.debug(extra)

        input_poi = parser_manager.parse_selected_points_from_args()
        beamline_image = parser_manager.get_focused_image()
        parser_manager.save_focused_image(beamline_image)
        focused_image_path = parser_manager.get_focused_image_path()
        formulatrix_image_path = parser_manager.get_formulatrix_image_path()
        job_id = parser_manager.get_job_id()

        # Create the images
        image1 = Image.from_file(formulatrix_image_path)
        image2 = beamline_image

        # Create results object
        service_result = ServiceResult(job_id, formulatrix_image_path,
                                       focused_image_path)

        # Perform alignment
        try:

            aligned_images, scaled_poi = self._perform_alignment(
                image1, image2, input_poi)
            service_result.set_image_alignment_results(aligned_images)

            # Perform Crystal Matching - only proceed if we have a valid alignment
            if aligned_images.alignment_status_code(
            ) == ALIGNED_IMAGE_STATUS_OK:
                match_results = self._perform_matching(aligned_images,
                                                       scaled_poi,
                                                       parser_manager)

                service_result.append_crystal_matching_results(match_results)

        except Exception as e:
            if sys.version_info[0] < 3:
                log.error("ERROR: " + e.message)
            else:
                log.error("ERROR: " + str(e))
            service_result.set_err_state(e)

        return service_result
Exemple #2
0
    def test_exit_code_in_std_out_with_error(self, mock_print):
        # Set up mock for successful image alignment
        status = ALIGNED_IMAGE_STATUS_OK
        confidence = 9.8
        transform = (1.0, Point(3.0, 4.0))
        mock_aligned_image = self.mock_aligned_images(confidence, status, transform)
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        result.set_image_alignment_results(mock_aligned_image)

        # Throw an exception and print results
        e = Exception("test exception")
        result.set_err_state(e)
        result.print_results(False)

        # Test for exit status of -1 with err message
        mock_print.assert_has_calls([call('exit_code:-1, test exception')])
Exemple #3
0
    def test_exit_code_in_json_output_with_error(self):
        # Set up mock for successful image alignment
        status = ALIGNED_IMAGE_STATUS_OK
        confidence = 9.8
        transform = (1.0, Point(3.0, 4.0))
        mock_aligned_image = self.mock_aligned_images(confidence, status, transform)
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        result.set_image_alignment_results(mock_aligned_image)

        # Throw an exception and print results
        e = Exception("test exception")
        result.set_err_state(e)
        json_obj = result.print_results(jason_output = True)

        # Test for exit status of -1 in JSON object
        self.failUnlessEqual(-1, json_obj['exit_code']['code'])
        self.failUnlessEqual('test exception', json_obj['exit_code']['err_msg'])