Ejemplo n.º 1
0
    def test_read_integer(self):
        """
        Tests if spike times are actually stored as integers if they are stored
        in time steps in the file.
        """
        filename = self.get_local_path('nest/0time_in_steps-1257-0.gdf')
        r = NestIO(filenames=filename)
        st = r.read_spiketrain(gdf_id=None, t_start=400. * pq.ms,
                               t_stop=500. * pq.ms,
                               time_unit=pq.CompoundUnit('0.1*ms'),
                               lazy=False, id_column=None, time_column=0)
        self.assertTrue(st.magnitude.dtype == np.int32)
        seg = r.read_segment(gid_list=[None], t_start=400. * pq.ms,
                             t_stop=500. * pq.ms,
                             time_unit=pq.CompoundUnit('0.1*ms'),
                             lazy=False, id_column_gdf=None, time_column_gdf=0)
        sts = seg.spiketrains
        self.assertTrue(all([st.magnitude.dtype == np.int32 for st in sts]))

        filename = self.get_local_path('nest/0gid-1time_in_steps-1258-0.gdf')
        r = NestIO(
            filenames=filename)
        st = r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms,
                               t_stop=500. * pq.ms,
                               time_unit=pq.CompoundUnit('0.1*ms'),
                               lazy=False, id_column=0, time_column=1)
        self.assertTrue(st.magnitude.dtype == np.int32)
        seg = r.read_segment(gid_list=[1], t_start=400. * pq.ms,
                             t_stop=500. * pq.ms,
                             time_unit=pq.CompoundUnit('0.1*ms'),
                             lazy=False, id_column_gdf=0, time_column_gdf=1)
        sts = seg.spiketrains
        self.assertTrue(all([st.magnitude.dtype == np.int32 for st in sts]))
