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 | def __init__(self): |
---|
53 | """ Initialization""" |
---|
54 | ## Dictionary of Parameter objects |
---|
55 | self.parameters = {} |
---|
56 | ## Dictionary of parameters, available for backward compatibility |
---|
57 | self.params = ParameterDict(self.parameters) |
---|
58 | ## Additional details, provided for backward compatibility |
---|
59 | self.details = {} |
---|
60 | self.description = '' |
---|
61 | ## Dictionary used to store the dispersity/averaging |
---|
62 | # parameters of dispersed/averaged parameters. |
---|
63 | ## Provided for backward compatibility |
---|
64 | self.dispersion = {} |
---|
65 | |
---|
66 | # Old-style methods that are no longer used |
---|
67 | def setParamWithToken(self, name, value, token, member): |
---|
68 | """ |
---|
69 | set Param With Token |
---|
70 | """ |
---|
71 | return NotImplemented |
---|
72 | |
---|
73 | def getParamWithToken(self, name, token, member): |
---|
74 | """ |
---|
75 | get Param With Token |
---|
76 | """ |
---|
77 | return NotImplemented |
---|
78 | |
---|
79 | def getParamListWithToken(self, token, member): |
---|
80 | """ |
---|
81 | get Param List With Token |
---|
82 | """ |
---|
83 | return NotImplemented |
---|
84 | def __add__(self, other): |
---|
85 | """ |
---|
86 | add |
---|
87 | """ |
---|
88 | raise ValueError, "Model operation are no longer supported" |
---|
89 | def __sub__(self, other): |
---|
90 | """ |
---|
91 | sub |
---|
92 | """ |
---|
93 | raise ValueError, "Model operation are no longer supported" |
---|
94 | def __mul__(self, other): |
---|
95 | """ |
---|
96 | mul |
---|
97 | """ |
---|
98 | raise ValueError, "Model operation are no longer supported" |
---|
99 | def __div__(self, other): |
---|
100 | """ |
---|
101 | div |
---|
102 | """ |
---|
103 | raise ValueError, "Model operation are no longer supported" |
---|
104 | |
---|
105 | if __name__ == "__main__": |
---|
106 | b = ModelAdaptor() |
---|
107 | #print b.operateOn |
---|
108 | |
---|