Skip to content

Commit

Permalink
Re #10532 written and tested option to write changed properties
Browse files Browse the repository at this point in the history
to HDD and load them back.
  • Loading branch information
abuts committed Dec 1, 2014
1 parent 64fb148 commit 66e5eed
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 59 deletions.
66 changes: 23 additions & 43 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,55 +719,22 @@ def convert_to_energy_transfer(self,wb_run=None,sample_run=None,ei_guess=None,re
wksp_out = prop_man.get_sample_ws_name();


# we may want to run absolute units normalization and this function has been called with monovan run or helper procedure
if prop_man.monovan_run != None :
# check if mono-vanadium is provided as multiple files list or just put in brackets occasionally
prop_man.log("****************************************************************",'notice');
prop_man.log('*** Output will be in absolute units of mb/str/mev/fu','notice')
non_changed = prop_man.check_monovan_par_changed();
if len(non_changed) > 0:
for prop in non_changed:
value = getattr(prop_man,prop)
message = '\n***WARNING!: Absolute units reduction parameter : {0} has its default value: {1}'+\
'\n This may need to change for correct absolute units reduction\n'

prop_man.log(message.format(prop,value),'warning')

# Process old legacy parameters which are easy to re-define in dgreduce rather then transfer through Mantid
#TODO (verify)
#program_args = process_legacy_parameters(**kwargs)
start_time=time.time()


# inform user about changed parameters
prop_man.log("*** Provisional Incident energy: {0:>12.3f} mEv".format(ei_guess),'notice')
prop_man.log("****************************************************************",'notice');
changed_Keys= prop_man.getChangedProperties();
for key in changed_Keys:
val = getattr(prop_man,key);
prop_man.log(" Value of : {0:<25} is set to : {1:<20} ".format(key,val),'notice')


save_dir = config.getString('defaultsave.directory')
prop_man.log("****************************************************************",'notice');
if prop_man.monovan_run != None and not('van_mass' in changed_Keys):
prop_man.log("*** Monochromatic vanadium mass used : {0} ".format(prop_man.van_mass),'notice')
prop_man.log("*** By default results are saved into: {0}".format(save_dir),'notice');
prop_man.log("****************************************************************",'notice');
# inform user on what parameters have changed
prop_man.log_changed_values('notice');
#process complex parameters

#process complex parameters


# defaults can be None too, but can be a file
if prop_man.map_file == None:
prop_man.log('*** one2one map selected','notice')
start_time=time.time()
# defaults can be None too, but can be a file

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

prop_man.log("*** Output will be normalized to {0}".format(prop_man.normalise_method),'notice');

# TODO: --check out if internal summation works
# Here was summation in dgreduce.

Expand Down Expand Up @@ -796,7 +763,7 @@ def convert_to_energy_transfer(self,wb_run=None,sample_run=None,ei_guess=None,re
if not masks_done:
prop_man.log("########### Run diagnose for sample run ##############################",'notice');
prop_man.log("########### Run diagnose for monochromatic vanadium run ##############",'notice');
masking = self.diagnose(wb_run,prop_man.mask_run,
masking = self.diagnose(prop_man.wb_run,prop_man.mask_run,
second_white=None,print_results=True)
header = "*** Diagnostics processed workspace with {0:d} spectra and masked {1:d} bad spectra"

Expand All @@ -807,7 +774,7 @@ def convert_to_energy_transfer(self,wb_run=None,sample_run=None,ei_guess=None,re
if prop_man.use_sam_msk_on_monovan == True:
prop_man.log(' Applying sample run mask to mono van')
else:
if not prop_man.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace Should be better soulution for that.
if not prop_man.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace Should be better solution for that.
prop_man.log("########### Run diagnose for monochromatic vanadium run ##############",'notice');

masking2 = self.diagnose(prop_man.wb_for_monovan_run,prop_man.monovan_run,
Expand Down Expand Up @@ -1274,7 +1241,15 @@ def __init__(self, instr_name=None):
"""
Constructor
"""
self.initialise(instr_name);
# Internal properties and keys
self._keep_wb_workspace = False;
self._do_ISIS_normalization = True;
self.spectra_masks = None;

if instr_name:
self.initialise(instr_name);
else:
self._propMan = None;


def initialise(self, instr,reload_instrument=False):
Expand All @@ -1290,11 +1265,16 @@ def initialise(self, instr,reload_instrument=False):
# Instrument and default parameter setup
# formats available for saving. As the reducer has to have a method to process one of this, it is private property
if not hasattr(self,'_propMan') or self._propMan is None:
self._propMan = DirectPropertyManager(instr);
if isinstance(instr,DirectPropertyManager):
self._propMan = instr;
else:
self._propMan = DirectPropertyManager(instr);
else:
old_name = self._propMan.instrument.getName();
if isinstance(instr,geometry._geometry.Instrument):
new_name = self._propMan.instrument.getName();
elif isinstance(instr,DirectPropertyManager):
new_name = instr.instr_name;
else:
new_name = instr
#end if
Expand Down
118 changes: 103 additions & 15 deletions Code/Mantid/scripts/Inelastic/DirectPropertyManager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" File contains number of various classes defining interface for Direct inelastic reduction """
""" File contains classes defining the interface for Direct inelastic reduction with properties
present in Instrument_Properties.xml file
"""

from mantid.simpleapi import *
from mantid import api
Expand Down Expand Up @@ -209,7 +211,7 @@ def __set__(self,instance,value):
if not(value in SaveFormat.save_formats):
instance.log("Trying to set saving in unknown format: \""+str(value)+"\" No saving will occur for this format")
return
elif isinstance(value,list):
elif isinstance(value,list) or isinstance(value,set):
# set single default save format recursively
for val in value:
self.__set__(instance,val);
Expand Down Expand Up @@ -313,6 +315,7 @@ def __init__(self,Instrument,instr_run=None):
#
# define private properties served the class
private_properties = {'descriptors':[],'subst_dict':{},'prop_allowed_values':{},'changed_properties':set(),
'advanced_properties':set(),
'file_properties':[],'abs_norm_file_properties':[]};
# place these properties to __dict__ with proper decoration
self._set_private_properties(private_properties);
Expand Down Expand Up @@ -424,6 +427,8 @@ def __setattr__(self,name0,val):

# record changes in the property
self.__changed_properties.add(name);
if self.record_advanced_properties:
self.__advanced_properties.add(name);

# ----------------------------
def __getattr__(self,name):
Expand Down Expand Up @@ -470,6 +475,13 @@ def __getattr__(self,name):
def getChangedProperties(self):
""" method returns set of the properties changed from defaults """
return self.__dict__[self._class_wrapper+'changed_properties'];
def getChangedAdvancedProperties(self):
""" method returns advanced properties, changed from defaults
and recorded when record_advanced_properties was set to True
TODO: deal with this recording better.
"""
return self.__dict__[self._class_wrapper+'advanced_properties'];

@property
def relocate_dets(self) :
Expand All @@ -490,8 +502,6 @@ def get_sample_ws_name(self):
def set_input_parameters(self,**kwargs):
""" Set input properties from a dictionary of parameters
Auxiliary method used in old interface.
Returns the list of changed properties.
"""

for par_name,value in kwargs.items() :
Expand Down Expand Up @@ -520,17 +530,6 @@ def get_diagnostics_parameters(self):

return result;

def check_monovan_par_changed(self):
""" method verifies, if properties necessary for monovanadium reduction have indeed been changed from defaults """

# list of the parameters which should usually be changed by user and if not, user should be warn about it.
momovan_properties=['sample_mass','sample_rmm','monovan_run']
changed_prop = self.getChangedProperties();
non_changed = [];
for property in momovan_properties:
if not property in changed_prop:
non_changed.append(property)
return non_changed;

# TODO: finish refactoring this.
def init_idf_params(self, reinitialize_parameters=False):
Expand Down Expand Up @@ -591,6 +590,95 @@ def check_files_list(files_list):

if base_file_missing or abs_file_missing:
raise RuntimeError(" Files needed for the run are missing ")
#
def _check_monovan_par_changed(self):
""" method verifies, if properties necessary for monovanadium reduction have indeed been changed from defaults """

# list of the parameters which should usually be changed by user and if not, user should be warn about it.
momovan_properties=['sample_mass','sample_rmm','monovan_run']
changed_prop = self.getChangedProperties();
non_changed = [];
for property in momovan_properties:
if not property in changed_prop:
non_changed.append(property)
return non_changed;

#
def log_changed_values(self,log_level='notice'):
""" inform user about changed parameters and about the parameters that should be changed but have not
This method is abstract method of DirectReductionProperties but is fully defined in
DirectPropertyManager
"""

# we may want to run absolute units normalization and this function has been called with monovan run or helper procedure
if self.monovan_run != None :
# check if mono-vanadium is provided as multiple files list or just put in brackets occasionally
self.log("****************************************************************",'notice');
self.log('*** Output will be in absolute units of mb/str/mev/fu','notice')
non_changed = self._check_monovan_par_changed();
if len(non_changed) > 0:
for prop in non_changed:
value = getattr(self,prop)
message = '\n***WARNING!: Absolute units reduction parameter : {0} has its default value: {1}'+\
'\n This may need to change for correct absolute units reduction\n'

self.log(message.format(prop,value),'warning')


# now let's report on normal run.
self.log("*** Provisional Incident energy: {0:>12.3f} mEv".format(self.incident_energy),log_level)
self.log("****************************************************************",log_level);
changed_Keys= self.getChangedProperties();
for key in changed_Keys:
val = getattr(self,key);
self.log(" Value of : {0:<25} is set to : {1:<20} ".format(key,val),log_level)


save_dir = config.getString('defaultsave.directory')
self.log("****************************************************************",log_level);
if self.monovan_run != None and not('van_mass' in changed_Keys): # This output is
self.log("*** Monochromatic vanadium mass used : {0} ".format(self.van_mass),log_level) # Adroja request from may 2014
#
self.log("*** By default results are saved into: {0}".format(save_dir),log_level);
self.log("*** Output will be normalized to {0}".format(self.normalise_method),log_level);
if self.map_file == None:
self.log('*** one2one map selected',log_level)
self.log("****************************************************************",log_level);

def export_changed_values(self,FileName='reduce_vars.py'):
""" Method to write changed simple and advanced properties into dictionary, to process by
web reduction interface
"""
changed_Keys= self.getChangedProperties();
advancedKeys= self.getChangedAdvancedProperties();

f=open(FileName,'w')
f.write("standard_vars = {\n")
str_wrapper = ' '
for key in changed_Keys:
if not key in advancedKeys:
val = getattr(self,key);
if isinstance(val,str):
row = "{0}\'{1}\':\'{2}\'".format(str_wrapper,key,val)
else:
row = "{0}\'{1}\':{2}".format(str_wrapper,key,val)
f.write(row);
str_wrapper=',\n '
f.write("}\nadvanced_vars={\n")

str_wrapper=' '
for key in advancedKeys:
val = getattr(self,key);
if isinstance(val,str):
row = "{0}\'{1}\':\'{2}\'".format(str_wrapper,key,val)
else:
row = "{0}\'{1}\':{2}".format(str_wrapper,key,val)
f.write(row);
str_wrapper=',\n '
f.write("}\n")
f.close();




Expand Down
17 changes: 16 additions & 1 deletion Code/Mantid/scripts/Inelastic/DirectReductionProperties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
""" File contains number of various classes defining interface for Direct inelastic reduction """
""" File contains classes defining the interface for Direct inelastic reduction with properties
necessary for reduction but not present in Instrument_Properties.xml file
Main example of such properties are run numbers, energy bins and incident energies.
"""

from mantid.simpleapi import *
from mantid import api
Expand Down Expand Up @@ -154,6 +158,8 @@ def __init__(self,Instrument,run_workspace=None):
object.__setattr__(self,'_second_white',None);
object.__setattr__(self,'_mono_correction_factor',None);

#
object.__setattr__(self,'_record_advanced_properties',False);

self._set_instrument_and_facility(Instrument,run_workspace);

Expand Down Expand Up @@ -195,6 +201,15 @@ def seclond_white(self,value):
def apply_detector_eff(self):
return True;
#-----------------------------------------------------------------------------------
#TODO: Implement auto-clearing decorator around it
@property
def record_advanced_properties(self):
return self._record_advanced_properties;
#
@record_advanced_properties.setter
def record_advanced_properties(self,value):
object.__setattr__(self,'_record_advanced_properties',bool(value));
#-----------------------------------------------------------------------------------
@property
def psi(self):
""" rotation angle (not available from IDF)"""
Expand Down

0 comments on commit 66e5eed

Please sign in to comment.