Skip to content

Commit

Permalink
refs #6667 Modified Save procedure in DirectEnergyConversion
Browse files Browse the repository at this point in the history
to use different save routines as lambda functions

plus some small debugging statements which will probably be reverted
  • Loading branch information
abuts committed Jun 24, 2013
1 parent ae375be commit ee8b3ad
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
14 changes: 12 additions & 2 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@
<value val="False"/>
</parameter>

<!-- **************************************** 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)
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-->
If None is there, no internal script saving occurs and one needs to use external save operations -->
<parameter name="save_format" type="string">
<value val="None"/>
<value val=".nxs"/>
</parameter>

<!-- If one wants to sum runs -->
Expand All @@ -320,6 +322,14 @@
<value val="True"/>
</parameter>

<!-- # Try to keep and maintain the list of the integrals/operations which can be reusded number of times -->
<parameter name="cash_reusable_parameters" type="bool">
<value val="True"/>
</parameter>
<!-- # Save intermediate workspaces/intergals for debugging purposes -->
<parameter name="do_checkpoint_savings" type="bool">
<value val="True"/>
</parameter>


<!-- List of the words which can be used as a command line arguments to define reducer keywords
Expand Down
64 changes: 49 additions & 15 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,25 @@ def diagnose(self, white, **kwargs):
DeleteWorkspace(Workspace=kwargs['second_white'])
# Return a mask workspace
diag_mask, det_ids = ExtractMask(InputWorkspace=whiteintegrals,OutputWorkspace=var_name)
if self.do_checkpoint_savings :
file_name = self.make_ckpt_name('white_integrals_masked',white)
SaveNexus(whiteintegrals,file_name)

DeleteWorkspace(Workspace=whiteintegrals)
self.spectra_masks = diag_mask
return diag_mask


def do_white(self, white_run, spectra_masks, map_file,mon_number=None):
"""
Normalise to a specified white-beam run
Create the workspace, which each spectra containing the correspondent white beam integral (single value)
These intergrals are used as estimate for detector efficiency in wide range of energies
(rather the detector electronic's efficientcy as the geuger counters are very different in efficiency)
and is used to remove the influence of this efficiency to the different detectors.
"""


whitews_name = common.create_resultname(white_run, suffix='-white')
if whitews_name in mtd:
DeleteWorkspace(Workspace=whitews_name)
Expand All @@ -216,6 +227,9 @@ def do_white(self, white_run, spectra_masks, map_file,mon_number=None):

# White beam scale factor
white_ws *= self.wb_scale_factor
if self.do_checkpoint_savings :
result_fileName=self.make_ckpt_name('do_white',white_run, spectra_masks, map_file,mon_number)
SaveNexus(white_ws,result_fileName +'.nxs')

return white_ws

Expand Down Expand Up @@ -562,6 +576,8 @@ def remap(self, result_ws, spec_masks, map_file):
"""
if not spec_masks is None:
MaskDetectors(Workspace=result_ws, MaskedWorkspace=spec_masks)
print " check workspace masks for ws: ",result_ws.name()
ar = raw_input("Enter something to continue: ")
if not map_file is None:
result_ws = GroupDetectors(InputWorkspace=result_ws,OutputWorkspace=result_ws,
MapFile= map_file, KeepUngroupedSpectra=0, Behaviour='Average')
Expand Down Expand Up @@ -699,30 +715,27 @@ def save_results(self, workspace, save_path, formats = None):
pass

if formats is None:
formats = self.__save_formats
formats = [self.save_format]
if type(formats) == str:
formats = [formats]
#Make sure we just have a file stem
ext = self.save_format
ext = formats

# if ext is none, no need to write anything
if ext == None :
return

if len(ext) == 0:
ext = '.spe'

# if ext is none, no need to write anything
if len(ext) == 1 and ext[0] == None :
return

save_path = os.path.splitext(save_path)[0]
for ext in formats:
filename = save_path + ext
if ext == '.spe':
SaveSPE(InputWorkspace=workspace,Filename= filename)
elif ext == '.nxs':
SaveNexus(InputWorkspace=workspace,Filename= filename)
elif ext == '.nxspe':
SaveNXSPE(InputWorkspace=workspace,Filename= filename, KiOverKfScaling=self.apply_kikf_correction,Psi=self.psi)
if ext in self.__save_formats :
filename = save_path + ext
self.__save_formats[ext](workspace,filename)
else:
self.log('Unknown file format "%s" encountered while saving results.')
self.log('Unknown file format "{0} requested while saving results.'.format(ext))


#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -799,7 +812,12 @@ def init_idf_params(self, reload_instrument=False):
specify some parameters which may be not in IDF Parameters file
"""
# fomats availible for saving. As the reducer has to have a method to process one of this, it is private property
self.__save_formats = ['.spe','.nxs','.nxspe']
self.__save_formats = {}
self.__save_formats['.spe'] = lambda workspace,filename : SaveSPE(InputWorkspace=workspace,Filename= filename)
self.__save_formats['.nxspe'] = lambda workspace,filename : SaveNXSPE(InputWorkspace=workspace,Filename= filename, KiOverKfScaling=self.apply_kikf_correction,Psi=self.psi)
self.__save_formats['.nxs'] = lambda workspace,filename : SaveNexus(InputWorkspace=workspace,Filename= filename)



