Exemplo n.º 1
0
def _calibration_processing(calibration_dir, calibration_runs, cross_correlate_params, get_det_offset_params,
                            grouping_file_name, input_ws, instrument, offset_file, rebin_1_params, rebin_2_params):
    calibration_ws = input_ws
    if calibration_ws.getAxis(0).getUnit().unitID() != WORKSPACE_UNITS.d_spacing:
        calibration_ws = mantid.Rebin(InputWorkspace=input_ws, Params=rebin_1_params)
        calibration_ws = mantid.ConvertUnits(InputWorkspace=calibration_ws, Target="dSpacing")
    spectrum_list = []
    for i in range(0, calibration_ws.getNumberHistograms()):
        try:
            calibration_ws.getDetector(i)

        except RuntimeError:
            pass
        else:
            spectrum_list.append(i)
    calibration_ws = mantid.ExtractSpectra(InputWorkspace=calibration_ws, WorkspaceIndexList=spectrum_list)
    rebinned = mantid.Rebin(InputWorkspace=calibration_ws, Params=rebin_2_params)
    cross_correlated = mantid.CrossCorrelate(InputWorkspace=rebinned, **cross_correlate_params)

    # Offsets workspace must be referenced as string so it can be deleted, as simpleapi doesn't recognise it as a ws
    offsets_ws_name = "offsets"
    mantid.GetDetectorOffsets(InputWorkspace=cross_correlated, GroupingFileName=offset_file,
                              OutputWorkspace=offsets_ws_name, **get_det_offset_params)
    rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF")
    aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof, CalibrationFile=offset_file)
    grouping_file = os.path.join(calibration_dir, grouping_file_name)
    focused = mantid.DiffractionFocussing(InputWorkspace=aligned, GroupingFileName=grouping_file,
                                          OutputWorkspace=instrument._generate_output_file_name(calibration_runs)
                                          + "_grouped")
    print("Saved cal file to " + offset_file)
    common.remove_intermediate_workspace([calibration_ws, rebinned, cross_correlated, rebinned_tof,
                                          offsets_ws_name])
    return focused
Exemplo n.º 2
0
def create_calibration(calibration_runs, instrument, offset_file_name,
                       grouping_file_name, calibration_dir, rebin_1_params,
                       rebin_2_params, cross_correlate_params,
                       get_det_offset_params):
    """
    Create a calibration file from (usually) a ceria run
    :param calibration_runs: Run number(s) for this run
    :param instrument: The PEARL instrument object
    :param offset_file_name: Name of the file to write detector offset information to
    :param grouping_file_name: Name of grouping calibration file
    :param calibration_dir: Path to directory containing calibration information
    :param rebin_1_params: Parameters for the first rebin step (as a string in the usual format)
    :param rebin_2_params: Parameters for the second rebin step (as a string in the usual format)
    :param cross_correlate_params: Parameters for CrossCorrelate (as a dictionary PropertyName: PropertyValue)
    :param get_det_offset_params: Parameters for GetDetectorOffsets (as a dictionary PropertyName: PropertyValue)
    """
    input_ws_list = common.load_current_normalised_ws_list(
        run_number_string=calibration_runs,
        instrument=instrument,
        input_batching=INPUT_BATCHING.Summed)

    input_ws = input_ws_list[0]
    calibration_ws = mantid.Rebin(InputWorkspace=input_ws,
                                  Params=rebin_1_params)

    if calibration_ws.getAxis(
            0).getUnit().unitID() != WORKSPACE_UNITS.d_spacing:
        calibration_ws = mantid.ConvertUnits(InputWorkspace=calibration_ws,
                                             Target="dSpacing")

    rebinned = mantid.Rebin(InputWorkspace=calibration_ws,
                            Params=rebin_2_params)
    cross_correlated = mantid.CrossCorrelate(InputWorkspace=rebinned,
                                             **cross_correlate_params)

    offset_file = os.path.join(calibration_dir, offset_file_name)
    # Offsets workspace must be referenced as string so it can be deleted, as simpleapi doesn't recognise it as a ws
    offsets_ws_name = "offsets"
    mantid.GetDetectorOffsets(InputWorkspace=cross_correlated,
                              GroupingFileName=offset_file,
                              OutputWorkspace=offsets_ws_name,
                              **get_det_offset_params)

    rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF")
    aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof,
                                    CalibrationFile=offset_file)

    grouping_file = os.path.join(calibration_dir, grouping_file_name)
    focused = mantid.DiffractionFocussing(
        InputWorkspace=aligned,
        GroupingFileName=grouping_file,
        OutputWorkspace=instrument._generate_output_file_name(calibration_runs)
        + "_grouped")

    common.remove_intermediate_workspace([
        calibration_ws, rebinned, cross_correlated, rebinned_tof, aligned,
        offsets_ws_name
    ])
    return focused
