Exemplo n.º 1
0
    def test_functional_connectivity(self):
        # assert log warning was issued
        root_logger = logging.getLogger()
        with self.assertLogs(root_logger, level="ERROR") as cm:
            fcs = self.signal.functional_connectivity()
            self.assertEqual(
                cm.output,
                [
                    "ERROR:root:Cannot compute functional connectivity from one timeseries."
                ],
            )
        # should be None when computing on one timeseries
        self.assertEqual(None, fcs)

        # now proper example with network - 3D case
        ds = Dataset("gw")
        aln = ALNModel(Cmat=ds.Cmat, Dmat=ds.Dmat)
        # in ms, simulates for 2 minutes
        aln.params["duration"] = 2 * 1000
        aln.run()
        network_sig = RatesSignal.from_model_output(aln)
        fcs = network_sig.functional_connectivity()
        self.assertTrue(isinstance(fcs, xr.DataArray))
        correct_shape = (network_sig.shape[0], network_sig.shape[1],
                         network_sig.shape[1])
        self.assertTupleEqual(fcs.shape, correct_shape)

        # 2D case
        fc = network_sig["rates_exc"].functional_connectivity()
        self.assertTrue(isinstance(fc, xr.DataArray))
        correct_shape = (network_sig.shape[1], network_sig.shape[1])
        self.assertTupleEqual(fc.shape, correct_shape)
Exemplo n.º 2
0
 def test_load_save(self):
     # create temp folder
     os.makedirs(self.TEST_FOLDER)
     # save
     filename = os.path.join(self.TEST_FOLDER, "temp")
     # do operation so we also test saving and loading of preprocessing steps
     self.signal.normalize(std=True)
     # test basic properties
     repr(self.signal)
     str(self.signal)
     self.signal.shape
     self.signal.dims_not_time
     self.signal.coords_not_time
     self.signal.start_time
     self.signal.end_time
     self.signal.time
     self.signal.preprocessing_steps
     # now save
     self.signal.save(filename)
     # load
     loaded = RatesSignal.from_file(filename)
     # remove folder
     rmtree(self.TEST_FOLDER)
     # compare they are equal
     self.assertEqual(self.signal, loaded)
Exemplo n.º 3
0
 def setUpClass(cls):
     np.random.seed(42)
     aln = ALNModel()
     # simulate 10 seconds
     aln.params["duration"] = 10.0 * 1000
     aln.params["sigma_ou"] = 0.1  # add some noise
     aln.run()
     # init RatesSignal
     cls.signal = RatesSignal.from_model_output(aln)
Exemplo n.º 4
0
    def test_iterate(self):
        # 1D case
        sig = RatesSignal(xr.DataArray(np.random.rand(100), dims=["time"], coords={"time": np.arange(100)}))
        for name, it in sig.iterate(return_as="signal"):
            self.assertTrue(isinstance(it, RatesSignal))
            self.assertTrue(isinstance(name, dict))
            self.assertTupleEqual(it.shape, (sig.shape[-1],))
        # multiD case
        for name, it in self.signal.iterate(return_as="signal"):
            self.assertTrue(isinstance(it, RatesSignal))
            self.assertTrue(isinstance(name, dict))
            # test it is one-dim with only time axis
            self.assertTupleEqual(it.shape, (1, self.signal.shape[-1]))

        for name, it in self.signal.iterate(return_as="xr"):
            self.assertTrue(isinstance(it, xr.DataArray))
            self.assertTrue(isinstance(name, tuple))
            # test it is one-dim with only time axis
            self.assertTupleEqual(it.shape, (self.signal.shape[-1], 1))

        with pytest.raises(ValueError):
            for name, it in self.signal.iterate(return_as="abcde"):
                pass
Exemplo n.º 5
0
 def test_load_save(self):
     # save
     filename = os.path.join(self.TEST_FOLDER, "temp")
     # do operation so we also test saving and loading of preprocessing steps
     self.signal.normalize(std=True)
     # test basic properties
     repr(self.signal)
     str(self.signal)
     self.signal.start_time
     self.signal.end_time
     self.signal.preprocessing_steps
     # now save
     self.signal.save(filename)
     # load
     loaded = RatesSignal.from_file(filename)
     # compare they are equal
     self.assertEqual(self.signal, loaded)