\(\renewcommand\AA{\unicode{x212B}}\)

CropWorkspace v1

Summary

Extracts a ‘block’ from a workspace and places it in a new workspace.

See Also

CropWorkspaceRagged, CropToComponent, RemoveBins, ExtractSingleSpectrum, ExtractSpectra

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

The input workspace

OutputWorkspace

Output

MatrixWorkspace

Mandatory

Name of the output workspace

XMin

Input

number

Optional

An X value that is within the first (lowest X value) bin that will be retained (default: workspace min)

XMax

Input

number

Optional

An X value that is in the highest X value bin to be retained (default: max X)

StartWorkspaceIndex

Input

number

0

The index number of the first entry in the Workspace that will be loaded (default: first entry in the Workspace)

EndWorkspaceIndex

Input

number

Optional

The index number of the last entry in the Workspace to be loaded (default: last entry in the Workspace)

Description

Extracts a ‘block’ from a workspace and places it in a new workspace (or, to look at it another way, lops bins or spectra off a workspace).

CropWorkspace works on workspaces with common X arrays/bin boundaries or on so-called ragged workspace. If the input workspace has common bin boundaries/X values then cropping in X will lead to an output workspace with fewer bins than the input one. If the boundaries are not common then the output workspace will have the same number of bins as the input one, but with data values outside the X range given set to zero.

If an X value given for XMin/XMax does not match a bin boundary (within a small tolerance to account for rounding errors), then the closest bin boundary on the left will be used. Note that if none of the optional properties are given, then the output workspace will be a copy of the input one. If XMin==XMax the single bin that X falls into will be extracted.

Usage

Example - Crop a 5-bin workspace

# Create a workspace with 1 spectrum with five bins of width 10
ws = CreateSampleWorkspace(WorkspaceType="Histogram",  NumBanks=1, BankPixelWidth=1, BinWidth=10, Xmax=50)

# Run algorithm  removing first and last bins
OutputWorkspace = CropWorkspace(InputWorkspace=ws,XMin=10.0,XMax=40.0)

# Show workspaces
print("TOF Before CropWorkspace {}".format(ws.readX(0)))
print("TOF After CropWorkspace {}".format(OutputWorkspace.readX(0)))

Output:

TOF Before CropWorkspace [  0.  10.  20.  30.  40.  50.]
TOF After CropWorkspace [ 10.  20.  30.  40.]

Categories: AlgorithmIndex | Transforms\Splitting

Source

C++ header: CropWorkspace.h

C++ source: CropWorkspace.cpp