Skip to content

Commit

Permalink
refs #6667 Something like working for MARI
Browse files Browse the repository at this point in the history
but further investigations pending if it is exactly right
  • Loading branch information
abuts committed Jul 5, 2013
1 parent 4359af7 commit a80b20b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
9 changes: 5 additions & 4 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!-- Extension of the data files obtained from DAE -->
<parameter name="data_file_ext" type="string">
<value val=".raw"/>
<value val=".RAW"/>
</parameter>
<!-- The name of the hard mask file to use together with diag masking 4to1_124mod.msk-->
<parameter name="hard_mask_file" type="string">
Expand Down Expand Up @@ -114,10 +114,10 @@

<!-- integration range for background tests (in TOF) - composite property -->
<parameter name="bkgd-range-min">
<value val="12000"/>
<value val="15000"/>
</parameter>
<parameter name="bkgd-range-max">
<value val="18000"/>
<value val="19000"/>
</parameter>
<parameter name="background_range" type="string">
<value val="bkgd-range-min:bkgd-range-max"/>
Expand Down Expand Up @@ -298,7 +298,8 @@

<!-- **************************************** Workflow control **************************** -->

<!-- This parameter controls the format of output data writteb by reducer. Three values are currently supported, namely spe, nxspe, and nexus (mantid workspace)
<!-- This parameter controls the format of output data written by reducer.
Three values are currently supported, namely .spe, .nxspe, and nexus (mantid workspace) (.nxs)
Three possible values for this are defined inin DirectEnergyConversion init routine as recognized by save method
If None is there, no internal script saving occurs and one needs to use external save operations -->
<parameter name="save_format" type="string">
Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/instrument/MARI_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
<parameter name="det_cal_file" type="string">
<value val="None"/>
</parameter>
<!-- mari.cal -->
<!-- The file which defines detectors to spectra mapping; File extension has to be specified here but filepath not
if None - one2one map is used -->
<parameter name="map_file" type="string">
<value val="None"/>
<value val="mari_res"/>
</parameter>

<!-- Extension of the data files obtained from DAE -->
Expand All @@ -31,7 +32,7 @@
<!-- The map file used when calculating absolute units conversion integrals
This map usually groups together large areas of detectors to obtain proper vanadium statistics -->
<parameter name="monovan_mapfile" type="string">
<value val="None"/>
<value val="mari_res"/>
</parameter>


Expand Down Expand Up @@ -229,7 +230,7 @@
*** ??? should be negative?
-->
<parameter name="monovan_lo_frac">
<value val="0.8"/>
<value val="-0.8"/>
</parameter>

<!-- This property is the part of the composite definition for abs_units_van_range:
Expand All @@ -242,7 +243,7 @@
<!-- This property is the part of the composite definition for abs_units_van_range
It specifies the relative to incident energy higher integration limit for monochromatic vanadium in the mono-vanadium integration -->
<parameter name="monovan_hi_frac">
<value val="1.2"/>
<value val="0.8"/>
</parameter>
<!-- This property is the part of the composite definition for abs_units_van_range
It specifies the the higher limit of energy range in the monochromatic-vanadium integration
Expand Down
19 changes: 15 additions & 4 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def diagnose(self, white, **kwargs):
self._keep_wb_workspace = False
if isinstance(white,str) and white in mtd:
self._keep_wb_workspace = True
if isinstance(white,api.Workspace) : # it is workspace itself
self._keep_wb_workspace = True

# If we have a hard_mask, check the instrument name is defined
if 'hard_mask_file' in kwargs:
Expand Down Expand Up @@ -397,14 +399,17 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
self.log('_do_mono: Raw file detector header is superceeded')
if self.relocate_dets:
self.log('_do_mono: Moving detectors to positions specified in cal file ')
if str(self.det_cal_file) in mtd: # it is already workspace
self.__det_cal_file_ws = self.det_cal_file

if self.__det_cal_file_ws == None :
self.log('_do_mono: Loading detector info from file ' + self.det_cal_file)
self.log('_do_mono: Loading detector info from file ' + self.det_cal_file,'debug')
LoadDetectorInfo(Workspace=result_name,DataFilename=self.det_cal_file,RelocateDets= self.relocate_dets)
self.log('_do_mono: Loading detector info completed ')
else:
self.log('_do_mono: Copying detectors positions from det_cal_file workspace: '+self.det_cal_file_ws.name())
self.log('_do_mono: Copying detectors positions from det_cal_file workspace: '+self.__det_cal_file_ws.name())
CopyInstrumentParameters(InputWorkspace=self.__det_cal_file_ws,OutputWorkspace=result_name)
self.log('_do_mono: Copying detectors positions complete')
self.log('_do_mono: Copying detectors positions complete','debug')

if self.background == True:
# Remove the count rate seen in the regions of the histograms defined as the background regions, if the user defined such region
Expand Down Expand Up @@ -775,7 +780,6 @@ def __init__(self, instr_name=None):
self._idf_values_read = False
self._keep_wb_workspace=False # when input data for reducer is wb workspace rather then run number, we want to keep this workspace. But usually not

