Difference between revisions of "ISIS direct reduction script description."
Line 99: | Line 99: | ||
The data will be loaded in memory and properly calibrated if this have not happened yet. | The data will be loaded in memory and properly calibrated if this have not happened yet. | ||
− | Note the difference between getting the whole property above, allowing access to the properties methods, and getting access to property value within ''PropertyManager'' instance: | + | Note the difference between getting the whole property above, allowing access to the properties methods, and getting access to property value within ''PropertyManager'' instance (PropertyManager instantiated in DirectEnergyConversion as prop_man): |
dc = DirectEnergyConversion('MER') | dc = DirectEnergyConversion('MER') | ||
dc.prop_man.sample_run = 2034 | dc.prop_man.sample_run = 2034 | ||
Line 108: | Line 108: | ||
ws = PropertyManager.sample_run.get_workspace() | ws = PropertyManager.sample_run.get_workspace() | ||
after assigning number to the sample run will try to load Merlin workspace and will return it if Merlin run file for experiment with run number 2034 can be found on the Mantid search path. | after assigning number to the sample run will try to load Merlin workspace and will return it if Merlin run file for experiment with run number 2034 can be found on the Mantid search path. | ||
+ | |||
+ | Simplest reduction script can be build on the basis of ''DirectEnergyConversion'' class as follows: | ||
+ | Usage: | ||
+ | red = DirectEnergyConversion('InstrumentName') | ||
+ | red.prop_man.sample_run = run number | ||
+ | red.prop_man.wb_run = Whitebeam | ||
+ | red.prop_man.incident_energy = energy guess | ||
+ | red.prop_man.energy_bins = [min_val,step,max_val] | ||
+ | red.convert_to_energy() | ||
+ | |||
+ | Or in more functional form: | ||
+ | red = DirectEnergyConversion('InstrumentName') | ||
+ | and then: | ||
+ | red.convert_to_energy(wb_run,sample_run,ei_guess,rebin) | ||
+ | or | ||
+ | red.convert_to_energy(wb_run,sample_run,ei_guess,rebin,**arguments) | ||
+ | or | ||
+ | red.convert_to_energy(wb_run,sample_run,ei_guess,rebin,mapfile,**arguments) | ||
+ | In more details various form of calls to convert_to_energy method are described within [https://github.com/mantidproject/mantid/blob/master/scripts/Inelastic/Direct/DirectEnergyConversion.py ''DirectEnergyConversion''] class itself. |
Revision as of 18:38, 14 April 2016
Overview
All ISIS direct inelastic reduction scripts have similar interface and layout, with only parameters different for different instruments. Some parameters change from one cycle and sometimes one experiment to another but most of them are instrument specific and changes only when instrument is modified. Instrument scientists prepare sample Mantid python reduction scripts, which are then automatically distributed to Isiscompute users according to the rules described here.
From the links below one can retrieve resent versions of these scripts and their default reduction parameters stored in XML files, namely:
Instrument | Simple reduction script | Full reduction script | Default reduction parameters | User Settings Description file |
MARI: | template_mari.py | MARIReduction_Sample.py | MARI_Parameters.xml | MARI User settings |
MAPS: | template_maps.py | MAPSReduction_Sample.py | MAPS_Parameters.xml | MARI User settings |
MERLIN: | --- | MERLINReduction_Sample.py | MERLIN_Parameters.xml | MERLIN User settings |
LET: | --- | LETReduction_Sample.py | LET_Parameters.xml | LET User settings |
The teplate_instrument_name.py and InstrumentReduction_Sample.py files referenced in column two and three above are processed by MantidConfigurationScript, which replaces the strings, specified in correspondent User Settings Description file (Column 5) and produces simple and full reduction scripts for users.
Simple reduction script created for users who prefer old functional interface used by qtiGenie and Libisis. It highlights only the parameters user needs to change during an experiment and allows users to separate all parameters, necessary to reduce data and user's parameters in different files. User parameters are usually the run number or list of run numbers to process, run number for a white beam vanadium run, energies the user is interested in and energy binning. There are couple of other parameters, directly related to the experiment in progress. These parameters are better described in the script itself.
Simple reduction script is then imports full reduction script, which sets up the parameters specific to a cycle and may be to an experiment. After that the advanced script picks up all other parameter's default values from the appropriate xml file and runs the reduction algorithms itself.
User may work directly with the full reduction script as this one has all necessary parameters which can then be fine tuned for particular runs in the __main__ section of the script as described in the script. In fact, setting up small number of simple parameters in a separate script or setting up all parameters together in one big script is the matter of personal choice between using one big file with all parameters or two files with different sets of parameters.
For instruments, where simple reduction script is present, user can find the iliad function, used by the simple reduction script inside the advanced reduction script.
Reduction Scripts in Depth
This chapter intended for advanced users or instrument scientists who wants to modify reduction scripts and add some new features to them. To benefit from reading the following, a user should be familiar with OOP jargon and have some knowledge of Python concepts for Properties descriptors, Decorators, and usage of __setattr__ and __getattr__ methods. We also use word Run as synonym for the results of single inelastic experiment (a file or range of files, recorded during experiment and have particular number (run number))
Reduction script files and their purpose
ISIS reduction scripts are part of Mantid and located under Mantid installation folder in /scripts/Inelastic/Direct directory (/opt/Mantid/scripts/Inelastic/Direct on Unix, c:\Mantid\scripts\Inelastic\Direct under Windows or see it on the web here). The following files are located in Direct:
Script | Description |
---|---|
DirectEnergyConversion.py | The python class implementing ISIS direct inelastic reduction workflow. Its most important method is convert_to_energy,invoked for each run or sum of runs, and converting data, obtained in experiment into reduced data. All other methods of this class are directly or indirectly called by this method. The class also imports diagnostics.py file, containing number of functions, responsible for various diagnostics operations over a Mantid workspace. |
NonIDF_Properties.py | The file contains the parent class for the PropertyManager class below. It instantiates and controls properties, not related to the properties found in Instrument_Parameters.xml file. (e.g. incident_energy, or sample_run) |
PropertyManager.py | The python class, together with NonIDF_Properties class responsible for processing user input, attached to Instrument parameter files described above and all other properties, and providing input data and settings to DirectEnergyConversion. This class, together with NonIDF_Properties class instantiates classes found in three other files, namely: PropertiesDescriptors.py,RunDescriptor.py and ReductionHelpers.py. |
PropertiesDescriptors.py,RunDescriptor.py and ReductionHelpers.py contain small classes and functions helping to process and provide various input parameters to DirectEnergyConversion, namely :
Script | Description |
ReductionHelpers.py | contains range of helper functions and the class, which is automatically instantiated for the Instrument_Parameters.xml fields, which do not need complex behaviour (e.g. load_monitors_with_workspace True or False) |
PropertiesDescriptors.py | contains classes related to properties, described in Instrument_Parameters.xml but providing more complex behaviour for such properties. E.g. DetCalFile class describes detector calibration file det_cal_file Instrument_Parameters.xml but contains valiadators, used to check correct file extension and if the calibration file is indeed present. |
RunDescriptor.py | contains one but most important property descriptor, related to the reduced and auxiliary experimental data. It's responsible for conversion between run numbers and file names, loading appropriate files to Mantid to use in reduction, renaming workspaces according to different stages of reduction process, etc. Each run related property such as sample_run,wb_run, monovan_run, etc are the instances of this class located in NonIDF_Properties class. |
Note: PropertyManager and many properties descriptors form files above are implemented as singletons so any property instance can be accessed in reduction as:
prop = PropertyManager.property_name
e.g.:
is_multirep = PropertyManager.incident_energy.multirep_mode() Return true if energy is defined as list of energies and false otherwise (multirep mode)
or:
run_nuber = PropertyManager.sample_run.run_number() Get run number for defined sample run. ws = PropertyManager.sample_run.get_workspace() Get Mantid workspace correspondent to sample run (if one is defined) at current state of reduction The data will be loaded in memory and properly calibrated if this have not happened yet.
Note the difference between getting the whole property above, allowing access to the properties methods, and getting access to property value within PropertyManager instance (PropertyManager instantiated in DirectEnergyConversion as prop_man):
dc = DirectEnergyConversion('MER') dc.prop_man.sample_run = 2034 print "Sample run number is: ",dc.prop_man.sample_run
prints:
Sample run number is:2034
while calling
ws = PropertyManager.sample_run.get_workspace()
after assigning number to the sample run will try to load Merlin workspace and will return it if Merlin run file for experiment with run number 2034 can be found on the Mantid search path.
Simplest reduction script can be build on the basis of DirectEnergyConversion class as follows:
Usage: red = DirectEnergyConversion('InstrumentName') red.prop_man.sample_run = run number red.prop_man.wb_run = Whitebeam red.prop_man.incident_energy = energy guess red.prop_man.energy_bins = [min_val,step,max_val] red.convert_to_energy()
Or in more functional form:
red = DirectEnergyConversion('InstrumentName') and then: red.convert_to_energy(wb_run,sample_run,ei_guess,rebin) or red.convert_to_energy(wb_run,sample_run,ei_guess,rebin,**arguments) or red.convert_to_energy(wb_run,sample_run,ei_guess,rebin,mapfile,**arguments)
In more details various form of calls to convert_to_energy method are described within DirectEnergyConversion class itself.