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""" |
---|
55 | ## Dictionary of parameters, available for backward compatibility |
---|
56 | self.params = ParameterDict(self.parameters) |
---|
57 | ## Additional details, provided for backward compatibility |
---|
58 | self.details = {} |
---|
59 | |
---|
60 | ## Dictionary used to store the dispersity/averaging |
---|
61 | # parameters of dispersed/averaged parameters. |
---|
62 | ## Provided for backward compatibility |
---|
63 | self.dispersion = {} |
---|
64 | |
---|
65 | def __getattribute__(self, name): |
---|
66 | """ |
---|
67 | Provide additional information when accessing old-style |
---|
68 | data members. |
---|
69 | """ |
---|
70 | if name in ['operateOn', 'other']: |
---|
71 | raise AttributeError, "Model operation are no longer supported" |
---|
72 | |
---|
73 | return object.__getattribute__(self, name) |
---|
74 | |
---|
75 | # Old-style methods that are no longer used |
---|
76 | def setParamWithToken(self, name, value, token, member): return NotImplemented |
---|
77 | def getParamWithToken(self, name, token, member): return NotImplemented |
---|
78 | def getParamListWithToken(self, token, member): return NotImplemented |
---|
79 | def __add__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
80 | def __sub__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
81 | def __mul__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
82 | def __div__(self, other): raise ValueError, "Model operation are no longer supported" |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | if __name__ == "__main__": |
---|
87 | b = BaseModel() |
---|
88 | print b.operateOn |
---|
89 | |
---|