self.instr_name = instr_name
if not (instr_name is None or len(instr_name)==0) : # first time run or empty run
self.initialise(instr_name)

Expand Down Expand Up @@ -1408,6 +1412,7 @@ def test_set_non_default_simple_value(self):
kw["vanadium-mass"]=200
kw["diag_van_median_sigma"]=1
kw["det_cal_file"]=None
kw["save_format"]=''
prop_changed=tReducer.set_input_parameters(**kw)

self.assertTrue("van_mass" in prop_changed,"vanadium-mass should correspond to van_mass")
Expand All @@ -1417,6 +1422,8 @@ def test_set_non_default_simple_value(self):
self.assertEqual(tReducer.det_cal_file,None);
self.assertAlmostEqual(tReducer.van_sig,1.,7)



def test_set_non_default_comples_value(self):
tReducer = self.reducer
# should do nothing as already initialized above, but if not will initiate the instrument
Expand Down Expand Up @@ -1497,7 +1504,11 @@ def test_comlex_set(self):
tReducer.save_format = '.spe'
self.assertEqual('.spe',tReducer.save_format)

def test_set_format(self):
tReducer = self.reducer

tReducer.save_format = '';
self.assertTrue(tReducer.save_format is None)

#self.assertRaises(KeyError,tReducer.energy_bins=20,None)
def test_default_warnings(self):
Expand Down
46 changes: 39 additions & 7 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def setup(instname=None,reload=False):
instname = config['default.instrument']


if Reducer != None :
if Reducer.instr_name.upper()[0:2] == instname.upper()[0:2] :
if not (Reducer is None) :
if Reducer.instr_name.upper()[0:3] == instname.upper()[0:3] :
if not reload :
return # has been already defined

Expand Down Expand Up @@ -191,8 +191,8 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No

# set rebinning range
Reducer.energy_bins = rebin
if Reducer.energy_bins[2] >= ei_guess:
Reducer.log('Error: rebin max rebin range {0:f} exceeds incident energy {1:f}'.format(energy_bins[2],ei_guess),'Error')
if Reducer.energy_bins[2] > ei_guess:
Reducer.log('Error: rebin max rebin range {0:f} exceeds incident energy {1:f}'.format(Reducer.energy_bins[2],ei_guess),'Error')
return

# Process old legacy parameters which are easy to re-define in dgreduce rather then transfer through Mantid
Expand Down Expand Up @@ -225,7 +225,10 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
mask_run=sample_run

if Reducer.det_cal_file != None :
Reducer.log('Setting detector calibration file to '+Reducer.det_cal_file)
if isinstance(Reducer.det_cal_file,str) and not Reducer.det_cal_file in mtd : # it is a file
Reducer.log('Setting detector calibration file to '+Reducer.det_cal_file)
else:
Reducer.log('Setting detector calibration to {0}, which is probably a workspace '.format(str(Reducer.det_cal_file)))
else:
Reducer.log('Setting detector calibration to detector block info from '+str(sample_run))

Expand Down Expand Up @@ -497,9 +500,12 @@ def process_legacy_parameters(**kwargs) :
if key == 'hardmaskOnly': # legacy key defines other mask file here
params["hard_mask_file"] = value;
params["use_hard_mask_only"] = True;
elif key == 'normalise_method' or key == 'norm_method':
params[key]=value.lower();
else:
params[key]=value;


return params


Expand Down Expand Up @@ -590,7 +596,7 @@ def get_abs_normalization_factor(Reducer,deltaE_wkspaceName,ei_monovan) :
#---------------- Loop finished

if( weight1_sum==0.0 or weight2_sum == 0.0 or weight3_sum == 0.0 or weight4_sum == 0.0) :
print "WB integral has been calculated incorrectrly, look at van_int workspace and input workspace: ",deltaE_wkspaceName
print "WB integral has been calculated incorrectrly, look at van_int workspace in the input workspace: ",deltaE_wkspaceName
raise IOError(" divided by 0 weight")

integral_monovanLibISIS=signal1_sum / weight1_sum
Expand Down Expand Up @@ -699,11 +705,37 @@ def test_process_legacy_parameters(self):
kw=dict();
kw["hardmaskOnly"]="someFileName"
kw["someKeyword"] ="aaaa"
kw["normalise_method"] ="Monitor-1"
params = process_legacy_parameters(**kw);
self.assertEqual(len(params),3)
self.assertEqual(len(params),4)
self.assertTrue("someKeyword" in params);
self.assertTrue("hard_mask_file" in params);
self.assertTrue("use_hard_mask_only" in params)
self.assertEqual(params['normalise_method'],'monitor-1')

def test_setup(self):

setup('mari')
self.assertTrue(not (Reducer is None))

self.assertEqual(Reducer.instr_name,'MAR')

Reducer.save_format = ''
self.assertTrue(Reducer.save_format is None)

Reducer.save_format = 'none'
self.assertTrue(Reducer.save_format is None)

Reducer.save_format = []
self.assertTrue(Reducer.save_format is None)

def test_setup_empty(self):
# clear up singleton
global Reducer
Reducer = None


setup(None)



Expand Down

0 comments on commit a80b20b

Please sign in to comment.