Example #1
0
 def test_histogram(self):
     # in this special case, cf.histogram and np.histogram must yield equal results
     # check hist and edges
     cfh, cfe = cf.histogram(self.data, bins=20, range=(0, 1), shape=0)
     nph, npe = np.histogram(self.data, bins=20, range=(0, 1))
     self.assertListEqual(list(nph), list(cfh))
     self.assertListEqual(list(npe), list(cfe))
 def test_histogram(self):
     # in this special case, cf.histogram and np.histogram must yield equal results
     # check hist and edges
     cfh, cfe = cf.histogram(self.data, bins=20, range=(0,1), shape=0)
     nph, npe = np.histogram(self.data, bins=20, range=(0,1))
     self.assertListEqual(list(nph), list(cfh))
     self.assertListEqual(list(npe), list(cfe))
Example #3
0
 def test_histogramo2(self):
     cfh, cfe = cf.histogram(self.data, bins=100, range=(0.0, 1.0), shape=2)
     nph, npe = np.histogram(self.data, bins=100, range=(0.0, 1.0))
     # just check that no mass is lost (cfh.base includes ghost cells)
     totalmass = len(self.data)
     self.assertAlmostEqual(np.sum(cfh.base) - totalmass, 0)
     self.assertAlmostEqual(np.sum(nph) - totalmass, 0)
     self.assertListEqual(list(npe), list(cfe))
 def test_histogramo2w(self):
     cfh, cfe = cf.histogram(self.data, bins=100, range=(0.0,1.0), shape=2, weights=self.weights)
     nph, npe = np.histogram(self.data, bins=100, range=(0.0,1.0), weights=self.weights)
     # just check that no mass is lost (cfh.base includes ghost cells)
     totalmass = np.sum(self.weights)
     self.assertAlmostEqual(np.sum(cfh.base) - totalmass, 0)
     self.assertAlmostEqual(np.sum(nph) - totalmass, 0)
     self.assertListEqual(list(npe), list(cfe))
 def test_histogramw(self):
     # in this special case, cf.histogram and np.histogram must yield equal results
     # check hist and edges
     cfh, cfe = cf.histogram(self.data, bins=100, range=(0,1), shape=0, weights=self.weights)
     nph, npe = np.histogram(self.data, bins=100, range=(0,1), weights=self.weights)
     diff = np.abs(cfh - nph)
     self.assertAlmostEqual(np.sum(diff), 0)
     self.assertListEqual(list(npe), list(cfe))
Example #6
0
 def time1D(data, bins, weights, shape, tn):
     t = timeit.Timer(lambda: cf.histogram(data,
                                           range=(0.001, 0.999),
                                           bins=bins,
                                           weights=weights,
                                           shape=shape))
     tc = t.timeit(number=5) / 5.0
     ws = '       ' if weights is None else 'weights'
     print('1D, {:d} shape, {:s}: {:0.2e} sec -> factor {:5.2f} faster'.
           format(shape, ws, tc, tn / tc))
Example #7
0
 def test_histogramw(self):
     # in this special case, cf.histogram and np.histogram must yield equal results
     # check hist and edges
     cfh, cfe = cf.histogram(self.data,
                             bins=100,
                             range=(0, 1),
                             shape=0,
                             weights=self.weights)
     nph, npe = np.histogram(self.data,
                             bins=100,
                             range=(0, 1),
                             weights=self.weights)
     diff = np.abs(cfh - nph)
     self.assertAlmostEqual(np.sum(diff), 0)
     self.assertListEqual(list(npe), list(cfe))
 def particleshapedemo(shape):
     import postpic.cythonfunctions as cf
     import matplotlib.pyplot as plt
     ptclpos = np.array([4.5, 9.75, 15.0, 20.25])
     y, edges = cf.histogram(ptclpos, bins=25, range=(0,25), shape=shape)
     x = np.convolve(edges, [0.5, 0.5], mode='valid')
     fig = plt.figure()
     fig.suptitle('ParticleShape: {:s}'.format(str(shape)))
     ax = fig.add_subplot(111)
     ax.plot(x,y)
     ax.set_ylim((0,1))
     ax.set_xticks(x, minor=True)
     ax.grid(which='minor')
     for ix in ptclpos:
         ax.axvline(x=ix, color='y')
     fig.savefig(savedir + 'particleshapedemo{:s}.png'.format(str(shape)), dpi=160)
     plt.close(fig)
Example #9
0
 def particleshapedemo(shape):
     import postpic.cythonfunctions as cf
     import matplotlib.pyplot as plt
     ptclpos = np.array([4.5, 9.75, 15.0, 20.25])
     y, edges = cf.histogram(ptclpos, bins=25, range=(0, 25), shape=shape)
     x = np.convolve(edges, [0.5, 0.5], mode='valid')
     fig = plt.figure()
     fig.suptitle('ParticleShape: {:s}'.format(str(shape)))
     ax = fig.add_subplot(111)
     ax.plot(x, y)
     ax.set_ylim((0, 1))
     ax.set_xticks(x, minor=True)
     ax.grid(which='minor')
     for ix in ptclpos:
         ax.axvline(x=ix, color='y')
     fig.savefig(savedir + 'particleshapedemo{:s}.png'.format(str(shape)),
                 dpi=160)
     plt.close(fig)
 def time1D(data, bins, weights, shape, tn):
     t = timeit.Timer(lambda: cf.histogram(data, range=(0.001,0.999), bins=bins, weights=weights, shape=shape))
     tc = t.timeit(number=5)/5.0
     ws = '       ' if weights is None else 'weights'
     print('1D, {:d} shape, {:s}: {:0.2e} sec -> factor {:5.2f} faster'.format(shape, ws, tc, tn/tc))