Пример #1
0
class TestSingleNeuronTypeSetup(unittest.TestCase):
    def setUp(self):
        config = JSONConfig(file=single_neuron_config)
        self.scaffold = Scaffold(config)
        self.scaffold.compile_network()
        self.nest_adapter = self.scaffold.configuration.simulations[
            "test_single_neuron"]
        self.nest_adapter.reset()

    def tearDown(self):
        self.nest_adapter.delete_lock()

    def test_single_neuron(self):
        self.scaffold.run_simulation("test_single_neuron")
        test_cell_model = self.nest_adapter.cell_models["test_cell"]
        self.assertEqual(test_cell_model.nest_identifiers, list(range(1, 5)))

        test_neuron_status = self.nest_adapter.nest.GetStatus(
            test_cell_model.nest_identifiers)
        self.assertEqual(test_neuron_status[0]["t_ref"], 1.5)
        self.assertEqual(test_neuron_status[0]["C_m"], 7.0)
        self.assertEqual(test_neuron_status[0]["V_th"], -41.0)
        self.assertEqual(test_neuron_status[0]["V_reset"], -70.0)
        self.assertEqual(test_neuron_status[0]["E_L"], -62.0)
        self.assertEqual(test_neuron_status[0]["I_e"], 0.0)
Пример #2
0
    def test_aa_goc(self):
        # 5) GrC (aa) - GoC
        # To check it, 20syn on basal dendrites, not near the soma.
        # AMPA/NMDA syn with a burst of 5 spike at 100Hz. The response should be a burst
        # composed by 3 spikes
        config = JSONConfig(aa_goc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        grc_to_golgi = scaffold.configuration.connection_types[
            "granule_to_golgi"]
        grcs = scaffold.get_placement_set("granule_cell").identifiers
        golgis = scaffold.get_placement_set("golgi_cell").identifiers
        m_gol = scaffold.morphology_repository.get_morphology("GolgiCell")
        m_grc = scaffold.morphology_repository.get_morphology("GranuleCell")
        comps = m_gol.get_compartments(["basal_dendrites"])

        conns = np.array([[grcs[0], golgis[0]]] * 20)
        morpho_map = ["GranuleCell", "GolgiCell"]
        morphologies = np.array([[0, 1]] * 20)
        compartments = np.ones(
            (20, 2)) * m_grc.get_compartments(["ascending_axon"])[0].id
        compartments[:, 1] = np.random.choice([c.id for c in comps], size=20)
        scaffold.connect_cells(
            grc_to_golgi,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )

        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure([
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                ),
                go.Scatter(
                    x=f["recorders/soma_voltages/1"][:, 0],
                    y=f["recorders/soma_voltages/1"][:, 1],
                ),
            ]).show()
Пример #3
0
    def test_grc_sc(self):
        # 9) GrC - SC
        # 3 random synapses on the dendrites. AMPA/NMDA, 10 spikes at 100Hz.
        # It should do a burst of 5 spikes.
        config = JSONConfig(grc_sc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        grc_to_golgi = scaffold.configuration.connection_types[
            "granule_to_stellate"]
        grcs = scaffold.get_placement_set("granule_cell").identifiers
        golgis = scaffold.get_placement_set("stellate_cell").identifiers
        m_grc = scaffold.morphology_repository.get_morphology("GranuleCell")
        m_gol = scaffold.morphology_repository.get_morphology("StellateCell")
        comps = m_gol.get_compartments(["dendrites"])

        conns = np.array([[grcs[0], golgis[0]]] * 3)
        morpho_map = ["GranuleCell", "StellateCell"]
        morphologies = np.array([[0, 1]] * 3)
        compartments = np.ones(
            (3, 2)) * m_grc.get_compartments(["ascending_axon"])[0].id
        compartments[:, 1] = np.random.choice([c.id for c in comps], size=3)
        scaffold.connect_cells(
            grc_to_golgi,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )

        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure([
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                ),
                go.Scatter(
                    x=f["recorders/soma_voltages/1"][:, 0],
                    y=f["recorders/soma_voltages/1"][:, 1],
                ),
            ]).show()
Пример #4
0
    def test_pf_pc(self):
        # 6) GrC (aa) - PC
        # 100 random syn, on the apical dendrites. AMPA only, 10 spikes
        # 500Hz. The response should be a burst composed by 3 spikes.
        config = JSONConfig(aa_pc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        grc_to_golgi = scaffold.configuration.connection_types[
            "granule_to_purkinje"]
        grcs = scaffold.get_placement_set("granule_cell").identifiers
        golgis = scaffold.get_placement_set("purkinje_cell").identifiers
        m_gol = scaffold.morphology_repository.get_morphology("PurkinjeCell")
        m_grc = scaffold.morphology_repository.get_morphology("GranuleCell")
        comps = [c.id for c in m_gol.compartments if c.type == 3]

        conns = np.array([[grcs[0], golgis[0]]] * 80)
        morpho_map = ["GranuleCell", "PurkinjeCell"]
        morphologies = np.array([[0, 1]] * 80)
        compartments = np.ones(
            (80, 2)) * m_grc.get_compartments(["parallel_fiber"])[0].id
        compartments[:, 1] = np.random.choice(comps, size=80)
        scaffold.connect_cells(
            grc_to_golgi,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )

        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure([
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                ),
                go.Scatter(
                    x=f["recorders/soma_voltages/1"][:, 0],
                    y=f["recorders/soma_voltages/1"][:, 1],
                ),
            ]).show()
