\(\renewcommand\AA{\unicode{x212B}}\)
Python in Mantid: Solution 2¶
All the data for these solutions can be found in the TrainingCourseData on the Downloads page.
A - Processing ISIS Data¶
# import mantid algorithms, numpy and matplotlib
from mantid.simpleapi import *
import matplotlib.pyplot as plt
import numpy as np
# Load the main data file and its monitor
Load(Filename='LOQ48097.raw', OutputWorkspace='Small_Angle', LoadMonitors='Separate')
# Convert monitor to wavelength
ConvertUnits(InputWorkspace='Small_Angle_monitors', OutputWorkspace='Small_Angle_monitors', Target='Wavelength')
# Convert data to wavelength
ConvertUnits(InputWorkspace='Small_Angle', OutputWorkspace='Small_Angle', Target='Wavelength')
# Rebin the monitors with a suggested set of parameters
rebin_var = Rebin(InputWorkspace='Small_Angle_monitors', OutputWorkspace='Small_Angle_monitors', Params='2.2,-0.035,10')
# Extract binning params from the first Rebin-algm
rebin_alg = rebin_var.getHistory().lastAlgorithm()
params = rebin_alg.getPropertyValue('Params')
# Log the Rebin params at the level information
logger.information("Rebin parameters: {}".format(params))
# Rebin the data with the params extracted from the earlier Rebin
Rebin(InputWorkspace='Small_Angle', OutputWorkspace='Small_Angle', Params= params)
# Extract the Spectrum for correcting the data
ExtractSingleSpectrum(InputWorkspace='Small_Angle_monitors', OutputWorkspace='Small_Angle_monitors', WorkspaceIndex=1)
# Correct the data by dividing by the monitor spectrum
Divide(LHSWorkspace='Small_Angle', RHSWorkspace='Small_Angle_monitors', OutputWorkspace='Corrected_data')
B - Plotting ILL Data¶
Enable :plots: using DOCS_PLOTDIRECTIVE in CMake
C - Processing and Plotting SNS Data¶
Enable :plots: using DOCS_PLOTDIRECTIVE in CMake