Skip to content

Commit

Permalink
Re #10647 All collected together
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Dec 12, 2014
1 parent c3727fb commit b12ab4a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 61 deletions.
51 changes: 27 additions & 24 deletions Code/Mantid/scripts/Inelastic/DirectPropertyManager.py
Expand Up @@ -73,14 +73,23 @@ def __set__(self,instance,value):
fileName, fileExtension = os.path.splitext(value)
if (not fileExtension):
value=value+self._file_ext;
else:
if self._field_name=='hard_mask_file':
if instance.use_hard_mask_only:
instance.run_diagnostics = False;


prop_helpers.gen_setter(instance.__dict__,self._field_name,value);
#end MapMaskFile

class HardMaskPlus(object):
""" Legacy HardMaskPlus class which sets up hard_mask_file to file and use_hard_mask_only to True"""
def __get__(self,instance,type=None):
is_masked = prop_helpers.gen_getter(instance.__dict__,'hard_mask_only');
return prop_helpers.gen_getter(instance.__dict__,'hard_mask_file');

def __set__(self,instance,value):
if value != None:
fileName, fileExtension = os.path.splitext(value)
if (not fileExtension):
value=value+self._file_ext;


class HardMaskOnly(object):
""" Sets diagnostics algorithm to use hard mask file provided and to disable all other diagnostics routines
Expand Down Expand Up @@ -573,27 +582,28 @@ def __getattr__(self,name):
# Overloaded setters/getters
#----------------------------------------------------------------------------------
#
van_rmm = VanadiumRMM();
van_rmm = VanadiumRMM()
#
det_cal_file = DetCalFile();
det_cal_file = DetCalFile()
#
map_file = MapMaskFile('map_file','.map',"Spectra to detector mapping file for the sample run");
map_file = MapMaskFile('map_file','.map',"Spectra to detector mapping file for the sample run")
#
monovan_mapfile = MapMaskFile('monovan_mapfile','.map',"Spectra to detector mapping file for the monovanadium integrals calculation");
monovan_mapfile = MapMaskFile('monovan_mapfile','.map',"Spectra to detector mapping file for the monovanadium integrals calculation")
#
hard_mask_file = MapMaskFile('hard_mask_file','.msk',"Hard mask file");
hard_mask_file = MapMaskFile('hard_mask_file','.msk',"Hard mask file")
#
monovan_integr_range = MonovanIntegrationRange();
monovan_integr_range = MonovanIntegrationRange()
#
spectra_to_monitors_list = SpectraToMonitorsList();
spectra_to_monitors_list = SpectraToMonitorsList()
#
save_format = SaveFormat();
save_format = SaveFormat()
#
use_hard_mask_only = HardMaskOnly();
use_hard_mask_only = HardMaskOnly()
hardmaskPlus = HardMaskPlus()
#
diag_spectra = DiagSpectra();
diag_spectra = DiagSpectra()
#
background_test_range = BackbgroundTestRange();
background_test_range = BackbgroundTestRange()

#----------------------------------------------------------------------------------------------------------------
def getChangedProperties(self):
Expand All @@ -612,14 +622,7 @@ def relocate_dets(self) :
return True
else:
return False

def get_sample_ws_name(self):
""" build and return sample workspace name """
if not self.sum_runs:
return common.create_resultname(self.sample_run,self.instr_name);
else:
return common.create_resultname(self.sample_run,self.instr_name,'-sum');


def set_input_parameters_ignore_nan(self,**kwargs):
""" Like similar method set_input_parameters this one is used to
set changed parameters from dictionary of parameters.
Expand Down
18 changes: 0 additions & 18 deletions Code/Mantid/scripts/Inelastic/DirectReductionHelpers.py
Expand Up @@ -199,8 +199,6 @@ def gen_getter(keyval_dict,key):
return a_val.__get__(keyval_dict);
else:
return a_val


#end
#end

Expand Down Expand Up @@ -280,19 +278,3 @@ def check_instrument_name(old_name,new_name):
config['default.instrument'] = full_name
return (new_name,full_name,facility);



#if not hasattr(self,'instrument') or self.instrument.getName() != instr_name :
# # Load an empty instrument if one isn't already there
# idf_dir = config.getString('instrumentDefinition.directory')
# try:
# idf_file=api.ExperimentInfo.getInstrumentFilename(new_name)
# tmp_ws_name = '__empty_' + new_name
# if not mtd.doesExist(tmp_ws_name):
# LoadEmptyInstrument(Filename=idf_file,OutputWorkspace=tmp_ws_name)
# self.instrument = mtd[tmp_ws_name].getInstrument()
# except:
# self.instrument = None
# self._instr_name = None
# raise RuntimeError('Cannot load instrument for prefix "%s"' % new_name)

