Example #1
0
    def _convert_to_angle(self, w, name):
        """
        Output the integrated intensity for each elastic detector versus
        detector angle with the neutron beam.

        Masked elastic detectors are assigned a zero intensity

        Parameters
        ----------
        w: Mantid.MatrixWorkspace2D
        name: str
            Name of output workspace
        Returns
        -------
        Mantid.MatrixWorkspace2D
        """
        id_s, id_e = 16386, 17534  # start and end for elastic detector ID's
        _t_w_name = tws('convert_to_angle')
        _t_w = Integration(w, OutputWorkspace=_t_w_name)
        sp = _t_w.spectrumInfo()
        x, y, e = [list(), list(), list()]
        for i in range(_t_w.getNumberHistograms()):
            id_i = _t_w.getDetector(i).getID()
            if id_s <= id_i <= id_e:
                x.append(np.degrees(sp.twoTheta(i)))
                if sp.isMasked(i) is True:
                    y.append(0.0)
                    e.append(1.0)
                else:
                    y.append(_t_w.readY(i)[0])
                    e.append(_t_w.readE(i)[0])
        x = np.asarray(x)
        y = np.asarray(y)
        e = np.asarray(e)
        od = np.argsort(x)  # order in ascending angles
        title = 'Angle between detector and incoming neutron beam'
        _t_w = CreateWorkspace(DataX=x[od],
                               DataY=y[od],
                               DataE=e[od],
                               NSpec=1,
                               UnitX='Degrees',
                               WorkspaceTitle=title,
                               OutputWorkspace=_t_w_name)
        RenameWorkspace(_t_w, OutputWorkspace=name)
        return _t_w
    def PyExec(self):
        from mantid.simpleapi import CropWorkspace, Integration, DeleteWorkspace

        in_ws = self.getPropertyValue("InputWorkspace")
        min_wavelength = self.getPropertyValue("StartWavelength")
        keep_workspaces = self.getPropertyValue("KeepIntermediateWorkspaces")

        # Crop off lower wavelengths where the signal is also lower.
        cropped_ws = CropWorkspace(InputWorkspace=in_ws,
                                   XMin=float(min_wavelength))
        # Integrate over the higher wavelengths after cropping.
        summed_ws = Integration(InputWorkspace=cropped_ws)
        # Loop through each histogram, and fetch out each intensity value from the single bin to generate a list of all values.
        n_histograms = summed_ws.getNumberHistograms()
        y_data = np.empty([n_histograms])
        for i in range(0, n_histograms):
            intensity = summed_ws.readY(i)[0]
            y_data[i] = intensity
        #Remove the background
        y_data = self.__remove_background(y_data)
        #Find the peaks
        peak_index_list = self.__find_peak_spectrum_numbers(y_data, summed_ws)
        #Reverse the order so that it goes from high spec number to low spec number
        peak_index_list.reverse()
        n_peaks_found = len(peak_index_list)

        output_ws = WorkspaceFactory.createTable("TableWorkspace")
        output_ws.addColumn("int", "Reflected Spectrum Number")

        if n_peaks_found > 2:
            raise PeakFindingException("Found more than two peaks.")
        elif n_peaks_found == 0:
            raise PeakFindingException("No peaks found")
        elif n_peaks_found == 1:
            output_ws.addRow(peak_index_list)
        elif n_peaks_found == 2:
            output_ws.addColumn("int", "Transmission Spectrum Number")
            output_ws.addRow(peak_index_list)

        if int(keep_workspaces) == 0:
            DeleteWorkspace(Workspace=cropped_ws)
            DeleteWorkspace(Workspace=summed_ws)

        self.setProperty("OutputWorkspace", output_ws)
    def PyExec(self):
    	from mantid.simpleapi import CropWorkspace, Integration, DeleteWorkspace

    	in_ws = self.getPropertyValue("InputWorkspace")
    	min_wavelength = self.getPropertyValue("StartWavelength")
    	keep_workspaces = self.getPropertyValue("KeepIntermediateWorkspaces")

    	# Crop off lower wavelengths where the signal is also lower.
    	cropped_ws = CropWorkspace(InputWorkspace=in_ws,XMin=float(min_wavelength))
    	# Integrate over the higher wavelengths after cropping.
    	summed_ws = Integration(InputWorkspace=cropped_ws)
    	# Loop through each histogram, and fetch out each intensity value from the single bin to generate a list of all values.
    	n_histograms = summed_ws.getNumberHistograms()
    	y_data = np.empty([n_histograms])
    	for i in range(0, n_histograms):
    		intensity = summed_ws.readY(i)[0]
    		y_data[i] = intensity
    	#Remove the background
    	y_data = self.__remove_background(y_data)
    	#Find the peaks
    	peak_index_list = self.__find_peak_spectrum_numbers(y_data, summed_ws)
        #Reverse the order so that it goes from high spec number to low spec number
    	peak_index_list.reverse()
    	n_peaks_found = len(peak_index_list)

    	output_ws = WorkspaceFactory.createTable("TableWorkspace")
    	output_ws.addColumn("int", "Reflected Spectrum Number")

    	if n_peaks_found > 2:
    		raise PeakFindingException("Found more than two peaks.")
    	elif n_peaks_found == 0:
    		raise PeakFindingException("No peaks found")
    	elif n_peaks_found == 1:
    		output_ws.addRow(peak_index_list)
    	elif n_peaks_found == 2:
    		output_ws.addColumn("int", "Transmission Spectrum Number")
    		output_ws.addRow(peak_index_list)

    	if int(keep_workspaces) == 0:
    		DeleteWorkspace(Workspace=cropped_ws)
    		DeleteWorkspace(Workspace=summed_ws)

    	self.setProperty("OutputWorkspace", output_ws)
    def _convert_to_angle(self, w):
        """
        Output the integrated intensity for each elastic detector versus
        detector angle with the neutron beam.

        Masked elastic detectors are assigned a zero intensity

        Parameters
        ----------
        w: Mantid.MatrixWorkspace2D

        Returns
        -------
        Mantid.MatrixWorkspace2D
        """
        id_s, id_e = 16386, 17534  # start and end for elastic detector ID's
        _t_w = Integration(w)
        sp = _t_w.spectrumInfo()
        x, y, e = [list(), list(), list()]
        for i in range(_t_w.getNumberHistograms()):
            id_i = _t_w.getDetector(i).getID()
            if id_s <= id_i <= id_e:
                x.append(np.degrees(sp.twoTheta(i)))
                if sp.isMasked(i) is True:
                    y.append(0.0)
                    e.append(1.0)
                else:
                    y.append(_t_w.readY(i)[0])
                    e.append(_t_w.readE(i)[0])
        x = np.asarray(x)
        y = np.asarray(y)
        e = np.asarray(e)
        od = np.argsort(x)  # order in ascending angles
        title = 'Angle between detector and incoming neutron beam'
        _t_w = CreateWorkspace(DataX=x[od], DataY=y[od], DataE=e[od],
                               NSpec=1, UnitX='Degrees',
                               WorkspaceTitle=title)
        return _t_w