Ejemplo n.º 2
0
 def test_t_stop_undefined_raises_error(self):
     """
     Tests if undefined t_stop, i.e., t_stop=None raises error.
     """
     filename = self.get_local_path('nest/0gid-1time-1256-0.gdf')
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, lazy=False,
                           id_column=0, time_column=1)
     with self.assertRaises(ValueError):
         r.read_segment(gid_list=[1, 2, 3], t_start=400. * pq.ms, lazy=False,
                        id_column_gdf=0, time_column_gdf=1)
 def test_t_stop_undefined_raises_error(self):
     """
     Tests if undefined t_stop, i.e., t_stop=None raises error.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, lazy=False,
                           id_column=0, time_column=1)
     with self.assertRaises(ValueError):
         r.read_segment(gid_list=[1, 2, 3], t_start=400. * pq.ms, lazy=False,
                        id_column_gdf=0, time_column_gdf=1)
Ejemplo n.º 4
0
 def test_t_stop_undefined_raises_error(self):
     """
     Tests if undefined t_stop, i.e., t_stop=None raises error.
     """
     filename = get_test_file_full_path(
         ioclass=NestIO,
         filename='0gid-1time-1256-0.gdf',
         directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, lazy=False,
                           id_column=0, time_column=1)
     with self.assertRaises(ValueError):
         r.read_segment(gid_list=[1, 2, 3], t_start=400. * pq.ms, lazy=False,
                        id_column_gdf=0, time_column_gdf=1)
Ejemplo n.º 5
0
 def test_read_float(self):
     """
     Tests if spike times are stored as floats if they
     are stored as floats in the file.
     """
     filename = get_test_file_full_path(ioclass=NestIO,
                                        filename='0gid-1time-1256-0.gdf',
                                        directory=self.local_test_dir,
                                        clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=1,
                            t_start=400. * pq.ms,
                            t_stop=500. * pq.ms,
                            lazy=False,
                            id_column=0,
                            time_column=1)
     self.assertTrue(st.magnitude.dtype == np.float)
     seg = r.read_segment(gid_list=[1],
                          t_start=400. * pq.ms,
                          t_stop=500. * pq.ms,
                          lazy=False,
                          id_column_gdf=0,
                          time_column_gdf=1)
     sts = seg.spiketrains
     self.assertTrue(all([s.magnitude.dtype == np.float for s in sts]))
Ejemplo n.º 6
0
 def test_read_spiketrain_annotates(self):
     """
     Tests if correct annotation is added when reading a spike train.
     """
     filename = self.get_local_path('nest/0gid-1time-1256-0.gdf')
     r = NestIO(filenames=filename)
     ID = 7
     st = r.read_spiketrain(gdf_id=ID, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms)
     self.assertEqual(ID, st.annotations['id'])
Ejemplo n.º 7
0
 def test_read_spiketrain_can_return_empty_spiketrain(self):
     """
     Tests if read_spiketrain returns an empty SpikeTrain if no spikes are in
     time range.
     """
     filename = self.get_local_path('nest/0gid-1time-1256-0.gdf')
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=410. * pq.ms)
     self.assertEqual(st.size, 0)
Ejemplo n.º 8
0
    def test_read_spiketrain(self):
        """
        Tests reading files in the 4 different formats:
        - without GIDs, with times as floats
        - without GIDs, with times as integers in time steps
        - with GIDs, with times as floats
        - with GIDs, with times as integers in time steps
        """
        filename = get_test_file_full_path(
            ioclass=NestIO,
            filename='0time-1255-0.gdf',
            directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms, lazy=False,
                          id_column=None, time_column=0)
        r.read_segment(t_start=400. * pq.ms, t_stop=500. * pq.ms, lazy=False,
                       id_column_gdf=None, time_column_gdf=0)

        filename = get_test_file_full_path(
            ioclass=NestIO,
            filename='0time_in_steps-1257-0.gdf',
            directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                          id_column=None, time_column=0)
        r.read_segment(t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                       id_column_gdf=None, time_column_gdf=0)

        filename = get_test_file_full_path(
            ioclass=NestIO,
            filename='0gid-1time-1256-0.gdf',
            directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          lazy=False, id_column_gdf=0, time_column_gdf=1)
        r.read_segment(gid_list=[1], t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       lazy=False, id_column_gdf=0, time_column_gdf=1)

        filename = get_test_file_full_path(
            ioclass=NestIO,
            filename='0gid-1time_in_steps-1258-0.gdf',
            directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                          id_column=0, time_column=1)
        r.read_segment(gid_list=[1], t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                       id_column_gdf=0, time_column_gdf=1)
    def test_read_spiketrain(self):
        """
        Tests reading files in the 4 different formats:
        - without GIDs, with times as floats
        - without GIDs, with times as integers in time steps
        - with GIDs, with times as floats
        - with GIDs, with times as integers in time steps
        """
        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0time-1255-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms, lazy=False,
                          id_column=None, time_column=0)
        r.read_segment(t_start=400. * pq.ms, t_stop=500. * pq.ms, lazy=False,
                       id_column_gdf=None, time_column_gdf=0)

        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0time_in_steps-1257-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                          id_column=None, time_column=0)
        r.read_segment(t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                       id_column_gdf=None, time_column_gdf=0)

        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0gid-1time-1256-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          lazy=False, id_column_gdf=0, time_column_gdf=1)
        r.read_segment(gid_list=[1], t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       lazy=False, id_column_gdf=0, time_column_gdf=1)

        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0gid-1time_in_steps-1258-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms, t_stop=500. * pq.ms,
                          time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                          id_column=0, time_column=1)
        r.read_segment(gid_list=[1], t_start=400. * pq.ms, t_stop=500. * pq.ms,
                       time_unit=pq.CompoundUnit('0.1*ms'), lazy=False,
                       id_column_gdf=0, time_column_gdf=1)
 def test_read_spiketrain_annotates(self):
     """
     Tests if correct annotation is added when reading a spike train.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     ID = 7
     st = r.read_spiketrain(gdf_id=ID, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms)
     self.assertEqual(ID, st.annotations['id'])
    def test_read_integer(self):
        """
        Tests if spike times are actually stored as integers if they are stored
        in time steps in the file.
        """
        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0time_in_steps-1257-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(filenames=filename)
        st = r.read_spiketrain(gdf_id=None, t_start=400. * pq.ms,
                               t_stop=500. * pq.ms,
                               time_unit=pq.CompoundUnit('0.1*ms'),
                               lazy=False, id_column=None, time_column=0)
        self.assertTrue(st.magnitude.dtype == np.int32)
        seg = r.read_segment(gid_list=[None], t_start=400. * pq.ms,
                             t_stop=500. * pq.ms,
                             time_unit=pq.CompoundUnit('0.1*ms'),
                             lazy=False, id_column_gdf=None, time_column_gdf=0)
        sts = seg.spiketrains
        self.assertTrue(all([st.magnitude.dtype == np.int32 for st in sts]))

        filename = get_test_file_full_path(
                ioclass=NestIO,
                filename='0gid-1time_in_steps-1258-0.gdf',
                directory=self.local_test_dir, clean=False)
        r = NestIO(
                filenames=filename)
        st = r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms,
                               t_stop=500. * pq.ms,
                               time_unit=pq.CompoundUnit('0.1*ms'),
                               lazy=False, id_column=0, time_column=1)
        self.assertTrue(st.magnitude.dtype == np.int32)
        seg = r.read_segment(gid_list=[1], t_start=400. * pq.ms,
                             t_stop=500. * pq.ms,
                             time_unit=pq.CompoundUnit('0.1*ms'),
                             lazy=False, id_column_gdf=0, time_column_gdf=1)
        sts = seg.spiketrains
        self.assertTrue(all([st.magnitude.dtype == np.int32 for st in sts]))
