Coverage for m_pool\axis_obj.py : 42%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
'''An Axis object is used to define the axes of Matrix objects
For interpolation, an axis can transform its values to (hopefully) make them more linear. (e.g. log10 for an axis spanning orders of magnitude)
*** Structured to easily pickle via a dictionary of named values for properties. *** '''
'transform':None, 'roundDigits':4} ): '''Initialize with a dictionary so that pickle files can easily save and read objects'''
return {'name':self.name, 'valueL':self.valueL, 'units':self.units, 'transform':self.transform, 'roundDigits':self.roundDigits}
return self.valueL[:] # return a copy
sL = ['Axis: %s'%self.name + ' ' + str(self.valueL)] return '\n'.join(sL)
return self.valueL[i]
'''Save all connections to Matrix objects''' # Save a tuple of index position in Matrix and Matrix itself
# Keep a transformed array for later linear interpolation
'''Index used for quad_terp interpolation''' val = float(val) i = bisect.bisect_left(self.valueArr, val) - 1
if i<0: return 0 elif i>self.valueArr.size-3: return self.valueArr.size-3 return i
'''Get Index into self.valueL from the val input''' except: pass
# Otherwise, see if val is within roundoff error of an included value i = bisect.bisect_left( self.valueL, val ) try: #print ' Round A i=%i'%i,round(val, self.roundDigits),round(self.valueL[i], self.roundDigits) if round(val, self.roundDigits)==round(self.valueL[i], self.roundDigits): return i except: pass
try: #print ' Round B i=%i'%i,round(val, self.roundDigits),round(self.valueL[i-1], self.roundDigits) if round(val, self.roundDigits)==round(self.valueL[i-1], self.roundDigits): return i-1 except: pass
return None # Can't find the index... return None
val = float(val) i = bisect.bisect_left( self.valueL, val ) if i>= len(self.valueL): self.valueL.append( val )
else: if self.valueL[i]==val: print(val,'is already in Axis... skipping insert') return None
#print 'i=',i,'for',val,'inserted into',self.valueL,'v[i]=',self.valueL[i] self.valueL.insert(i,val) #print 'new vL=',self.valueL self.make_supt_objects()
for iaxis,M in self.matrixConnectionL: M.insert_dimension( iaxis,i )
return i # calling routine might need insertion point
epsAxis = Axis({'name':'eps', 'valueL':[1.,2.,3.,5.,10.,20.,40.], 'units':'', 'transform':'log10'}) print(epsAxis.get_pickleable_dict()) print() print('epsAxis.transArr =',epsAxis.transArr) print() epsAxis.add_value( 1.6 ) epsAxis.add_value( 1.5 ) epsAxis.add_value( 7 ) epsAxis.add_value( 40.0001 ) epsAxis.add_value( 0.0 ) print(epsAxis.valueArr) print('len(epsAxis) =',len(epsAxis)) print() for val in [0, -1.1, 0.5, 1, 1.25, 4,40, 40.0001, 40.00001, 40.000001]:
i = epsAxis.getExactIndex(val) if i==None: print('for val=',val,' i=',i) else: print('for val=',val,' i=%i'%i, ' valueL[i]=',epsAxis.valueL[i])
|