source: issm/trunk/src/m/classes/qmu/histogram_bin_uncertain.py@ 25836

Last change on this file since 25836 was 25836, checked in by Mathieu Morlighem, 4 years ago

merged trunk-jpl and trunk for revision 25834

File size: 6.0 KB
Line 
1import numpy as np
2
3from MatlabArray import string_dim
4
5
6class histogram_bin_uncertain(object):
7 '''
8 HISTOGRAM_BIN_UNCERTAIN class definition
9
10 Usage:
11 [hbu] = histogram_bin_uncertain(
12 'descriptor', descriptor,
13 'pairs_per_variable', pairs_per_variable,
14 'abscissas', abscissas,
15 'counts', counts
16 )
17
18 where the required args are:
19 descriptor (char, description, '')
20 pairs_per_variable (double list, [])
21 abscissas (double list, [])
22 counts (int list, [])
23
24 NOTE: A call to the constructor with zero arguments will return a default
25 instance; one argument of the class copies the instance; three or more
26 arguments constructs a new instance from the arguments.
27 '''
28
29 def __init__(self): #{{{
30 self.descriptor = ''
31 self.pairs_per_variable = []
32 self.abscissas = []
33 self.counts = []
34 #}}}
35
36 @staticmethod
37 def histogram_bin_uncertain(*args): #{{{
38 nargin = len(args)
39
40 # create a default object
41 if nargin == 0:
42 return histogram_bin_uncertain()
43
44 # copy the object
45 elif nargin == 1:
46 if isinstance(args[0], histogram_bin_uncertain):
47 hbu = args[0]
48 else:
49 raise Exception("Object {} is a {} class object, not 'histogram_bin_uncertain'.".format(str(args[0]), str(type(args[0]))))
50
51 elif nargin == 2 or nargin == 3:
52 raise Exception("Construction of 'histogram_bin_uncertain' class object requires at least {} inputs.".format(4))
53
54 # create the object from the input
55 elif nargin == 4:
56 hbu = histogram_bin_uncertain()
57
58 #recover options:
59 options = pairoptions(*args)
60
61 #initialize fields:
62 hbu.descriptor = options.getfieldvalue('descriptor')
63 hbu.pairs_per_variable = options.getfieldvalue('pairs_per_variable')
64 hbu.abscissas = options.getfieldvalue('abscissas')
65 hbu.counts = options.getfieldvalue('counts')
66
67 else:
68 raise Exception("Construction of histogram_bin_uncertain class object requires either (1) no arguments, (2) a histogram_bin_uncertain instance to copy from, or (3) a descriptor and pairs per variable, abscissas, and counts lists")
69
70 @staticmethod
71 def __repr__(hbu): #{{{
72 s = ""
73 for i in range(len(hbu)):
74 s += "class {} object {} = \n".format(hbu.__class__.__name__, string_dim(hbu, i))
75 s = "{}\n{}".format(s, fielddisplay(self, 'descriptor', 'name tag'))
76 s = "{}\n{}".format(s, fielddisplay(self, 'pairs_per_variable', 'pairs per variable'))
77 s = "{}\n{}".format(s, fielddisplay(self, 'abscissas', 'abscissas'))
78 s = "{}\n{}".format(s, fielddisplay(self, 'counts', 'counts'))
79
80 return s
81 #}}}
82
83 def checkconsistency(self, md, solution, analyses): #{{{
84 return
85 #}}}
86
87 #virtual functions needed by qmu processing algorithms
88 #implemented:
89
90 @staticmethod
91 def prop_desc(hbu, dstr): #{{{
92 desc = ['' for i in range(np.size(hbu))]
93 for i in range(np.size(hbu)):
94 if hbu[i].descriptor != '' or type(hbu[i].descriptor) != str:
95 desc[i] = str(hbu[i].descriptor)
96 elif dstr != '':
97 desc[i] = str(dstr) + str(string_dim(hbu, i, 'vector'))
98 else:
99 desc[i] = 'hbu' + str(string_dim(hbu, i, 'vector'))
100
101 desc = allempty(desc)
102
103 return desc
104 #}}}
105
106 @staticmethod
107 def prop_mean(hbu): #{{{
108 mean = np.zeros(np.size(hbu))
109 for i in range(np.size(hbu)):
110 mean[i] = hbu[i].mean
111 return mean
112 #}}}
113
114 @staticmethod
115 def prop_stddev(hbu): #{{{
116 stddev = np.zeros(np.size(hbu))
117 for i in range(np.size(hbu)):
118 stddev[i] = hbu[i].stddev
119 return stddev
120 #}}}
121
122 @staticmethod
123 def prop_lower(hbu): #{{{
124 lower = []
125 return
126 #}}}
127
128 @staticmethod
129 def prop_upper(hbu): #{{{
130 upper = []
131 return upper
132 #}}}
133
134 #default
135 @staticmethod
136 def prop_abscissas(hbu): #{{{
137 abscissas = []
138 for i in range(len(hbu)):
139 abscissas.extend(hbu[i].abscissas)
140 abscissas = allequal(abscissas, -np.inf)
141 return abscissas
142 #}}}
143
144 @staticmethod
145 def prop_pairs_per_variable(hbu): #{{{
146 pairs_per_variable = np.zeros((1, len(hbu)))
147 for i in range(len(hbu)):
148 pairs_per_variable[i] = hbu[i].pairs_per_variable
149 abscissas = allequal(pairs_per_variable, -np.inf)
150 return pairs_per_variable
151 #}}}
152
153 @staticmethod
154 def prop_counts(hbu): #{{{
155 counts = []
156 for i in range(len(hbu)):
157 counts.extend(hbu[i].counts)
158 counts = allequal(counts, -np.inf)
159 return counts
160 #}}}
161
162 @staticmethod
163 def prop_initpt(hbu): #{{{
164 initpt = []
165 return initpt
166 #}}}
167
168 @staticmethod
169 def prop_initst(hbu): #{{{
170 inist = []
171 return inist
172 #}}}
173
174 @staticmethod
175 def prop_stype(hbu): #{{{
176 stype = []
177 return stype
178 #}}}
179
180 @staticmethod
181 def prop_scale(hbu): #{{{
182 scale = []
183 return scale
184 #}}}
185
186 #new methods:
187 def isscaled(self): #{{{
188 if strncmp(self.descriptor, 'scaled_', 7):
189 return True
190 else:
191 return False
192 #}}}
193
194 @staticmethod
195 def dakota_write(fidi, dvar):
196 # possible namespace pollution, the above import seems not to work
197 from vlist_write import vlist_write
198 # collect only the variables of the appropriate class
199 hbu = deepcopy(dvar)
200 fields = fieldnames(hbu)
201 for field in fields:
202 if getattr(hbu, field)[0].__class__.__name__ != 'histogram_bin_uncertain':
203 delattr(hbu, field)
204 if len(hbu) > 0:
205 vlist_write(fidi, 'histogram_bin_uncertain', 'hbu', hbu)
206 #}}}
Note: See TracBrowser for help on using the repository browser.