class TestMorhologySetsRotations(unittest.TestCase): """ Test scaffold with cells associated to a certain rotated morphology """ @classmethod def setUpClass(self): import dbbs_models test_setup.prep_morphologies() test_setup.prep_rotations() super().setUpClass() config = JSONConfig(config_file) self.scaffold = Scaffold(config) self.scaffold.morphology_repository = MorphologyRepository(test_setup.mr_rot_path) def test_morphology_map(self): # Create and place a set of 10 Golgi cells and assign them to a morphology based on their rotation cell_type = self.scaffold.get_cell_type("golgi_cell") positions = np.random.rand(9, 3) # Construct rotation matrix for cell_type phi_values = np.linspace(0.0, 360.0, num=3) theta_values = np.linspace(0.0, 360.0, num=3) phi_values = np.repeat( phi_values, 3 ) # np.random.choice(len(phi_values), len(positions)) theta_values = np.repeat( theta_values, 3 ) # np.random.choice(len(theta_values), len(positions)) rotations = np.vstack((phi_values, theta_values)).T # Place cells and generate hdf5 output self.scaffold.place_cells( cell_type, cell_type.placement.layer_instance, positions, rotations ) self.scaffold.compile_output() ps = PlacementSet(self.scaffold.output_formatter, cell_type) ms = MorphologySet(self.scaffold, cell_type, ps) self.assertEqual( len(rotations), len(ms._morphology_index), "Not all cells assigned to a morphology!", ) random_sel = np.random.choice(len(ms._morphology_index)) morpho_sel = ms._morphology_map[ms._morphology_index[random_sel]] self.assertTrue( morpho_sel.find( "__" + str(int(rotations[random_sel, 0])) + "_" + str(int(rotations[random_sel, 1])) ) != -1, "Wrong morphology map!", )
class TestPlacementSets(unittest.TestCase): """ Check if the scaffold can create a single cell type. """ @classmethod def setUpClass(self): super(TestPlacementSets, self).setUpClass() test_setup.prep_morphologies() config = JSONConfig(file=double_neuron_config) self.scaffold = Scaffold(config) self.scaffold.compile_network() def test_hdf5_structure(self): with h5py.File(self.scaffold.output_formatter.file, "r") as h: for key in ["from", "to"]: group = h["cells/placement/" + key + "_cell"] self.assertTrue( "identifiers" in group, "Identifiers dataset missing for the " + key + "_cell", ) self.assertTrue( "positions" in group, "Positions dataset missing for the " + key + "_cell", ) self.assertEqual( group["positions"].shape, (4, 3), "Incorrect position dataset size for the " + key + "_cell", ) self.assertTrue( group["positions"].dtype == np.float64, "Incorrect position dataset dtype ({}) for the ".format( group["positions"].dtype) + key + "_cell", ) self.assertEqual( group["identifiers"].shape, (2, ), "Incorrect or noncontinuous identifiers dataset size for the " + key + "_cell", ) self.assertTrue( group["identifiers"].dtype == np.int32, "Incorrect identifiers dataset dtype ({}) for the ".format( group["identifiers"].dtype) + key + "_cell", ) def test_placement_set_properties(self): for key in ["from", "to"]: cell_type = self.scaffold.get_cell_type(key + "_cell") ps = PlacementSet(self.scaffold.output_formatter, cell_type) self.assertEqual( ps.identifiers.shape, (4, ), "Incorrect identifiers shape for " + key + "_cell", ) self.assertEqual( ps.positions.shape, (4, 3), "Incorrect positions shape for " + key + "_cell", ) self.assertRaises(DatasetNotFoundError, lambda: ps.rotations) self.assertEqual(type(ps.cells[0]), Cell, "PlacementSet.cells did not return Cells") self.assertEqual( ps.cells[1].id, 1 if key == "from" else 5, "PlacementSet.cells identifiers incorrect", ) self.assertEqual( ps.cells[1].position.shape, (3, ), "PlacementSet.cells positions wrong shape", )