예제 #1
0
 def test_matplotlib_figure(self):
     # Test figure drawing method (doesn't inspect output).
     # Select matplotlib backend that doesn't require a screen
     import matplotlib
     matplotlib.use('template')
     path = os.path.join(DIR_FORMATS, 'abf-v1.abf')
     abf = axon.AbfFile(path)
     abf.matplotlib_figure()
예제 #2
0
    def test_read_protocol_v1(self):
        # Test reading a v1 protocol file.

        # Load file
        path = os.path.join(DIR_FORMATS, 'abf-protocol.pro')
        abf = axon.AbfFile(path)

        # Check version info
        self.assertIn('version 1.65', abf.info())
        self.assertEqual(
            abf.info(),
            'Axon Protocol File: abf-protocol.pro\n'
            'ABF Format version 1.65\n'
            'Recorded on: 2005-06-17 14:33:02.160000\n'
            'Acquisition mode: 5: Episodic stimulation mode\n'
            'Protocol set for 1 trials, spaced 0.0s apart.\n'
            '    with 1 runs per trial, spaced 0.0s apart.\n'
            '     and 30 sweeps per run, spaced 5.0s apart.\n'
            'Sampling rate: 20000.0 Hz'
        )
        # Test getting full header runs without crashing
        abf.info(True)

        # Load, force as protocol
        path = os.path.join(DIR_FORMATS, 'abf-protocol.pro')
        abf = axon.AbfFile(path, is_protocol_file=True)

        # Check version info
        self.assertIn('version 1.65', abf.info())
        self.assertIn('Axon Protocol File', abf.info())

        # Test protocol extraction
        p = abf.myokit_protocol()
        self.assertEqual(len(p), 60)

        # Test step extraction
        p = abf.protocol_steps()
        self.assertEqual(len(p), 1)
        self.assertEqual(len(p[0]), 30)
예제 #3
0
    def test_read_v2(self):
        # Test reading a version 2 file.

        # Load file
        path = os.path.join(DIR_FORMATS, 'abf-v2.abf')
        abf = axon.AbfFile(path)

        # Check version info
        self.assertIn('version 2.0', abf.info())
        self.assertEqual(
            abf.info(),
            'Axon Binary File: abf-v2.abf\n'
            'ABF Format version 2.0\n'
            'Recorded on: 2014-10-01 14:03:55.980999\n'
            'Acquisition mode: 5: Episodic stimulation mode\n'
            'Protocol set for 1 trials, spaced 0.0s apart.\n'
            '    with 1 runs per trial, spaced 0.0s apart.\n'
            '     and 1 sweeps per run, spaced 5.0s apart.\n'
            'Sampling rate: 10000.0 Hz\n'
            'Channel 0: "IN 0"\n'
            '  Unit: pA\n'
            '  Low-pass filter: 10000.0 Hz\n'
            '  Cm (telegraphed): 6.34765625 pF')
        # Test getting full header runs without crashing
        abf.info(True)

        # Test len returns number of sweeps
        self.assertEqual(len(abf), 1)

        # Test data access
        self.assertEqual(abf.data_channels(), 1)    # 1 data channel
        x = abf.extract_channel(0)
        self.assertEqual(len(x), 1 + len(abf))      # sweeps + time
        self.assertEqual(len(x[0]), len(x[1]))
        y = abf.extract_channel_as_myokit_log(0)
        self.assertEqual(len(y), 1 + len(abf))      # sweeps + time
        z = abf.myokit_log()
        self.assertEqual(len(z), 6)     # time + channel + 4 protocol channels
        sweep = abf[0]
        self.assertEqual(len(sweep), 1)     # 1 channel in sweep
        channel = sweep[0]
        self.assertEqual(len(abf) * len(channel.times()), len(z.time()))
        self.assertEqual(len(abf) * len(channel.values()), len(z.time()))

        # Test protocol extraction
        self.assertEqual(abf.protocol_channels(), 4)    # 4 protocol channels
        p = abf.myokit_protocol()
        self.assertEqual(len(p), 2)     # 2 steps in this protocol
        self.assertEqual(abf.protocol_holding_level(0), -120)
        p = abf.myokit_protocol(0)
        self.assertEqual(len(p), 2)
예제 #4
0
    def test_read_v1(self):
        # Test reading a version 1 file.

        # Load file
        path = os.path.join(DIR_FORMATS, 'abf-v1.abf')
        abf = axon.AbfFile(path)
        self.assertEqual(abf.filename(), path)

        # Check version info
        self.assertIn('version 1.65', abf.info())
        self.assertEqual(
            abf.info(),
            'Axon Binary File: abf-v1.abf\n'
            'ABF Format version 1.65\n'
            'Recorded on: 2014-11-14 12:52:29.389999\n'
            'Acquisition mode: 5: Episodic stimulation mode\n'
            'Protocol set for 1 trials, spaced 0.0s apart.\n'
            '    with 1 runs per trial, spaced 0.0s apart.\n'
            '     and 9 sweeps per run, spaced 0.5s apart.\n'
            'Sampling rate: 10000.0 Hz\n'
            'Channel 0: "IN 0      "\n'
            '  Unit: pA'
        )
        # Test getting full header runs without crashing
        abf.info(True)

        # Test len returns number of sweeps
        self.assertEqual(len(abf), 9)

        # Test data access
        self.assertEqual(abf.data_channels(), 1)    # 1 data channel
        x = abf.extract_channel(0)
        self.assertEqual(len(x), 1 + len(abf))      # sweeps + time
        self.assertEqual(len(x[0]), len(x[1]))
        self.assertEqual(len(x[0]), len(x[2]))
        self.assertEqual(len(x[0]), len(x[3]))
        self.assertEqual(len(x[0]), len(x[4]))
        self.assertEqual(len(x[0]), len(x[5]))
        self.assertEqual(len(x[0]), len(x[6]))
        self.assertEqual(len(x[0]), len(x[7]))
        self.assertEqual(len(x[0]), len(x[8]))
        self.assertEqual(len(x[0]), len(x[9]))
        y = abf.extract_channel_as_myokit_log(0)
        self.assertEqual(len(y), 1 + len(abf))      # sweeps + time
        z = abf.myokit_log()
        self.assertEqual(len(z), 6)     # time + channel + 4 protocol channels
        sweep = abf[0]
        self.assertEqual(len(sweep), 1)     # 1 channel in sweep
        channel = sweep[0]
        self.assertIsInstance(channel.number(), int)
        self.assertIn('Channel', str(channel))
        self.assertEqual(len(abf) * len(channel.times()), len(z.time()))
        self.assertEqual(len(abf) * len(channel.values()), len(z.time()))

        # Test reading of sweeps as one long array
        x, y = abf.extract_channel(0, join=True)
        z = abf.extract_channel(0)
        self.assertEqual(len(x), len(y))
        self.assertEqual(len(x), len(abf) * len(z[0]))
        self.assertTrue(np.all(x[1:] > x[:-1]))

        # Test protocol extraction
        self.assertEqual(abf.protocol_channels(), 4)    # 4 protocol channels
        p = abf.myokit_protocol()
        self.assertEqual(len(p), 18)    # 18 steps in this protocol
        self.assertEqual(abf.protocol_holding_level(0), 0)
        p = abf.myokit_protocol(0)
        self.assertEqual(len(p), 18)