Skip to content

Commit

Permalink
Re #10803 Merging it back to develop as system tests do depend on it
Browse files Browse the repository at this point in the history
Merge branch 'feature/10803_DirectInelasticPack' into develop

Conflicts:
	Code/Mantid/scripts/Inelastic/Direct/NonIDF_Properties.py
  • Loading branch information
abuts committed Dec 22, 2014
2 parents 69d5391 + f207f0d commit c2bceaa
Show file tree
Hide file tree
Showing 20 changed files with 774 additions and 765 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Homer.cpp
Expand Up @@ -771,8 +771,8 @@ void Homer::setIDFValues(const QString &)

// Fill in default values for tab
QString param_defs =
"from DirectPropertyManager import DirectPropertyManager\n"
"prop_man = DirectPropertyManager('%1')\n"
"from Direct.PropertyManager import PropertyManager\n"
"prop_man = PropertyManager('%1')\n"
"prop_man.incident_energy = 1\n"
"int_range = prop_man.monovan_integr_range\n"
"bkg_rane = prop_man.bkgd_range\n";
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/deltaECalc.cpp
Expand Up @@ -38,7 +38,7 @@ void deltaECalc::createProcessingScript(const QStringList &runFiles, const QStri
const QStringList &absRunFiles, const QString &absWhiteBeam,
const QString & saveName)
{
QString pyCode = "import DirectEnergyConversion as direct\n";
QString pyCode = "import Direct.DirectEnergyConversion as direct\n";
pyCode += QString("mono_sample = direct.DirectEnergyConversion('%1')\n").arg(m_sets.cbInst->currentText());
//Turn off printing to stdout
pyCode += QString("mono_sample.prop_man.log_to_mantid = True\n");
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/MantidWidgets/src/MWDiag.cpp
Expand Up @@ -95,7 +95,7 @@ Instrument_const_sptr MWDiag::getInstrument(const QString & name)
if( !dataStore.doesExist(ws_name) )
{
QString pyInput =
"from DirectEnergyConversion import setup_reducer\n"
"from Direct.DirectEnergyConversion import setup_reducer\n"
"setup_reducer('%1')";
pyInput = pyInput.arg(QString::fromStdString(ws_name));
runPythonCode(pyInput);
Expand Down Expand Up @@ -396,7 +396,7 @@ QString MWDiag::createDiagnosticScript() const
QString bleed_pixels = m_designWidg.ignored_pixels->text();

QString diagCall =
"from DirectEnergyConversion import setup_reducer\n"
"from Direct.DirectEnergyConversion import setup_reducer\n"
"from mantid import config\n"
"reducer = setup_reducer(config['default.instrument'])\n"
"reducer.prop_man.log_to_mantid = True\n"
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/scripts/CMakeLists.txt
Expand Up @@ -4,7 +4,6 @@ set ( TEST_PY_FILES
test/SettingsTest.py
test/DirectReductionHelpersTest.py
test/DirectPropertyManagerTest.py
test/DgreduceTest.py
test/DirectEnergyConversionTest.py
test/ReductionWrapperTest.py
test/IndirectApplyCorrectionsTest.py
Expand Down
Expand Up @@ -192,3 +192,24 @@ def sum_files(accumulator, files, file_type):
Plus(LHSWorkspace=accumulator,RHSWorkspace=temp,OutputWorkspace=accumulator)
else:
pass

class switch(object):
""" Helper class providing nice switch statement"""
def __init__(self, value):
self.value = value
self.fall = False

def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration

def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False
@@ -1,43 +1,76 @@
"""
Conversion class defined for conversion to deltaE for
'direct' inelastic geometry instruments
The class defines various methods to allow users to convert their
files to DeltaE.
Usage:
>>red = DirectEnergyConversion('InstrumentName')
and then:
>>red.convert_to_energy_transfer(wb_run,sample_run,ei_guess,rebin)
or
>>red.convert_to_energy_transfer(wb_run,sample_run,ei_guess,rebin,**arguments)
or
>>red.convert_to_energy_transfer(wb_run,sample_run,ei_guess,rebin,mapfile,**arguments)
or
>>red.convert_to_energy_transfer(wb_run
Whitebeam run number or file name or workspace
sample_run sample run number or file name or workspace
ei_guess Ei guess
rebin Rebin parameters
mapfile Mapfile -- if absent/'default' the defaults from IDF are used
monovan_run If present will do the absolute units normalization. Number of additional parameters
specified in **kwargs is usually requested for this. If they are absent, program uses defaults,
but the defaults (e.g. sample_mass or sample_rmm ) are usually incorrect for a particular run.
arguments The dictionary containing additional keyword arguments.
The list of allowed additional arguments is defined in InstrName_Parameters.xml file, located in
MantidPlot->View->Preferences->Mantid->Directories->Parameter Definitions
with run numbers as input:
>>red.convert_to_energy_transfer(1000,10001,80,[-10,.1,70]) # will run on default instrument
>>red.convert_to_energy_transfer(1000,10001,80,[-10,.1,70],'mari_res', additional keywords as required)
>>red.convert_to_energy_transfer(1000,10001,80,'-10,.1,70','mari_res',fixei=True)
A detector calibration file must be specified if running the reduction with workspaces as input
namely:
>>w2=cred.onvert_to_energy_transfer('wb_wksp','run_wksp',ei,rebin_params,mapfile,det_cal_file=cal_file
,diag_remove_zero=False,norm_method='current')
from mantid.simpleapi import *
from mantid.kernel import funcreturns
from mantid import api
from mantid import geometry

import time as time
import glob,sys,os.path,math
import numpy as np

import CommonFunctions as common
import diagnostics
from PropertyManager import PropertyManager;


def setup_reducer(inst_name,reload_instrument=False):
"""
Given an instrument name or prefix this sets up a converter
object for the reduction
"""
try:
return DirectEnergyConversion(inst_name,reload_instrument)
except RuntimeError, exc:
raise RuntimeError('Unknown instrument "%s" or wrong IDF file for this instrument, cannot continue' % inst_name)


class DirectEnergyConversion(object):
"""
Performs a convert to energy assuming the provided instrument is an direct inelastic geometry instruments
The class defines various methods to allow users to convert their
files to Energy transfer
Usage:
>>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)
or
>>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()
Where:
Whitebeam run number or file name or workspace
sample_run sample run number or file name or workspace
ei_guess suggested value for incident energy of neutrons in direct inelastic instrument
energy_bins energy binning requested for resulting spe workspace.
mapfile Mapfile -- if absent/'default' the defaults from IDF are used
monovan_run If present will do the absolute units normalization. Number of additional parameters
specified in **kwargs is usually requested for this. If they are absent, program uses defaults,
but the defaults (e.g. sample_mass or sample_rmm ) are usually incorrect for a particular run.
arguments The dictionary containing additional keyword arguments.
The list of allowed additional arguments is defined in InstrName_Parameters.xml file, located in
MantidPlot->View->Preferences->Mantid->Directories->Parameter Definitions
Usage examples:
with run numbers as input:
>>red.convert_to_energy(1000,10001,80,[-10,.1,70]) # will run on default instrument
>>red.convert_to_energy(1000,10001,80,[-10,.1,70],'mari_res', additional keywords as required)
>>red.convert_to_energy(1000,10001,80,'-10,.1,70','mari_res',fixei=True)
A detector calibration file must be specified if running the reduction with workspaces as input
namely:
>>w2=cred.onvert_to_energy_transfer('wb_wksp','run_wksp',ei,rebin_params,mapfile,det_cal_file=cal_file
,diag_remove_zero=False,norm_method='current')
All available keywords are provided in InstName_Parameters.xml file
Expand Down Expand Up @@ -90,36 +123,6 @@
hardmaskPlus=Filename :load a hardmarkfile and apply together with diag mask
hardmaskOnly=Filename :load a hardmask and use as only mask
"""


from mantid.simpleapi import *
from mantid.kernel import funcreturns
from mantid import api
from mantid import geometry

import time as time
import glob,sys,os.path,math
import numpy as np

import CommonFunctions as common
import diagnostics
from DirectPropertyManager import DirectPropertyManager;

def setup_reducer(inst_name,reload_instrument=False):
"""
Given an instrument name or prefix this sets up a converter
object for the reduction
"""
try:
return DirectEnergyConversion(inst_name,reload_instrument)
except RuntimeError, exc:
raise RuntimeError('Unknown instrument "%s" or wrong IDF file for this instrument, cannot continue' % inst_name)


class DirectEnergyConversion(object):
"""
Performs a convert to energy assuming the provided instrument is an elastic instrument
"""

def diagnose(self, white,diag_sample=None,**kwargs):
Expand Down Expand Up @@ -231,7 +234,7 @@ def diagnose(self, white,diag_sample=None,**kwargs):
RangeLower=bkgd_range[0],RangeUpper=bkgd_range[1],
IncludePartialBins=True)
total_counts = Integration(result_ws, IncludePartialBins=True)
background_int = ConvertUnits(background_int, "Energy", AlignBins=0)
background_int = ConvertUnits(background_int, Target="Energy",EMode='Elastic', AlignBins=0)
prop_man.log("Diagnose: finished convertUnits ",'information')

background_int *= prop_man.scale_factor;
Expand Down Expand Up @@ -1143,7 +1146,7 @@ def save_results(self, workspace, save_file=None, formats = None):


for file_format in formats:
for case in switch(file_format):
for case in common.switch(file_format):
if case('nxspe'):
filename = save_file +'.nxspe';
SaveNXSPE(InputWorkspace=workspace,Filename= filename, KiOverKfScaling=prop_man.apply_kikf_correction,psi=prop_man.psi)
Expand Down Expand Up @@ -1299,10 +1302,10 @@ def prop_man(self):
@prop_man.setter
def prop_man(self,value):
""" Assign new instance of direct property manager to provide DirectEnergyConversion parameters """
if isinstance(value,DirectPropertyManager):
if isinstance(value,PropertyManager):
self._propMan = value;
else:
raise KeyError("Property manager can be initialized by an instance of DirectProperyManager only")
raise KeyError("Property manager can be initialized by an instance of ProperyManager only")
#---------------------------------------------------------------------------
# Behind the scenes stuff
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -1335,21 +1338,21 @@ def initialise(self, instr,reload_instrument=False):
# Instrument and default parameter setup
# formats available for saving. As the reducer has to have a method to process one of this, it is private property
if not hasattr(self,'_propMan') or self._propMan is None:
if isinstance(instr,DirectPropertyManager):
if isinstance(instr,PropertyManager):
self._propMan = instr;
else:
self._propMan = DirectPropertyManager(instr);
self._propMan = PropertyManager(instr);
else:
old_name = self._propMan.instrument.getName();
if isinstance(instr,geometry._geometry.Instrument):
new_name = self._propMan.instrument.getName();
elif isinstance(instr,DirectPropertyManager):
elif isinstance(instr,PropertyManager):
new_name = instr.instr_name;
else:
new_name = instr
#end if
if old_name != new_name or reload_instrument:
self._propMan = DirectPropertyManager(new_name);
self._propMan = PropertyManager(new_name);
#end if
#

Expand All @@ -1358,7 +1361,7 @@ def setup_instrument_properties(self, workspace = None,reload_instrument=False):
instrument = workspace.getInstrument();
name = instrument.getName();
if name != self.prop_man.instr_name:
self.prop_man = DirectPropertyManager(name,workspace);
self.prop_man = PropertyManager(name,workspace);


def check_abs_norm_defaults_changed(self,changed_param_list) :
Expand All @@ -1379,28 +1382,8 @@ def check_abs_norm_defaults_changed(self,changed_param_list) :





class switch(object):
""" Helper class providing nice switch statement"""
def __init__(self, value):
self.value = value
self.fall = False

def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration

def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False


def get_failed_spectra_list_from_masks(masking_wksp):
"""Compile a list of spectra numbers that are marked as
Expand Down
@@ -1,16 +1,9 @@
""" File contains classes defining the interface for Direct inelastic reduction with properties
necessary for reduction but not present in Instrument_Properties.xml file
from PropertiesDescriptors import *

Main example of such properties are run numbers, energy bins and incident energies.
"""

from mantid.simpleapi import *
from mantid import api
from mantid import geometry
from mantid import config
import DirectReductionHelpers as prop_helpers
import CommonFunctions as common
import os
class NonIDF_Properties(object):
""" Class defines the interface for main properties, used in reduction, and not described in
IDF ( Instrument_Properties.xml file)
#-----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -158,6 +151,7 @@ class DirectReductionProperties(object):
These properties are main set of properties, user have to set up
for reduction to work with defaults.

The example of such properties are run numbers, energy bins and incident energies.
"""

# logging levels available for user
Expand Down Expand Up @@ -220,6 +214,8 @@ def getDefaultParameterValue(self,par_name):
""" method to get default parameter value, specified in IDF """
return prop_helpers.get_default_parameter(self.instrument,par_name);
#-----------------------------------------------------------------------------
# Complex properties with personal descriptors
#-----------------------------------------------------------------------------
incident_energy = IncidentEnergy()
#
energy_bins = EnergyBins()
Expand Down Expand Up @@ -414,7 +410,7 @@ def _set_instrument_and_facility(self,Instrument,run_workspace=None):
def log(self, msg,level="notice"):
"""Send a log message to the location defined
"""
lev,logger = DirectReductionProperties.log_options[level]
lev,logger = NonIDF_Properties.log_options[level]
if self._log_to_mantid:
logger(msg)
else:
Expand Down

0 comments on commit c2bceaa

Please sign in to comment.