Exemplo n.º 3
0
    def _do_silicon_calibration(self, runs_to_process, cal_file_name, grouping_file_name):
        create_si_ws = common._read_ws(number=runs_to_process, instrument=self)
        cycle_details = self._get_cycle_information(runs_to_process)
        instrument_version = cycle_details["instrument_version"]

        if instrument_version == "new" or instrument_version == "new2":
            create_si_ws = mantid.Rebin(InputWorkspace=create_si_ws, Params="100,-0.0006,19950")

        create_si_d_spacing_ws = mantid.ConvertUnits(InputWorkspace=create_si_ws, Target="dSpacing")

        if instrument_version == "new2":
            create_si_d_spacing_rebin_ws = mantid.Rebin(InputWorkspace=create_si_d_spacing_ws, Params="1.71,0.002,2.1")
            create_si_cross_corr_ws = mantid.CrossCorrelate(InputWorkspace=create_si_d_spacing_rebin_ws,
                                                            ReferenceSpectra=20, WorkspaceIndexMin=9,
                                                            WorkspaceIndexMax=1063, XMin=1.71, XMax=2.1)
        elif instrument_version == "new":
            create_si_d_spacing_rebin_ws = mantid.Rebin(InputWorkspace=create_si_d_spacing_ws, Params="1.85,0.002,2.05")
            create_si_cross_corr_ws = mantid.CrossCorrelate(InputWorkspace=create_si_d_spacing_rebin_ws,
                                                            ReferenceSpectra=20, WorkspaceIndexMin=9,
                                                            WorkspaceIndexMax=943, XMin=1.85, XMax=2.05)
        elif instrument_version == "old":
            create_si_d_spacing_rebin_ws = mantid.Rebin(InputWorkspace=create_si_d_spacing_ws, Params="3,0.002,3.2")
            create_si_cross_corr_ws = mantid.CrossCorrelate(InputWorkspace=create_si_d_spacing_rebin_ws,
                                                            ReferenceSpectra=500, WorkspaceIndexMin=1,
                                                            WorkspaceIndexMax=1440, XMin=3, XMax=3.2)
        else:
            raise NotImplementedError("The instrument version is not supported for creating a silicon calibration")

        common.remove_intermediate_workspace(create_si_d_spacing_ws)
        common.remove_intermediate_workspace(create_si_d_spacing_rebin_ws)

        calibration_output_path = self.calibration_dir + cal_file_name
        create_si_offsets_ws = mantid.GetDetectorOffsets(InputWorkspace=create_si_cross_corr_ws,
                                                         Step=0.002, DReference=1.920127251, XMin=-200, XMax=200,
                                                         GroupingFileName=calibration_output_path)
        create_si_aligned_ws = mantid.AlignDetectors(InputWorkspace=create_si_ws,
                                                     CalibrationFile=calibration_output_path)
        grouping_output_path = self.calibration_dir + grouping_file_name
        create_si_grouped_ws = mantid.DiffractionFocussing(InputWorkspace=create_si_aligned_ws,
                                                           GroupingFileName=grouping_output_path)
        del create_si_offsets_ws, create_si_grouped_ws