## Detector diagnosis
# Diag parameters -- keys used by diag method to pick from default parameters. Diag cuts these keys removing diag_ word
Expand All @@ -812,6 +830,10 @@ def init_idf_params(self, reload_instrument=False):

# list of the parameters which should usually be changed by user and if not, user should be warn about it.
self.__abs_units_par_to_change=['sample_mass','sample_rmm']

# the list of the reduction parameters which can be used number of times
self.__reusable_parameters = {}
# mandatrory command line parameter
self.energy_bins = None

# should come from Mantid
Expand Down Expand Up @@ -1068,6 +1090,11 @@ def build_idf_parameters(self,list_param_names) :
# reset the list of composite names defined using synonims
self.composite_keys_set=new_comp_name_set

@staticmethod
def make_ckpt_name(*argi) :
""" Make the name of the checkpoint from the function arguments
"""
return ''.join(str(arg) for arg in argi if arg is not None)


def log(self, msg,level="notice"):
Expand Down Expand Up @@ -1294,6 +1321,13 @@ def test_default_warnings(self):

keys_changed=['somethins_else1','somethins_else2']
self.assertEqual(2,tReducer.check_abs_norm_defaults_changed(keys_changed))
def test_do_white(self) :
tReducer = self.reducer
monovan = 1000
data = None
name = tReducer.make_ckpt_name('do_white',monovan,data,'t1')
self.assertEqual('do_white1000t1',name)


#def test_diag_call(self):
# tReducer = self.reducer
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def apply_absolute_normalization(Reducer,deltaE_wkspace_sample,monovan_run,ei_gu
if Reducer.monovan_integr_range is None: # integration in the range relative to incident energy
Reducer.monovan_integr_range = [Reducer.monovan_lo_frac*ei_guess,Reducer.monovan_hi_frac*ei_guess]
Reducer.log('##### Evaluate the integral from the monovan run and calculate the correction factor ######')
print ' Using absolute units vanadion integration range : ', Reducer.monovan_integr_range
Reducer.log(' Using absolute units vanadion integration range : '+str(Reducer.monovan_integr_range))
#now on the mono_vanadium run swap the mapping file
map_file = Reducer.map_file;
Reducer.map_file = Reducer.monovan_mapfile;
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/scripts/Inelastic/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def diagnose(white_int, **kwargs):
LoadMask(Instrument=kwargs.get('instrument_name',''),InputFile=parser.hard_mask,
OutputWorkspace='hard_mask_ws')
MaskDetectors(Workspace=white_int, MaskedWorkspace='hard_mask_ws')
print 'check masks for workspace: ',white_int.name()
var = raw_input("Enter something to continue: ")
# Find out how many detectors we hard masked
_dummy_ws,masked_list = ExtractMask(InputWorkspace='hard_mask_ws')
DeleteWorkspace('_dummy_ws')
Expand Down

0 comments on commit ee8b3ad

Please sign in to comment.