def iahistogram(f): """ o Purpose Image histogram. o Synopsis h = iahistogram(f) o Input f: o Output h: o Description o Examples f = iaread('woodlog.pgm') iashow(f) h = iahistogram(f) g,d = iaplot(h) g('set data style boxes') g.plot(d) showfig(h) """ from Numeric import asarray,searchsorted,sort,ravel,concatenate,product f = asarray(f) n = searchsorted(sort(ravel(f)), range(max(ravel(f))+1)) n = concatenate([n, [product(f.shape)]]) h = n[1:]-n[:-1] return h
def column_degeneracy(a,cutoff=.5): """Returns the number of characters that's needed to cover >= cutoff a: Numeric array cutoff: number that should be covered in the array Example: [ [.1 .8 .3], [.3 .2 .3], [.6 0 .4]] if cutoff = .75: column_degeneracy -> [2,1,3] if cutoff = .45: column_degeneracy -> [1,1,2] WARNING: watch out with floating point numbers. if the cutoff= 0.9 and in the array is also 0.9, it might not be found >>> searchsorted(cumsum(array([.6,.3,.1])),.9) 2 >>> searchsorted(cumsum(array([.5,.4,.1])),.9) 1 If the cutoff value is not found, the result is clipped to the number of rows in the array. """ if not a: return [] b = cumsum(sort(a,0)[::-1]) try: degen = [searchsorted(b[:,idx],cutoff) for idx in range(len(b[0]))] except TypeError: raise ValueError, "Array has to be two dimensional" #degen contains now the indices at which the cutoff was hit #to change to the number of characters, add 1 return clip(array(degen)+1,0,a.shape[0])
def row_degeneracy(a,cutoff=.5): """Returns the number of characters that's needed to cover >= cutoff a: Numeric array cutoff: number that should be covered in the array Example: [ [.1 .3 .4 .2], [.5 .3 0 .2], [.8 0 .1 .1]] if cutoff = .75: row_degeneracy -> [3,2,1] if cutoff = .95: row_degeneracy -> [4,3,3] WARNING: watch out with floating point numbers. if the cutoff= 0.9 and in the array is also 0.9, it might not be found >>> searchsorted(cumsum(array([.6,.3,.1])),.9) 2 >>> searchsorted(cumsum(array([.5,.4,.1])),.9) 1 If the cutoff value is not found, the result is clipped to the number of columns in the array. """ if not a: return [] try: b = cumsum(sort(a)[:,::-1],1) except IndexError: raise ValueError, "Array has to be two dimensional" degen = [searchsorted(aln_pos,cutoff) for aln_pos in b] #degen contains now the indices at which the cutoff was hit #to change to the number of characters, add 1 return clip(array(degen)+1,0,a.shape[1])
def rotationalConstants(self, conf=None): """Returns a sorted array of rotational constants A, B, C in internal units.""" from Numeric import sort from Units import h, pi com, i = self.centerAndMomentOfInertia(conf) pmi = i.eigenvalues() return sort(h / (8.*pi*pi*pmi))[::-1]