示例#1
0
 def testSetupSlicerBinsize(self):
     """Test setting up slicer using binsize."""
     dvmin = 0
     dvmax = 1
     dv = makeTimes(1000, dvmin, dvmax)
     binsize = 0.1
     for cumulative in ([True, False]):
         self.testslicer = MovieSlicer(sliceColName='times',
                                       binsize=binsize,
                                       cumulative=cumulative,
                                       forceNoFfmpeg=True)
         self.testslicer.setupSlicer(dv)
         # Bins of the right size?
         bindiff = np.diff(self.testslicer.bins)
         self.assertAlmostEqual(bindiff.max(), binsize)
         self.assertAlmostEqual(bindiff.min(), binsize)
     # Test that warning works.
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         self.testslicer = MovieSlicer(sliceColName='times',
                                       bins=200,
                                       binsize=binsize,
                                       cumulative=False,
                                       forceNoFfmpeg=True)
         self.testslicer.setupSlicer(dv)
         # Verify some things
         self.assertTrue("binsize" in str(w[-1].message))
示例#2
0
 def testSlicing(self):
     """Test slicing."""
     dvmin = 0
     dvmax = 1
     nbins = 100
     binsize = (dvmax - dvmin) / (float(nbins))
     # Test that testbinner raises appropriate error before it's set up (first time)
     self.assertRaises(NotImplementedError, self.testslicer._sliceSimData,
                       0)
     for nvalues in (100, 1000):
         dv = makeTimes(nvalues, dvmin, dvmax)
         # Test differential case.
         self.testslicer = MovieSlicer(sliceColName='times',
                                       bins=nbins,
                                       cumulative=False,
                                       forceNoFfmpeg=True)
         self.testslicer.setupSlicer(dv)
         sum = 0
         for i, s in enumerate(self.testslicer):
             idxs = s['idxs']
             dataslice = dv['times'][idxs]
             sum += len(idxs)
             if len(dataslice) > 0:
                 self.assertEqual(len(dataslice), nvalues / float(nbins))
             else:
                 raise ValueError(
                     'Data in test case expected to always be > 0 len after slicing'
                 )
         self.assertEqual(sum, nvalues)
         # And cumulative case.
         self.testslicer = MovieSlicer(sliceColName='times',
                                       bins=nbins,
                                       cumulative=True,
                                       forceNoFfmpeg=True)
         self.testslicer.setupSlicer(dv)
         for i, s in enumerate(self.testslicer):
             idxs = s['idxs']
             dataslice = dv['times'][idxs]
             self.assertTrue(len(dataslice) > 0)
示例#3
0
 def testSetupSlicerNbinsZeros(self):
     """Test what happens if give slicer test data that is all single-value."""
     dv = np.zeros(100, float)
     dv = np.array(zip(dv), dtype=[('times', 'float')])
     nbins = 10
     self.testslicer = MovieSlicer(sliceColName='times',
                                   bins=nbins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         self.testslicer.setupSlicer(dv)
         self.assertTrue("creasing binMax" in str(w[-1].message))
     self.assertEqual(self.testslicer.nslice, nbins)
示例#4
0
 def testSetupSlicerBins(self):
     """Test setting up slicer using defined bins."""
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     bins = np.arange(dvmin, dvmax, 0.1)
     dv = makeTimes(nvalues, dvmin, dvmax)
     # Used right bins?
     self.testslicer = MovieSlicer(sliceColName='times',
                                   bins=bins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     self.testslicer.setupSlicer(dv)
     np.testing.assert_equal(self.testslicer.bins, bins)
     self.assertEqual(self.testslicer.nslice, len(bins) - 1)
示例#5
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two Movie slicers will be considered equal if they are both the same kind of
     # slicer AND have the same bins.
     # Set up self..
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     bins = np.arange(dvmin, dvmax, 0.01)
     dv = makeTimes(nvalues, dvmin, dvmax)
     self.testslicer = MovieSlicer(sliceColName='times',
                                   bins=bins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     self.testslicer.setupSlicer(dv)
     # Set up another slicer to match (same bins, although not the same data).
     dv2 = makeTimes(nvalues + 100, dvmin, dvmax)
     testslicer2 = MovieSlicer(sliceColName='times',
                               bins=bins,
                               cumulative=False,
                               forceNoFfmpeg=True)
     testslicer2.setupSlicer(dv2)
     self.assertEqual(self.testslicer, testslicer2)
     # Set up another slicer that should not match (different bins)
     dv2 = makeTimes(nvalues, dvmin + 1, dvmax + 1)
     testslicer2 = MovieSlicer(sliceColName='times',
                               bins=len(bins),
                               cumulative=False,
                               forceNoFfmpeg=True)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
     # Set up a different kind of slicer that should not match.
     dv2 = makeTimes(100, 0, 1)
     testslicer2 = UniSlicer()
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
示例#6
0
 def testSetupSlicerLimits(self):
     """Test setting up slicer using binMin/Max."""
     binMin = 0
     binMax = 1
     nbins = 10
     dvmin = -.5
     dvmax = 1.5
     dv = makeTimes(1000, dvmin, dvmax)
     self.testslicer = MovieSlicer(sliceColName='times',
                                   binMin=binMin,
                                   binMax=binMax,
                                   bins=nbins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     self.testslicer.setupSlicer(dv)
     self.assertAlmostEqual(self.testslicer.bins.min(), binMin)
     self.assertAlmostEqual(self.testslicer.bins.max(), binMax)
示例#7
0
 def testIndexing(self):
     """Test iteration and indexing."""
     dvmin = 0
     dvmax = 1
     bins = np.arange(dvmin, dvmax + 0.05, 0.05)
     self.testslicer = MovieSlicer(sliceColName='times',
                                   bins=bins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     dv = makeTimes(1000, dvmin, dvmax)
     self.testslicer.setupSlicer(dv)
     for i, (s, b) in enumerate(zip(self.testslicer, bins)):
         self.assertEqual(s['slicePoint']['sid'], i)
         self.assertEqual(s['slicePoint']['binLeft'], b)
         self.assertTrue(s['slicePoint']['binRight'] <= bins[i + 1])
     for i in ([0, len(self.testslicer) / 2, len(self.testslicer) - 1]):
         self.assertEqual(self.testslicer[i]['slicePoint']['sid'], i)
         self.assertEqual(self.testslicer[i]['slicePoint']['binLeft'],
                          bins[i])
示例#8
0
 def setUp(self):
     self.testslicer = MovieSlicer(sliceColName='times',
                                   cumulative=False,
                                   forceNoFfmpeg=True)