Пример #5
0
    def test_pf_goc(self):
        # 7) GrC (pf) - GoC
        # The same as 5) except on 80 apical dendrites.
        config = JSONConfig(aa_goc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        grc_to_golgi = scaffold.configuration.connection_types[
            "granule_to_golgi"]
        grcs = scaffold.get_placement_set("granule_cell").identifiers
        golgis = scaffold.get_placement_set("golgi_cell").identifiers
        m_gol = scaffold.morphology_repository.get_morphology("GolgiCell")
        m_grc = scaffold.morphology_repository.get_morphology("GranuleCell")
        comps = m_gol.get_compartments(["apical_dendrites"])

        conns = np.array([[grcs[0], golgis[0]]] * 80)
        morpho_map = ["GranuleCell", "GolgiCell"]
        morphologies = np.array([[0, 1]] * 80)
        compartments = np.ones(
            (80, 2)) * m_grc.get_compartments(["ascending_axon"])[0].id
        compartments[:, 1] = np.random.choice([c.id for c in comps], size=80)
        scaffold.connect_cells(
            grc_to_golgi,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )

        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure([
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                ),
                go.Scatter(
                    x=f["recorders/soma_voltages/1"][:, 0],
                    y=f["recorders/soma_voltages/1"][:, 1],
                ),
            ]).show()
Пример #6
0
    def test_mf_granule(self):
        config = JSONConfig(mf_grc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        mf_to_glom = scaffold.configuration.connection_types[
            "mossy_to_glomerulus"]
        glom_to_grc = scaffold.configuration.connection_types[
            "glomerulus_to_granule"]
        mfs = scaffold.get_placement_set("mossy_fibers").identifiers
        gloms = scaffold.get_placement_set("glomerulus").identifiers
        grcs = scaffold.get_placement_set("granule_cell").identifiers
        scaffold.connect_cells(
            mf_to_glom, np.array([[mfs[0], gloms[0]], [mfs[1], gloms[1]]]))
        scaffold.connect_cells(
            mf_to_glom, np.array([[mfs[0], gloms[0]], [mfs[1], gloms[1]]]))
        conns = np.array([[gloms[0], grcs[0]], [gloms[1], grcs[0]]])
        morpho_map = ["GranuleCell"]
        morphologies = np.array([[0, 0], [0, 0]])
        compartments = np.array([[0, 9], [0, 18]])
        scaffold.connect_cells(
            glom_to_grc,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )
        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure(
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                )).show()
Пример #7
0
    def test_sc_pc(self):
        # 9) GrC - SC
        # 3 random synapses on the dendrites. AMPA/NMDA, 10 spikes at 100Hz.
        # It should do a burst of 5 spikes.
        config = JSONConfig(sc_pc_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            go.Figure([
                go.Scatter(
                    x=f["recorders/soma_voltages/0"][:, 0],
                    y=f["recorders/soma_voltages/0"][:, 1],
                ),
            ]).show()
Пример #8
0
    def test_glom_golgi_granule(self):
        config = JSONConfig(mf_gol_config)
        scaffold = Scaffold(config)
        scaffold.place_cell_types()
        scaffold.compile_output()
        mf_to_glom = scaffold.configuration.connection_types[
            "mossy_to_glomerulus"]
        glom_to_gc = scaffold.configuration.connection_types[
            "glomerulus_to_golgi"]
        gc_to_grc = scaffold.configuration.connection_types["golgi_to_granule"]
        mfs = scaffold.get_placement_set("mossy_fibers").identifiers
        gloms = scaffold.get_placement_set("glomerulus").identifiers
        golgis = scaffold.get_placement_set("golgi_cell").identifiers
        granules = scaffold.get_placement_set("granule_cell").identifiers
        scaffold.connect_cells(mf_to_glom, np.array([[mfs[0], gloms[0]]]))
        conns = np.array([[gloms[0], golgis[0]]] * 20)
        m = scaffold.morphology_repository.get_morphology("GolgiCell")
        morpho_map = ["GolgiCell"]
        morphologies = np.zeros((20, 2))
        compartments = np.zeros((20, 2))
        compartments[:, 1] = np.random.choice(
            [c.id for c in m.compartments if c.type == 302], size=20)
        scaffold.connect_cells(
            glom_to_gc,
            conns,
            morphologies=morphologies,
            compartments=compartments,
            morpho_map=morpho_map,
        )

        conns_grc = np.array([[golgis[0], granules[0]]] * 4)
        morpho_map_grc = ["GranuleCell", "GolgiCell"]
        morphologies_grc = np.zeros((4, 2))
        morphologies_grc[:, 0] = [1] * 4
        compartments_grc = np.zeros((4, 2))
        compartments_grc[:, 0] = [c.id for c in m.compartments
                                  if c.type == 2][0:4]
        compartments_grc[:, 1] = [9 * (i + 1) for i in range(4)]
        scaffold.connect_cells(
            gc_to_grc,
            conns_grc,
            morphologies=morphologies_grc,
            compartments=compartments_grc,
            morpho_map=morpho_map_grc,
        )
        scaffold.compile_output()
        scaffold = from_hdf5(scaffold.output_formatter.file)
        scaffold.run_simulation("test")

        from glob import glob
        from plotly import graph_objs as go

        results = glob("results_test_*")[-1]
        with h5py.File(results, "r") as f:
            g = f["recorders/soma_voltages"]
            a = f["recorders/axons"]

            def L(g, s):
                h = g[s]
                return {"x": h[:, 0], "y": h[:, 1], "name": h.attrs["label"]}

            go.Figure([
                *(go.Scatter(**L(g, i)) for i in g),
                *(go.Scatter(**L(a, i)) for i in a),
            ]).show()