Skip to content

Commit

Permalink
Re #10803 Comments and removed outdated pieces of code
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jan 8, 2015
1 parent f69e8f2 commit 92617bc
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 214 deletions.
1 change: 0 additions & 1 deletion Code/Mantid/scripts/CMakeLists.txt
Expand Up @@ -4,7 +4,6 @@ set ( TEST_PY_FILES
test/SettingsTest.py
test/DirectReductionHelpersTest.py
test/DirectPropertyManagerTest.py
test/DgreduceTest.py
test/DirectEnergyConversionTest.py
test/ReductionWrapperTest.py
test/IndirectApplyCorrectionsTest.py
Expand Down
21 changes: 21 additions & 0 deletions Code/Mantid/scripts/Inelastic/Direct/CommonFunctions.py
Expand Up @@ -192,3 +192,24 @@ def sum_files(accumulator, files, file_type):
Plus(LHSWorkspace=accumulator,RHSWorkspace=temp,OutputWorkspace=accumulator)
else:
pass

class switch(object):
""" Helper class providing nice switch statement"""
def __init__(self, value):
self.value = value
self.fall = False

def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration

def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False
25 changes: 3 additions & 22 deletions Code/Mantid/scripts/Inelastic/Direct/DirectEnergyConversion.py
Expand Up @@ -11,6 +11,7 @@
import diagnostics
from PropertyManager import PropertyManager;


def setup_reducer(inst_name,reload_instrument=False):
"""
Given an instrument name or prefix this sets up a converter
Expand Down Expand Up @@ -1145,7 +1146,7 @@ def save_results(self, workspace, save_file=None, formats = None):


for file_format in formats:
for case in switch(file_format):
for case in common.switch(file_format):
if case('nxspe'):
filename = save_file +'.nxspe';
SaveNXSPE(InputWorkspace=workspace,Filename= filename, KiOverKfScaling=prop_man.apply_kikf_correction,psi=prop_man.psi)
Expand Down Expand Up @@ -1381,28 +1382,8 @@ def check_abs_norm_defaults_changed(self,changed_param_list) :





class switch(object):
""" Helper class providing nice switch statement"""
def __init__(self, value):
self.value = value
self.fall = False

def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration

def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False


def get_failed_spectra_list_from_masks(masking_wksp):
"""Compile a list of spectra numbers that are marked as
Expand Down
14 changes: 7 additions & 7 deletions Code/Mantid/scripts/Inelastic/Direct/PropertiesDescriptors.py
@@ -1,4 +1,4 @@
""" File contains collection of Descriptors used to define complex reduction properties """
""" File contains collection of Descriptors used to define complex properties in NonIDF_Properties and PropertyManager classes """

from mantid.simpleapi import *
from mantid import api
Expand Down Expand Up @@ -117,9 +117,11 @@ def __set__(self,instance,value):
self._file_name = value
#end SaveFileName


#
class InstrumentDependentProp(object):
""" Generic property describing some aspects of instrument (e.g. name, short name etc),
which are undefined if no instrument is defined
"""
def __init__(self,prop_name):
self._prop_name = prop_name;
def __get__(self,instance,owner=None):
Expand Down Expand Up @@ -190,8 +192,8 @@ def __set__(self,instance,val):
# 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))

#end DetCalFile

#
class MapMaskFile(object):
""" common method to wrap around an auxiliary file name """
Expand Down Expand Up @@ -227,7 +229,7 @@ def __set__(self,instance,value):
prop_helpers.gen_setter(instance.__dict__,'hard_mask_file',value);
# This property enables diagnostics
instance.run_diagnostics = True;

#end HardMaskPlus


class HardMaskOnly(object):
Expand Down Expand Up @@ -372,12 +374,10 @@ def convert_to_list(self,spectra_list):
else:
result =[int(spectra_list)];
return result

#end SpectraToMonitorsList

# format(s) to save data
class SaveFormat(object):
# formats available for saving
# formats available for saving the data
save_formats = ['spe','nxspe','nxs'];

def __get__(self,instance,type=None):
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/scripts/Inelastic/Direct/PropertyManager.py
Expand Up @@ -110,7 +110,7 @@ def _convert_params_to_properties(self,param_list,detine_subst_dict=True):
param_list = prop_helpers.build_properties_dict(param_list,self.__subst_dict)

#--------------------------------------------------------------------------------------
# modify some IDF properties, which need overloaded getter (and this getter is provided somewhere in this class)
# modify some IDF properties, which need overloaded getter (and this getter is provided somewhere among PropertiesDescriptors)
if 'background_test_range' in param_list:
val = param_list['background_test_range']
param_list['_background_test_range'] = val;
Expand All @@ -125,7 +125,7 @@ def _convert_params_to_properties(self,param_list,detine_subst_dict=True):
#end
#
if 'monovan_integr_range' in param_list:
# get reference to class method
# get reference to the existing class method
param_list['_monovan_integr_range']=self.__class__.__dict__['monovan_integr_range']
#
val = param_list['monovan_integr_range']
Expand Down
10 changes: 7 additions & 3 deletions Code/Mantid/scripts/Inelastic/Direct/ReductionWrapper.py
@@ -1,7 +1,7 @@
from mantid.simpleapi import *
from mantid import config
from Direct.DirectEnergyConversion import DirectEnergyConversion
from Direct.PropertyManager import PropertyManager;

from PropertyManager import PropertyManager;
#import inspect
import os
from abc import abstractmethod
Expand All @@ -11,7 +11,7 @@ class ReductionWrapper(object):
""" Abstract class provides interface to direct inelastic reduction
allowing it to be run from Mantid, web services, or system tests
using the same interface and the same run file placed in different
locations
locations.
"""
def __init__(self,instrumentName,web_var=None):
""" sets properties defaults for the instrument with Name"""
Expand Down Expand Up @@ -117,6 +117,10 @@ def iliad(F):
""" This decorator wraps around main procedure, tries to identify if the procedure is run from web services or
from Mantid directly and sets up web-modified variables as input for reduction if it runs from web services.
The procedure to identify web services presence is simplified and contains two checks:
1) file reduce_vars.py is present and has been imported by reduction script as web_vars
2) the method, this decorators frames, is called with arguments, where second argument defines output directory for reduction data
(this variable is present and not empty)
"""
def iliad_wrapper(*args):
Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/scripts/Inelastic/Direct/__init__.py
@@ -0,0 +1,9 @@
""" properties exported from Direct Reduction Package:
dgreduce -- outdated functions, provided for compartibility with old qtiGenie
DirectEnergyConversion -- main reduction class
PropertyManager -- helper class providing access and functionality for IDF properties
ReductionWrapper -- parent class for reduction, After overloading for particular insrument provides common interface for Mantid and web services
CommonFunctions -- outdated, common functions used in Direct reducton package
"""
__all__=['dgreduce','DirectEnergyConversion','PropertyManager','ReductionWrapper','CommonFunctions']
84 changes: 0 additions & 84 deletions Code/Mantid/scripts/Inelastic/Direct/dgreduce.py
Expand Up @@ -41,17 +41,6 @@ def setup(instname=None,reload=False):

Reducer = DRC.setup_reducer(instname,reload)

def help(keyword=None) :
"""function returns help on reduction parameters.
Returns the list of the parameters available if provided without arguments
or the description and the default value for the key requested
"""
if Reducer == None:
raise ValueError("Reducer has not been defined, call setup(instrument_name) first.")

Reducer.help(keyword)


def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=None,second_wb=None,**kwargs):
""" One step conversion of run into workspace containing information about energy transfer
Expand Down Expand Up @@ -272,79 +261,6 @@ def abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,sam




def process_legacy_parameters(**kwargs) :
""" The method to deal with old parameters which have logi c different from default and easy to process using
subprogram. All other parameters just copied to output
"""
params = dict();
for key,value in kwargs.iteritems():
if key == 'hardmaskOnly': # legacy key defines other mask file here
params["hard_mask_file"] = value;
params["use_hard_mask_only"] = True;
elif key == 'hardmaskPlus': # legacy key defines other mask file here
params["hard_mask_file"] = value;
params["use_hard_mask_only"] = False;
else:
params[key]=value;

# Check all possible ways to define hard mask file:
if 'hard_mask_file' in params and not params['hard_mask_file'] is None:
if type(params['hard_mask_file']) == str and params['hard_mask_file']=="None":
params['hard_mask_file'] = None;
elif type(params['hard_mask_file']) == bool:
if params['hard_mask_file']:
raise TypeError("hard_mask_file has to be a file name or None. It can not be boolean True")
else:
params['hard_mask_file'] = None;
elif len(params['hard_mask_file']) == 0:
params['hard_mask_file'] = None;


return params




def sum_files(inst_name, accumulator, files):
""" Custom sum for multiple runs
Left for compatibility as internal summation had some unspecified problems.
Will go in a future
"""
accum_name = accumulator
if isinstance(accum_name,api.Workspace): # it is actually workspace
accum_name = accumulator.name()


if type(files) == list:
#tmp_suffix = '_plus_tmp'

for filename in files:
print 'Summing run ',filename,' to workspace ',accumulator
temp = common.load_run(inst_name,filename, force=False,load_with_workspace=Reducer.load_monitors_with_workspace)

if accum_name in mtd: # add current workspace to the existing one
if not isinstance(accumulator,api.Workspace):
accumulator = mtd[accum_name]
accumulator+= temp
DeleteWorkspace(Workspace=temp)
else:
print 'Create output workspace: '
accumulator=RenameWorkspace(InputWorkspace=temp,OutputWorkspace=accum_name)

return accumulator
else:
temp = common.load_run(inst_name,files, force=False,load_with_workspace=Reducer.load_monitors_with_workspace)
accumulator=RenameWorkspace(InputWorkspace=temp,OutputWorkspace=accum_name)
return accumulator;







if __name__=="__main__":
pass
# unittest.main()
Expand Down
91 changes: 0 additions & 91 deletions Code/Mantid/scripts/test/DgreduceTest.py

This file was deleted.

0 comments on commit 92617bc

Please sign in to comment.