def test_soma_mode(self): self._handler.attributes.mode = RepresentationMode.SOMA self._handler.update() self.engine.frame() tmp = image_compare.capture_temporary(self.view) self._handler.apply(NeuronClipping().clipAll(False)) try: image_compare.capture_and_compare(self.view, tmp, prepend_sample_path=False) finally: os.remove(tmp) self._handler.attributes.mode = RepresentationMode.NO_DISPLAY self._handler.update() self.engine.frame() tmp = image_compare.capture_temporary(self.view) self._handler.apply(NeuronClipping().clipAll(True)) try: image_compare.capture_and_compare(self.view, tmp, prepend_sample_path=False) finally: os.remove(tmp)
def test(self): mc0 = self.simulation.gids('MiniColumn_2') mc1 = self.simulation.gids('MiniColumn_5') mc2 = self.simulation.gids('MiniColumn_8') target = numpy.union1d(numpy.union1d(mc0, mc1), mc2) circuit = self.simulation.open_circuit() synapses = circuit.afferent_synapses(target) # Reference image with two columns attributes = AttributeMap() attributes.mode = RepresentationMode.SOMA attributes.color = [1, 1, 1, 1] self.scene.addNeurons(mc0, attributes) attributes.color = [1, 0, 0, 1] self.scene.addNeurons(mc1, attributes) self.tmp_images.append(image_compare.capture_temporary(self.view)) self.scene.clear() self.engine.frame() # Reference image with three columns and synapses attributes = AttributeMap() attributes.mode = RepresentationMode.SOMA attributes.color = [1, 1, 1, 1] self.scene.addNeurons(mc0, attributes) attributes.color = [1, 0, 0, 1] self.scene.addNeurons(mc1, attributes) attributes.color = [0, 0, 1, 1] self.scene.addNeurons(mc2, attributes) self.scene.addAfferentSynapses(synapses) self.tmp_images.append(image_compare.capture_temporary(self.view)) self.scene.clear() self.engine.frame() # Now do the same with incremental loads attributes.color = [1, 1, 1, 1] self.scene.addNeurons(mc0, attributes) self.engine.frame() attributes.color = [1, 0, 0, 1] self.scene.addNeurons(mc1, attributes) self.engine.frame() self.compare_with(0) attributes.color = [0, 0, 1, 1] handler1 = self.scene.addNeurons(mc2, attributes) self.engine.frame() handler2 = self.scene.addAfferentSynapses(synapses) self.engine.frame() self.compare_with(1) # Compare after removing a neuron and a synapse target self.scene.remove(handler1) self.engine.frame() self.scene.remove(handler2) self.engine.frame() self.compare_with(0)
def _remove_colormaps_test(self, spikes=False): if self.tmp: os.remove(self.tmp) rtneuron.engine.player.timestamp = 5 # Remove from same handler self.tmp = image_compare.capture_temporary(self.view) subsets, colormaps = self._apply_colormaps(spikes) for subset in subsets: subset.attributes.colormaps = AttributeMap() subset.update() image_compare.capture_and_compare(self.view, self.tmp, prepend_sample_path=False) # Remove from top handler subsets, colormaps = self._apply_colormaps(spikes) handler = self.view.scene.objects[0] handler.attributes.colormaps = AttributeMap() handler.update() image_compare.capture_and_compare(self.view, self.tmp, prepend_sample_path=False) self._clear_colormaps(subsets) # To avoid warning # Remove from an overlapping subhandler subsets, colormaps = self._apply_colormaps(spikes) subset = handler.query(self.gids) subset.attributes.colormaps = AttributeMap() subset.update() image_compare.capture_and_compare(self.view, self.tmp, prepend_sample_path=False) self._clear_colormaps(subsets) # To avoid warning
def test_axon_mode_protected(self): tmp = image_compare.capture_temporary(self.view) self._handler.apply(NeuronClipping().unclipAll()) try: image_compare.capture_and_compare( self.view, tmp, prepend_sample_path = False) finally: os.remove(tmp)
def test_add_remove(self): handler = self.scene.addModel(cube_path) tmp = image_compare.capture_temporary(self.view) try: self.scene.remove(handler) image_compare.capture_and_compare(self.view, 'empty.png', 1, tmp) except: os.remove(tmp)
def test_clip_chain_1(self): tmp = image_compare.capture_temporary(self.view) self._handler.apply( NeuronClipping().clipAll() .unclip(range(500), [0] * 500, [1.0] * 500)) try: image_compare.capture_and_compare( self.view, tmp, prepend_sample_path = False) finally: os.remove(tmp)
def test_clip_and_unclip_are_perfect_opposites(self): from random import random starts = [random() for i in range(500)] ends = [s + random() * (1 - s) for s in starts] tmp = image_compare.capture_temporary(self.view) self._handler.apply(NeuronClipping().clip(range(500), starts, ends)) self._handler.apply(NeuronClipping().unclip(range(500), starts, ends)) try: image_compare.capture_and_compare( self.view, tmp, prepend_sample_path = False) finally: os.remove(tmp)
def test_clip_soma_interval(self): # Soma is clipping with any range self._handler.apply(NeuronClipping().clipAll()) self._handler.apply(NeuronClipping().clip([0], [0], [0.1])) tmp = image_compare.capture_temporary(self.view) self._handler.attributes.mode = RepresentationMode.NO_DISPLAY self._handler.update() try: image_compare.capture_and_compare( self.view, tmp, prepend_sample_path = False) finally: os.remove(tmp)
def test_clip_axon(self): sections = [int(x) for x in self._morphology.section_ids( [brain.neuron.SectionType.axon])] length = len(sections) self._handler.apply(NeuronClipping().clip( sections, [0] * length, [1] * length)) tmp = image_compare.capture_temporary(self.view) self._handler.attributes.mode = RepresentationMode.NO_AXON self._handler.update() try: image_compare.capture_and_compare( self.view, tmp, prepend_sample_path = False) finally: os.remove(tmp)
def _test_mode_to_no_display(self, mode): tmp = image_compare.capture_temporary(self._view) self._scene.addNeurons(self._gids, AttributeMap({'mode': mode})) for i in range(2): self._engine.frame() self._engine.waitFrame() obj = self._scene.objects[0] obj.attributes.mode = RepresentationMode.NO_DISPLAY obj.update() try: image_compare.capture_and_compare(self._view, tmp, prepend_sample_path=False) finally: os.remove(tmp)
def test_apply_colormaps(self): rtneuron.engine.player.timestamp = 5.5 self.tmp = image_compare.capture_temporary(self.view) subsets, colormaps = self._apply_colormaps() image_compare.capture_and_compare( self.view, 'compartments_with_colormaps_on_soma.png') colormaps[0].setRange(-80, -60) colormaps[1].setRange(-70, -60) colormaps[2].setRange(-70, -50) for s in subsets: s.update() image_compare.capture_and_compare( self.view, 'compartments_with_colormaps_on_soma_2.png') self._clear_colormaps(subsets) # To avoid warning subsets = self._set_default_colormap_at_subsets() image_compare.capture_and_compare(self.view, self.tmp, prepend_sample_path=False) self._clear_colormaps(subsets) # To avoid warning
def test_with_subset_modifications(self): simulation = self.simulation mc0 = simulation.gids('MiniColumn_2') mc1 = simulation.gids('MiniColumn_5') gids = numpy.append(mc0, mc1) circuit = self.simulation.open_circuit() synapses = circuit.afferent_synapses(numpy.union1d(mc0, mc1)) # Reference image attributes = AttributeMap() attributes.mode = RepresentationMode.SOMA attributes.color = [1, 1, 1, 1] handler = self.scene.addNeurons(gids, attributes) self.scene.addAfferentSynapses(synapses) self.engine.frame() subset = handler.query(mc0) subset.attributes.color = [1, 0, 1, 1] subset.update() self.tmp_images.append(image_compare.capture_temporary(self.view)) self.scene.clear() self.engine.frame() # And now the same but doing the subset modification before adding # the synapses. attributes = AttributeMap() attributes.mode = RepresentationMode.SOMA attributes.color = [1, 1, 1, 1] handler = self.scene.addNeurons(gids, attributes) subset = handler.query(mc0) subset.attributes.color = [1, 0, 1, 1] subset.update() self.engine.frame() self.scene.addAfferentSynapses(synapses) self.compare_with(0)
def compare_with(self, index): try: tmp = image_compare.capture_temporary(self.view) image_compare.compare(tmp, self.tmp_images[index]) finally: os.remove(tmp)