Skip to content

Commit

Permalink
Re #10841 Conflicts with develp
Browse files Browse the repository at this point in the history
Merge branch 'bugfix/10841_BinningCanBeNone' into develop

Conflicts:
	Code/Mantid/scripts/Inelastic/Direct/NonIDF_Properties.py
  • Loading branch information
abuts committed Dec 22, 2014
2 parents 0bc50f8 + d06d899 commit ff44598
Showing 1 changed file with 189 additions and 15 deletions.
204 changes: 189 additions & 15 deletions Code/Mantid/scripts/Inelastic/Direct/NonIDF_Properties.py
@@ -1,14 +1,163 @@
from PropertiesDescriptors import *


class NonIDF_Properties(object):
""" Class defines the interface for main properties, used in reduction, and not described in
IDF ( Instrument_Properties.xml file)
""" File contains classes defining the interface for Direct inelastic reduction with properties
necessary for reduction but not present in Instrument_Properties.xml file
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


#-----------------------------------------------------------------------------------------
# Descriptors, providing overloads for some complex properties in DirectReductionProperties
#-----------------------------------------------------------------------------------------
class IncidentEnergy(object):
""" descriptor for incident energy or range of incident energies to be processed """
def __init__(self):
pass
def __get__(self,instance,owner=None):
""" return incident energy or list of incident energies """
return instance._incident_energy;
def __set__(self,instance,value):
""" Set up incident energy or range of energies in various formats """
if value != None:
if isinstance(value,str):
en_list = str.split(value,',');
if len(en_list)>1:
rez = [];
for en_str in en_list:
val = float(en_str);
rez.append(val)
instance._incident_energy=rez;
else:
instance._incident_energy=float(value);
else:
if isinstance(value,list):
rez = [];
for val in value:
en_val = float(val);
if en_val<=0:
raise KeyError("Incident energy has to be positive, but is: {0} ".format(en_val));
else:
rez.append(en_val);

object.__setattr__(instance,'_incident_energy',rez);
else:
object.__setattr__(instance,'_incident_energy',float(value));
else:
raise KeyError("Incident energy have to be positive number of list of positive numbers. Got None")

#
inc_en=instance._incident_energy
if isinstance(inc_en,list):
for en in inc_en:
if en<= 0:
raise KeyError("Incident energy have to be positive number of list of positive numbers."+
" For input argument {0} got negative value {1}".format(value,en))
else:
if inc_en<= 0:
raise KeyError("Incident energy have to be positive number of list of positive numbers."+
" For value {0} got negative {1}".format(value,inc_en))
# end IncidentEnergy
class EnergyBins(object):
""" Property provides various energy bin possibilities """
def __get__(self,instance,owner=None):
""" binning range for the result of convertToenergy procedure or list of such ranges """
return instance._energy_bins

def __set__(self,instance,values):
if values != None:
if isinstance(values,str):
lst = str.split(values,',');
nBlocks = len(lst);
for i in xrange(0,nBlocks,3):
value = [float(lst[i]),float(lst[i+1]),float(lst[i+2])]
else:
value = values;
nBlocks = len(value);
if nBlocks%3 != 0:
raise KeyError("Energy_bin value has to be either list of n-blocks of 3 number each or string representation of this list with numbers separated by commas")
else:
value = None
#TODO: implement single value settings according to rebin
object.__setattr__(instance,'_energy_bins',value);
#end EnergyBins
class SaveFileName(object):
""" Property defines default file name to save result to
See similar property get_sample_ws_name TODO: (leave only one)
"""
def __init__(self,Name=None):
self._file_name = Name
def __get__(self,instance,owner=None):
if self._file_name:
return self._file_name
else:
if instance.instr_name:
name = instance.short_inst_name
else:
name = '_EMPTY'
try:
sr = instance.sample_run
except:
sr = 0
try:
name +='{0:0<5}Ei{1:<4.2f}meV'.format(sr,instance.incident_energy)
if instance.sum_runs:
name +='sum'
if instance.monovan_run:
name +='_Abs'
except:
name = None
return name

