Пример #1
0
def test_path_ctor():
    #  make sure constructors that take file paths can use pathlib.Path
    path = pathlib.Path(PATH)

    NodeStorage(path / 'nodes1.h5')
    EdgeStorage(path / 'edges1.h5')
    SpikeReader(path / 'spikes.h5')
    SomaReportReader(path / 'somas.h5')
    ElementReportReader(path / 'elements.h5')
Пример #2
0
def test_path_ctor():
    #  make sure constructors that take file paths can use pathlib.Path
    path = pathlib.Path(PATH)

    NodeStorage(path / 'nodes1.h5')
    EdgeStorage(path / 'edges1.h5')
    SpikeReader(path / 'spikes.h5')
    SomaReportReader(path / 'somas.h5')
    ElementReportReader(path / 'elements.h5')
    NodeSets.from_file(path / 'node_sets.json')
    CircuitConfig.from_file(path / 'config/circuit_config.json')
Пример #3
0
 def setUp(self):
     self.population = NodeStorage(os.path.join(
         PATH, 'nodes1.h5')).open_population('nodes-A')
Пример #4
0
class TestNodePopulationNodeSet(unittest.TestCase):
    def setUp(self):
        self.population = NodeStorage(os.path.join(
            PATH, 'nodes1.h5')).open_population('nodes-A')

    def test_BasicScalarInt(self):
        sel = NodeSets('{ "NodeSet0": { "attr-Y": 21 } }').materialize(
            "NodeSet0", self.population)
        self.assertEqual(sel, Selection(((0, 1), )))

    def test_BasicScalarString(self):
        sel = NodeSets(
            '{ "NodeSet0": { "attr-Z": ["aa", "cc"] } }').materialize(
                "NodeSet0", self.population)
        self.assertEqual(sel, Selection(((0, 1), (2, 3))))

    def test_BasicScalarEnum(self):
        sel = NodeSets(
            '{ "NodeSet0": { "E-mapping-good": "C" } }').materialize(
                "NodeSet0", self.population)
        self.assertEqual(sel, Selection((
            (0, 1),
            (2, 3),
            (4, 6),
        )))

    def test_BasicScalarAnded(self):
        j = '''{"NodeSet0": {"E-mapping-good": "C",
                             "attr-Y": [21, 22]
                            }
            }'''
        sel = NodeSets(j).materialize("NodeSet0", self.population)
        self.assertEqual(sel, Selection(((0, 1), )))

    def test_BasicScalarNodeId(self):
        sel = NodeSets('{ "NodeSet0": { "node_id": [1, 3, 5] } }').materialize(
            "NodeSet0", self.population)
        self.assertEqual(sel, Selection(((1, 2), (3, 4), (5, 6))))

    def test_BasicScalarPopulation(self):
        sel = NodeSets(
            '{ "NodeSet0": { "population": "nodes-A" } }').materialize(
                "NodeSet0", self.population)
        self.assertEqual(sel, self.population.select_all())

        sel = NodeSets('{ "NodeSet0": { "population": ["nodes-A",  "FAKE"] } }'
                       ).materialize("NodeSet0", self.population)
        self.assertEqual(sel, self.population.select_all())

        sel = NodeSets(
            '{ "NodeSet0": { "population": "NOT_A_POP" } }').materialize(
                "NodeSet0", self.population)
        self.assertEqual(sel, Selection([]))

    def test_NodeSetCompound(self):
        j = '''{"NodeSet0": { "node_id": [1] },
                "NodeSet1": { "node_id": [2] },
                "NodeSetCompound0": ["NodeSet0", "NodeSet1"],
                "NodeSetCompound1": ["NodeSetCompound0", "NodeSet2"],
                "NodeSet2": { "node_id": [3] }
        }'''
        sel = NodeSets(j).materialize("NodeSetCompound1", self.population)
        self.assertEqual(sel, Selection(((1, 4), )))

    def test_NodeSet_toJSON(self):
        j = '''
        {"bio_layer45": {
              "model_type": "biophysical",
              "location": ["layer4", "layer5"]
          },
          "V1_point_prime": {
              "population": "biophysical",
              "model_type": "point",
              "node_id": [1, 2, 3, 5, 7, 9]
          },
          "combined": ["bio_layer45", "V1_point_prime"]
        }'''
        new = NodeSets(j).toJSON()
        ns1 = NodeSets(new)
        self.assertEqual(new, ns1.toJSON())

        ns = NodeSets.from_file(os.path.join(PATH, 'node_sets.json'))
        self.assertEqual(new, ns.toJSON())
