Performing linecuts using the Scissors class¶
Importing the Scissors class¶
from nxs_analysis_tools import Scissors, load_transform
from nxs_analysis_tools.datasets import cubic
sample_directory = cubic() # Download the example data into cache directory
from nexusformat.nexus import NXdata, NXfield
import numpy as np
Setting up a linecut - Method 1¶
You can set the data, linecut center, integration window, and integration axis when you initialize the Scissors object.
data = load_transform(f'{sample_directory}/cubic_15.nxs')
data:NXdata
@axes = ['Qh', 'Qk', 'Ql']
@signal = 'counts'
Qh = float64(100)
Qk = float64(150)
Ql = float64(200)
counts = float64(100x150x200)
scissors = Scissors(data, center=(0,0,0), window=(0.75,0.2,0.15), axis=None)
Setting up a linecut - Method 2¶
…or you can set them one by one after initializing the object.
scissors = Scissors()
scissors.set_data(data)
scissors.set_center((0,0,0))
scissors.set_window((0.75,0.2,0.15))
Performing a linecut¶
You can use .cut_data() to perform the cut, returning an NXdata object.
linecut = scissors.cut_data()
Plotting a linecut¶
The .integration_window attribute stores a tuple of slice objects over which the integration was performed.
scissors.integration_window
(slice(np.float64(-0.75), np.float64(0.75), None),
slice(np.float64(-0.2), np.float64(0.2), None),
slice(np.float64(-0.15), np.float64(0.15), None))
To show where the integration was performed, use the .plot_integration_window() method.
scissors.plot_integration_window()
(<matplotlib.collections.QuadMesh at 0x7e1312d96560>,
<matplotlib.collections.QuadMesh at 0x7e1310b3ad10>,
<matplotlib.collections.QuadMesh at 0x7e1310b9fca0>)
Use the optional width and height parameters to zoom in on the region of interest.
scissors.plot_integration_window(width=1.5, height=0.5, cbar=False)
(<matplotlib.collections.QuadMesh at 0x7e134c537550>,
<matplotlib.collections.QuadMesh at 0x7e13109d9450>,
<matplotlib.collections.QuadMesh at 0x7e13108043d0>)
The label parameter allows you to specify a label for the highlighted region.
scissors.plot_integration_window(label='My Cut')
(<matplotlib.collections.QuadMesh at 0x7e1316a2a6b0>,
<matplotlib.collections.QuadMesh at 0x7e131075d360>,
<matplotlib.collections.QuadMesh at 0x7e13107bec20>)
The .plot() method of the NXdata object can be used to generate a basic plot of the linecut.
linecut.plot()