def __set__(self,instance,value):
self._file_name = value
#end SaveFileName


#
class InstrumentDependentProp(object):
def __init__(self,prop_name):
self._prop_name = prop_name;
def __get__(self,instance,owner=None):
if instance._pInstrument is None:
raise KeyError("Attempt to use uninitialized property manager");
else:
return getattr(instance,self._prop_name);
def __set__(self,instance,values):
raise AttributeError("Property {0} can not be assigned".format(self._prop_name))
#end InstrumentDependentProp

def check_ei_bin_consistent(ei,binning_range):
""" function verifies if the energy binning is consistent with incident energies """
if isinstance(ei,list):
for en in ei:
range = binning_range[en]
if range[2]>en:
return (False,'Max rebin range {0:f} exceeds incident energy {1:f}'.format(range[2],en))
else:
if binning_range[2]>ei:
return (False,'Max rebin range {0:f} exceeds incident energy {1:f}'.format(binning_range[2],ei))

return (True,'')

#-----------------------------------------------------------------------------------------
# END Descriptors for DirectReductionProperties
#-----------------------------------------------------------------------------------------

class DirectReductionProperties(object):
""" Class contains main properties, used in reduction, and not described in
IDF
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 All @@ -31,6 +180,11 @@ def __init__(self,Instrument,run_workspace=None):

object.__setattr__(self,'_monovan_run',None)
object.__setattr__(self,'_wb_for_monovan_run',None)
object.__setattr__(self,'_mask_run',None)


object.__setattr__(self,'_incident_energy',None)
object.__setattr__(self,'_energy_bins',None)

# Helper properties, defining logging options
object.__setattr__(self,'_log_level','notice')
Expand All @@ -45,6 +199,7 @@ def __init__(self,Instrument,run_workspace=None):


object.__setattr__(self,'_second_white',None)
object.__setattr__(self,'_mono_correction_factor',None)

object.__setattr__(self,'_save_file_name',None)

Expand All @@ -65,20 +220,15 @@ 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()
#
save_file_name = SaveFileName()
save_file_name = SaveFileName()
#
instr_name = InstrumentDependentProp('_instr_name')
short_inst_name = InstrumentDependentProp('_short_instr_name')
facility = InstrumentDependentProp('_facility')
#
van_rmm = VanadiumRMM()

#-----------------------------------------------------------------------------------
@property
def instrument(self):
Expand Down Expand Up @@ -109,6 +259,17 @@ def print_diag_results(self,value):
pass
#-----------------------------------------------------------------------------------
@property
def mono_correction_factor(self):
""" pre-calculated absolute units correction factor"""
if self._mono_correction_factor:
return self._mono_correction_factor;
else:
return None;
@mono_correction_factor.setter
def mono_correction_factor(self,value):
object.__setattr__(self,'_mono_correction_factor',value)
#-----------------------------------------------------------------------------------
@property
#-----------------------------------------------------------------------------------
def sample_run(self):
""" run number to process or list of the run numbers """
Expand Down Expand Up @@ -160,7 +321,20 @@ def wb_for_monovan_run(self,value):
object.__setattr__(self,'_wb_for_monovan_run',value)

#-----------------------------------------------------------------------------------

@property
def mask_run(self):
""" run used to get masks to remove unreliable spectra
Usually it is sample run but separate run may be used
"""
if self._mask_run:
return self._mask_run
else:
return self._sample_run
@mask_run.setter
def mask_run(self,value):
object.__setattr__(self,'_mask_run',value)

# -----------------------------------------------------------------------------
@property
def log_to_mantid(self):
Expand Down Expand Up @@ -240,7 +414,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 = NonIDF_Properties.log_options[level]
lev,logger = DirectReductionProperties.log_options[level]
if self._log_to_mantid:
logger(msg)
else:
Expand Down

0 comments on commit ff44598

Please sign in to comment.