예제 #1
0
    def test_output_prints_correctly_with_no_crystal_match_results(self, mock_print):
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        result.print_results(False)

        # Test for presence of poi: objects in output
        output = self.get_output(mock_print)
        self.failIf("poi:" in output)
예제 #2
0
    def test_job_id_and_image_paths_printed_correctly_for_file(self, mock_print):
        result = ServiceResult("", "test/file/path/fomulatrix", "test/file/path/beamline/test.tif")
        result.print_results(False)

        mock_print.assert_any_call('input_image:"' + abspath('test/file/path/fomulatrix') + '"')
        mock_print.assert_any_call('output_image:"' + abspath('test/file/path/beamline/test.tif') + '"')
        output = self.get_output(mock_print)
        self.failIf("job_id" in output)
 def test_add_image_alignment_results(self):
     mock_aligned_image = Mock(spec_set=[
         "alignment_status_code", "overlap_metric", "pixel_offset",
         "get_alignment_transform"
     ])
     mock_aligned_image.get_alignment_transform = MagicMock(
         return_value=(1.0, Point(0, 0)))
     result = ServiceResult("job-id", "fomulatrix", "beamline")
     result.set_image_alignment_results(mock_aligned_image)
예제 #4
0
    def test_print_without_alignment_results_shows_default_values(self, mock_print):
        Mock(spec_set=["alignment_status_code", "overlap_metric", "pixel_offset", "get_alignment_transform"])
        result = ServiceResult("job-id","fomulatrix","beamline")
        result.print_results(False)

        # Test output
        mock_print.assert_has_calls([
            call('align_transform:1.0, (0.00, 0.00)'),
            call('align_status:-1, NOT SET'),
            call('align_error:0.0')
        ])
예제 #5
0
    def test_exit_code_in_json_output_success(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)
        json_obj = result.print_results(jason_output = True)

        # Test for exit status of -1 in JSON object
        self.failUnlessEqual(0, json_obj['exit_code']['code'])
        self.failIf('err_msg' in json_obj['exit_code'].keys())
예제 #6
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"),
        ])
예제 #7
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
예제 #8
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')])
예제 #9
0
    def test_exit_code_in_std_out_success(self, mock_print):
        # Set up mock for successful image match
        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)
        result.print_results(False)

        # Test for exit status present in output
        mock_print.assert_has_calls([call('exit_code:0')])
예제 #10
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'])
예제 #11
0
    def test_image_alignment_results_print_for_success_case(self, mock_print):
        # Set up mock for successful image match
        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)
        result.print_results(False)

        # Test output
        mock_print.assert_has_calls([
            call("align_transform:" + str(transform[0]) + ", " + str(transform[1])),
            call("align_status:1, OK"),
            call("align_error:9.8")])
예제 #12
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"),
        ])
예제 #13
0
    def test_image_alignment_results_print_for_failure_case(self, mock_print):
        # Set up mock for successful image match
        status = ALIGNED_IMAGE_STATUS_FAIL
        confidence = 0.0
        transform = (1.0, Point(0, 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)
        result.print_results(False)

        # Test output
        mock_print.assert_has_calls([
            call("align_transform:1.0, (0.00, 0.00)"),
            call("align_status:0, FAIL"),
            call("align_error:0.0")])
예제 #14
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")
        ])
예제 #15
0
    def test_exit_code_starting_state_is_negative_1(self, mock_print):
        result = ServiceResult("job-id", "fomulatrix", "beamline")
        result.print_results(False)

        mock_print.assert_has_calls([call('exit_code:-1')])