\(\renewcommand\AA{\unicode{x212B}}\)
Python in Mantid: Exercise 2¶
The aim of this exercise is to create a general script that can accept user interaction to alter the parameters for future uses
Perform a set of algorithms by pointing and clicking within Mantid Use the history window to generate a script based upon the executed algorithms Use the dialog functions to make the script more general for future runs.
A - Processing ISIS Data¶
Running an analysis Manually¶
Here you are going to perform a number of steps in the Mantid user interface to correct a LOQ dataset using the incident beam monitor. For more information in a specific algorithm, click on its name.
- Load v1 - Use the LOQ48097.raw file, set the OutputWorkspace to Small_Angle and set LoadMonitors to Separate. 
- ConvertUnits v1 - Convert the units for the Monitor workspace to wavelength with EMode=Elastic. 
- ConvertUnits v1 - Do the same for the small_angle data with EMode=Elastic. 
- Rebin v1 - Rebin the monitor from 2.2 to 10 in log steps of 0.035. To achieve this, the rebin params string will be “2.2,-0.035,10.0”. 
- Rebin v1 - Do the same for the small_angle data. 
- ExtractSingleSpectrum v1 - Use WorkspaceIndex=1 on the Small_Angle_monitors workspace to pull out the 2nd monitor spectrum, putting the answer back into the input workspace. 
- Divide v1 - Run divide with LHSWorkspace as the small_angle data workspace & RHSWorkspace as the monitor, into an OutputWorkspace called Corrected_data. 
Generating a script from a workspace¶
Once you have performed an analysis you can easily save it out as a script
- Right-Click on the final result workspace, then select Show History 
- Click on the Script to Clipboard button 
- Paste the code into the Script Editor 
- Delete all the entries in the Workspace Toolbox 
- Run the script to check it works! 
One step further¶
- Extract the binning params from the first Rebin, print them using the logger, AND use them as the input for the second Rebin 
- Add comments to your script to explain what it does! 
B - Plotting ILL Data¶
Load and Plot¶
- Load v1 the file 164198.nxs 
- Double-click on the main data workspace 164198 
- Produce a normal plot of the spectrum numbers: 50,100,200,300 
Generating a script from a plot¶
C - Processing and Plotting SNS Data¶
Running an analysis Manually¶
- Load v1 - Load the file EQSANS_6071_event.nxs. 
- ConvertUnits v1 - Convert the units for both the monitor and detector workspaces to wavelength 
- Rebin v1 - Rebin both workspaces in wavelength from 2.5 to 5.5 in linear steps of 0.1 
- SumSpectra v1 - Sum up all the detectors to give the beam profile 
- Divide v1 - Normalize the rebinned and summed spectra in wavelength by the monitors 
Generating a script from a workspace¶
Once you have performed an analysis you can easily save it out as a script.
- Right-Click on the final result workspace normalized, then select Show History 
- Click on the Script to File button and save the file somewhere useful! 
- Open the script by selecting File > Open Script or use the keyboard shortcut Ctrl+O (or Cmd+O) 
- Delete all workspaces and Run the script to check it works! 
Plot and Edit¶
- Double-click on the normalized spectrum to plot it 
- Right-click on run_monitors_lambda_rebinned and select Plot > Overplot Spectrum. 
- Also, overplot with run_lambda_summed 
- In the Options menu (Gear icon) 
- Set the x-upper-limit to 4.5 
- Set the y-scale to log 
- Click Apply 
