Skip to content

Commit

Permalink
refs #6667 works correctly with necessary file as run number
Browse files Browse the repository at this point in the history
also tries to modify SNS reduction to understand new properties.
  • Loading branch information
abuts committed Jul 9, 2013
1 parent d02604f commit ce9456e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
37 changes: 34 additions & 3 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,

if self.__det_cal_file_ws == None :
self.log('_do_mono: Loading detector info from file ' +str(self.det_cal_file),'debug')
file = FileFinder.getFullPath(self.det_cal_file)
file = FileFinder.getFullPath(str(self.det_cal_file))
if len(file) == 0: # try to find run
file = common.find_file(self.det_cal_file)

LoadDetectorInfo(Workspace=result_name,DataFilename=file,RelocateDets= self.relocate_dets)
self.log('_do_mono: Loading detector info completed ','debug')
else:
Expand Down Expand Up @@ -1010,7 +1013,9 @@ def initialise(self, instr_name,reload_instrument=False):
'diag_van_out_lo', 'diag_van_out_hi', 'diag_van_lo', 'diag_van_hi', 'diag_van_sig', 'diag_variation',\
'diag_bleed_test','diag_bleed_pixels','diag_bleed_maxrate','diag_hard_mask_file','diag_use_hard_mask_only','diag_background_test_range']


# before starting long run, makes sence to verify if all files requested for the run are in fact availible. Here we specify the properties which describe files
self.__file_properties = ['det_cal_file','map_file','hard_mask_file','monovan_mapfile']

self.__normalization_methods=['none','monitor-1','current'] # 'monitor-2','uamph', peak -- disabled/unknown at the moment

# list of the parameters which should usually be changed by user and if not, user should be warn about it.
Expand Down Expand Up @@ -1302,7 +1307,33 @@ def make_ckpt_name(*argi) :
"""
return ''.join(str(arg) for arg in argi if arg is not None)


def check_necessary_files(self):
""" Method verifies if all files necessary for a run are availible.
usefull for long runs to check if all files necessary for it are present/accessible
"""
file_missing = False
for prop in self.__file_properties :
file = getattr(self,prop)
if not (file is None) and isinstance(file,str):
file_path = FileFinder.getFullPath(file)
if len(file_path) == 0:
# it still can be run number
try:
file_path = common.find_file(file)
except:
file_path=''

if len(file_path)==0:
self.log(" Can not find file ""{0}"" for property: {1} ".format(file,prop),'error')
file_missing=True

if file_missing:
raise RuntimeError(" Files needed for the run are missing ")




def log(self, msg,level="notice"):
"""Send a log message to the location defined
"""
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
val = getattr(Reducer,key);
Reducer.log(" Value of : {0:<25} is set to : {1:<20} ".format(key,val))


#do we run absolute units normalization and need to warn users if the parameters needed for that have not changed from defaults
if abs_units_defaults_check :
Reducer.check_abs_norm_defaults_changed(changed_Keys);
Expand Down Expand Up @@ -238,6 +237,8 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
Reducer.log('use Keyword det_cal_file with a valid detctor file or run number','error')
return

# check if reducer can find all non-run files necessary for the reduction before starting long run.
Reducer.check_necessary_files();

print 'Output will be normalised to', Reducer.normalise_method
if (numpy.size(sample_run)) > 1 and Reducer.sum_runs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,41 @@ def _self_check(self):
if self._instrument is None:
raise ValueError("Instrument was not loaded, cannot retrieve parameters.")

def get_parameter(self, parname):
def get_parameter(self, name):
default = -1
try:
self._self_check()
except ValueError:
return default
values = self._instrument.getNumberParameter(parname)

type_name = self._instrument.getParameterType(name)
if type_name == "double":
val = self._instrument.getNumberParameter(name)
elif type_name == "bool":
val = self._instrument.getBoolParameter(name)
elif type_name == "string":
val = self._instrument.getStringParameter(name)
if val[0] == "None" :
return None
elif type_name == "int" :
val = self._instrument.getIntParameter(name)
else :
return default
try:
return values[0]
return val[0]
except IndexError:
return default


def get_bool_param(self, parname):
default = False
try:
self._self_check()
except ValueError:
return default
values = self._instrument.getNumberParameter(parname)
try:
return bool(values[0])
except IndexError:
return default

param = self.get_parameter(parname)
if param < 0 :
return False
return bool(param)

21 changes: 18 additions & 3 deletions Code/Mantid/scripts/test/DirectEnergyConversionTest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
import inspect
import os, sys
lib_path = os.path.abspath('../Inelastic')
sys.path.append(lib_path)
import DirectEnergyConversion
#test_path = (os.path.realpath(__file__))
#lib_path = os.path.abspath(test_path+'/../../Inelastic')
#sys.path.append(lib_path)
from DirectEnergyConversion import DirectEnergyConversion


#-----------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -215,6 +217,19 @@ def test_do_white(self) :
name = tReducer.make_ckpt_name('do_white',monovan,data,'t1')
self.assertEqual('do_white1000t1',name)

def test_get_parameter(self):
tReducer = self.reducer
param = tReducer.get_default_parameter('map_file')
self.assertTrue(isinstance(param,str))

param = tReducer.get_default_parameter('ei-mon1-spec')
self.assertTrue(isinstance(param,int))

param = tReducer.get_default_parameter('background')
self.assertTrue(isinstance(param,bool))




#def test_diag_call(self):
# tReducer = self.reducer
Expand Down

0 comments on commit ce9456e

Please sign in to comment.