Exemplo n.º 4
0
    def _create_calibration(self, calibration_runs, offset_file_name, grouping_file_name):
        input_ws = common._read_ws(number=calibration_runs, instrument=self)
        cycle_information = self._get_cycle_information(calibration_runs)

        # TODO move these hard coded params to instrument specific
        if cycle_information["instrument_version"] == "new" or cycle_information["instrument_version"] == "new2":
            input_ws = mantid.Rebin(InputWorkspace=input_ws, Params="100,-0.0006,19950")

        d_spacing_cal = mantid.ConvertUnits(InputWorkspace=input_ws, Target="dSpacing")
        d_spacing_cal = mantid.Rebin(InputWorkspace=d_spacing_cal, Params="1.8,0.002,2.1")

        if cycle_information["instrument_version"] == "new2":
            cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=20,
                                                 WorkspaceIndexMin=9, WorkspaceIndexMax=1063, XMin=1.8, XMax=2.1)

        elif cycle_information["instrument_version"] == "new":
            cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=20,
                                                 WorkspaceIndexMin=9, WorkspaceIndexMax=943, XMin=1.8, XMax=2.1)
        else:
            cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=500,
                                                 WorkspaceIndexMin=1, WorkspaceIndexMax=1440, XMin=1.8, XMax=2.1)
        if self._old_api_uses_full_paths:  # Workaround for old API setting full paths
            grouping_file_path = grouping_file_name
            offset_file_path = offset_file_name
        else:
            offset_file_path = self.calibration_dir + offset_file_name
            grouping_file_path = self.calibration_dir + grouping_file_name

        # Ceo Cell refined to 5.4102(3) so 220 is 1.912795
        offset_output_path = mantid.GetDetectorOffsets(InputWorkspace=cross_cor_ws, Step=0.002, DReference=1.912795,
                                                       XMin=-200, XMax=200, GroupingFileName=offset_file_path)
        del offset_output_path  # This isn't used so delete it to keep linters happy
        aligned_ws = mantid.AlignDetectors(InputWorkspace=input_ws, CalibrationFile=offset_file_path)
        cal_grouped_ws = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, GroupingFileName=grouping_file_path)

        common.remove_intermediate_workspace(d_spacing_cal)
        common.remove_intermediate_workspace(cross_cor_ws)
        common.remove_intermediate_workspace(aligned_ws)
        common.remove_intermediate_workspace(cal_grouped_ws)
Exemplo n.º 5
0
def create_calibration(self, calibration_runs, offset_file_name,
                       grouping_file_name):
    input_ws_list = common.load_current_normalised_ws_list(
        run_number_string=calibration_runs,
        instrument=self,
        input_batching=INPUT_BATCHING.Summed)
    input_ws = input_ws_list[0]
    run_details = self._get_run_details(calibration_runs)

    if run_details.instrument_version == "new" or run_details.instrument_version == "new2":
        input_ws = mantid.Rebin(InputWorkspace=input_ws,
                                Params="100,-0.0006,19950")

    d_spacing_cal = mantid.ConvertUnits(InputWorkspace=input_ws,
                                        Target="dSpacing")
    d_spacing_cal = mantid.Rebin(InputWorkspace=d_spacing_cal,
                                 Params="1.8,0.002,2.1")

    if run_details.instrument_version == "new2":
        cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal,
                                             ReferenceSpectra=20,
                                             WorkspaceIndexMin=9,
                                             WorkspaceIndexMax=1063,
                                             XMin=1.8,
                                             XMax=2.1)

    elif run_details.instrument_version == "new":
        cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal,
                                             ReferenceSpectra=20,
                                             WorkspaceIndexMin=9,
                                             WorkspaceIndexMax=943,
                                             XMin=1.8,
                                             XMax=2.1)
    else:
        cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal,
                                             ReferenceSpectra=500,
                                             WorkspaceIndexMin=1,
                                             WorkspaceIndexMax=1440,
                                             XMin=1.8,
                                             XMax=2.1)
    if self._old_api_uses_full_paths:  # Workaround for old API setting full paths
        grouping_file_path = grouping_file_name
        offset_file_path = offset_file_name
    else:
        offset_file_path = os.path.join(self.calibration_dir, offset_file_name)
        grouping_file_path = os.path.join(self.calibration_dir,
                                          grouping_file_name)

    # Ceo Cell refined to 5.4102(3) so 220 is 1.912795
    offset_output_path = mantid.GetDetectorOffsets(
        InputWorkspace=cross_cor_ws,
        Step=0.002,
        DReference=1.912795,
        XMin=-200,
        XMax=200,
        GroupingFileName=offset_file_path)
    del offset_output_path  # This isn't used so delete it to keep linters happy
    aligned_ws = mantid.AlignDetectors(InputWorkspace=input_ws,
                                       CalibrationFile=offset_file_path)
    cal_grouped_ws = mantid.DiffractionFocussing(
        InputWorkspace=aligned_ws, GroupingFileName=grouping_file_path)

    common.remove_intermediate_workspace(d_spacing_cal)
    common.remove_intermediate_workspace(cross_cor_ws)
    common.remove_intermediate_workspace(aligned_ws)
    common.remove_intermediate_workspace(cal_grouped_ws)