def test_alternate_morphology(self): alternate_morphs = {"h5v1": str(self.morph_path)} test_obj = test_module.MorphHelper( None, self.nodes, alternate_morphologies=alternate_morphs ) node_id = CircuitNodeId("default", 1) assert self.nodes.get(node_id, properties="morphology") == "morph-B" expected = self.morph_path / "morph-B.h5" actual = test_obj.get_filepath(node_id, extension="h5") assert actual == expected alternate_morphs = {"neurolucida-asc": str(self.morph_path)} test_obj = test_module.MorphHelper( None, self.nodes, alternate_morphologies=alternate_morphs ) node_id = CircuitNodeId("default", 1) assert self.nodes.get(node_id, properties="morphology") == "morph-B" expected = self.morph_path / "morph-B.asc" actual = test_obj.get_filepath(node_id, extension="asc") assert actual == expected with pytest.raises(BluepySnapError, match="'morphologies_dir' is not defined in config"): node_id = CircuitNodeId("default", 0) test_obj.get_filepath(node_id)
def test_get_morphology_standard_rotation(self): nodes = create_node_population(str(TEST_DATA_DIR / 'nodes.h5'), "default") test_obj = test_module.MorphHelper(str(self.morph_path), nodes) node_id = 0 actual = test_obj.get(node_id, transform=True).points # check if the input node positions / orientation values are still the same pdt.assert_series_equal( self.nodes.positions(node_id), pd.Series([101., 102., 103.], index=[Node.X, Node.Y, Node.Z], name=0)) npt.assert_almost_equal(nodes.orientations(node_id), [ [0.738219, 0., 0.674560], [0., 1., 0.], [-0.674560, 0., 0.738219], ], decimal=6) assert len(actual) == 32 expected = [[100.7637696, 103, 103.2158592, 0.725], [100.7637696, 102.9, 103.2158592, 0.820]] npt.assert_almost_equal(expected, actual[:2])
def test_get_morphology_standard_rotation(self): nodes = create_node_population(str(TEST_DATA_DIR / "nodes.h5"), "default") test_obj = test_module.MorphHelper(str(self.morph_path), nodes) node_id = 0 actual = test_obj.get(node_id, transform=True).points # check if the input node positions / orientation values are still the same pdt.assert_series_equal( self.nodes.positions(node_id), pd.Series([101.0, 102.0, 103.0], index=[Node.X, Node.Y, Node.Z], name=0), ) npt.assert_almost_equal( nodes.orientations(node_id), [ [0.738219, 0.0, 0.674560], [0.0, 1.0, 0.0], [-0.674560, 0.0, 0.738219], ], decimal=6, ) assert len(actual) == 13 expected = [[101.0, 107.0, 103.0], [102.47644, 111.0, 101.65088]] npt.assert_almost_equal(actual[:2], expected, decimal=6)
def test_MorphHelper_cache_2(nm_load): nodes = Mock() nodes.get.side_effect = ['morph-A', 'morph-A'] with patch.object(test_module.MorphHelper, '_is_biophysical', return_value=True): test_obj = test_module.MorphHelper('morph-dir', nodes) nm_load.side_effect = Mock morph1 = test_obj.get(0) # same morphology, but no caching assert test_obj.get(1) is not morph1
def test_get_alternate_morphology(self): alternate_morphs = {"h5v1": str(self.morph_path)} test_obj = test_module.MorphHelper( None, self.nodes, alternate_morphologies=alternate_morphs ) actual = test_obj.get(0, extension="h5") assert len(actual.points) == 13 expected = [ [0.0, 5.0, 0.0], [2.0, 9.0, 0.0], ] npt.assert_almost_equal(expected, actual.points[:2]) npt.assert_almost_equal([2.0, 2.0], actual.diameters[:2])
def test_MorphHelper_cache_1(nm_load): nodes = Mock() nodes.get.side_effect = ['morph-A', 'morph-A', 'morph-B', 'morph-A'] with patch.object(test_module.MorphHelper, '_is_biophysical', return_value=True): test_obj = test_module.MorphHelper('morph-dir', nodes) nm_load.side_effect = Mock morph0 = test_obj.get(0) # should get cached object for 'morph-A' assert test_obj.get(1) is morph0 # should get new object ('morph-B') assert test_obj.get(2) is not morph0 # 'morph-A' was evicted from cache assert test_obj.get(3) is not morph0
def setup(self): self.nodes = create_node_population( str(TEST_DATA_DIR / 'nodes_quaternions.h5'), "default") self.morph_path = TEST_DATA_DIR / 'morphologies' self.test_obj = test_module.MorphHelper(str(self.morph_path), self.nodes)