def _findLine(self, ws):
     """Return a peak position workspace."""
     # TODO There should be a better algorithm in Mantid to achieve this.
     integratedWSName = self._names.withSuffix('integrated')
     integratedWS = Integration(InputWorkspace=ws,
                                OutputWorkspace=integratedWSName,
                                EnableLogging=self._subalgLogging)
     transposedWSName = self._names.withSuffix('transposed')
     transposedWS = Transpose(InputWorkspace=integratedWS,
                              OutputWorkspace=transposedWSName,
                              EnableLogging=self._subalgLogging)
     self._cleanup.cleanup(integratedWS)
     # Convert spectrum numbers to WS indices.
     wsIndices = numpy.arange(0, ws.getNumberHistograms())
     xs = transposedWS.dataX(0)
     ys = transposedWS.readY(0)
     numpy.copyto(xs, wsIndices)
     indexOfMax = ys.argmax()
     heightGuess = ys[indexOfMax]
     posGuess = xs[indexOfMax]
     sigmaGuess = 3
     f = 'name=Gaussian, PeakCentre={}, Height={}, Sigma={}'.format(
         posGuess, heightGuess, sigmaGuess)
     fitResult = Fit(Function=f,
                     InputWorkspace=transposedWS,
                     EnableLogging=self._subalgLogging)
     self._cleanup.cleanup(transposedWS)
     peakPos = fitResult.Function.PeakCentre
     posTable = self._createFakePeakPositionTable(peakPos)
     return posTable
 def _findLine(self, ws):
     """Return a peak position workspace."""
     # TODO There should be a better algorithm in Mantid to achieve this.
     integratedWSName = self._names.withSuffix('integrated')
     integratedWS = Integration(InputWorkspace=ws,
                                OutputWorkspace=integratedWSName,
                                EnableLogging=self._subalgLogging)
     transposedWSName = self._names.withSuffix('transposed')
     transposedWS = Transpose(InputWorkspace=integratedWS,
                              OutputWorkspace=transposedWSName,
                              EnableLogging=self._subalgLogging)
     self._cleanup.cleanup(integratedWS)
     # Convert spectrum numbers to WS indices.
     wsIndices = numpy.arange(0, ws.getNumberHistograms())
     xs = transposedWS.dataX(0)
     ys = transposedWS.readY(0)
     numpy.copyto(xs, wsIndices)
     indexOfMax = ys.argmax()
     heightGuess = ys[indexOfMax]
     posGuess = xs[indexOfMax]
     sigmaGuess = 3
     f = 'name=Gaussian, PeakCentre={}, Height={}, Sigma={}'.format(posGuess, heightGuess, sigmaGuess)
     fitResult = Fit(Function=f,
                     InputWorkspace=transposedWS,
                     EnableLogging=self._subalgLogging)
     self._cleanup.cleanup(transposedWS)
     peakPos = fitResult.Function.PeakCentre
     posTable = self._createFakePeakPositionTable(peakPos)
     return posTable
Exemplo n.º 3
0
def plot_specular_pixel_check(input_workspace: EventWorkspace,
                              flood_workspace: EventWorkspace, ax):
    flooded_ws = ApplyFloodWorkspace(input_workspace, flood_workspace)

    integrated = Integration(flooded_ws,
                             RangeLower=9000,
                             RangeUpper=88000,
                             StartWorkspaceIndex=70,
                             EndWorkspaceIndex=95)

    integrated_transposed = Transpose(integrated)

    def _1gaussian(x, ampl, cent, sigma):
        return ampl * (1 / sigma *
                       (np.sqrt(2 * np.pi))) * (np.exp(-((x - cent)**2) /
                                                       (2 * sigma)**2))

    xval = integrated_transposed.readX(0)
    yval = integrated_transposed.readY(0)
    popt_gauss, pcov_gauss = optimize.curve_fit(_1gaussian,
                                                xval,
                                                yval,
                                                p0=[56000, 86, 0.8])
    perr_gauss = np.sqrt(np.diag(pcov_gauss))

    fit_yvals = _1gaussian(xval, *popt_gauss)

    ax.plot(xval, yval, "rx")
    ax.plot(xval, fit_yvals, 'k--')
    ax.axvline(x=86.0, color='b', linestyle='--')
    ax.set_xlabel("Spectrum")
    ax.set_ylabel("Counts")
    max_pos = fit_yvals.argmax()
    annot_y = fit_yvals[max_pos]
    annot_x = xval[max_pos]
    ax.annotate(f"X:{annot_x}, Y:{annot_y}",
                xy=(annot_x, annot_y),
                xytext=(annot_x * 1.02, annot_y))
    ax.minorticks_on()
    ax.grid(True, which="both")
    ax.set_title("Specular pixel")

    # make interactive plotly figure
    fig = go.Figure()
    fig.add_trace(
        go.Scatter(x=xval,
                   y=yval,
                   name="Data",
                   mode="markers",
                   marker_symbol=4))
    fig.add_trace(go.Scatter(x=xval, y=fit_yvals, mode="lines", name="Fit"))
    fig.add_vline(x=86, line_dash="dash", line_color="blue")
    fig.update_layout(xaxis_title="Spectrum",
                      yaxis_title="Counts",
                      width=600,
                      title_text="Specular pixel",
                      title_x=0.5)
    return fig
Exemplo n.º 4
0
def load_data_from_bin(bin_file_name):
    """
    """
    ws_name = os.path.basename(bin_file_name).split('.')[0]
    LoadSpiceXML2DDet(Filename=bin_file_name,
                      OutputWorkspace=ws_name,
                      LoadInstrument=False)

    # get vector of counts
    counts_ws = Transpose(InputWorkspace=ws_name, OutputWorkspace='temp')
    count_vec = counts_ws.readY(0)

    return ws_name, count_vec