diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp index 997aa0e6919a859be1ac37381725c91060cd9d38..4d17cb89f0bbe8b60c431cae08b829911b0f1f24 100644 --- a/Framework/Algorithms/src/Stitch1D.cpp +++ b/Framework/Algorithms/src/Stitch1D.cpp @@ -564,22 +564,14 @@ void Stitch1D::exec() { const double intersectionMin = intesectionXRegion.get<0>(); const double intersectionMax = intesectionXRegion.get<1>(); - - double startOverlap; - double endOverlap; - if (lhsWS->isHistogramData()) { - startOverlap = getStartOverlap(intersectionMin, intersectionMax); - endOverlap = getEndOverlap(intersectionMin, intersectionMax); - if (startOverlap > endOverlap) { - std::string message = boost::str( - boost::format("Stitch1D cannot have a StartOverlap > EndOverlap. " - "StartOverlap: %0.9f, EndOverlap: %0.9f") % - startOverlap % endOverlap); - throw std::runtime_error(message); - } - } else { - startOverlap = intersectionMin; - endOverlap = intersectionMax; + double startOverlap = getStartOverlap(intersectionMin, intersectionMax); + double endOverlap = getEndOverlap(intersectionMin, intersectionMax); + if (startOverlap > endOverlap) { + std::string message = boost::str( + boost::format("Stitch1D cannot have a StartOverlap > EndOverlap. " + "StartOverlap: %0.9f, EndOverlap: %0.9f") % + startOverlap % endOverlap); + throw std::runtime_error(message); } const bool scaleRHS = this->getProperty("ScaleRHSWorkspace"); diff --git a/docs/source/algorithms/Stitch1D-v3.rst b/docs/source/algorithms/Stitch1D-v3.rst index a582109fd036f7f4be963165618014426bddedb6..e965f9e70aa85528cd6a86c06c99f2879a55861b 100644 --- a/docs/source/algorithms/Stitch1D-v3.rst +++ b/docs/source/algorithms/Stitch1D-v3.rst @@ -75,7 +75,7 @@ workspace by this number takes into account its error. Usage ----- -**Example - a basic example using stitch1D to stitch two workspaces together.** +**Example - a basic example using stitch1D to stitch two histogram workspaces together.** .. plot:: :include-source: @@ -88,7 +88,7 @@ Usage """Creates a Gaussian peak centered on mu and with width sigma.""" return (1/ sigma * np.sqrt(2 * np.pi)) * np.exp( - (x-mu)**2 / (2*sigma**2)) - #create two histograms with a single peak in each one + # create two histograms with a single peak in each one x1 = np.arange(-1, 1, 0.02) x2 = np.arange(0.4, 1.6, 0.02) ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1[:-1], 0, 0.1)+1) @@ -109,6 +109,40 @@ Usage # uncomment the following line to show the plot window #fig.show() +**Example - a basic example using stitch1D to stitch two point data workspaces together.** + +.. plot:: + :include-source: + + from mantid.simpleapi import * + import matplotlib.pyplot as plt + import numpy as np + + def gaussian(x, mu, sigma): + """Creates a Gaussian peak centered on mu and with width sigma.""" + return (1/ sigma * np.sqrt(2 * np.pi)) * np.exp( - (x-mu)**2 / (2*sigma**2)) + + # create two histograms with a single peak in each one + x1 = np.arange(-1, 1, 0.02) + x2 = np.arange(0.4, 1.6, 0.02) + ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1, 0, 0.1)+1) + ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=gaussian(x2, 1, 0.05)+1) + + #stitch the histograms together + stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, StartOverlap=0.4, EndOverlap=0.6) + + # plot the individual workspaces alongside the stitched one + fig, axs = plt.subplots(nrows=1, ncols=2, subplot_kw={'projection':'mantid'}) + + axs[0].plot(mtd['ws1'], wkspIndex=0, label='ws1') + axs[0].plot(mtd['ws2'], wkspIndex=0, label='ws2') + axs[0].legend() + axs[1].plot(mtd['stitched'], wkspIndex=0, color='k', label='stitched') + axs[1].legend() + + # uncomment the following line to show the plot window + #fig.show() + **Example - a practical example using reflectometry data and a scale factor.** .. plot:: diff --git a/docs/source/release/v3.13.0/framework.rst b/docs/source/release/v3.13.0/framework.rst index fa3581d5ea378698fa98d6fa9a0eb145b48a7532..5720dd83295bb8401dccaedcba9ffdff4f5dfeb8 100644 --- a/docs/source/release/v3.13.0/framework.rst +++ b/docs/source/release/v3.13.0/framework.rst @@ -27,7 +27,7 @@ Improved - :ref:`Maxent <algm-Maxent>` when outputting the results of the iterations, it no longer pads with zeroes but returns as many items as iterations done for each spectrum, making the iterations easy to count. -- XError values (Dx) can now be treated by the following algorithms: :ref:`ConjoinXRuns <algm-ConjoinXRuns>`, :ref:`ConvertToHistogram <algm-ConvertToHistogram>`, :ref:`ConvertToPointData <algm-ConvertToPointData>`, :ref:`CreateWorkspace <algm-CreateWorkspace>`, :ref:`SortXAxis <algm-SortXAxis>`, :ref:`algm-Stitch1D`. +- XError values (Dx) can now be treated by the following algorithms: :ref:`ConjoinXRuns <algm-ConjoinXRuns>`, :ref:`ConvertToHistogram <algm-ConvertToHistogram>`, :ref:`ConvertToPointData <algm-ConvertToPointData>`, :ref:`CreateWorkspace <algm-CreateWorkspace>`, :ref:`SortXAxis <algm-SortXAxis>`, :ref:`algm-Stitch1D` (case point data). - :ref:`Stitch1D <algm-Stitch1D>` can treat point data. - The algorithm :ref:`SortXAxis <algm-SortXAxis>` has a new input option that allows ascending (default) and descending sorting. The documentation needed to be corrected in general.