Beispiel #1
0
    def test_that_can_merge_without_fitting(self):
        # Arrange
        fit_type = FitModeForMerge.NoFit
        scale_input = 32.0
        shift_input = 12.65
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)

        bundles = {
            ISISReductionMode.LAB: [sample_lab, can_lab],
            ISISReductionMode.HAB: [sample_hab, can_hab]
        }

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        scale = result.scale
        shift = result.shift
        self.assertTrue(abs(scale - scale_input) < 1e-4)
        self.assertTrue(abs(shift - shift_input) < 1e-4)

        # There is an overlap of two bins between HAB and LAB, the values are tested in SANSStitch
        self.assertEqual(merged_workspace.blocksize(), 10)
Beispiel #2
0
    def test_that_can_merge_with_scale_only_fitting(self):
        # Arrange
        fit_type = FitModeForMerge.ScaleOnly
        scale_input = 1.67
        shift_input = 2.7
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)
        bundles = {
            ISISReductionMode.LAB: [sample_lab, can_lab],
            ISISReductionMode.HAB: [sample_hab, can_hab]
        }

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertEqual(merged_workspace.blocksize(), 10)

        scale = result.scale
        shift = result.shift

        self.assertNotEqual(scale, scale_input)
        self.assertLess(abs(scale - 1.0), 1e-4)
        self.assertLess(abs(shift - shift_input), 1e-4)
Beispiel #3
0
def get_merge_bundle_for_merge_request(output_bundles, parent_alg):
    """
    Create a merge bundle for the reduction outputs and perform stitching if required
    :param output_bundles: a list of output_bundles
    :param parent_alg: a handle to the parent algorithm
    """
    # Order the reductions. This leaves us with a dict mapping from the reduction type (i.e. HAB, LAB) to
    # a list of reduction settings which contain the information for sample and can.
    reduction_mode_vs_output_bundles = get_reduction_mode_vs_output_bundles(
        output_bundles)

    # Get the underlying state from one of the elements
    state = output_bundles[0].state

    merge_factory = MergeFactory()
    merger = merge_factory.create_merger(state)

    # Run the merger and return the merged output workspace
    merged = merger.merge(reduction_mode_vs_output_bundles, parent_alg)
    replace_prop = True
    if state.save.user_file:
        merged.merged_workspace.getRun().addProperty(
            "UserFile", os.path.basename(state.save.user_file), replace_prop)
    if state.save.batch_file:
        merged.merged_workspace.getRun().addProperty(
            "BatchFile", os.path.basename(state.save.batch_file), replace_prop)
    return merged
Beispiel #4
0
    def test_that_can_merge_fitting(self):
        # Arrange
        fit_type = FitModeForMerge.BOTH
        scale_input = 1.67
        shift_input = 2.7
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)
        bundles = {
            ReductionMode.LAB: [sample_lab, can_lab],
            ReductionMode.HAB: [sample_hab, can_hab]
        }

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertEqual(merged_workspace.blocksize(), 10)

        scale = result.scale
        shift = result.shift
        self.assertNotEqual(scale, scale_input)
        self.assertNotEqual(shift, shift_input)
        self.assertTrue(abs(scale - (-15.0)) < 1e-4)
        self.assertTrue(abs(shift - 0.0472222222222) < 1e-4)
    def test_that_can_merge_without_fitting(self):
        # Arrange
        fit_type = FitModeForMerge.NoFit
        scale_input = 32.0
        shift_input = 12.65
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)

        bundles = {ISISReductionMode.LAB: [sample_lab, can_lab],
                   ISISReductionMode.HAB: [sample_hab, can_hab]}

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        scale = result.scale
        shift = result.shift
        self.assertTrue(abs(scale - scale_input) < 1e-4)
        self.assertTrue(abs(shift - shift_input) < 1e-4)

        # There is an overlap of two bins between HAB and LAB, the values are tested in SANSStitch
        self.assertTrue(merged_workspace.blocksize() == 10)
    def test_that_can_merge_with_scale_only_fitting(self):
        # Arrange
        fit_type = FitModeForMerge.ScaleOnly
        scale_input = 1.67
        shift_input = 2.7
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)
        bundles = {ISISReductionMode.LAB: [sample_lab, can_lab],
                   ISISReductionMode.HAB: [sample_hab, can_hab]}

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertTrue(merged_workspace.blocksize() == 10)

        scale = result.scale
        shift = result.shift

        self.assertTrue(scale != scale_input)
        self.assertTrue(abs(scale-1.0) < 1e-4)
        self.assertTrue(abs(shift-shift_input) < 1e-4)
Beispiel #7
0
    def test_that_can_merge_with_scale_only_fitting(self):
        # Same arguments as above, tie shift to -3 and fit scale : should result in scale of 0.5
        fit_type = FitModeForMerge.SCALE_ONLY
        scale_input = 0.1
        shift_input = -3
        expected_scale = 0.5
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)
        bundles = {ReductionMode.LAB: [sample_lab, can_lab],
                   ReductionMode.HAB: [sample_hab, can_hab]}

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertEqual(merged_workspace.blocksize(),  10)

        scale = result.scale
        shift = result.shift

        self.assertNotEqual(scale,  scale_input)
        self.assertLess(abs(scale - expected_scale), 1e-4)
        self.assertLess(abs(shift-shift_input), 1e-4)
