Data.stitch¶
- Data.stitch(other, xcol=None, ycol=None, overlap=None, min_overlap=0.0, mode='All', func=None, p0=None)¶
Apply a scaling to this data set to make it stich to another dataset.
- Parameters
other (DataFile) – Another data set that is used as the base to stitch this one on to
xcol,ycol (index or None) – The x and y data columns. If left as None then the current setas attribute is used.
- Keyword Arguments
overlap (tuple of (lower,higher) or None) – The band of x values that are used in both data sets to match, if left as None, thenthe common overlap of the x data is used.
min_overlap (float) – If you know that overlap must be bigger than a certain amount, the bounds between the two data sets needs to be adjusted. In this case min_overlap shifts the boundary of the overlap on this DataFile.
mode (str) – Unless func is specified, controls which parameters are actually variable, defaults to all of them.
func (callable) – a stitching function that transforms \((x,y)\rightarrow(x',y')\). Default is to use functions defined by mode
p0 (iterable) – if func is not None then p0 should be the starting values for the stitching function parameters
- Returns
(
Stoner.Data
) – A copy of the currentAnalysisMixin
with the x and y data columns adjusted to stitch
To stitch the data together, the x and y data in the current data file is transforms so that \(x'=x+A\) and \(y'=By+C\) where \(A,B,C\) are constants and \((x',y')\) are close matches to the \((x,y)\) data in other. The algorithm assumes that the overlap region contains equal numbers of \((x,y)\) points mode controls whether A,B, and C are fixed or adjustable
“All” - all three parameters adjustable
“Scale y, shift x” - C is fixed at 0.0
“Scale and shift y” A is fixed at 0.0
“Scale y” - only B is adjustable
“Shift y” - Only c is adjsutable
“Shift x” - Only A is adjustable
“Shift both” - B is fixed at 1.0
See also
User Guide section Stitching Datasets together
Example
"""Scale data to stitch it together. This example demonstrates specifying the overlap as an integer and scaling both curves to match the other.""" import matplotlib.pyplot as plt from Stoner import Data from Stoner.Util import format_error # Load and plot two sets of data s1 = Data("Stitch-scan1.txt", setas="xy") s2 = Data("Stitch-scan2.txt", setas="xy") s3 = s2.clone s1.plot(fmt="b-", label="Set 1", linewidth=1) s2.fig = s1.fig s2.plot(fmt="r-", label="Set 2", linewidth=1) # Stitch scan 2 onto scan 1 s2.stitch(s1, overlap=100) s2.plot(fmt="b:", label="Set 2 Stictched on Set 1", linewidth=1) s2.title = "Stictching Example" # Tidy up the plot by adding annotation fo the stirching co-efficients labels = ["A", "B", "C"] txt = [] lead = r"$x'\rightarrow x+A$" + "\n" + r"$y'=\rightarrow By+C$" + "\n" for l, v, e in zip( labels, s2["Stitching Coefficients"], s2["Stitching Coeffient Errors"] ): txt.append(format_error(v, e, latex=True, prefix=l + "=")) plt.text(1.5, 1.25, lead + "\n".join(txt), fontdict={"size": "x-small"}) # Now stich s1 onto the clone of s2 and plot and label s1.stitch(s3, overlap=100) s1.plot(fmt="r:", label="Set 1 sticked on Set 2", linewidth=1) txt = [] lead = r"$x'\rightarrow x+A$" + "\n" + r"$y'=\rightarrow By+C$" + "\n" for l, v, e in zip( labels, s1["Stitching Coefficients"], s1["Stitching Coeffient Errors"] ): txt.append(format_error(v, e, latex=True, prefix=l + "=")) plt.text(5.0, 1.25, lead + "\n".join(txt), fontdict={"size": "x-small"})