Changeset 25090 for issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.py
- Timestamp:
- 06/21/20 21:48:26 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.py
r25044 r25090 14 14 15 15 Usage: 16 nuv = normal_uncertain('descriptor',descriptor,'mean',mean,'stddev',stddev,'partition',partition) 17 where nuv is the normal_uncertain object returned by the constructor, mean and stddev are self 18 explanatory. partition is the partition vector for distributed variables. Can be a partition 19 vector over elements or vertices. 16 [nuv] = normal_uncertain( 17 'descriptor', descriptor, 18 'mean', mean, 19 'stddev', stddev, 20 'partition', partition 21 ) 22 23 where nuv is the normal_uncertain object returned by the constructor, 24 mean and stddev are self explanatory, and partition is the partition 25 vector for distributed variables. Can be a partition vector over 26 elements or vertices. 20 27 21 28 Example: … … 32 39 ) 33 40 ''' 34 def __init__(self): 41 def __init__(self): #{{{ 35 42 self.descriptor = '' 36 43 self.mean = np.NaN … … 38 45 self.partition = [] 39 46 self.nsteps = 0 47 #}}} 40 48 41 49 @staticmethod … … 52 60 nuv = args[0] 53 61 else: 54 raise RuntimeError('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "normal_uncertain".')62 raise Exception('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "normal_uncertain".') 55 63 56 64 # create the object from the input 57 65 else: 58 # lines differ here in other classes / tests; see asizec problem in notes59 66 nuv = normal_uncertain() 60 67 … … 67 74 nuv.stddev = options.getfieldvalue('stddev') 68 75 69 #if the variable is scaled, a partition vector should have been supplied, and70 # that partition vector should have as many partitions as the mean and stddev71 # vectors:76 #if the variable is scaled, a partition vector should have been 77 #supplied, and that partition vector should have as many partitions 78 #as the mean and stddev vectors: 72 79 if nuv.isscaled(): 73 80 nuv.partition = options.getfieldvalue('partition') … … 75 82 npart = qmupart2npart(nuv.partition) 76 83 if npart != nuv.mean.shape[0]: 77 raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the row size of the mean field should be identical to the number of partitions" % nuv.descriptor)84 raise Exception("normal_uncertain constructor: for the scaled variable %s the row size of the mean field should be identical to the number of partitions" % nuv.descriptor) 78 85 if npart != nuv.stddev.shape[0]: 79 raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the row size of the stddev field should be identical to the number of partitions" % nuv.descriptor)86 raise Exception("normal_uncertain constructor: for the scaled variable %s the row size of the stddev field should be identical to the number of partitions" % nuv.descriptor) 80 87 if nuv.nsteps != nuv.mean.shape[1]: 81 raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the col size of the mean field should be identical to the number of time steps" % nuv.descriptor)88 raise Exception("normal_uncertain constructor: for the scaled variable %s the col size of the mean field should be identical to the number of time steps" % nuv.descriptor) 82 89 if nuv.nsteps != nuv.stddev.shape[1]: 83 raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the col size of the stddev field should be identical to the number of time steps" % nuv.descriptor)90 raise Exception("normal_uncertain constructor: for the scaled variable %s the col size of the stddev field should be identical to the number of time steps" % nuv.descriptor) 84 91 85 92 return [nuv] # Always return a list, so we have something akin to a MATLAB single row matrix … … 107 114 def checkconsistency(self, md, solution, analyses): #{{{ 108 115 md = checkfield(md, 'field', self.mean, 'fieldname', 'normal_uncertain.mean', 'NaN', 1, 'Inf', 1, '>=', 0) 109 md = checkfield(md, 'field', self.stddev, 'fieldname', 'normal_uncertain.stddev', 'NaN', 1, 'Inf', 1, '>=', 0 , 'numel', len(self.mean))116 md = checkfield(md, 'field', self.stddev, 'fieldname', 'normal_uncertain.stddev', 'NaN', 1, 'Inf', 1, '>=', 0) 110 117 if self.isscaled(): 111 118 if self.partition == []: 112 raise RuntimeError("normal_uncertain is a scaled variable, but it's missing a partition vector")119 raise Exception("normal_uncertain is a scaled variable, but it's missing a partition vector") 113 120 #better have a partition vector that has as many partitions as stddev's size: 114 121 if self.stddev.shape[0] != partition_npart(self.partititon): 115 raise RuntimeError("normal_uncertain error message: row size of stddev and partition size should be identical")122 raise Exception("normal_uncertain error message: row size of stddev and partition size should be identical") 116 123 if self.mean.shape[0] != partition_npart(self.partition): 117 raise RuntimeError("normal_uncertain error message: row size of mean and partition size should be identical")124 raise Exception("normal_uncertain error message: row size of mean and partition size should be identical") 118 125 #we need as many steps in stddev and mean as there are in time steps 119 126 if self.stddev.shape[1] != self.nsteps: 120 raise RuntimeError("normal_uncertain error message: col size of stddev and partition size should be identical")127 raise Exception("normal_uncertain error message: col size of stddev and partition size should be identical") 121 128 if self.mean.shape[1] != self.nsteps: 122 raise RuntimeError("normal_uncertain error message: col size of mean and partition size should be identical")129 raise Exception("normal_uncertain error message: col size of mean and partition size should be identical") 123 130 md = checkfield(md, 'field', self.partition, 'fieldname', 'normal_uncertain.partition', 'NaN', 1, 'Inf', 1, '>=', -1, 'numel', [md.mesh.numberofvertices, md.mesh.numberofvertices]) 124 131 if self.partition.shape[1] > 1: 125 raise RuntimeError("normal_uncertain error message: partition should be a column vector")132 raise Exception("normal_uncertain error message: partition should be a column vector") 126 133 partcheck = np.unique(self.partition) 127 134 partmin = min(partcheck) 128 135 partmax = max(partcheck) 129 136 if partmax < -1: 130 raise RuntimeError("normal_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0")137 raise Exception("normal_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0") 131 138 nmax = max(md.mesh.numberofelements, md.mesh.numberofvertices) 132 139 if partmax > nmax: 133 raise RuntimeError("normal_uncertain error message: partition vector's values cannot go over the number of vertices or elements")140 raise Exception("normal_uncertain error message: partition vector's values cannot go over the number of vertices or elements") 134 141 #}}} 135 142
Note:
See TracChangeset
for help on using the changeset viewer.