Skip to content

Commit

Permalink
Re #10836 minor bug in HardMaskOnly implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jan 8, 2015
1 parent 235584e commit 0698080
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
34 changes: 21 additions & 13 deletions Code/Mantid/scripts/Inelastic/Direct/PropertiesDescriptors.py
Expand Up @@ -259,6 +259,10 @@ def __set__(self,instance,value):
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[False,True])
else:
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[True,False])
try:
del instance.__changed_properties['hardmaskOnly']
except:
pass



Expand All @@ -281,13 +285,11 @@ def __get__(self,instance,type=None):
def __set__(self,instance,value):
if value is None:
use_hard_mask_only = False
run_diagnostics = True
instance.hard_mask_file = None
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[use_hard_mask_only,run_diagnostics])
elif isinstance(value,bool):
use_hard_mask_only = False
run_diagnostics = instance.run_diagnostics
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[use_hard_mask_only,run_diagnostics])
hard_mask_file = None
elif isinstance(value,bool) or isinstance(value,int):
use_hard_mask_only = bool(value)
hard_mask_file= instance.hard_mask_file
elif isinstance(value,str):
if value.lower() in ['true','yes']:
use_hard_mask_only = True
Expand All @@ -297,14 +299,20 @@ def __set__(self,instance,value):
instance.hard_mask_file = value
use_hard_mask_only = True
hard_mask_file = instance.hard_mask_file

# if no hard mask file is there and use_hard_mask_only is True, diagnostics should not run
if instance.use_hard_mask_only and hard_mask_file is None:
run_diagnostics = False
else:
run_diagnostics = True
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[use_hard_mask_only,run_diagnostics])
#end

# if no hard mask file is there and use_hard_mask_only is True, diagnostics should not run
if use_hard_mask_only and hard_mask_file is None:
run_diagnostics = False
else:
run_diagnostics = True
prop_helpers.ComplexProperty.__set__(self,instance.__dict__,[use_hard_mask_only,run_diagnostics])
try:
del instance.__changed_properties['hardmaskPlus']
except:
pass



#end HardMaskOnly

Expand Down
11 changes: 6 additions & 5 deletions Code/Mantid/scripts/Inelastic/Direct/PropertyManager.py
Expand Up @@ -33,17 +33,18 @@ class PropertyManager(NonIDF_Properties):
########
design remarks:
1) Simple properties from IDF are stored in class dictionary in the form __dict__[property name]==property value
1) Simple properties from IDF are stored in class dictionary in the form __dict__[property name]=property value
2) Complex properties from IDF implemented as instances of ReductionHelpers.ComplexProperty class and are stored
in class dictionary in the forn __dict__[_property name] = ReductionHelpers.ComplexProperty([dependent properties list])
__getattr__ and __setattr__ are overloaded to understand such calls
3) Descriptors with the name present in IDF do not store their values and names in __dict__ but keep their information in the descriptor
3) Descriptors with the name present in IDF do not store their values and names in __dict__
(the name is removed during IDF parsing) but keep their information in the descriptor.
This is not considered a problem as only one instance of property manager is expected.
4) __getattr__ method is overloaded to provide call to descriptor before the search in the system dictionary. This works only
if Python does not find a property name in the __dict__ or __class__.__dict__ (and mro()) first
4) __getattr__ (and __setattr__ ) method is overloaded to provide call to descriptor before the search in the system dictionary.
This works only if Python does not find a property name in the __dict__ or __class__.__dict__ (and mro()) first
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand Down Expand Up @@ -241,7 +242,7 @@ def getChangedProperties(self):
""" method returns set of the properties changed from defaults """
decor_prop = '_'+type(self).__name__+'__changed_properties'
return self.__dict__[decor_prop]
def setChangedProperties(self,value=set()):
def setChangedProperties(self,value=set([])):
""" Method to clear changed properties list"""
if isinstance(value,set):
decor_prop = '_'+type(self).__name__+'__changed_properties'
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/scripts/test/DirectPropertyManagerTest.py
@@ -1,5 +1,5 @@
import os
os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
#os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
from mantid.simpleapi import *
from mantid import api
import unittest
Expand Down Expand Up @@ -651,6 +651,17 @@ def test_hadmask_options_locked(self):
self.assertFalse(propman1.use_hard_mask_only)
self.assertEqual(propman1.hard_mask_file,'a_hard_mask_file.msk')
self.assertTrue(propman1.run_diagnostics)

propman1.setChangedProperties(set())
propman1.hardmaskOnly = 'more_hard_mask_file'

# verify if changed properties list does not change anything
changed_prop=propman1.update_defaults_from_instrument( ws.getInstrument())
self.assertTrue(propman1.use_hard_mask_only)
self.assertEqual(propman1.hard_mask_file,'more_hard_mask_file.msk')
self.assertTrue(propman1.run_diagnostics)


#def test_default_warnings(self):
# tReducer = self.reducer

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/test/DirectReductionHelpersTest.py
@@ -1,5 +1,5 @@
import os
os.environ["PATH"] = r"c:/Mantid/Code/builds/br_10803/bin/Release;"+os.environ["PATH"]
#os.environ["PATH"] = r"c:/Mantid/Code/builds/br_10803/bin/Release;"+os.environ["PATH"]
from mantid.simpleapi import *
from mantid import api
import unittest
Expand Down

0 comments on commit 0698080

Please sign in to comment.