def test_getting_bundle_data( self ): '''Test bundling a signal and getting the data back''' block = Bundle( self.q_in, self.q_out ) block.start() [self.q_in.put( i ) for i in self.input + [LastEvent()]] block.join() bundled_data = self.q_out.get() self.assertEqual( len( bundled_data ), 100 ) self.assertEqual( type( bundled_data ), numpy.ndarray ) values = bundled_data["Value"] self.assertTrue( all( values == 1 ) ) tags = bundled_data["Tag"] [self.assertEquals( tags[i] , i ) for i in xrange( 100 ) ]
def test_plotting(self): bundler = Bundle(self.q_in, self.q_out) bundlingPlotter = BundlePlotter(self.q_out, self.title) [block.start() for block in [bundler, bundlingPlotter]] [self.q_in.put(i) for i in self.input + [LastEvent()]] [block.join() for block in [bundler, bundlingPlotter]] self.assertTrue(os.path.exists(self.url))
def test_unbundle(self): '''Test the unbundler and the bundler''' bundler = Bundle(self.q_in, self.q_out) unbundler = Unbundle(self.q_out, self.q_out2) [block.start() for block in [bundler, unbundler]] [self.q_in.put(i) for i in self.input + [LastEvent()]] [block.join() for block in [bundler, unbundler]] [self.assertEquals(self.q_out2.get(), i) for i in self.input] self.assertTrue(self.q_out2.get().last)
def __init__(self): '''Setup the simulation''' connection1 = Channel() connection2 = Channel() connection3 = Channel() connection4 = Channel() src1 = Ramp(connection1) src2 = RandomSource(connection2) summer = Summer([connection1, connection2], connection3) bundler = Bundle(connection3, connection4) dst = BundlePlotter(connection4, title="Scipy-Simulation: Noise + Ramp Sum", show=True) #dst = Plotter(connection3) self.components = [src1, src2, summer, bundler, dst]
def __init__(self, N=5): '''Set up the simulation''' super(MultiSumPlot, self).__init__() wires = MakeChans(N + 2) # Create N random source blocks rndSources = [RandomSource(wires[i], resolution=15) for i in xrange(N)] # Create Summer Block summer = Summer(wires[:N], wires[N]) # Create Bundler Block bundler = Bundle(wires[N], wires[N + 1]) dst = BundleHistPlotter(wires[N + 1], title="Summing %d Noise sources" % N, show=True) self.components = rndSources + [summer, dst, bundler]
def test_getting_bundle_data(self): '''Test bundling a signal and getting the data back''' block = Bundle(self.q_in, self.q_out) block.start() [self.q_in.put(i) for i in self.input + [LastEvent()]] block.join() bundled_data = self.q_out.get() self.assertEqual(len(bundled_data), 100) self.assertEqual(type(bundled_data), numpy.ndarray) values = bundled_data["Value"] self.assertTrue(all(values == 1)) tags = bundled_data["Tag"] [self.assertEquals(tags[i], i) for i in xrange(100)]
def test_first_order_diff(self): '''Test a first order diff''' input_values = [0, 1, 2, 3, 3, 3, 3, 1] outs = [1, 1, 1, 0, 0, 0, -2] self.input = [Event(value=input_values[i], tag=i) for i in xrange(len(input_values))] bundler = Bundle(self.q_in, self.q_out) diffblock = BundleDerivative(self.q_out, self.q_out2, threshold=50) [self.q_in.put(i) for i in self.input + [LastEvent()]] [block.start() for block in [bundler, diffblock]] [block.join() for block in [bundler, diffblock]] outputs = self.q_out2.get() self.assertNotEqual(outputs, None) [self.assertEquals(outs[i], outputs['Value'][i]) for i in xrange(len(outs))] self.assertTrue(self.q_out2.get().last)
def test_bundle_full_signal(self): '''Test sending a basic integer tagged signal all at once''' bundle_size = 1000 #expected_output = [Event(value=1, tag=i + delay) for i in xrange(100)] block = Bundle(self.q_in, self.q_out, bundle_size) block.start() [self.q_in.put(i) for i in self.input + [LastEvent()]] block.join() actual_output = self.q_out.get() self.assertEqual(actual_output.size, 100) self.assertTrue(self.q_out.get().last)