Skip to content

Commit

Permalink
refs #6667 more changes to parameters and some unit tests attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jun 12, 2013
1 parent 4f6b1bd commit 22d5bcf
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 51 deletions.
57 changes: 39 additions & 18 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<parameter-file instrument = "MAPS" date = "2010-05-05T00:00:00">
<parameter-file instrument = "MAPS" date = "2013-06-12T00:00:00">

<component-link name = "MAPS">

Expand All @@ -20,18 +20,50 @@
<value val="None"/>
</parameter>

<!-- The network name of the machine responsible for controlling DAE -->
<parameter name="inst_dae_name" type="string">
<value val="ndxmerlin"/>
</parameter>
<!-- Extension of the data files obtained from DAE -->
<parameter name="data_file_ext" type="string">
<value val=".RAW"/>
</parameter>
<!-- The name of the hard mas file to use -->
<parameter name="hard_mask_file" type="string">
<value val="None"/>
</parameter>
<!-- The if true, use only hard mask file specified above and do not run diagnostics procedures -->
<parameter name="use_hard_mask_only" type="bool">
<value val="False"/>
</parameter>



<!-- RunNumber to use for diag instead of the input run number if none - use input run -->
<parameter name="mask_run" type="string">
<value val="None"/>
</parameter>

<!-- Energy conversion mode direct/indirect/elastic (the one reducer understands) -->
<!-- Energy conversion mode direct/indirect/elastic (the one the reducer understands) -->
<parameter name="deltaE-mode" type="string">
<value val="direct"/>
</parameter>

<!-- Monitor used to estimate total current on the sample -->
<parameter name="norm-mon1-spec">
<value val="41473"/>
</parameter>
<parameter name="norm-mon1-min">
<value val="1000"/>
</parameter>
<parameter name="norm-mon1-max">
<value val="2000"/>
</parameter>
<parameter name="mon_norm_range" type="string">
<value val="norm-mon1-min:norm-mon1-max"/>
</parameter>


<!-- First spectra number (monitor number) to use when measuring incident energy
Should be spectra with well defined energy peak -->
<parameter name="ei-mon1-spec" type="int">
Expand Down Expand Up @@ -89,20 +121,6 @@
</parameter>


<parameter name="norm-mon1-spec">
<value val="41473"/>
</parameter>


<parameter name="norm-mon1-min">
<value val="1000"/>
</parameter>
<parameter name="norm-mon1-max">
<value val="2000"/>
</parameter>
<parameter name="mon_norm_range" type="string">
<value val="norm-mon1-min:norm-mon1-max"/>
</parameter>


<parameter name="monovan-integr-min">
Expand All @@ -121,7 +139,7 @@
<value val="30.1"/>
</parameter>

<!-- Diagnostic defaults -->
<!-- --------------------------- DIAGNOSTICS DEFAILTS ---------------------------------------- -->

<!-- Perform diag by bank. These are the spectrum numbers -->
<parameter name="diag_spectra" type="string">
Expand Down Expand Up @@ -193,6 +211,7 @@
<value val="1.1"/>
</parameter>

<!-- ------------------ DIAGNOSTICS DEFAILTS END --------------- -->
<!-- -->

<!-- Absolute units conversion average -->
Expand Down Expand Up @@ -283,7 +302,9 @@
wb_integr_range=detector_van_range;
van_mass=vanadium-mass;
background_range=bkgd_range;
monovan_integr_range=abs_units_van_range"
monovan_integr_range=abs_units_van_range;
hard_mask_file=hardmaskPlus,
use_hard_mask_only=hardmaskOnly"
/>
</parameter>

Expand Down
79 changes: 55 additions & 24 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
from mantid.kernel import funcreturns
from mantid import api
import glob
import sys
import os.path
import math
import unittest

def setup_reducer(inst_name):
"""
Expand Down Expand Up @@ -690,15 +692,18 @@ def load_data(self, runs):
# Behind the scenes stuff
#---------------------------------------------------------------------------

def __init__(self, instr_name):
def __init__(self, instr_name=None):
"""
Constructor
"""
self._to_stdout = True
self._log_to_mantid = False
self._idf_values_read = False
if instr_name is None or len(instr_name)==0 :
self.instr_name=None
else:
# Instrument and default parameter setup
self.initialise(instr_name)
self.initialise(instr_name)

def initialise(self, instr_name,reload_instrument=False):
"""
Expand Down Expand Up @@ -776,18 +781,17 @@ def init_idf_params(self, reload_instrument=False):
self.sample_mass = 1.0
self.sample_rmm = 1.0

# All this stuff should go to IDF file
# Detector Efficiency Correction
#self.apply_detector_eff = True
self.apply_detector_eff = True

# Ki/Kf factor correction
#self.apply_kikf_correction = True
self.apply_kikf_correction = True

# Detector calibration file
#self.det_cal_file = None
# the workspace which contains already loaded detector calibration file and used to save time on multiple det_cal_file loadings
# the workspace which contains already loaded detector calibration file and used to save time on multiple det_cal_file loadings -- not yet implemented
#self.det_cal_file_ws = None
# Option to move detector positions based on the information
#self.relocate_dets = False
self.relocate_dets = False

