def histogram(data, nbins, range = None): """ Create a histogram. Comes from Konrad Hinsen: Scientific Python :param data: data list or array :type data: [any] :param nbins: number of bins :type nbins: int :param range: data range to create histogram from (min val, max val) :type range: (float, float) OR None :return: array (2 x len(data) ) with start of bin and witdh of bin. :rtype: array """ data = N0.array(data, N0.Float) if range is None: min = N0.minimum.reduce(data) max = N0.maximum.reduce(data) else: min, max = range data = N0.repeat(data, N0.logical_and(N0.less_equal(data, max), N0.greater_equal(data, min))) bin_width = (max-min)/nbins data = N0.floor((data - min)/bin_width).astype(N0.Int) histo = N0.add.reduce(N0.equal( N0.arange(nbins)[:,N0.NewAxis], data), -1) histo[-1] = histo[-1] + N0.add.reduce(N0.equal(nbins, data)) bins = min + bin_width*(N0.arange(nbins)+0.5) return N0.transpose(N0.array([bins, histo]))
def group( self, a_indices, maxPerCenter ): """ Group a bunch of integers (atom indices in PDBModel) so that each group has at most maxPerCenter items. @param a_indices: atom indices @type a_indices: [int] @param maxPerCenter: max entries per group @type maxPerCenter: int @return: list of lists of int @rtype: [[int],[int]..] """ ## how many groups are necessary? n_centers = len( a_indices ) // maxPerCenter ## floor division if len( a_indices ) % maxPerCenter: n_centers += 1 ## how many items/atoms go into each group? nAtoms = N0.ones(n_centers, N0.Int) * int(len( a_indices ) / n_centers) i=0 while N0.sum(nAtoms) != len( a_indices ): nAtoms[i] += 1 i += 1 ## distribute atom indices into groups result = [] pos = 0 for n in nAtoms: result += [ N0.take( a_indices, N0.arange(n) + pos) ] pos += n return result
def removeFrames( self, indices ): """ Remove given frames from this trajectory object. :param indices: frame numbers :type indices: [int] """ i = N0.arange( self.lenFrames()) i = N0.delete( i, indices ) self.keepFrames( i )
def test_plot(self): """gnuplot.plot test""" # List of (x, y) pairs # plot([(0.,1),(1.,5),(2.,3),(3.,4)]) # plot( zip( range(10), range(10) ) ) # Two plots; each given by a 2d array import biskit.core.oldnumeric as N0 x = N0.arange(10) y1 = x**2 y2 = (10 - x)**2 plot(N0.transpose(N0.array([x, y1])), N0.transpose(N0.array([x, y2])))
def test_plot( self ): """gnuplot.plot test""" # List of (x, y) pairs # plot([(0.,1),(1.,5),(2.,3),(3.,4)]) # plot( zip( range(10), range(10) ) ) # Two plots; each given by a 2d array import biskit.core.oldnumeric as N0 x = N0.arange(10) y1 = x**2 y2 = (10-x)**2 plot( N0.transpose(N0.array([x, y1])), N0.transpose(N0.array([x, y2])))
def colorRange( nColors, palette='plasma2' ): """Quick access to a range of colors. :param nColors: number of colors needed :type nColors: int :param palette: type of color spectrum :type palette: str :return: a range of color values :rtype: [ int ] """ c = ColorSpectrum( palette=palette, vmin=0, vmax=1. ) r = 1. * N0.arange( 0, nColors ) / nColors return c.colors( r )
def test_area(self): """mathUtils.area test""" self.c = list(zip( N0.arange(0,1.01,0.1), N0.arange(0,1.01,0.1) )) self.area = area( self.c ) self.assertAlmostEqual( self.area, 0.5, 7 )
def test_area(self): """mathUtils.area test""" self.c = list(zip(N0.arange(0, 1.01, 0.1), N0.arange(0, 1.01, 0.1))) self.area = area(self.c) self.assertAlmostEqual(self.area, 0.5, 7)
def test_hist( self ): """hist test""" self.x = N0.arange( 4, 12, 1.2 ) self.data = density( self.x, 3, hist=1 ) self.assertTrue( N.all( self.data == self.EXPECT) )