[1b162dfa] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | This software was developed by the University of Tennessee as part of the |
---|
| 4 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 5 | project funded by the US National Science Foundation. |
---|
| 6 | |
---|
| 7 | If you use DANSE applications to do scientific research that leads to |
---|
| 8 | publication, we ask that you acknowledge the use of the software with the |
---|
| 9 | following sentence: |
---|
| 10 | |
---|
| 11 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
| 12 | |
---|
| 13 | copyright 2008, University of Tennessee |
---|
| 14 | """ |
---|
| 15 | |
---|
| 16 | """ |
---|
| 17 | Provide base functionality for all model components |
---|
| 18 | |
---|
| 19 | The following has changed since going from BaseComponent to BaseModel: |
---|
| 20 | |
---|
| 21 | - Arithmetic operation between models is no longer supported. |
---|
| 22 | It was found to be of little use and not very flexible. |
---|
| 23 | |
---|
| 24 | - Parameters are now stored as Parameter object to provide |
---|
| 25 | the necessary extra information like limits, units, etc... |
---|
| 26 | """ |
---|
| 27 | |
---|
| 28 | class ParameterDict(dict): |
---|
| 29 | """ |
---|
| 30 | Parameter dictionary used for backward |
---|
| 31 | compatibility between the old-style 'params' |
---|
| 32 | dictionary and the new-style 'parameters' |
---|
| 33 | dictionary. |
---|
| 34 | """ |
---|
| 35 | def __init__(self, parameters): |
---|
| 36 | """ |
---|
| 37 | Initialization |
---|
| 38 | @param parameters: new-style 'parameters' dictionary |
---|
| 39 | """ |
---|
| 40 | self.parameters = parameters |
---|
| 41 | |
---|
| 42 | def __setitem__(self, name, value): |
---|
| 43 | self.parameters[name].value = value |
---|
| 44 | |
---|
| 45 | def __getitem__(self, name): |
---|
| 46 | return self.parameters[name].value |
---|
| 47 | |
---|
| 48 | class ModelAdaptor(object): |
---|
| 49 | """ |
---|
| 50 | Model adaptor to provide old-style model functionality |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | def __init__(self): |
---|
| 54 | """ Initialization""" |
---|
[8809e48] | 55 | ## Dictionary of Parameter objects |
---|
| 56 | self.parameters = {} |
---|
[1b162dfa] | 57 | ## Dictionary of parameters, available for backward compatibility |
---|
| 58 | self.params = ParameterDict(self.parameters) |
---|
| 59 | ## Additional details, provided for backward compatibility |
---|
| 60 | self.details = {} |
---|
[5f89fb8] | 61 | self.description='' |
---|
[1b162dfa] | 62 | ## Dictionary used to store the dispersity/averaging |
---|
| 63 | # parameters of dispersed/averaged parameters. |
---|
| 64 | ## Provided for backward compatibility |
---|
| 65 | self.dispersion = {} |
---|
[ae60f86] | 66 | |
---|
[1b162dfa] | 67 | # Old-style methods that are no longer used |
---|
| 68 | def setParamWithToken(self, name, value, token, member): return NotImplemented |
---|
| 69 | def getParamWithToken(self, name, token, member): return NotImplemented |
---|
| 70 | def getParamListWithToken(self, token, member): return NotImplemented |
---|
| 71 | def __add__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
| 72 | def __sub__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
| 73 | def __mul__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
| 74 | def __div__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | if __name__ == "__main__": |
---|
[dacf52f] | 79 | b = ModelAdaptor() |
---|
| 80 | #print b.operateOn |
---|
[1b162dfa] | 81 | |
---|