#The rmm of Vanadium is a constant, should not be instrument parameter. Atom not exposed to python :(
self.van_rmm = 50.9415#self.get_default_parameter("vanadium-rmm")
Expand All @@ -807,7 +811,7 @@ def init_idf_params(self, reload_instrument=False):
raise RuntimeError("Can not obtain instrument parameters describing inelastic conversion ")

# build the dictionary of necessary allowed substitution names and substitute parameters with their values
self.build_subst_dictionary()
self.synonims = build_subst_dictionary(self.synonims)

# build the dictionary which allows to process coupled property, namely the property, expressed through other properties values
self.build_coupled_keys_dict(par_names)
Expand Down Expand Up @@ -840,29 +844,25 @@ def get_default_parameter(self, name):

return val[0]


def build_subst_dictionary(self) :
"""Method to process the field "synonims" in the parameters string
@staticmethod
def build_subst_dictionary(synonims_list=None) :
"""Method to process the field "synonims_list" in the parameters string
it takes string of synonyms in the form key1=subs1=subst2=subts3;key2=subst4 and returns the dictionary
in the form dict[subs1]=key1 ; dict[subst2] = key1 ... dict[subst4]=key2
e.g. if one wants to use the IDF key word my_detector instead of e.g. norm-mon1-spec, he has to type
norm-mon1-spec=my_detector in the synonims field of the IDF parameters file.
"""
if not hasattr(self,'synonims') : # nothing to do
self.synonims = dict();
return
if self.synonims == None : # nothing to do
self.synonims = dict();
return
if type(self.synonims) == dict : # all done
return
if type(self.synonims) != str :
raise AttributeError("The synonims fielf of Reducer object has to be special format string or the dictionary")
if not synonims_list : # nothing to do
return dict();
if type(synonims_list) == dict : # all done
return synonims_list
if type(synonims_list) != str :
raise AttributeError("The synonims field of Reducer object has to be special format string or the dictionary")
# we are in the right place and going to transform string into dictionary

subst_lines = self.synonims.split(";")
subst_lines = synonims_list.split(";")
rez = dict()
for lin in subst_lines :
lin=lin.strip()
Expand All @@ -872,7 +872,7 @@ def build_subst_dictionary(self) :
for i in xrange(1,len(keys)) :
rez[keys[i]]=keys[0].strip()

self.synonims = rez
return rez;

def build_coupled_keys_dict(self,par_names) :
"""Method to build the dictionary of the keys which are expressed through other keys values
Expand Down Expand Up @@ -1008,5 +1008,36 @@ def help(self,keyword=None) :
else:
raise ValueError('Instrument parameter file does not contain a definition for "%s". Cannot continue' % keyword)

#-----------------------------------------------------------------
class TestReducer(unittest.TestCase):
def setUp(self):
self.reducer = DirectEnergyConversion();

def test_build_subst_dictionary(self):
self.assertEqual(dict(), DirectEnergyConversion.build_subst_dictionary(""))
self.assertEqual(dict(),DirectEnergyConversion.build_subst_dictionary())

#self.assertRaises(AttributeError,DirectEnergyConversion.build_subst_dictionary(10))
#self.assertRaises(AttributeError,DirectEnergyConversion.build_subst_dictionary("A="))
#self.assertRaises(AttributeError,DirectEnergyConversion.build_subst_dictionary("B=C;A="))

rez=dict();
rez['A']='B';
self.assertEqual(rez, DirectEnergyConversion.build_subst_dictionary(rez))

myDict = DirectEnergyConversion.build_subst_dictionary("A=B")
self.assertEqual(myDict['B'],'A')

myDict = DirectEnergyConversion.build_subst_dictionary("A=B;C=DD")
self.assertEqual(myDict['B'],'A')
self.assertEqual(myDict['DD'],'C')
myDict = DirectEnergyConversion.build_subst_dictionary("A=B=C=DD")
self.assertEqual(myDict['B'],'A')
self.assertEqual(myDict['DD'],'A')
self.assertEqual(myDict['C'],'A')



#-----------------------------------------------------------------
if __name__=="__main__":
unittest.main()
13 changes: 4 additions & 9 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file=None,**kwargs):
dictionay = Reducer.combine_keys(dictionary)

for key in dictionary :
default_value = str(getattr(Reducer,key))
print " Replacing default value of: "+key+" from :"+default_vlaue+" to : ",dictionary.get(key)
setattr(Reducer,key,dictionary.get(key));
print " Setting "+key+" to : ",dictionary.get(key)


# map file in parameters overrides defaults
if map_file != None :
Expand Down Expand Up @@ -198,14 +200,7 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file=None,**kwargs):
RenameWorkspace(InputWorkspace=accum,OutputWorkspace=inst_name+str(sample_run[0])+'.raw')
sample_run=sample_run[0]

if kwargs.has_key('hardmaskPlus'):
HardMaskFile = kwargs.get('hardmaskPlus')
print 'Use hardmask from ', HardMaskFile
#hardMaskSpec=common.load_mask(HardMaskFile)
#MaskDetectors(Workspace='masking',SpectraList=hardMaskSpec)
else:
HardMaskFile=None


if kwargs.has_key('hardmaskOnly'):
totalmask = kwargs.get('hardmaskOnly')
print 'Using hardmask from ', totalmask
Expand Down

0 comments on commit 22d5bcf

Please sign in to comment.