def draw_hist(self): list_checked = [] for i in range(1, self.verticalLayout_hotels.count()): if self.verticalLayout_hotels.itemAt( i).widget().isChecked() == True: list_checked.append( self.verticalLayout_hotels.itemAt(i).widget().text()) print(list_checked) filter = self.filter_hist.currentText() filer_pos_neg = "" b = False if self.pos_hist.isChecked() and self.neg_hist.isChecked(): filer_pos_neg = "posneg" b = True else: if self.pos_hist.isChecked(): filer_pos_neg = "positive" b = True if self.neg_hist.isChecked(): filer_pos_neg = "negative" b = True if b and len(list_checked) > 0: histogram(self.file, filter, filer_pos_neg, list_checked)
def test__idiv__2(self): "histogram: h/=h1" h = self._histogram.copy() h2 = self._histogram2 h /= h2 self.assertVectorAlmostEqual( h[1.5,1], (1,2.0/3) ) h = self._histogram.copy() h2 = createHistogram( noerror = True ) h /= h2 self.assertVectorAlmostEqual( h[1.5,1], (1,1./3) ) from histogram import histogram, axis, arange, datasetFromFunction x = axis('x', arange(1, 2, .2 ) ) y = axis('y', arange(0, 3, .5 ) ) def fa(x,y): return x*y + x ha = histogram('a', [x,y], datasetFromFunction( fa, (x,y) ) ) for xi in x.binCenters(): for yi in y.binCenters(): self.assertAlmostEqual( fa(xi,yi), ha[xi,yi][0] ) def fb(x,y): return x hb = histogram('b', [x,y], datasetFromFunction( fb, (x,y) ) ) hc = ha/hb for xi in x.binCenters(): for yi in y.binCenters(): self.assertAlmostEqual( yi+1, hc[xi,yi][0] ) def fberr(x,y): return 0*x hb = histogram('b', [x,y], datasetFromFunction( fb, (x,y) ), datasetFromFunction( fberr, (x,y) ) ) hc = ha/hb for xi in x.binCenters(): for yi in y.binCenters(): self.assertAlmostEqual( yi+1, hc[xi,yi][0] ) #involve units h1 = histogram( 'h1', [ ('x', [1,2,3]), ], unit = 'meter', data = [1,2,3], errors = [1,2,3], ) h2 = histogram( 'h2', [ ('x', [1,2,3]), ], data = [1,1,1], errors = [1,1,1], unit = 'second', ) h3 = h1/h2 self.assertVectorAlmostEqual( h3.I, (1,2,3) ) self.assertVectorAlmostEqual( h3.E2, (2,6,12) ) return
def test_histogram1a(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction' """ def f(x): return x*x h = histogram('h', [ ('x',range(10)) ], fromfunction = f ) def g(x): return x h = histogram('h', [ ('x',range(10)) ], fromfunction = (f,g) ) return
def test_histogram1a(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction' """ def f(x): return x * x h = histogram('h', [('x', list(range(10)))], fromfunction=f) def g(x): return x h = histogram('h', [('x', list(range(10)))], fromfunction=(f, g)) return
def test_histogram1c(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction'. math.sin """ import math h = histogram('h', [ ('x', arange(0, 3.0, 0.1)), ], fromfunction=math.sin) h = histogram('h', [ ('x', arange(0, 3.0, 0.1)), ('y', arange(0, 3.0, 0.1)), ], fromfunction=lambda x, y: math.sin(x + y)) return
def test_as_floattype(self): from histogram import histogram, arange h = histogram( 'h', [ ('x',arange(10)) ], data_type = 'int') h1 = h.as_floattype() self.assertEqual( h1.typeCode(), 6 ) self.assertTrue( h1.axisFromName( 'x' ) is not h.axisFromName( 'x' ) ) return
def normalize(self, IQE): 'normalize IQE' # only the master node need to do normalization if self.mpiRank != 0: return #for debug from histogram.hdf import dump filename = 'IQE-nosolidanglenormalization.h5' import os if os.path.exists( filename ): os.remove( filename ) dump( IQE, filename, '/', 'c' ) info.log( 'node %s: convert I(Q,E) datatype from integer to double' % self.mpiRank) from histogram import histogram newIQE = histogram( IQE.name(), IQE.axes() ) newIQE[(), ()] = IQE[(), ()] Ei = self.Ei pixelPositions = self.pixelPositions pixelSolidAngles = self.pixelSolidAngles from arcseventdata.normalize_iqe import normalize_iqe info.log( 'node %s: normalize I(Q,E) by solid angle: Ei=%s, positions.shape=%s, solidangles.shape=%s' % (self.mpiRank, Ei, pixelPositions.shape, pixelSolidAngles.shape)) import time t0 = time.time() normalize_iqe( newIQE, Ei, pixelPositions, pixelSolidAngles ) t1 = time.time() info.log( 'node %s: normalization done: %s seconds' % ( self.mpiRank, t1-t0)) return newIQE
def test_as_floattype(self): from histogram import histogram, arange h = histogram( 'h', [ ('x',arange(10)) ], data_type = 'int') h1 = h.as_floattype() self.assertEqual( h1.typeCode(), 6 ) self.assert_( h1.axisFromName( 'x' ) is not h.axisFromName( 'x' ) ) return
def test_load(self): "Histogram: pickle.load" import pickle h = self._histogram pickle.dump( h, open( "tmp.pkl", 'w' ) ) h1 = pickle.load( open("tmp.pkl") ) self.assertEqual( h.name(), h1.name() ) print ("data=%s" % h1.data().storage().asNumarray() ) self.assert_( h.data().storage().compare( h1.data().storage() ) ) print ("errors=%s" % h1.errors().storage().asNumarray() ) self.assert_( h.errors().storage().compare( h1.errors().storage() ) ) for axisName in h.axisNameList(): print ("axis %s" % axisName) axis = h.axisFromName( axisName ) axis1 = h1.axisFromName( axisName ) self.assert_( axis.storage().compare( axis1.storage() ) ) continue from histogram import histogram h2 = histogram( 'h2', [ ('x', [1,2,3]), ], unit = 'meter' ) pickle.dump( h2, open( "tmp.pkl", 'w' ) ) h2a = pickle.load( open("tmp.pkl") ) return
def testIadd_and_SetItem(self): "Histogram: h[ x,y,z ] += sth" from histogram import histogram h = histogram( 'h', [('a', [1,2,3]),('b', [4,5])] ) import numpy as N h[ 1,5 ] = N.array( [1,1] ) return
def test_load(self): "Histogram: pickle.load" import pickle h = self._histogram pickle.dump( h, open( "tmp.pkl", 'wb' ) ) h1 = pickle.load( open("tmp.pkl", 'rb') ) self.assertEqual( h.name(), h1.name() ) print(("data=%s" % h1.data().storage().asNumarray() )) self.assertTrue( h.data().storage().compare( h1.data().storage() ) ) print(("errors=%s" % h1.errors().storage().asNumarray() )) self.assertTrue( h.errors().storage().compare( h1.errors().storage() ) ) for axisName in h.axisNameList(): print(("axis %s" % axisName)) axis = h.axisFromName( axisName ) axis1 = h1.axisFromName( axisName ) self.assertTrue( axis.storage().compare( axis1.storage() ) ) continue from histogram import histogram h2 = histogram( 'h2', [ ('x', [1,2,3]), ], unit = 'meter' ) pickle.dump( h2, open( "tmp.pkl", 'wb' ) ) h2a = pickle.load( open("tmp.pkl", 'rb') ) return
def frequency_weight(): weight_dictionary = {} sum_values = sum(histogram(word_list).values()) for word in word_list: word_occurances = word_list.count(word) weighted_occurances = word_occurances / sum_values return
def test_values2indexes(self): "Histogram: values2indexes" from histogram import histogram, axis, arange x = axis( 'x', arange(1., 10., 1.) ) y = axis( 'y', arange(-1., 1., 0.1) ) h = histogram('h', (x,y) ) self.assertVectorEqual( h.values2indexes( (2, 0.2) ), (1,12) ) return
def test_histogram6(self): """Histogram.__init__: errors = None""" h = histogram('h', [ ('x', [1, 2, 3]), ], unit='meter', data=[1, 2, 3]) self.assertVectorAlmostEqual(h.errors().storage().asNumarray(), [0, 0, 0]) return
def t2(): from histogram import histogram, arange from numpy import exp h = histogram("h", [("tof", arange(1000.0, 3000.0, 1.0), "microsecond")], fromfunction=lambda x: exp(-x / 1000.0)) print h plot(h) return
def t2(): from histogram import histogram, arange from numpy import exp h = histogram("h", [('tof', arange(1000., 3000., 1.0), "microsecond")], fromfunction=lambda x: exp(-x / 1000.)) print(h) plot(h) return
def test_axisFromId(self): "Histogram: axisFromId" from histogram import histogram, axis, arange x = axis( 'x', arange(1., 10., 1.) ) y = axis( 'y', arange(-1., 1., 0.1) ) h = histogram('h', (x,y) ) self.assertEqual( h.axisFromId(1), x ) self.assertEqual( h.axisFromId(2), y ) return
def test_histogram5(self): """Histogram.__init__: unit""" h = histogram( 'h', [ ('x', [1,2,3] ), ], unit = 'meter', ) return
def test_histogram1c(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction'. math.sin """ import math h = histogram( 'h', [ ('x',arange(0, 3.0, 0.1)), ], fromfunction = math.sin ) h = histogram( 'h', [ ('x',arange(0, 3.0, 0.1)), ('y',arange(0, 3.0, 0.1)), ], fromfunction = lambda x,y: math.sin(x+y) ) return
def testSetItem(self): "Histogram: h[ x,y,z ] = value" from histogram import histogram h = histogram( 'h', [('a', [1,2,3]),('b', [4,5])] ) h[ 1,5 ] = 1,1 self.assertVectorAlmostEqual( h.data().storage().asList(), [0,1,0,0,0,0] ) self.assertVectorAlmostEqual( h.errors().storage().asList(), [0,1,0,0,0,0] ) self.assertVectorAlmostEqual( h[1,5], (1,1) ) h = histogram( 'h', [('a', [1,2,3])] ) h[1] = 10,10 h = histogram( 'h', [('a', [1,2,3])], unit = 'meter') from pyre.units.length import meter h[1] = 10*meter,10*meter*meter return
def t7(): from histogram import histogram axes = [('x', [1, 2, 3]), ('yID', [1])] data = [[1], [2], [3]] errs = [[1], [2], [3]] h = histogram('h', axes, data, errs) assert h.shape() == (3, 1) h.reduce() assert h.shape() == (3, ) return
def testReplaceAxis(self): 'Hisogram: replaceAxis' from histogram import histogram, axis, arange a = axis('a', arange(1,10,1.0)) b = axis('b', arange(1,100,10.)) h = histogram( 'h', [a] ) self.assert_(a is h.axisFromName('a')) h.replaceAxis(name='a', axis=b) self.assert_(b is h.axisFromName('a')) return
def testReplaceAxis(self): 'Hisogram: replaceAxis' from histogram import histogram, axis, arange a = axis('a', arange(1,10,1.0)) b = axis('b', arange(1,100,10.)) h = histogram( 'h', [a] ) self.assertTrue(a is h.axisFromName('a')) h.replaceAxis(name='a', axis=b) self.assertTrue(b is h.axisFromName('a')) return
def test_histogram5(self): """Histogram.__init__: unit""" h = histogram( 'h', [ ('x', [1, 2, 3]), ], unit='meter', ) return
def t7(): from histogram import histogram axes = [("x", [1, 2, 3]), ("yID", [1])] data = [[1], [2], [3]] errs = [[1], [2], [3]] h = histogram("h", axes, data, errs) assert h.shape() == (3, 1) h.reduce() assert h.shape() == (3,) return
def test_histogram1b(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction'. 3D """ h = histogram('h', [ ('x', list(range(2))), ('y', list(range(2, 4))), ('z', list(range(4, 6))), ], fromfunction=lambda x, y, z: x + y + z) return
def testSlicingIsRefering(self): #slice is just a reference, not a copy from histogram import histogram h = histogram( 'h', [('a', [1,2,3]),('b', [4,5])] ) from numpy import ones h[(),()] = ones( (3,2) ), ones((3,2) ) self.assertVectorAlmostEqual( h[1,4], (1,1) ) sh = h[1,()] sh.clear() self.assertVectorAlmostEqual( h[1,4], (0,0) ) return
def _test_histogram3a(self): """Histogram.__init__: histogram of non-float datatype""" detaxis = axis('detectorID', list(range(10))) pixaxis = axis('pixelID', list(range(10))) mask = histogram('mask', (detaxis, pixaxis), data_type='char') from numpy import ones data = createDataset('data', shape=(10, 10), data=ones((10, 10), int), data_type='int') counts = histogram('counts', (detaxis, pixaxis), data=data, errors=None) counts1 = histogram('counts', (detaxis, pixaxis), data=ones((10, 10), int), errors=ones((10, 10), int), data_type='double') self.assertEqual(counts1.errors().name(), 'errors') return
def test_histogram6(self): """Histogram.__init__: errors = None""" h = histogram( 'h', [ ('x', [1,2,3] ), ], unit = 'meter', data = [1,2,3] ) self.assertVectorAlmostEqual( h.errors().storage().asNumarray(), [0,0,0] ) return
def _test_histogram3a(self): """Histogram.__init__: histogram of non-float datatype""" detaxis = axis('detectorID', range(10) ) pixaxis = axis('pixelID', range(10) ) mask = histogram( 'mask', (detaxis, pixaxis), data_type = 'char' ) from numpy import ones data = createDataset( 'data', shape = (10,10), data = ones( (10,10), int ), data_type = 'int' ) counts = histogram( 'counts', (detaxis, pixaxis), data = data, errors = None) counts1 = histogram( 'counts', (detaxis, pixaxis), data = ones( (10, 10), int ), errors = ones( (10,10), int ), data_type = 'double') self.assertEqual( counts1.errors().name(), 'errors' ) return
def test_histogram2(self): """Histogram.__init__: datasetFromFunction""" qaxis = axis( 'q', arange( 0, 13, 0.1), 'angstrom**(-1)' ) eaxis = axis( 'e', arange( -50, 50, 1.), 'meV' ) axes = (qaxis,eaxis) def f1(q,e): return q**2 + e**2 data = datasetFromFunction( f1, (qaxis,eaxis) ) errs = data**2 h = histogram('h', axes, data, errs) q = 6.; e = 10. self.assertVectorAlmostEqual( h[ q,e ] , (f1(q,e), f1(q,e)**2 ) ) return
def testClear(self): "Histogram: h.clear()" from histogram import histogram h = histogram( 'h', [('a', [1,2,3]),('b', [4,5])] ) from numpy import ones h[(),()] = ones( (3,2) ), ones( (3,2) ) self.assertVectorAlmostEqual( h[1,4] , (1,1) ) h.clear() self.assertVectorAlmostEqual( h.data().storage().asList(), [0,0,0,0,0,0] ) self.assertVectorAlmostEqual( h.errors().storage().asList(), [0,0,0,0,0,0] ) return
def test_histogram1b(self): """Histogram.__init__: histogram factory method, keyword 'fromfunction'. 3D """ h = histogram( 'h', [ ('x',range(2)), ('y',range(2,4)), ('z',range(4,6)), ], fromfunction = lambda x,y,z: x+y+z ) return
def test_histogram4(self): """Histogram.__init__: histogram factory method, axes are specified using a list of (name, values). data and errors are unspecified""" detIDaxis = "detID", list(range(100)) tofAxis = "tof", arange(1000, 5000, 1.0), "microsecond" shape = len(detIDaxis[1]), len(tofAxis[1]) from numpy import zeros h = histogram('h', (detIDaxis, tofAxis)) self.assertVectorAlmostEqual(h[30, 3000.], (0, 0)) return
def test_histogram4(self): """Histogram.__init__: histogram factory method, axes are specified using a list of (name, values). data and errors are unspecified""" detIDaxis = "detID", range(100) tofAxis = "tof", arange( 1000, 5000, 1.0), "microsecond" shape = len(detIDaxis[1]), len(tofAxis[1]) from numpy import zeros h = histogram('h', (detIDaxis, tofAxis) ) self.assertVectorAlmostEqual( h[ 30, 3000. ], (0,0) ) return
def test_getSliceCopyFromHistogram(self): '''Histogram.__init__: getSliceCopyFromHistogram''' h = histogram( 'h', [ ('x', [1, 2, 3]), ('y', [0.1, 0.2, 0.3]), ('z', list(range(0, 1000, 100))), ], unit='meter', ) xaxis = axis('x', [1, 2]) yaxis = axis('y', [0.2, 0.3]) s = getSliceCopyFromHistogram('s', [xaxis, yaxis], h) self.assertVectorEqual(s.shape(), (2, 2, 10)) return
def test_getSliceCopyFromHistogram(self): '''Histogram.__init__: getSliceCopyFromHistogram''' h = histogram( 'h', [ ('x', [1,2,3] ), ('y', [0.1,0.2,0.3] ), ('z', range(0,1000,100) ), ], unit = 'meter', ) xaxis = axis('x', [1, 2]) yaxis = axis('y', [0.2, 0.3]) s = getSliceCopyFromHistogram( 's', [xaxis, yaxis], h ) self.assertVectorEqual( s.shape(), (2,2,10) ) return
def test_histogram2(self): """Histogram.__init__: datasetFromFunction""" qaxis = axis('q', arange(0, 13, 0.1), 'angstrom**(-1)') eaxis = axis('e', arange(-50, 50, 1.), 'meV') axes = (qaxis, eaxis) def f1(q, e): return q**2 + e**2 data = datasetFromFunction(f1, (qaxis, eaxis)) errs = data**2 h = histogram('h', axes, data, errs) q = 6. e = 10. self.assertVectorAlmostEqual(h[q, e], (f1(q, e), f1(q, e)**2)) return
def test_histogram1(self): """Histogram.__init__: histogram factory method, axes are specified using instances of Axis""" detIDaxis = axis( "detID", range(10) ) pixIDaxis = axis( "pixID", range(8) ) axes = [detIDaxis, pixIDaxis] from numpy import fromfunction def f(i,j): return i+j data = fromfunction( f, (detIDaxis.size(), pixIDaxis.size()) ) errs = data**2 h = histogram('h', axes, data, errs) detID, pixID = 3, 5 self.assertVectorAlmostEqual( h[detID, pixID], ( f(detID, pixID), f(detID, pixID) ** 2 ) ) return
def test_getattribute(self): 'Histogram: __getattribute__' from histogram import histogram, axis, arange x = axis( 'x', arange(1., 10., 1.) ) y = axis( 'y', arange(-1., 1., 0.1) ) h = histogram('h', (x,y) ) self.assertVectorEqual( h.x, x.binCenters() ) self.assertVectorEqual( h.y, y.binCenters() ) t1 = h.I; t2 = h.data().storage().asNumarray() t1.shape = t2.shape = -1, self.assertVectorEqual( t1, t2 ) t1 = h.E2; t2 = h.errors().storage().asNumarray() t1.shape = t2.shape = -1, self.assertVectorEqual( t1, t2 ) return
def test_histogram1(self): """Histogram.__init__: histogram factory method, axes are specified using instances of Axis""" detIDaxis = axis("detID", list(range(10))) pixIDaxis = axis("pixID", list(range(8))) axes = [detIDaxis, pixIDaxis] from numpy import fromfunction def f(i, j): return i + j data = fromfunction(f, (detIDaxis.size(), pixIDaxis.size())) errs = data**2 h = histogram('h', axes, data, errs) detID, pixID = 3, 5 self.assertVectorAlmostEqual(h[detID, pixID], (f(detID, pixID), f(detID, pixID)**2)) return
def make_anagram_dict(words): anagramdict = {} for i in words: key = get_key(i) if key not in anagramdict: anagramdict[key] = [i] else: current = anagramdict[key] current.append(i) anagramdict[key] = current longest = sorted(anagramdict.values(), key=len)[-1][0] print('the longest is', longest) count = 0 for i, k in anagramdict.items(): if len(i) > count: count = len(i) biggest = k print(histogram(range(6), list(anagramdict.keys()), 30)) return anagramdict, biggest
def setUp(self): self.sample1 = histogram("This is the text that i will put in the histogram".split())
path_list = [] for dirpath, dirnames, filenames in os.walk(BASE_DIR): if dirpath not in ignore_dirs: for files in filenames: path_list.append(os.path.join(dirpath,files)) dbook_epub = [] zip_epub = [] largest = 0 hmin = 0.0 hmax = 8000000.0 nbins = 100 bin_size = (hmax-hmin)/nbins bin_center = bin_size/2 h = histogram("h", [('freq', arange(hmin+bin_center,hmax+bin_center,bin_size))]) for files in path_list: raw_base,raw_ext = os.path.splitext(files) base = raw_base.lower() ext = raw_ext.lower() if '.jpg' == ext: fsize = os.path.getsize(files) if fsize > largest: largest = fsize bin_value = h[fsize,fsize+0.01].I bin_value += 1 h[fsize,fsize+0.01] = bin_value ,None print "Largest File Size = " + str(largest)
#!/home/tgni/ml/env/bin/python3 from histogram import * def reverse_lookup(d, v): r = [] for k in d: if d[k] == v: r.append(k) return r h = histogram('parrot') for i in range(4): k = reverse_lookup(h, i) print k
ax.set_ylabel('count (# of times a water was found at that coordinate') minorLocator = MultipleLocator(2) majorLocator = MultipleLocator(10) ax.xaxis.set_major_locator(majorLocator) ax.xaxis.set_minor_locator(minorLocator) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') for line in ax.get_xticklines() + ax.get_yticklines(): line.set_markeredgewidth(3) line.set_markersize(10) for line in ax.xaxis.get_minorticklines(): line.set_markeredgewidth(2) line.set_markersize(5) ##the next part uses the histogram class (need histogram.py) to color the histogram. Not necessary from histogram import * from numpy import random h1 = histogram(xcoords, bins=500, range=[-20,80]) colors = ['red', 'blue', 'red'] ranges = [[-20,0], [0,43.3], [43.3,80]] for c, r in zip(colors, ranges): plt = ax.overlay(h1, range=r, facecolor=c) pyplot.savefig("ChannelCross-Section.png") #~ plt.savefig("ChannelCross-Section.png") #~ plt.show()
if dirpath not in ignore_dirs: for files in filenames: file_list.append(os.path.join(dirpath,files)) jpg_counter = 0 png_counter = 0 gif_counter = 0 bad_counter = 0 over_counter = 0 hmin = 0.0 hmax = 2000000.0 nbins = 9 bin_list = ['Thumbnail','XXXS','XXS','XS','S','M','L','XL','XXL'] bin_size = (hmax-hmin)/nbins bin_center = bin_size/2 h = histogram("h", [('Image Size', arange(hmin+bin_center,hmax+bin_center,bin_size))]) tmb_list = [] bin_number = 1 counter = 0 for files in file_list: counter += 1 raw_path,raw_name = os.path.split(files) raw_base,raw_ext = os.path.splitext(raw_name) base = raw_base.lower() ext = raw_ext.lower() pixels, image_type = get_img_size(files) if pixels > 1000000: print files
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Oct 18 19:21:38 2019 @author: craigdeng """ from histogram import * import matplotlib.pyplot as plt from skimage.util import img_as_ubyte from skimage import data if __name__ =='__main__': noisy_image = img_as_ubyte(data.camera())#import image as ubyte hist, hist_centers = histogram(noisy_image)#apply the function fig, ax = plt.subplots(ncols=2, figsize=(10, 5))#plot the image and histogram ax[0].imshow(noisy_image, cmap=plt.cm.gray) ax[0].axis('off')#adjust original image plot ax[1].plot(hist_centers, hist, lw=2) ax[1].set_title('Histogram of grey values')#adjust histogram plot plt.tight_layout()
import text_tokenizer import histogram import hashtable import Heap from text_tokenizer import * from hashtable import * from histogram import * from Heap import MaxHeap # If we subtract the Unix dictionary's keys from our word count dict's keys, # we can find specialized/jargon words in our corpus or words # we didn't normalize. We can even use this to refine our regular expressions # and normalization techniques! if __name__ == '__main__': user_input = "humannature.txt" tokenized_text = text_Parser(user_input) # TODO are we supposed to rewrite the histogram function to incorporate our hash table? histogram = histogram(tokenized_text) max_heap = MaxHeap() for i in histogram: max_heap.insert((i, histogram[i])) print(max_heap.peek(10))
def testSlicing(self): "Histogram: slicing" histogram = self._histogram #get element self.assertVectorEqual( histogram[1.5,1], (3,3) ) #get slice from histogram.SlicingInfo import SlicingInfo, all, front, back slice1 = histogram[SlicingInfo((0.5, 1.5)), SlicingInfo((1,3))] self.assertVectorEqual( slice1.shape(), (2,2 ) ) print slice1.name() slice1 = histogram[(0.5, 1.5), (1,3)] self.assertVectorEqual( slice1.shape(), (2,2 ) ) print slice1.name() slice2 = histogram[0.5, SlicingInfo((1,3))] self.assertVectorEqual(slice2.shape(), (2,) ) slice2 = histogram[0.5, (1,3)] self.assertVectorEqual(slice2.shape(), (2,) ) slice3 = histogram[all, 99] self.assertVectorEqual(slice3.shape(), (3,) ) slice3 = histogram[(), 99] self.assertVectorEqual(slice3.shape(), (3,) ) slice3a = slice3[ SlicingInfo( (1.5, back) ) ] self.assertVectorEqual(slice3a.shape(), (2,) ) slice3a = slice3[ (1.5, None) ] self.assertVectorEqual(slice3a.shape(), (2,) ) slice4 = histogram[all, all] self.assertVectorEqual(slice4.shape(), (3,3) ) slice4 = histogram[(), ()] self.assertVectorEqual(slice4.shape(), (3,3) ) slice5 = histogram[SlicingInfo( (1.5,back) ), all] self.assertVectorEqual(slice5.shape(), (2,3) ) slice5 = histogram[(1.5, None), ()] self.assertVectorEqual(slice5.shape(), (2,3) ) slice6 = histogram[SlicingInfo( (front,1.5) ), all] self.assertVectorEqual(slice6.shape(), (2,3) ) slice6 = histogram[(None,1.5), ()] self.assertVectorEqual(slice6.shape(), (2,3) ) #getitem with units from histogram._units import length meter = length.meter slice8 = histogram[ {'E':(0.5*meter, 1.5*meter), 'tubeId':(1,3)} ] self.assertVectorEqual(slice8.shape(), (2,2)) #getitem for 1D histogram number7 = histogram[ 1.5, () ][3] #getitem using dictionary number7 = histogram[ {'E':1.5, 'tubeId':3} ] number7 = histogram[ 1.5, () ][ {'tubeId':3} ] # special test case: coordinate = 0 from histogram import histogram, axis detIDaxis = axis('detID', range(5)) h = histogram( 'h', [detIDaxis]) h[ {'detID':0 } ] #get slice. units envolved h = histogram( 'distance', [ ('x', [1,2,3] ), ], unit = 'meter', data = [1,2,3] ) h1 = h[(2,3)] self.assertEqual( h1.unit(), h.unit() ) return
from histogram import * import sys # The number of arguments must be at least 2: the name of the file # with the raw data, and the size of the bin. f = sys.argv[1] of = "_hist_" + f print(f) s = float(sys.argv[2]) print(s) histogram(s, f, of) print("File " + of + " has been generated.") gp = open('_hist.gp', 'w') print('set style data histogram ', file=gp) print('set style histogram cluster gap 0', file=gp) print('set style fill solid 1.0', file=gp) print('plot \'' + of + '\' using 1:2 ti col smooth frequency with boxes', file=gp) gp.close() print("File _hist.gp has been generated.")
from histogram import * import sys # The number of arguments must be at least 2: the name of the file # with the raw data, and the size of the bin. f = sys.argv[1] of = "_hist_" + f print(f) s = float(sys.argv[2]) print(s) histogram(s,f,of) print("File "+of+" has been generated.") gp = open('_hist.gp','w') print('set style data histogram ',file=gp) print('set style histogram cluster gap 0',file=gp) print('set style fill solid 1.0',file=gp) print('plot \'' + of + '\' using 1:2 ti col smooth frequency with boxes',file=gp) gp.close() print("File _hist.gp has been generated.")