Beispiel #8
0
    def test_that_can_merge_with_shift_only_fitting(self):
        # Same argument as above, tie scale to 0.5 and fit shift : should result in shift of -3
        fit_type = FitModeForMerge.SHIFT_ONLY
        scale_input = 0.5
        shift_input = -1.0
        expected_shift = -3
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)
        bundles = {ReductionMode.LAB: [sample_lab, can_lab],
                   ReductionMode.HAB: [sample_hab, can_hab]}

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertEqual(merged_workspace.blocksize(),  10)

        scale = result.scale
        shift = result.shift

        self.assertNotEqual(shift,  shift_input)
        self.assertTrue(abs(scale - scale_input) < 1e-4)
        self.assertTrue(abs(shift - expected_shift ) < 1e-4)
Beispiel #9
0
    def test_that_can_merge_fitting(self):
        # If we fit both, we required that
        # 1 = f0.A0 + scaling*5    : @ x  = 0
        # 5 = f0.A0 + scaling*13   : @ x  = 2
        # This is a linear problem, in 2 variables, i.e. it has 1 unique solution: scaling = 0.5 : f0.A0 = -1.5
        # returning shift is f0.A0/scaling = -3
        fit_type = FitModeForMerge.BOTH
        scale_input = 0.4
        shift_input = -1
        expected_scale = 0.5
        expected_shift = -1.5/0.5
        state = self._get_simple_state(fit_type, scale_input, shift_input)
        merge_factory = MergeFactory()
        merger = merge_factory.create_merger(state)

        sample_lab, sample_hab, can_lab, can_hab = self._provide_data(state)

        bundles = {ReductionMode.LAB: [sample_lab, can_lab],
                   ReductionMode.HAB: [sample_hab, can_hab]}

        # Act
        result = merger.merge(bundles)
        merged_workspace = result.merged_workspace

        self.assertEqual(merged_workspace.blocksize(),  10)

        scale = result.scale
        shift = result.shift
        self.assertNotEqual(scale,  scale_input)
        self.assertNotEqual(shift,  shift_input)
        self.assertTrue(abs(scale - expected_scale) < 1e-4)
        self.assertTrue(abs(shift - expected_shift) < 1e-4)
Beispiel #10
0
    def test_that_correct_merger_is_generated(self):
        # Arrange
        state = self._get_simple_state()
        merge_factory = MergeFactory()

        # Act
        merger = merge_factory.create_merger(state)

        # Assert
        self.assertTrue(isinstance(merger, ISIS1DMerger))
    def test_that_correct_merger_is_generated(self):
        # Arrange
        state = self._get_simple_state()
        merge_factory = MergeFactory()

        # Act
        merger = merge_factory.create_merger(state)

        # Assert
        self.assertTrue(isinstance(merger, ISIS1DMerger))
def get_merge_bundle_for_merge_request(output_bundles, parent_alg):
    """
    Create a merge bundle for the reduction outputs and perform stitching if required
    :param output_bundles: a list of output_bundles
    :param parent_alg: a handle to the parent algorithm
    """
    # Order the reductions. This leaves us with a dict mapping from the reduction type (i.e. HAB, LAB) to
    # a list of reduction settings which contain the information for sample and can.
    reduction_mode_vs_output_bundles = get_reduction_mode_vs_output_bundles(output_bundles)

    # Get the underlying state from one of the elements
    state = output_bundles[0].state

    merge_factory = MergeFactory()
    merger = merge_factory.create_merger(state)

    # Run the merger and return the merged output workspace
    return merger.merge(reduction_mode_vs_output_bundles, parent_alg)
def get_merge_bundle_for_merge_request(output_bundles, parent_alg):
    """
    Create a merge bundle for the reduction outputs and perform stitching if required
    :param output_bundles: a list of output_bundles
    :param parent_alg: a handle to the parent algorithm
    """
    # Order the reductions. This leaves us with a dict mapping from the reduction type (i.e. HAB, LAB) to
    # a list of reduction settings which contain the information for sample and can.
    reduction_mode_vs_output_bundles = get_reduction_mode_vs_output_bundles(output_bundles)

    # Get the underlying state from one of the elements
    state = output_bundles[0].state

    merge_factory = MergeFactory()
    merger = merge_factory.create_merger(state)

    # Run the merger and return the merged output workspace
    return merger.merge(reduction_mode_vs_output_bundles, parent_alg)
Beispiel #14
0
def get_merge_bundle_for_merge_request(completed_slices: CompletedSlices,
                                       parent_alg):
    """
    Create a merge bundle for the reduction outputs and perform stitching if required
    :param completed_slices: a list of output_bundles
    :param parent_alg: a handle to the parent algorithm
    """
    # Order the reductions. This leaves us with a dict mapping from the reduction type (i.e. HAB, LAB) to
    # a list of reduction settings which contain the information for sample and can.
    wav_ranges = {k.wav_range for k in completed_slices}
    bank_based_reductions = []
    for wav_range in wav_ranges:
        matching_reductions = [
            i for i in completed_slices if i.wav_range == wav_range
        ]
        bank_based_reductions.append(
            get_reduction_mode_vs_output_bundles(matching_reductions))

    # Get the underlying state from one of the elements
    state = completed_slices[0].output_bundle.state

    merge_factory = MergeFactory()
    merger = merge_factory.create_merger(state)

    # Run the merger and return the merged output workspace
    merged_workspaces = []
    for matched_reductions in bank_based_reductions:
        merged = merger.merge(matched_reductions, parent_alg)
        replace_prop = True
        if state.save.user_file:
            merged.merged_workspace.getRun().addProperty(
                "UserFile", os.path.basename(state.save.user_file),
                replace_prop)
        if state.save.batch_file:
            merged.merged_workspace.getRun().addProperty(
                "BatchFile", os.path.basename(state.save.batch_file),
                replace_prop)
        merged_workspaces.append(merged)
    return merged_workspaces