Exemplo n.º 1
0
    def test_write_many_channels_transposed(self):
        'read/write more realistic test with transposed array'
        filetype = 'gdf2'
        filename = test_file(filetype, 'write')
        ns = 5 * 1000
        nch = 23
        test_array = numpy.random.rand(nch, ns).T

        f = XFile(filename, 'w', filetype)
        f.fs = 500
        for i in range(nch):
            ch_name = 'test_channel_{:d}'.format(i)
            f.channels.append(Channel(ch_name, -2., 2., 'dummy'))
        f.write(test_array)

        # open back for reading
        f = XFile(filename, 'r', filetype)

        # test metadatas
        # self.assertEqual(f.fs, 42)
        self.assertEqual(len(f.channels), nch)
        for i in range(nch):
            ch_name = 'test_channel_{:d}'.format(i)
            self.assertEqual(
                f.channels[i], {
                    'name': ch_name,
                    'physical_min': -2.,
                    'physical_max': 2.,
                    'unit': 'dummy'
                })

        # test data
        data = f.read()
        # test the first few data only: xdf formats do not support writing
        # less than a record. Record length is not configurable.
        self.assertGreaterEqual(len(data), ns)
        self.assertEqual(len(data[0]), nch)
        for i in range(ns):
            for j in range(nch):
                self.assertAlmostEqual(data[i][j],
                                       test_array[i][j],
                                       places=precision(filetype))
Exemplo n.º 2
0
    def test_write_simple(self):
        'read/write smoke test'
        for filetype in ['edf', 'bdf', 'gdf2']:
            filename = test_file(filetype, 'write')
            test_array = numpy.random.rand(7, 1)  # ns = 7, nch = 1

            f = XFile(filename, 'w', filetype)
            f.fs = 42
            f.channels.append(Channel('test_channel', -2., 2., 'dummy'))
            f.write(test_array)

            # open back for reading
            f = XFile(filename, 'r', filetype)

            # test metadatas
            # self.assertEqual(f.fs, 42)
            self.assertEqual(len(f.channels), 1)
            self.assertEqual(
                f.channels[0], {
                    'name': 'test_channel',
                    'physical_min': -2.,
                    'physical_max': 2.,
                    'unit': 'dummy'
                })

            # test data
            data = f.read()
            # test the first few data only: xdf formats do not support writing
            # less than a record. Record length is not configurable.
            self.assertGreater(len(data), len(test_array))
            self.assertEqual(len(data[0]), 1)
            for i in range(len(test_array)):
                # TODO: be less permissive
                # The rounding error depends on the closest stored data type
                # eg. edf only supported 16-bits data types, and that comes with
                # severe changes during rounding ...
                self.assertAlmostEqual(data[i][0],
                                       test_array[i][0],
                                       places=precision(filetype))
Exemplo n.º 3
0
    def test_readwrite_fields(self):
        'ensure that we can write on writable fields'
        f = XFile(test_file('gdf2', 'write'), 'w', 'gdf2')
        f.channels.append(Channel('test_channel', -2., 2., 'dummy'))
        self.assertEqual(len(f.channels), 1)
        self.assertEqual(
            f.channels[0], {
                'name': 'test_channel',
                'physical_min': -2.,
                'physical_max': 2.,
                'unit': 'dummy'
            })

        f.fs = 42.
        self.assertEqual(f.fs, 42.)

        f.record_time = 42.
        self.assertEqual(f.record_time, 42.)

        f.subject_desc = "dummy subject desc"
        self.assertEqual(f.subject_desc, "dummy subject desc")

        f.session_desc = "dummy session desc"
        self.assertEqual(f.session_desc, "dummy session desc")