Ejemplo n.º 12
0
 def test_adding_custom_annotation(self):
     """
     Tests if custom annotation is correctly added.
     """
     filename = self.get_local_path('nest/0gid-1time-1256-0.gdf')
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms,
                            layer='L23', population='I')
     self.assertEqual(0, st.annotations.pop('id'))
     self.assertEqual('L23', st.annotations.pop('layer'))
     self.assertEqual('I', st.annotations.pop('population'))
     self.assertEqual({}, st.annotations)
 def test_read_spiketrain_can_return_empty_spiketrain(self):
     """
     Tests if read_spiketrain returns an empty SpikeTrain if no spikes are in
     time range.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=1. * pq.ms)
     self.assertEqual(st.size, 0)
Ejemplo n.º 14
0
 def test_read_spiketrain_can_return_empty_spiketrain(self):
     """
     Tests if read_spiketrain returns an empty SpikeTrain if no spikes are in
     time range.
     """
     filename = get_test_file_full_path(
         ioclass=NestIO,
         filename='0gid-1time-1256-0.gdf',
         directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=410. * pq.ms)
     self.assertEqual(st.size, 0)
Ejemplo n.º 15
0
 def test_read_spiketrain_annotates(self):
     """
     Tests if correct annotation is added when reading a spike train.
     """
     filename = get_test_file_full_path(
         ioclass=NestIO,
         filename='0gid-1time-1256-0.gdf',
         directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     ID = 7
     st = r.read_spiketrain(gdf_id=ID, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms)
     self.assertEqual(ID, st.annotations['id'])
 def test_adding_custom_annotation(self):
     """
     Tests if custom annotation is correctly added.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms,
                            layer='L23', population='I')
     self.assertEqual(0, st.annotations.pop('id'))
     self.assertEqual('L23', st.annotations.pop('layer'))
     self.assertEqual('I', st.annotations.pop('population'))
     self.assertEqual({}, st.annotations)
Ejemplo n.º 17
0
 def test_adding_custom_annotation(self):
     """
     Tests if custom annotation is correctly added.
     """
     filename = get_test_file_full_path(
         ioclass=NestIO,
         filename='0gid-1time-1256-0.gdf',
         directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms,
                            layer='L23', population='I')
     self.assertEqual(0, st.annotations.pop('id'))
     self.assertEqual('L23', st.annotations.pop('layer'))
     self.assertEqual('I', st.annotations.pop('population'))
     self.assertEqual({}, st.annotations)
 def test_read_float(self):
     """
     Tests if spike times are stored as floats if they
     are stored as floats in the file.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     st = r.read_spiketrain(gdf_id=1, t_start=400. * pq.ms,
                            t_stop=500. * pq.ms,
                            lazy=False, id_column=0, time_column=1)
     self.assertTrue(st.magnitude.dtype == np.float)
     seg = r.read_segment(gid_list=[1], t_start=400. * pq.ms,
                          t_stop=500. * pq.ms,
                          lazy=False, id_column_gdf=0, time_column_gdf=1)
     sts = seg.spiketrains
     self.assertTrue(all([s.magnitude.dtype == np.float for s in sts]))
Ejemplo n.º 19
0
 def test_gdf_id_illdefined_raises_error(self):
     """
     Tests if ill-defined gdf_id in read_spiketrain (i.e., None, list, or
     empty list) raises error.
     """
     filename = self.get_local_path('nest/0gid-1time-1256-0.gdf')
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[1], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms)
Ejemplo n.º 20
0
 def test_gdf_id_illdefined_raises_error(self):
     """
     Tests if ill-defined gdf_id in read_spiketrain (i.e., None, list, or
     empty list) raises error.
     """
     filename = get_test_file_full_path(
         ioclass=NestIO,
         filename='0gid-1time-1256-0.gdf',
         directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[1], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms)
 def test_gdf_id_illdefined_raises_error(self):
     """
     Tests if ill-defined gdf_id in read_spiketrain (i.e., None, list, or
     empty list) raises error.
     """
     filename = get_test_file_full_path(
             ioclass=NestIO,
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
     r = NestIO(filenames=filename)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(gdf_id=[1], t_start=400. * pq.ms,
                           t_stop=500. * pq.ms)
     with self.assertRaises(ValueError):
         r.read_spiketrain(t_start=400. * pq.ms, t_stop=500. * pq.ms)