Пример #5
0
 def setUp(self):
     path = os.path.join(PATH, 'nodes1.h5')
     self.test_obj = NodeStorage(path).open_population('nodes-A')
Пример #6
0
class TestNodePopulation(unittest.TestCase):
    def setUp(self):
        path = os.path.join(PATH, 'nodes1.h5')
        self.test_obj = NodeStorage(path).open_population('nodes-A')

    def test_name(self):
        self.assertEqual(self.test_obj.name, "nodes-A")

    def test_size(self):
        self.assertEqual(self.test_obj.size, 6)
        self.assertEqual(len(self.test_obj), 6)

    def test_attribute_names(self):
        self.assertEqual(
            self.test_obj.attribute_names, {
                'attr-X', 'attr-Y', 'attr-Z', 'A-int8', 'A-int16', 'A-int32',
                'A-int64', 'A-uint8', 'A-uint16', 'A-uint32', 'A-uint64',
                'A-float', 'A-double', 'A-string', 'A-enum', 'E-mapping-good',
                'E-mapping-bad'
            })

    def test_get_attribute(self):
        self.assertEqual(self.test_obj.get_attribute('attr-X', 0), 11.)
        self.assertEqual(
            self.test_obj.get_attribute('attr-X', Selection([0, 5])).tolist(),
            [11., 16.])

        # different dtypes
        self.assertEqual(self.test_obj.get_attribute('attr-Y', 0), 21)
        self.assertEqual(self.test_obj.get_attribute('attr-Z', 0), 'aa')

        # default value
        self.assertEqual(
            self.test_obj.get_attribute('attr-X', Selection([0, 5]),
                                        42.).tolist(), [11., 16.])

        self.assertRaises(SonataError, self.test_obj.get_attribute,
                          'no-such-attribute', 0)

    def test_get_dynamics_attribute(self):
        self.assertEqual(self.test_obj.get_dynamics_attribute('dparam-X', 0),
                         1011.)
        self.assertEqual(
            self.test_obj.get_dynamics_attribute('dparam-X',
                                                 Selection([0, 5])).tolist(),
            [1011., 1016.])

        # different dtypes
        self.assertEqual(self.test_obj.get_dynamics_attribute('dparam-Y', 0),
                         1021)
        self.assertEqual(self.test_obj.get_dynamics_attribute('dparam-Z', 0),
                         'd-aa')

        # default value
        self.assertEqual(
            self.test_obj.get_dynamics_attribute('dparam-X', Selection([0, 5]),
                                                 42.).tolist(), [1011., 1016.])

        self.assertRaises(SonataError, self.test_obj.get_dynamics_attribute,
                          'no-such-attribute', 0)

    def test_enumeration_names(self):
        self.assertEqual(self.test_obj.enumeration_names,
                         {'E-mapping-good', 'E-mapping-bad'})

    def test_enumeration_values(self):
        self.assertEqual(
            self.test_obj.get_attribute("E-mapping-good",
                                        Selection([(0, 1), (2, 3)])).tolist(),
            ["C", "C"])

        self.assertEqual(
            self.test_obj.get_attribute("E-mapping-good",
                                        Selection([(0, 1), (2, 3)])).tolist(),
            ["C", "C"])

        self.assertEqual(
            self.test_obj.get_enumeration("E-mapping-good",
                                          Selection([(0, 1),
                                                     (2, 3)])).tolist(),
            [2, 2])

        self.assertEqual(self.test_obj.enumeration_values("E-mapping-good"),
                         ["A", "B", "C"])

        self.assertRaises(SonataError, self.test_obj.get_attribute,
                          "E-mapping-bad", 1)

        self.assertRaises(SonataError, self.test_obj.get_enumeration, "attr-X",
                          0)

    def test_select_all(self):
        self.assertEqual(self.test_obj.select_all().flat_size, 6)

    def test_match_values(self):
        # string
        self.assertEqual(
            self.test_obj.match_values("attr-Z", "bb").flatten().tolist(), [1])

        # enum
        self.assertEqual(
            self.test_obj.match_values("E-mapping-good",
                                       "C").flatten().tolist(), [0, 2, 4, 5])

        # int
        self.assertEqual(
            self.test_obj.match_values("attr-Y", 23).flatten().tolist(), [
                2,
            ])

        # float
        self.assertRaises(TypeError, self.test_obj.match_values, "attr-Y", 23.)