Skip to content

Commit

Permalink
Re #10708 Method to update instrument parameters from workspace
Browse files Browse the repository at this point in the history
and unit test to verify it
  • Loading branch information
abuts committed Dec 8, 2014
1 parent 391f852 commit 54d3f77
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Code/Mantid/scripts/Inelastic/DirectPropertyManager.py
Expand Up @@ -607,15 +607,25 @@ def get_diagnostics_parameters(self):

return result;

def update_defaults_from_instrument(pInstrument):
def update_defaults_from_instrument(self,pInstrument):
""" Method used to update default parameters from the same instrument.
Used if initial parameters correspond to instrument with one validity dates and
current instrument has different validity dates and different default values for
these dates.
List of synonims is not modified
"""
if self.instr_name != pInstrument.getName():
raise AttributeError("Can not change instrument parameters ")
else:
changed_properties = self.getChangedProperties()
param_list = prop_helpers.get_default_idf_param_list(pInstrument);
for key,val in param_list.iteritems():
if not (key in changed_properties):
setattr(self,key,val)
pass
#end

# TODO: finish refactoring this.
def init_idf_params(self, reinitialize_parameters=False):
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Inelastic/DirectReductionHelpers.py
Expand Up @@ -242,7 +242,7 @@ def check_instrument_name(old_name,new_name):
instrument = config.getFacility().instrument(new_name)
short_name = instrument.shortName()
full_name = instrument.name()
except:
except RuntimeError:
# it is possible to have wrong facility:
facilities = config.getFacilities()
old_facility = str(config.getFacility())
Expand Down
10 changes: 9 additions & 1 deletion Code/Mantid/scripts/Inelastic/DirectReductionProperties.py
Expand Up @@ -331,7 +331,15 @@ def _set_instrument_and_facility(self,Instrument,run_workspace=None):
if isinstance(Instrument,geometry._geometry.Instrument):
instrument = Instrument;
instr_name = instrument.getFullName()
new_name,full_name,facility_ = prop_helpers.check_instrument_name(None,instr_name);
try:
new_name,full_name,facility_ = prop_helpers.check_instrument_name(None,instr_name);
except KeyError: # the instrument pointer is not found in any facility but we have it after all
new_name=instr_name
full_name=instr_name
facility_= 'TEST'
#end


elif isinstance(Instrument,str): # instrument name defined
new_name,full_name,facility_ = prop_helpers.check_instrument_name(None,Instrument);
idf_dir = config.getString('instrumentDefinition.directory')
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/scripts/test/DirectEnergyConversionTest.py
Expand Up @@ -162,7 +162,6 @@ def test_get_abs_normalization_factor(self) :
self.assertAlmostEqual(nf3,nf4)



##def test_diag_call(self):
## tReducer = self.reducer
## # should do nothing as already initialized above, but if not will initiate the instrument
Expand Down
32 changes: 32 additions & 0 deletions Code/Mantid/scripts/test/DirectPropertyManagerTest.py
Expand Up @@ -409,6 +409,38 @@ def test_set_energy_bins_and_ei(self):

#TODO: this one is not completed

def test_set_defailts_from_instrument(self) :
ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=100)

SetInstrumentParameter(ws,ParameterName="TestParam1",Value="3.5",ParameterType="Number")
SetInstrumentParameter(ws,ParameterName="TestParam2",Value="initial1",ParameterType="String")
SetInstrumentParameter(ws,ParameterName="TestParam3",Value="initial2",ParameterType="String")

instr = ws.getInstrument()
propman = DirectPropertyManager(instr);

self.assertAlmostEqual(propman.TestParam1,3.5);
self.assertEquals(propman.TestParam2,"initial1");
self.assertEquals(propman.TestParam3,"initial2");

propman.TestParam2="gui_changed1"
self.assertEquals(propman.TestParam2,"gui_changed1");

SetInstrumentParameter(ws,ParameterName="TestParam2",Value="instr_changed1",ParameterType="String")
SetInstrumentParameter(ws,ParameterName="TestParam3",Value="instr_changed2",ParameterType="String")

self.assertAlmostEqual(propman.TestParam1,3.5);
self.assertEquals(propman.TestParam2,"gui_changed1");
self.assertEquals(propman.TestParam3,"initial2");


propman.update_defaults_from_instrument(ws.getInstrument());

self.assertAlmostEqual(propman.TestParam1,3.5);
self.assertEquals(propman.TestParam2,"gui_changed1");
self.assertEquals(propman.TestParam3,"instr_changed2");




#def test_default_warnings(self):
Expand Down

0 comments on commit 54d3f77

Please sign in to comment.