\(\renewcommand\AA{\unicode{x212B}}\)
Stitch1DMany v1¶
Summary¶
Stitches histogram matrix workspaces together
See Also¶
Properties¶
Name 
Direction 
Type 
Default 
Description 

InputWorkspaces 
Input 
str list 
Mandatory 
List or group of MatrixWorkspaces. Allowed values: [‘002192_Beam’, ‘002192_Beam_Flux’, ‘002193_Transmission’, ‘002194_Transmission’, ‘002195_Transmission’, ‘002196_Transmission’, ‘002197_Transmission’, ‘002219_Beam’, ‘002219_Beam_Flux’, ‘002227_Absorber’, ‘002228_Container’, ‘AgBE’, ‘AgBE_#1_d2.0m_c7.8m_w6.0A’, ‘D2O’, ‘D2O_#1_d2.0m_c7.8m_w6.0A’, ‘D33Mask2’, ‘D33_2m_SolidAngle’, ‘F127_D2O’, ‘F127_D2O_#1_d2.0m_c7.8m_w6.0A’, ‘F127_D2O_Anethol’, ‘F127_D2O_Anethol_#1_d2.0m_c7.8m_w6.0A’, ‘H2O’, ‘H2O_#1_d2.0m_c7.8m_w6.0A’, ‘SofTT’, ‘stitched’, ‘stitched_wav’, ‘trans1’, ‘trans1_wav’, ‘trans2’, ‘trans2_wav’, ‘ws’, ‘ws1’, ‘ws2’] 
OutputWorkspace 
Output 
Mandatory 
Stitched workspace. 

Params 
Input 
dbl list 
Rebinning Parameters, see Rebin algorithm for format. 

StartOverlaps 
Input 
dbl list 
Start overlaps for stitched workspaces (number of input workspaces minus one). 

EndOverlaps 
Input 
dbl list 
End overlaps for stitched workspaces (number of input workspaces minus one). 

ScaleRHSWorkspace 
Input 
optional boolean 
Unset 
Scaling either with respect to first (first hand side, LHS) or second (right hand side, RHS) workspace. This property no longer has an effect, please use the IndexOfReference property instead. Allowed values: [‘Unset’, ‘True’, ‘False’] 
UseManualScaleFactors 
Input 
boolean 
False 
True to use provided values for the scale factor. 
ManualScaleFactors 
Input 
dbl list 
Either a single scale factor which will be applied to all input workspaces or individual scale factors (number of input workspaces minus one) 

OutScaleFactors 
Output 
dbl list 
The actual used values for the scaling factors at each stitch step. 

ScaleFactorFromPeriod 
Input 
number 
1 
Provided index of period to obtain scale factor from; periods are indexed from 1 and used only if stitching group workspaces, UseManualScaleFactors is true and ManualScaleFactors is set to default. 
IndexOfReference 
Input 
number 
0 
Index of the workspace to be used as reference for scaling, or 1 to choose the last workspace as the reference. 
Description¶
Stitches Matrix Workspaces together outputting a stitched Matrix Workspace. This algorithm is a wrapper over Stitch1D v3.
Please note the different behavior for histogram and point data described in Stitch1D v3. You may consider to run ConvertToHistogram v1 on workspaces prior to passing them to this algorithm.
The algorithm expects pairs of StartOverlaps
and
EndOverlaps
values. The order in which these are provided determines
the pairing. There should be N entries in each of these lists, where N = 1 
(No. of workspaces to stitch). StartOverlaps and EndOverlaps are in the same
units as the Xaxis for the workspace and are optional. For each pair of these
values, the StartOverlaps
value cannot exceed its corresponding
EndOverlaps
value. Furthermore, if either the start or end value is
outside the range of Xaxis intersection, they will be forcibly changed to the
intersection min and max respectively.
This algorithm is also capable of stitching together matrix workspaces from multiple workspace groups. In this case, each group must contain the same number of workspaces. The algorithm will stitch together the workspaces in the first group before stitching workspaces from the next group on top of the previous ones.
When stitching the workspaces, we can specify manual scale factors to use by setting
UseManualScaleFactors
true and passing values to
ManualScaleFactors
. For group workspaces, we can also use
ScaleFactorFromPeriod
to select a period which will obtain a vector
of scale factors from the selected period. These scale factors are then applied
to all other periods when stitching.
The workspace that provides the scale for stitching output can be chosen by
specifying the desired index through IndexOfReference
property.
The reference workspace will not be scaled, and the other workspaces will be scaled
to match the reference. Note that this property should be used instead of
ScaleRHSWorkspace
, which no longer has any effect and will eventually be removed.
Workflow¶
The algorithm workflow is as follows:
A check is performed to find out whether the input workspaces are group workspaces or not. The algorithm handles matrix workspaces differently from group workspaces.
If matrix workspaces are supplied, the algorithm simply iterates over each workspace and calls the
Stitch1D
algorithm. This stitches each pair of workspaces together, with either the RHS or LHS workspace being scaled depending on the chosen reference workspace (given byIndexOfReference
). The resultant workspace and its scale factor are outputted.If group workspaces are supplied, the algorithm checks whether or not to scale workspaces using scale factors from a specific period (given by
ScaleFactorFromPeriod
). This is done only ifUseManualScaleFactors
is true andManualScaleFactors
is set to its default value (empty).If not using
ScaleFactorFromPeriod
, the algorithm collects the workspaces belonging to each period across all groups and callsStitch1DMany
for each period. As a selection of nongroup workspaces are passed to it, this essential repeats step 2 for each period. Each of the resultant stitched workspaces stored in a vector while each list of out scale factors are appended to each other and outputted.The vector of output stitched workspaces are passed to
GroupWorkspaces
, which groups the workspaces into a single workspace, which is then outputted.If using
ScaleFactorFromPeriod
, the algorithm callsStitch1DMany
for a period specified byScaleFactorFromPeriod
and passes the same input workspaces. This returns a vector of period scale factors obtained by stitching workspaces from a specific period.The algorithm iterates over each workspace for each period across all groups and calls
Stitch1D
, passing the scale factor from period scale factors for each period index. Like in step 4, the stitched workspaces are stored in a vector while the out scale factors are appended and outputted. Finally step 5 is performed, grouping the workspaces into a single one that is outputted.
In the diagram below, all input parameters other than
InputWorkspaces
, UseManualScaleFactors
,
ManualScaleFactors
and ScaleFactorFromPeriod
have been
omitted as they do not serve any purpose other than to be passed to the
Stitch1DMany
algorithm.
Usage¶
Example  a basic example using Stitch1DMany to stitch three workspaces together.
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(  (xmu)**2 / (2*sigma**2))
# Create three histograms with a single peak in each one
x1 = np.arange(1, 1, 0.02)
x2 = np.arange(0.4, 1.6, 0.02)
x3 = np.arange(1.3, 3, 0.02)
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1[:1], 0, 0.1)+1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=gaussian(x2[:1], 1, 0.05)+1)
ws3 = CreateWorkspace(UnitX="1/q", DataX=x3, DataY=gaussian(x3[:1], 2, 0.08)+1)
# Stitch the histograms together
workspaces = ws1.name() + "," + ws2.name() + "," + ws3.name()
stitched, scale = Stitch1DMany(InputWorkspaces=workspaces, StartOverlaps=[0.4, 1.2], EndOverlaps=[0.6, 1.4], Params=[0.02])
Output:
Example  another example using three group workspaces of two workspaces each.
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(  (xmu)**2 / (2*sigma**2))
# Create six histograms with a single peak in each one
x1 = np.arange(1, 1, 0.02)
x3 = np.arange(0.3, 1.8, 0.02)
x5 = np.arange(1.4, 2.8, 0.02)
x2 = np.arange(2.4, 3.5, 0.02)
x4 = np.arange(3.2, 4.9, 0.02)
x6 = np.arange(4.5, 5.2, 0.02)
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1[:1], 0, 0.1)+1)
ws3 = CreateWorkspace(UnitX="1/q", DataX=x3, DataY=gaussian(x3[:1], 1, 0.05)+1)
ws5 = CreateWorkspace(UnitX="1/q", DataX=x5, DataY=gaussian(x5[:1], 2, 0.12)+1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=gaussian(x2[:1], 3, 0.08)+1)
ws4 = CreateWorkspace(UnitX="1/q", DataX=x4, DataY=gaussian(x4[:1], 4, 0.06)+1)
ws6 = CreateWorkspace(UnitX="1/q", DataX=x6, DataY=gaussian(x6[:1], 5, 0.04)+1)
# Group first, second and third pairs of workspaces
groupWSNames1 = ws1.name() + "," + ws2.name()
gws1 = GroupWorkspaces(InputWorkspaces=groupWSNames1)
groupWSNames2 = ws3.name() + "," + ws4.name()
gws2 = GroupWorkspaces(InputWorkspaces=groupWSNames2)
groupWSNames3 = ws5.name() + "," + ws6.name()
gws3 = GroupWorkspaces(InputWorkspaces=groupWSNames3)
# Stitch together workspaces from each group
workspaceNames = gws1.name() + "," + gws2.name() + "," + gws3.name()
stitched, scale = Stitch1DMany(InputWorkspaces=workspaceNames, StartOverlaps=[0.3, 1.4], EndOverlaps=[3.3, 4.6], Params=[0.02])
Output:
Categories: AlgorithmIndex  Reflectometry
Source¶
C++ header: Stitch1DMany.h
C++ source: Stitch1DMany.cpp