Пример #1
0
    def test_get_output_name_should_return_standard_name_for_non_sliced_non_user_specified_name_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''

        output_name, group_output_name = get_output_name(state, ISISReductionMode.LAB, False)

        self.assertEqual(output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
        self.assertEqual(group_output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
    def test_get_output_name_should_return_standard_name_for_non_sliced_non_user_specified_name_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''

        output_name, group_output_name = get_output_name(state, ISISReductionMode.LAB, False)

        self.assertEqual(output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
        self.assertEqual(group_output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
Пример #3
0
    def test_get_output_name_replaces_name_with_user_specified_name_with_appended_detector_for_Merged_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.Merged

        output_name, group_output_name = get_output_name(state, ISISReductionMode.Merged, False)

        self.assertEqual(output_name, 'user_output_name_merged')
        self.assertEqual(group_output_name, 'user_output_name_merged')
Пример #4
0
    def test_get_output_name_should_replace_name_with_user_specified_name_for_HAB_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.LAB

        output_name, group_output_name = get_output_name(state, ISISReductionMode.HAB, False)

        self.assertEqual(output_name, 'user_output_name')
        self.assertEqual(group_output_name, 'user_output_name')
    def test_get_output_name_should_replace_name_with_user_specified_name_for_HAB_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.LAB

        output_name, group_output_name = get_output_name(state, ISISReductionMode.HAB, False)

        self.assertEqual(output_name, 'user_output_name')
        self.assertEqual(group_output_name, 'user_output_name')
    def test_get_output_name_replaces_name_with_user_specified_name_with_appended_detector_for_Merged_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.Merged

        output_name, group_output_name = get_output_name(state, ISISReductionMode.Merged, False)

        self.assertEqual(output_name, 'user_output_name_merged')
        self.assertEqual(group_output_name, 'user_output_name_merged')
Пример #7
0
    def test_get_output_name_should_return_standard_name_for_non_sliced_non_user_specified_name_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''

        wav_range = state.wavelength.wavelength_interval.wavelength_full_range
        output_name, group_output_name = get_output_name(state, ReductionMode.LAB, False, wav_range=wav_range)

        expected = "12345_rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37"

        self.assertEqual(expected, output_name)
        self.assertEqual(expected, group_output_name)
Пример #8
0
    def test_returned_name_for_time_sliced_merged_reduction_without_user_specified_name_correct(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''
        state.reduction.reduction_mode = ReductionMode.MERGED
        multi_reduction_type = {"period": False,
                                "event_slice": True,
                                "wavelength_range": False}

        output_name, group_output_name = get_output_name(state, ReductionMode.MERGED, True,
                                                         multi_reduction_type=multi_reduction_type)

        self.assertEqual(output_name, '12345_merged_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
        self.assertEqual(group_output_name, '12345_merged_1DPhi12.0_56.0')
Пример #9
0
    def test_returned_name_for_all_multi_reduction_with_user_specified_name_correct(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.Merged
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        output_name, group_output_name = get_output_name(state, ISISReductionMode.Merged, True,
                                                         multi_reduction_type=multi_reduction_type)

        self.assertEqual(output_name, 'user_output_name_merged_p0_t4.57_T12.37_12.0_34.0')
        self.assertEqual(group_output_name, 'user_output_name_merged')
Пример #10
0
    def test_returned_name_for_all_multi_reduction_without_user_specified_name_correct_LAB_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''
        state.reduction.reduction_mode = ISISReductionMode.LAB
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        output_name, group_output_name = get_output_name(state, ISISReductionMode.LAB, True,
                                                         multi_reduction_type=multi_reduction_type)

        self.assertEqual(output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
        self.assertEqual(group_output_name, '12345rear_1DPhi12.0_56.0')
Пример #11
0
    def test_get_output_name_should_replace_name_with_user_specified_name_for_HAB_reduction(self):
        state = self._get_state()
        custom_user_name = 'user_output_name'
        state.save.user_specified_output_name = custom_user_name
        state.reduction.reduction_mode = ReductionMode.HAB

        output_name, group_output_name = get_output_name(state, ReductionMode.HAB, False)
        reduction_settings = "_front_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37"

        expected = custom_user_name + reduction_settings

        self.assertEqual(expected, output_name)
        self.assertEqual(expected, group_output_name)
Пример #12
0
    def test_returned_name_for_all_multi_reduction_with_user_specified_name_correct(self):
        state = self._get_state()
        state.save.user_specified_output_name = 'user_output_name'
        state.reduction.reduction_mode = ISISReductionMode.Merged
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        output_name, group_output_name = get_output_name(state, ISISReductionMode.Merged, True,
                                                         multi_reduction_type=multi_reduction_type)

        self.assertEqual(output_name, 'user_output_name_merged_p0_t4.57_T12.37_12.0_34.0')
        self.assertEqual(group_output_name, 'user_output_name_merged')
Пример #13
0
    def test_returned_name_for_all_multi_reduction_without_user_specified_name_correct_LAB_reduction(self):
        state = self._get_state()
        state.save.user_specified_output_name = ''
        state.reduction.reduction_mode = ISISReductionMode.LAB
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        output_name, group_output_name = get_output_name(state, ISISReductionMode.LAB, True,
                                                         multi_reduction_type=multi_reduction_type)

        self.assertEqual(output_name, '12345rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37')
        self.assertEqual(group_output_name, '12345rear_1DPhi12.0_56.0')
Пример #14
0
    def test_get_output_name_replaces_name_with_user_specified_name_with_appended_detector_for_Merged_reduction(self):
        state = self._get_state()
        custom_name = 'user_output_name'
        state.save.user_specified_output_name = custom_name
        state.reduction.reduction_mode = ReductionMode.MERGED

        reduction_settings = "_merged_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37"

        expected = custom_name + reduction_settings

        output_name, group_output_name = get_output_name(state, ReductionMode.MERGED, False)

        self.assertEqual(expected, output_name)
        self.assertEqual(expected, group_output_name)
Пример #15
0
    def test_get_output_name_replaces_name_with_user_specified_name_with_appended_detector_for_All_reduction(self):
        state = self._get_state()
        custom_user_name = 'user_output_name'
        state.reduction.reduction_mode = ReductionMode.ALL
        state.save.user_specified_output_name = custom_user_name

        reduction_settings = "rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37"

        expected = custom_user_name + '_' + reduction_settings

        wav_range = state.wavelength.wavelength_interval.wavelength_full_range
        output_name, group_output_name = get_output_name(state, ReductionMode.LAB, False, wav_range=wav_range)

        self.assertEqual(expected, output_name)
        self.assertEqual(expected, group_output_name)
Пример #16
0
    def test_returned_name_for_period_reduction_with_user_specified_name_correct(self):
        state = self._get_state()
        custom_name = 'user_output_name'
        state.save.user_specified_output_name = custom_name
        multi_reduction_type = {"period": True,
                                "event_slice": False,
                                "wavelength_range": False}

        output_name, group_output_name = get_output_name(state, ReductionMode.MERGED, True,
                                                         multi_reduction_type=multi_reduction_type)

        single_ws_name = custom_name + '_merged_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37_p0'
        group_ws_name = custom_name + '_merged_1DPhi12.0_56.0'

        self.assertEqual(single_ws_name, output_name)
        self.assertEqual(group_ws_name, group_output_name)
Пример #17
0
    def test_returned_name_for_all_multi_reduction_with_user_specified_name_correct_LAB_reduction(self):
        state = self._get_state()
        custom_name = 'user_output_name'
        state.save.user_specified_output_name = custom_name
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        output_name, group_output_name = get_output_name(state, ReductionMode.LAB, True,
                                                         multi_reduction_type=multi_reduction_type)

        single_ws_name = custom_name + "_rear_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37_p0_t4.57_T12.37_12.0_34.0"
        group_expected_name = custom_name + "_rear_1DPhi12.0_56.0"

        self.assertEqual(single_ws_name, output_name)
        self.assertEqual(group_expected_name, group_output_name)
Пример #18
0
    def _get_output_workspace_name(self,
                                   state,
                                   reduction_mode=None,
                                   data_type=None,
                                   can=False,
                                   sample=False,
                                   transmission=False,
                                   fitted=False):
        """
        Get the output names for the sliced workspaces (within the group workspaces, which are already named).

        :param state: a SANS state object
        :param reduction_mode: an optional ISISReductionMode enum: "HAB", "LAB", "Merged", or "All"
        :param data_type: an optional DataType enum: "Sample" or "Can"
        :param can: optional bool. If true then creating name for a can workspace
        :param sample: optional bool. If true then creating name for a sample workspace. Sample and can cannot both be
                       true
        :param transmission: optional bool. If true then creating name for a transmission workspace
        :param fitted: optional bool. If true then workspace is a fitted transmission workspace, otherwise unfitted
        :return: name of the workspace
        """
        _multi = {
            "event_slice": True,
            "period": self.getProperty("Period").value,
            "wavelength_range": self.getProperty("WavelengthRange").value
        }

        if not transmission:
            _suffix = ""
            if can:
                if reduction_mode == ISISReductionMode.HAB:
                    _suffix = "_hab_can"
                elif reduction_mode == ISISReductionMode.LAB:
                    _suffix = "_lab_can"
            elif sample:
                if reduction_mode == ISISReductionMode.HAB:
                    _suffix = "_hab_sample"
                elif reduction_mode == ISISReductionMode.LAB:
                    _suffix = "_lab_sample"
            return get_output_name(state,
                                   reduction_mode,
                                   True,
                                   suffix=_suffix,
                                   multi_reduction_type=_multi)[0]
        else:
            return get_transmission_output_name(state, data_type, _multi,
                                                fitted)[0]
Пример #19
0
    def test_returned_name_for_all_multi_reduction_with_user_specified_name_correct(self):
        state = self._get_state()
        custom_name = 'user_output_name'
        state.save.user_specified_output_name = custom_name
        multi_reduction_type = {"period": True,
                                "event_slice": True,
                                "wavelength_range": True}

        wav_range = state.wavelength.wavelength_interval.wavelength_full_range
        output_name, group_output_name = get_output_name(state, ReductionMode.MERGED, True, wav_range=wav_range,
                                                         multi_reduction_type=multi_reduction_type)

        single_ws_name = custom_name + "_merged_1D_12.0_34.0Phi12.0_56.0_t4.57_T12.37_p0_t4.57_T12.37"
        group_ws_name = custom_name + "_merged_1DPhi12.0_56.0"

        self.assertEqual(single_ws_name, output_name)
        self.assertEqual(group_ws_name, group_output_name)
Пример #20
0
    def _set_output_name(_reduction_alg,
                         _reduction_package,
                         _is_group,
                         _reduction_mode,
                         _property_name,
                         _attr_out_name,
                         _atrr_out_name_base,
                         _suffix=None):
        _out_name, _out_name_base = get_output_name(_reduction_package.state,
                                                    _reduction_mode, _is_group)

        if _suffix is not None:
            _out_name += _suffix
            _out_name_base += _suffix

        _reduction_alg.setProperty(_property_name, _out_name)
        setattr(_reduction_package, _attr_out_name, _out_name)
        setattr(_reduction_package, _atrr_out_name_base, _out_name_base)
Пример #21
0
def WavRangeReduction(wav_start=None, wav_end=None, full_trans_wav=None, name_suffix=None, combineDet=None,
                      resetSetup=True, out_fit_settings=None, output_name=None, output_mode=OutputMode.PUBLISH_TO_ADS,
                      use_reduction_mode_as_suffix=False):
    """
        Run reduction from loading the raw data to calculating Q. Its optional arguments allows specifics
        details to be adjusted, and optionally the old setup is reset at the end. Note if FIT of RESCALE or SHIFT
        is selected then both REAR and FRONT detectors are both reduced EXCEPT if only the REAR detector is selected
        to be reduced

        @param wav_start: the first wavelength to be in the output data
        @param wav_end: the last wavelength in the output data
        @param full_trans_wav: if to use a wide wavelength range, the instrument's default wavelength range,
                               for the transmission correction, false by default
        @param name_suffix: append the created output workspace with this
        @param combineDet: combineDet can be one of the following:
                           'rear'                (run one reduction for the 'rear' detector data)
                           'front'               (run one reduction for the 'front' detector data, and
                                                  rescale+shift 'front' data)
                           'both'                (run both the above two reductions)
                           'merged'              (run the same reductions as 'both' and additionally create
                                                  a merged data workspace)
                            None                 (run one reduction for whatever detector has been set as the
                                                  current detector
                                                  before running this method. If front apply rescale+shift)
        @param resetSetup: if true reset setup at the end
        @param out_fit_settings: An output parameter. It is used, specially when resetSetup is True, in order
                                 to remember the 'scale and fit' of the fitting algorithm.
        @param output_name: name of the output workspace/file, if none is specified then one is generated internally.
        @param output_mode: the way the data should be put out: Can be PublishToADS, SaveToFile or Both
        @param use_reduction_mode_as_suffix: If true then a second suffix will be used which is
                                             based on the reduction mode.
        @return Name of one of the workspaces created
    """
    print_message('WavRangeReduction(' + str(wav_start) + ', ' + str(wav_end) + ', ' + str(full_trans_wav) + ')')
    _ = resetSetup
    _ = out_fit_settings

    # Set the provided parameters
    if combineDet is None:
        reduction_mode = None
    elif combineDet == 'rear':
        reduction_mode = ReductionMode.LAB
    elif combineDet == "front":
        reduction_mode = ReductionMode.HAB
    elif combineDet == "merged":
        reduction_mode = ReductionMode.MERGED
    elif combineDet == "both":
        reduction_mode = ReductionMode.ALL
    else:
        raise RuntimeError("WavRangeReduction: The combineDet input parameter was given a value of {0}. rear, front,"
                           " both, merged and no input are allowed".format(combineDet))

    if wav_start is not None:
        wav_start = float(wav_start)

    if wav_end is not None:
        wav_end = float(wav_end)

    wavelength_command = NParameterCommand(command_id=NParameterCommandId.WAV_RANGE_SETTINGS,
                                           values=[wav_start, wav_end, full_trans_wav, reduction_mode])
    director.add_command(wavelength_command)

    # Save options
    if output_name is not None:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.USER_SPECIFIED_OUTPUT_NAME,
                                               values=[output_name]))
    if name_suffix is not None:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.USER_SPECIFIED_OUTPUT_NAME_SUFFIX,
                                               values=[name_suffix]))
    if use_reduction_mode_as_suffix:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.USE_REDUCTION_MODE_AS_SUFFIX,
                                               values=[use_reduction_mode_as_suffix]))

    # Get the states
    state = director.process_commands()

    # Run the reduction
    batch_alg = SANSBatchReduction()
    batch_alg(states=[state], use_optimizations=True, output_mode=output_mode)

    # -----------------------------------------------------------
    # Return the name fo the reduced workspace (or WorkspaceGroup)
    # -----------------------------------------------------------
    reduction_mode = state.reduction.reduction_mode
    is_group = is_part_of_reduced_output_workspace_group(state)
    if reduction_mode != ReductionMode.ALL:
        _, output_workspace_base_name = get_output_name(state, reduction_mode, is_group)
    else:
        _, output_workspace_base_name_hab = get_output_name(state, ReductionMode.HAB, is_group)
        _, output_workspace_base_name_lab = get_output_name(state, ReductionMode.LAB, is_group)
        output_workspace_base_name = [output_workspace_base_name_lab, output_workspace_base_name_hab]
    return output_workspace_base_name
Пример #22
0
def WavRangeReduction(wav_start=None, wav_end=None, full_trans_wav=None, name_suffix=None, combineDet=None,
                      resetSetup=True, out_fit_settings=None, output_name=None, output_mode=OutputMode.PublishToADS,
                      use_reduction_mode_as_suffix=False):
    """
        Run reduction from loading the raw data to calculating Q. Its optional arguments allows specifics
        details to be adjusted, and optionally the old setup is reset at the end. Note if FIT of RESCALE or SHIFT
        is selected then both REAR and FRONT detectors are both reduced EXCEPT if only the REAR detector is selected
        to be reduced

        @param wav_start: the first wavelength to be in the output data
        @param wav_end: the last wavelength in the output data
        @param full_trans_wav: if to use a wide wavelength range, the instrument's default wavelength range,
                               for the transmission correction, false by default
        @param name_suffix: append the created output workspace with this
        @param combineDet: combineDet can be one of the following:
                           'rear'                (run one reduction for the 'rear' detector data)
                           'front'               (run one reduction for the 'front' detector data, and
                                                  rescale+shift 'front' data)
                           'both'                (run both the above two reductions)
                           'merged'              (run the same reductions as 'both' and additionally create
                                                  a merged data workspace)
                            None                 (run one reduction for whatever detector has been set as the
                                                  current detector
                                                  before running this method. If front apply rescale+shift)
        @param resetSetup: if true reset setup at the end
        @param out_fit_settings: An output parameter. It is used, specially when resetSetup is True, in order
                                 to remember the 'scale and fit' of the fitting algorithm.
        @param output_name: name of the output workspace/file, if none is specified then one is generated internally.
        @param output_mode: the way the data should be put out: Can be PublishToADS, SaveToFile or Both
        @param use_reduction_mode_as_suffix: If true then a second suffix will be used which is
                                             based on the reduction mode.
        @return Name of one of the workspaces created
    """
    print_message('WavRangeReduction(' + str(wav_start) + ', ' + str(wav_end) + ', ' + str(full_trans_wav) + ')')
    _ = resetSetup
    _ = out_fit_settings

    # Set the provided parameters
    if combineDet is None:
        reduction_mode = None
    elif combineDet == 'rear':
        reduction_mode = ISISReductionMode.LAB
    elif combineDet == "front":
        reduction_mode = ISISReductionMode.HAB
    elif combineDet == "merged":
        reduction_mode = ISISReductionMode.Merged
    elif combineDet == "both":
        reduction_mode = ISISReductionMode.All
    else:
        raise RuntimeError("WavRangeReduction: The combineDet input parameter was given a value of {0}. rear, front,"
                           " both, merged and no input are allowed".format(combineDet))

    if wav_start is not None:
        wav_start = float(wav_start)

    if wav_end is not None:
        wav_end = float(wav_end)

    wavelength_command = NParameterCommand(command_id=NParameterCommandId.wavrange_settings,
                                           values=[wav_start, wav_end, full_trans_wav, reduction_mode])
    director.add_command(wavelength_command)

    # Save options
    if output_name is not None:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.user_specified_output_name,
                                               values=[output_name]))
    if name_suffix is not None:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.user_specified_output_name_suffix,
                                               values=[name_suffix]))
    if use_reduction_mode_as_suffix:
        director.add_command(NParameterCommand(command_id=NParameterCommandId.use_reduction_mode_as_suffix,
                                               values=[use_reduction_mode_as_suffix]))

    # Get the states
    state = director.process_commands()

    # Run the reduction
    batch_alg = SANSBatchReduction()
    batch_alg(states=[state], use_optimizations=True, output_mode=output_mode)

    # -----------------------------------------------------------
    # Return the name fo the reduced workspace (or WorkspaceGroup)
    # -----------------------------------------------------------
    reduction_mode = state.reduction.reduction_mode
    is_group = is_part_of_reduced_output_workspace_group(state)
    if reduction_mode != ISISReductionMode.All:
        _, output_workspace_base_name = get_output_name(state, reduction_mode, is_group)
    else:
        _, output_workspace_base_name_hab = get_output_name(state, ISISReductionMode.HAB, is_group)
        _, output_workspace_base_name_lab = get_output_name(state, ISISReductionMode.LAB, is_group)
        output_workspace_base_name = [output_workspace_base_name_lab, output_workspace_base_name_hab]
    return output_workspace_base_name