def printSpikes(self, filename, gather=True): """ Write spike time information from the population to a given file. :param filename: the absoluete file path for where the spikes are to be printed in :param gather: Supported from the PyNN language, but Spinnaker only does gather = True. """ if not gather: logger.warn("Spynnaker only supports gather = true, will execute" " as if gather was true anyhow") spikes = self.getSpikes(compatible_output=True) if spikes is not None: first_id = 0 num_neurons = self._vertex.n_atoms dimensions = self._vertex.n_atoms last_id = self._vertex.n_atoms - 1 utility_calls.check_directory_exists_and_create_if_not(filename) spike_file = open(filename, "w") spike_file.write("# first_id = {}\n".format(first_id)) spike_file.write("# n = {}\n".format(num_neurons)) spike_file.write("# dimensions = [{}]\n".format(dimensions)) spike_file.write("# last_id = {}\n".format(last_id)) for (neuronId, time) in spikes: spike_file.write("{}\t{}\n".format(time, neuronId)) spike_file.close()
def print_gsyn(self, filename, gather=True): """ Write conductance information from the population to a given file. :param filename: the absolute file path for where the gsyn are to be\ printed in :param gather: Supported from the PyNN language, but ignored here """ time_step = (self._spinnaker_control.machine_time_step * 1.0) / 1000.0 gsyn_exc = self._get_recorded_variable('gsyn_exc') gsyn_inh = self._get_recorded_variable('gsyn_inh') first_id = 0 num_neurons = self._vertex.n_atoms dimensions = self._vertex.n_atoms utility_calls.check_directory_exists_and_create_if_not(filename) file_handle = open(filename, "w") file_handle.write("# first_id = {}\n".format(first_id)) file_handle.write("# n = {}\n".format(num_neurons)) file_handle.write("# dt = {}\n".format(time_step)) file_handle.write("# dimensions = [{}]\n".format(dimensions)) file_handle.write("# last_id = {{}}\n".format(num_neurons - 1)) file_handle = open(filename, "w") # TODO will need adjusting when filters and views assemblies work for ((neuronId, time, value_e), (_, _, value_i)) in zip( gsyn_exc, gsyn_inh): file_handle.write("{}\t{}\t{}\t{}\n".format( time, neuronId, value_e, value_i)) file_handle.close()
def printSpikes(self, filename, gather=True): """ Write spike time information from the population to a given file. :param filename: the absolute file path for where the spikes are to\ be printed in :param gather: Supported from the PyNN language, but ignored here """ if not gather: logger.warn("Spynnaker only supports gather = true, will execute" " as if gather was true anyhow") spikes = self._get_recorded_variable('spikes') if spikes is not None: first_id = 0 num_neurons = self._vertex.n_atoms dimensions = self._vertex.n_atoms last_id = self._vertex.n_atoms - 1 utility_calls.check_directory_exists_and_create_if_not(filename) spike_file = open(filename, "w") spike_file.write("# first_id = {}\n".format(first_id)) spike_file.write("# n = {}\n".format(num_neurons)) spike_file.write("# dimensions = [{}]\n".format(dimensions)) spike_file.write("# last_id = {}\n".format(last_id)) for (neuronId, time) in spikes: spike_file.write("{}\t{}\n".format(time, neuronId)) spike_file.close()
def test_check_directory_not_exists(self): test_dir = os.path.join(os.path.dirname(__file__), "test_utility_call") test_file = os.path.join(test_dir, "test") if os.path.exists(test_dir): shutil.rmtree(test_dir) print("Directory existed. Deleting...") utility_calls.check_directory_exists_and_create_if_not(test_file) if not os.path.exists(test_dir): raise AssertionError("Directory was not created") print("Directory created successfully. Deleting...") os.rmdir(test_dir)
def test_check_directory_not_exists(self): test_dir = os.path.join(os.path.dirname(__file__), "test_utility_call") test_file = os.path.join(test_dir, "test") if os.path.exists(test_dir): shutil.rmtree(test_dir) print "Directory existed. Deleting..." utility_calls.check_directory_exists_and_create_if_not(test_file) if os.path.exists(test_dir): os.rmdir(test_dir) print "Directory created successfully. Deleting..." else: raise AssertionError("Directory was not created")
def _get_io(filename): """ Return a Neo IO instance, guessing the type based on the filename\ suffix. """ logger.debug("Creating Neo IO for filename {}", filename) directory = os.path.dirname(filename) utility_calls.check_directory_exists_and_create_if_not(directory) extension = os.path.splitext(filename)[1] if extension in ('.txt', '.ras', '.v', '.gsyn'): raise IOError( "ASCII-based formats are not currently supported for output" " data. Try using the file extension '.pkl' or '.h5'") elif extension in ('.h5', ): return NeoHdf5IO(filename=filename) elif extension in ('.pkl', '.pickle'): return PickleIO(filename=filename) elif extension == '.mat': return NeoMatlabIO(filename=filename) else: # function to be improved later raise Exception("file extension %s not supported" % extension)
def print_v(self, filename, gather=True): """ Write membrane potential information from the population to a\ given file. :param filename: the absolute file path for where the voltage are to\ be printed in :param gather: Supported from the PyNN language, but ignored here """ time_step = (self._spinnaker.machine_time_step * 1.0) / 1000.0 v = self.get_v(gather, compatible_output=True) utility_calls.check_directory_exists_and_create_if_not(filename) file_handle = open(filename, "w") first_id = 0 num_neurons = self._vertex.n_atoms dimensions = self._vertex.n_atoms file_handle.write("# first_id = {}\n".format(first_id)) file_handle.write("# n = {}\n".format(num_neurons)) file_handle.write("# dt = {}\n".format(time_step)) file_handle.write("# dimensions = [{}]\n".format(dimensions)) file_handle.write("# last_id = {}\n".format(num_neurons - 1)) for (neuronId, time, value) in v: file_handle.write("{}\t{}\t{}\n".format(time, neuronId, value)) file_handle.close()
def print_gsyn(self, filename, gather=True): """ Write conductance information from the population to a given file. :param filename: the absoluete file path for where the gsyn are to be\ printed in :param gather: Supported from the PyNN language, but ignored here """ time_step = (self._spinnaker.machine_time_step * 1.0) / 1000.0 gsyn = self.get_gsyn(gather, compatible_output=True) first_id = 0 num_neurons = self._vertex.n_atoms dimensions = self._vertex.n_atoms utility_calls.check_directory_exists_and_create_if_not(filename) file_handle = open(filename, "w") file_handle.write("# first_id = {}\n".format(first_id)) file_handle.write("# n = {}\n".format(num_neurons)) file_handle.write("# dt = {}\n".format(time_step)) file_handle.write("# dimensions = [{}]\n".format(dimensions)) file_handle.write("# last_id = {{}}\n".format(num_neurons - 1)) file_handle = open(filename, "w") for (neuronId, time, value_e, value_i) in gsyn: file_handle.write("{}\t{}\t{}\t{}\n".format( time, neuronId, value_e, value_i)) file_handle.close()
def test_check_directory_exists(self): utility_calls.check_directory_exists_and_create_if_not( os.path.dirname(os.path.realpath(__file__))) self.assertTrue( os.path.exists(os.path.dirname(os.path.realpath(__file__))))
def test_check_directory_exists(self): utility_calls.check_directory_exists_and_create_if_not(os.path.dirname( os.path.realpath(__file__))) self.assertTrue(os.path.exists(os.path.dirname( os.path.realpath(__file__))))