예제 #1
0
    def test_append_multiple_crystal_match_results(self, mock_print):
        # Setup - create mock result
        result = ServiceResult("job-id", "fomulatrix", "beamline")

        # Set 1
        new_positions = [Point(100, 100)]
        deltas = [Point(3, 4)]
        mean_errors = ["0.45"]
        status_codes = [CRYSTAL_MATCH_STATUS_OK]
        mock_match_results = self.mock_crystal_matcher_results(deltas, mean_errors, new_positions, status_codes)
        result.append_crystal_matching_results(mock_match_results)

        # Set 2
        new_positions = [Point(123, 456), Point(654, 321)]
        deltas = [Point(1, 2), Point(7, 8)]
        mean_errors = ["4.56", "65.4"]
        status_codes = [CRYSTAL_MATCH_STATUS_OK, CRYSTAL_MATCH_STATUS_FAIL]
        mock_match_results = self.mock_crystal_matcher_results(deltas, mean_errors, new_positions, status_codes)
        result.append_crystal_matching_results(mock_match_results)
        result.print_results(False)

        # Test
        mock_print.assert_has_calls([
            call("\nlocation ; transform ; status ; mean error"),
            call("poi:(100.00, 100.00) z: 0 ; (3.00, 4.00) ; 1, OK ; 0.45"),
            call("poi:(123.00, 456.00) z: 0 ; (1.00, 2.00) ; 1, OK ; 4.56"),
            call("poi:(654.00, 321.00) z: 0 ; (7.00, 8.00) ; 0, FAIL ; 65.4"),
        ])
예제 #2
0
    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
예제 #3
0
    def test_failed_crystal_match_result_prints_correctly(self, mock_print):
        # Setup - create mock result
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        new_positions = [Point(654, 321)]
        deltas = [Point(7, 8)]
        mean_errors = ["65.4"]
        status_codes = [CRYSTAL_MATCH_STATUS_FAIL]
        mock_match_results = self.mock_crystal_matcher_results(deltas, mean_errors, new_positions, status_codes)
        result.append_crystal_matching_results(mock_match_results)
        result.print_results(False)

        # Test
        mock_print.assert_has_calls([
            call("\nlocation ; transform ; status ; mean error"),
            call("poi:(654.00, 321.00) z: 0 ; (7.00, 8.00) ; 0, FAIL ; 65.4"),
        ])
예제 #4
0
    def test_append_single_crystal_match_result(self, mock_print):
        # Setup - create mock result
        new_positions = [Point(100, 100)]
        deltas = [Point(3, 4)]
        mean_errors = ["0.45"]
        status_codes = [CRYSTAL_MATCH_STATUS_OK]
        mock_match_results = self.mock_crystal_matcher_results(deltas, mean_errors, new_positions, status_codes)

        # Run
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        result.append_crystal_matching_results(mock_match_results)
        result.print_results(False)

        # Test
        mock_print.assert_has_calls([
            call("\nlocation ; transform ; status ; mean error"),
            call("poi:(100.00, 100.00) z: 0 ; (3.00, 4.00) ; 1, OK ; 0.45")
        ])