本文整理汇总了Python中histogram.Histogram类的典型用法代码示例。如果您正苦于以下问题:Python Histogram类的具体用法?Python Histogram怎么用?Python Histogram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Histogram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cut_2d
def test_cut_2d(self):
h2 = Histogram((100,[0,10]),(90,[-3,3]))
#h2a = h2.cut((-1,1),axis=0)
h3 = Histogram((100,[-30,330]), (100,[-50,50]))
#h3a = h3.cut(-30,30,axis=0)
h3b = h3.cut(270,330,axis=0)
示例2: producerLoop
def producerLoop(exclusiveUnprocessedFileQueue, processedHistogramBuffer, numProducers):
'''
loops through, each time grabs a file from the unprocessed queue
and creates an individual histogram for that file.
Then adds that histogram to the processed buffer
for the consumer to acess
'''
global doneProducing
#while not doneProducing:
while not exclusiveUnprocessedFileQueue.isEmpty():
fileToProcess = exclusiveUnprocessedFileQueue.pop()
if fileToProcess != None: #none returned if unprocessed q was empty
#makes individual file histogram
fileHistogram = Histogram(fileToProcess)
fileHistogram.buildHistogram()
processedHistogramBuffer.add(fileHistogram)
itemsAvailable.release()
else:
continue
producerProcessedLock.acquire()
if exclusiveUnprocessedFileQueue.isEmpty() and not doneProducing:
doneProducing = 1
producerProcessedLock.release()
#tells consumer that a thread is done processing
itemsAvailable.release()
示例3: _get_ping_property
def _get_ping_property(cursor, path):
is_histogram = False
is_keyed_histogram = False
if path[0] == "histograms":
is_histogram = True
elif path[0] == "keyedHistograms":
# Deal with histogram names that contain a slash...
path = path[:2] + (["/".join(path[2:])] if len(path) > 2 else [])
is_keyed_histogram = True
for partial in path:
cursor = cursor.get(partial, None)
if cursor is None:
break
if cursor is None:
return None
if is_histogram:
return Histogram(path[-1], cursor)
elif is_keyed_histogram:
histogram = Histogram(path[-2], cursor)
histogram.name = "/".join(path[1:])
return histogram
else:
return cursor
示例4: _get_ping_property
def _get_ping_property(cursor, path, histograms_url, additional_histograms):
is_histogram = False
is_keyed_histogram = False
if path[0] == "histograms":
is_histogram = True
elif path[0] == "keyedHistograms":
# Deal with histogram names that contain a slash...
path = path[:2] + (["/".join(path[2:])] if len(path) > 2 else [])
is_keyed_histogram = True
try:
for field in path:
cursor = cursor[field]
except:
return None
if cursor is None:
return None
if is_histogram:
return Histogram(path[-1], cursor, histograms_url=histograms_url,
additional_histograms=additional_histograms)
elif is_keyed_histogram:
histogram = Histogram(path[-2], cursor, histograms_url=histograms_url,
additional_histograms=additional_histograms)
histogram.name = "/".join(path[-2:])
return histogram
else:
return cursor
示例5: __init__
def __init__(self, dates, open, high, low, close, vol, start, end):
if start > end:
(start, end) = (end, start)
self.report_log = []
max = None
max_date = None
min = None
min_date = None
seq_start = dates[0]
seq_end = dates[0]
series = []
n = 0
for i in range(len(dates)):
d = dates[i]
if (d > start) and (d < end):
series.append(close[i])
if (d < seq_start):
seq_start = d
if (d > seq_end):
seq_end = d
n = n + 1
h = high[i]
if max == None:
max = h
max_date = d
else:
if h > max:
max = h
max_date = d
l = low[i]
if min == None:
min = l
min_date = d
else:
if l < min:
min = l
min_date = d
self.report_log.append('%s - %s' % (seq_start, seq_end))
self.report_log.append('%d trading days' % n)
self.report_log.append('Max = %s - %s' % (str(max), max_date))
self.report_log.append('Min = %s - %s' % (str(min), min_date))
h = Histogram(series)
for l in h.report():
self.report_log.append(l)
示例6: load_hue_histograms
def load_hue_histograms(self):
for h in self.known_histograms.keys():
hist = Histogram()
hist.load(self.known_histograms[h][0])
self.known_histograms[h][1] = hist
for h in self.known_histograms:
print h
print self.known_histograms[h][1]
示例7: test_plot_hist2d
def test_plot_hist2d():
npoints = 100000
h2 = Histogram((100,(0,10),'x'),(100,(0,10),'y'),'z','title')
h2.fill(rand.normal(5,2,npoints),
rand.uniform(0,10,npoints))
fig,ax = pyplot.subplots(1,2)
ax[0].plothist(h2)
ax[1].plothist(h2)
ax[1].plothist(h2.smooth(1), style='contour', overlay=True)
pyplot.savefig('test_images/test_plotting_fig_hist2d.png')
示例8: test_1dfit
def test_1dfit(self):
p = [100, -20, 1, -0.2]
h = Histogram(100, [0, 10])
x = h.axes[0].bincenters
h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))
p0 = [1, 1, 1, 1]
popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)
assert np.allclose(popt, p, rtol=0.03, atol=0.5)
assert pcov.shape == (len(p), len(p))
示例9: test_plot_hist1d
def test_plot_hist1d():
npoints = 100000
h1 = Histogram(100,(0,10),'x','y','title')
h1.fill(rand.normal(5,2,npoints))
fig,ax = pyplot.subplots(2,2)
ax[0,0].plothist(h1, style='polygon' , baseline='bottom')
ax[0,1].plothist(h1, style='errorbar', baseline='bottom')
ax[1,0].plothist(h1, style='polygon' )#, baseline='left')
ax[1,1].plothist(h1, style='errorbar')#, baseline='left')
pyplot.savefig('test_images/test_plotting_fig_hist1d.png')
示例10: HistogramTest
class HistogramTest(unittest.TestCase):
def setUp(self):
self.h = Histogram()
self.h.add("Apache")
self.h.add("Apache")
def test_add(self):
assert self.h.get_dict().get("Apache") is not None
def test_count(self):
self.assertEqual(self.h.count("Apache"), 2)
示例11: test_2dfit
def test_2dfit(self):
fn = lambda xy, *p: poly(p[:4])(xy[0]) + poly([0] + list(p[4:]))(xy[1])
p = [100, -20, 1, -0.2, 80, -5, 0.8]
h = Histogram(100, [0, 10], 100, [0, 10])
xy = h.grid
h.data = fn(xy, *p)
h.data += rand.normal(0, np.sqrt(p[0]), h.data.shape)
p0 = [1, 1, 1, 1, 1, 1, 1]
popt, pcov, ptest = h.fit(fn, p0)
assert np.allclose(popt, p, rtol=0.01, atol=0.01)
assert pcov.shape == (len(p), len(p))
示例12: test_1dfit_zeros
def test_1dfit_zeros(self):
p = [100, -20, 1, -0.2]
h = Histogram(100, [0, 10])
x = h.axes[0].bincenters
h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))
ii = rand.randint(0, h.axes[0].nbins, 5)
h.data[ii] = 0
p0 = [1, 1, 1, 1]
popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)
assert np.allclose(popt, p, rtol=0.1, atol=1.0)
assert pcov.shape == (len(p), len(p))
示例13: test_mean
def test_mean(self):
h = Histogram(10,[0,10])
h.fill([3,3,3])
assert_almost_equal(h.mean()[0],3.5)
h.fill([1,5])
assert_almost_equal(h.mean()[0],3.5)
示例14: test_rebin
def test_rebin(self):
h = Histogram(10,[0,10])
h.set(1)
hexpect = Histogram(5,[0,10])
hexpect.set(2)
hrebin = h.rebin(2)
assert_array_almost_equal(hrebin.data, hexpect.data)
assert_array_almost_equal(hrebin.axes[0].edges, hexpect.axes[0].edges)
示例15: test_hdf5
def test_hdf5(self):
try:
import h5py
h = self.h.clone()
filename = 'h.hdf5'
h.save(filename)
hh = Histogram.load(filename)
assert h.isidentical(hh)
except ImportError:
pass