Ejemplo n.º 1
0
    def __call__(self, file_name, workspace):
        """Write a PeaksWorkspace to an ASCII file using this formatter.

        :param file_name: the file name to output data to.
        :param workspace: the PeaksWorkspace to write to file.
        """
        if has_modulated_indexing(workspace):
            raise NotImplementedError("Cannot currently save modulated structures to GSAS or SHELX formats")
        SaveHKL(Filename=file_name, InputWorkspace=workspace, OutputWorkspace=workspace.name())
Ejemplo n.º 2
0
    def __call__(self, file_name, workspace, _):
        """Write a PeaksWorkspace to an ASCII file using this formatter.

        :param file_name: the file name to output data to.
        :param workspace: the PeaksWorkspace to write to file.
        :param _: Ignored parameter for compatability with other savers
        """
        if has_modulated_indexing(workspace):
            raise RuntimeError(
                "Cannot currently save modulated structures to GSAS or SHELX formats")

        from mantid.simpleapi import SaveHKL
        SaveHKL(Filename=file_name, InputWorkspace=workspace, OutputWorkspace=workspace.name())
Ejemplo n.º 3
0
    def PyExec(self):
        input_workspaces, peak_workspaces = self._expand_groups()
        output_workspace_name = self.getPropertyValue("OutputWorkspace")

        peak_radius = self.getProperty("PeakRadius").value
        inner_radius = self.getProperty("BackgroundInnerRadius").value
        outer_radius = self.getProperty("BackgroundOuterRadius").value

        remove_0_intensity = self.getProperty("RemoveZeroIntensity").value
        use_lorentz = self.getProperty("ApplyLorentz").value

        multi_ws = len(input_workspaces) > 1

        output_workspaces = []

        for input_ws, peak_ws in zip(input_workspaces, peak_workspaces):
            if multi_ws:
                peaks_ws_name = input_ws + '_' + output_workspace_name
                output_workspaces.append(peaks_ws_name)
            else:
                peaks_ws_name = output_workspace_name

            IntegratePeaksMD(InputWorkspace=input_ws,
                             PeakRadius=peak_radius,
                             BackgroundInnerRadius=inner_radius,
                             BackgroundOuterRadius=outer_radius,
                             PeaksWorkspace=peak_ws,
                             OutputWorkspace=peaks_ws_name)

        if multi_ws:
            peaks_ws_name = output_workspace_name
            CreatePeaksWorkspace(
                InstrumentWorkspace=input_workspaces[0],
                NumberOfPeaks=0,
                OutputWorkspace=peaks_ws_name,
                OutputType=mtd[peak_workspaces[0]].id().replace(
                    'sWorkspace', ''))
            CopySample(InputWorkspace=output_workspaces[0],
                       OutputWorkspace=peaks_ws_name,
                       CopyName=False,
                       CopyMaterial=False,
                       CopyEnvironment=False,
                       CopyShape=False,
                       CopyLattice=True)
            for peak_ws in output_workspaces:
                CombinePeaksWorkspaces(peaks_ws_name,
                                       peak_ws,
                                       OutputWorkspace=peaks_ws_name)
                DeleteWorkspace(peak_ws)

        if use_lorentz:
            # Apply Lorentz correction:
            peaks = AnalysisDataService[peaks_ws_name]
            for p in range(peaks.getNumberPeaks()):
                peak = peaks.getPeak(p)
                lorentz = abs(
                    np.sin(peak.getScattering() * np.cos(peak.getAzimuthal())))
                peak.setIntensity(peak.getIntensity() * lorentz)

        if remove_0_intensity:
            FilterPeaks(InputWorkspace=peaks_ws_name,
                        OutputWorkspace=peaks_ws_name,
                        FilterVariable='Intensity',
                        FilterValue=0,
                        Operator='>')

        # Write output only if a file path was provided
        if not self.getProperty("OutputFile").isDefault:
            out_format = self.getProperty("OutputFormat").value
            filename = self.getProperty("OutputFile").value

            if out_format == "SHELX":
                SaveHKL(InputWorkspace=peaks_ws_name,
                        Filename=filename,
                        DirectionCosines=True,
                        OutputWorkspace="__tmp")
                DeleteWorkspace("__tmp")
            elif out_format == "Fullprof":
                SaveReflections(InputWorkspace=peaks_ws_name,
                                Filename=filename,
                                Format="Fullprof")
            else:
                # This shouldn't happen
                RuntimeError("Invalid output format given")

        self.setProperty("OutputWorkspace", AnalysisDataService[peaks_ws_name])