16 changes: 15 additions & 1 deletion Code/Mantid/scripts/Inelastic/DirectReductionProperties.py
Expand Up @@ -86,7 +86,10 @@ def __set__(self,instance,values):
object.__setattr__(instance,'_energy_bins',value);
#end EnergyBins
class SaveFileName(object):
""" Property defines default file name to save result to"""
""" 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):
Expand All @@ -103,6 +106,8 @@ def __get__(self,instance,owner=None):
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:
Expand Down Expand Up @@ -199,6 +204,15 @@ def __init__(self,Instrument,run_workspace=None):
self._set_instrument_and_facility(Instrument,run_workspace)

#end
def get_sample_ws_name(self):
""" build and return sample workspace name
See similar property save_file_name TODO: (leave only one)
"""
if not self.sum_runs:
return common.create_resultname(self.sample_run,self.instr_name);
else:
return common.create_resultname(self.sample_run,self.instr_name,'-sum');

def getDefaultParameterValue(self,par_name):
""" method to get default parameter value, specified in IDF """
Expand Down
19 changes: 7 additions & 12 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Expand Up @@ -146,13 +146,15 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
# --------------------------------------------------------------------------------------------------------
# Deal with mandatory parameters for this and may be some top level procedures
# --------------------------------------------------------------------------------------------------------
if sample_run:
Reducer.prop_man.sample_run = sample_run
try:
n,r=funcreturns.lhs_info('both')
wksp_out=r[0]
except:
wksp_out = Reducer.prop_man.get_sample_ws_name();
#
res = Reducer.convert_to_energy_transfer(wb_run,sample_run,ei_guess,rebin,map_file,monovan_run,second_wb,**kwargs)
res = Reducer.convert_to_energy(wb_run,sample_run,ei_guess,rebin,map_file,monovan_run,second_wb,**kwargs)
#
results_name = res.name();
if results_name != wksp_out:
Expand Down Expand Up @@ -250,22 +252,15 @@ def abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,sam
kwargs['sample_mass'] = samp_mass
kwargs['sample_rmm'] = samp_rmm

# service property, which tells arb_units that here defaults have changed and no need to check they are changed
kwargs['_defaults_have_changed'] = True
if sample_run:
Reducer.prop_man.sample_run = sample_run
try:
n,r=funcreturns.lhs_info('both')
wksp_out=r[0]
results_name=r[0]

except:
if sample_run == 0:
#deal with the current run being parsed as 0 rather than 00000
sample_run='00000'
wksp_out=Reducer.instr_name+str(sample_run)+'.spe'
if kwargs.has_key('sum') and kwargs.get('sum')==True:
wksp_out=inst_name+str(sample_run[0])+'sum'+'.spe'
results_name = Reducer.prop_man.get_sample_ws_name();


results_name = wksp_out
wksp_out = arb_units(wb_for_run,sample_run,ei_guess,rebin,map_file,monovan_run,wb_for_monovanadium,**kwargs)


Expand Down
17 changes: 11 additions & 6 deletions Code/Mantid/scripts/test/DirectPropertyManagerTest.py
Expand Up @@ -88,10 +88,6 @@ def test_overloaded_setters_getters(self):
propman.map_file = 'a_map_file'
self.assertEqual(propman.map_file,'a_map_file.map');

self.assertTrue(propman.hard_mask_file is None);
propman.hard_mask_file = 'a_mask_file'
self.assertEqual(propman.hard_mask_file,'a_mask_file.msk');

self.assertFalse(propman.monovan_mapfile is None," Monovan map file by default is defined");
propman.monovan_mapfile = 'a_monovan_map_file'
self.assertEqual(propman.monovan_mapfile,'a_monovan_map_file.map');
Expand All @@ -100,12 +96,21 @@ def test_overloaded_setters_getters(self):


prop_changed =propman.getChangedProperties()
self.assertEqual(len(prop_changed),4)
self.assertEqual(len(prop_changed),3)
self.assertTrue('det_cal_file' in prop_changed)
self.assertTrue('hard_mask_file' in prop_changed)
self.assertTrue('map_file' in prop_changed)
self.assertTrue('monovan_mapfile' in prop_changed)

def test_hartmask_plus_or_only(self):
propman = self.prop_man

self.assertTrue(propman.hard_mask_file is None);
propman.hard_mask_file = 'a_mask_file'
self.assertEqual(propman.hard_mask_file,'a_mask_file.msk');

prop_changed =propman.getChangedProperties()
self.assertTrue('hard_mask_file' in prop_changed)


def test_set_spectra_to_mon(self):
propman = self.prop_man
Expand Down

0 comments on commit b12ab4a

Please sign in to comment.