def ImageFromSpikes(input_spikes, file_path="./latest.png", show=True, save=True, xmin=False, xmax=False): '''Input: get converted to: spikes = list of lists (neurons) of ms ie. [[1, 3, 5], [2, 4, 5]] # 2 neurons, 3 spikes/neuron, ms 1, 3... ''' global sp from plugins.importer import spikesDictToArray spikes = spikesDictToArray(input_spikes) if xmax or xmin: #TODO: Use numpy (faster) v1.0 new_spikes = [] for i in spikes: i = [l for l in i if l < xmax and l > xmin] new_spikes.append(i) spikes = new_spikes if save: cprint("\t*\tSaving image to %s" % file_path, 'info') sp.set_fig_name(file_path) sp.set_figsize((24, 18)) sp.set_linestyle('-') sp.set_markerscale(0.8) sp.plot_spikes(spikes, draw=show, savefig=save) # del sp #fixes memory leak? Seems not del spikes del input_spikes # Debug code # from subprocess import call # call(["feh", file_path]) return True
def POST(self): global Work global client_port cprint("Data received, saving!", 'okgreen') save = open("MultiHeaded-analisys.csv", 'a') save.write(web.data()) save.close() cprint("Sending next!", 'okgreen') work_append( web.ctx['ip'], client_port, Work.pop(1,1)) work_start(web.ctx['ip'], client_port)
def main_loop(content, remote, dummy): i = 0 total = len(content) for values in content: filename = "./%s/%s_%s.png" % (values[1], values[2], values[3]) cprint("[%s/%s] %s match and is missing, generating image\r" % (i, total, filename), 'info') #TODO:allow compressed data = import_history("%s/%s_%s_output.gz" % (values[0], values[2], values[3]), compressed=True) state = ImageIO.ImageFromSpikes( data["NeMo"][1], file_path = filename, save = True, show = False ) del state del data #Memory leak again? i += 1
def info_print(total, core_number, print_only = False): from libs.IO import cprint if not total: cprint("No simulations to analyze, exiting") exit() cprint("Total number of analysis to be run: %s" % (total), 'okblue') cprint("And we are going to use %s%s %s" % ( #Style :D "even " if core_number >= 8 \ else "well " if core_number >= 4 \ else "just " if core_number <= 2 \ else "" , core_number , "thread" if core_number == 1 else "threads" ) #Style again XD , 'okgreen' if core_number >= 4 \ else 'okblue' if core_number >= 3 \ else 'warning' if core_number >= 2 \ else 'red' ) if print_only: #Print simulations number and exit! exit()
def showImageFile(image_path): try: img = Image.open(image_path) img.show() except IOError: cprint("ERROR: cannot load image (Image file does not exists)", 'fail')
#!/usr/bin/env python2 from PIL import Image from libs.IO import cprint from libs.IO import COLORS try: from neuronpy.graphics import spikeplot except ImportError: cprint("You need nepuronpy to create spikes images\n\ (as root) pip2 install neuronpy; pip2 install matplotlib", 'fail') sp = spikeplot.SpikePlot(savefig=True) def showImageFile(image_path): try: img = Image.open(image_path) img.show() except IOError: cprint("ERROR: cannot load image (Image file does not exists)", 'fail') def saveRawImage(img, name, close=True): try: img.save(name) except AttributeError: try: img.savefig(name) if close: img.close() except: raise return True
Work = workQueue(list_all(args.path, args.start_from, args.end_to)) if __name__ == "__main__": from libs.IO import cprint from time import sleep app = Worker(urls, globals()) info = {} #Get info needed as core number etc for client in clients: info[client] = {} success = False while not success: try: response = requests.get(ip_port(client,client_port)+"/cores").text success = True except requests.exceptions.ConnectionError: cprint("Cannot connect to %s" % (client),'fail') cprint("Retry in 1 sec", 'info') sleep(1) info[client]["cores"] = json.loads(response)["cores"] info[client]["multiplier"] = json.loads(response)["multiplier"] #Add work to queue. Will be started when everyone get it's own #(that way we can start the server that receive the results in time) #Append a work for every core of every client for client_ip in info: cprint("Loading data for %s" % client_ip, 'info') work_append( client_ip, client_port, Work.pop( info[client_ip]["cores"] , info[client_ip]["multiplier"]))
) parser.add_argument('--cores', help = 'Number of cores to use. All by default' , dest = 'cores' , default = get_cores() ) args = parser.parse_args() path = args.path #Read ANALYSIS file fname = args.analysis_file with open(fname) as f: content = f.readlines() cprint("Total files provided: %s; Number of cores: %s" % (len(content), args.cores), 'info') is_folder(args.images_path) real_content = [] # existing = listdir(args.images_path) #Slower than isfile for line in content: file_data = line.split(",") general = file_data[0] config = file_data[1] if args.run_all or (file_data[2] == "1" == file_data[7]): filename = "%s_%s.png" % (general, config) if not isfile("./%s" % args.images_path + filename): # if filename not in existing: #Slower than isfile O.o real_content.append((args.path, args.images_path, general, config)) # else: existing.remove(filename)
commands = substituteRanges([args], []) #fix parentheses: commands = [ i for i in commands if not missing(i) ] #set just to be sure no duplicate runs real_commands = set(commands) #TODO: #FIXME: remove "--show-image" etc to prevent different hashes of same config session_hash = hashDict(real_commands) #Save commands list is_folder("./commands") commands_file = "./commands/" + session_hash + "_commands" cprint ("Saving %s commands to file: %s" % (len(real_commands), commands_file), 'info') saveKey(commands_file, commands) # Debug: re-enable in release # cprint("Running in 5s", "warning") # time.sleep(5) #Start is_folder (output_dir) cprint("We'll use %s as output dir" % (output_dir), 'info') #Let's run the simulations (surely not the best way, but does the job) #TODO: add the loop inside Runner? start = time.time() try: run = import_history(output_dir + "/" + session_hash + "_batch")
def return_analysis_output(f, neurons_info, input_conf, steps): try: to_write = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % ( f.split("_")[0] #Save somewhere to save time, used multimple times #1 , f.split("_")[1] , neurons_info[4]["mode"] , neurons_info[4]["on_time"] , neurons_info[4]["off_time"] , neurons_info[4]["burst_freq"] , neurons_info[4]["not_burst_freq"] , neurons_info[5]["mode"] , neurons_info[5]["on_time"] , neurons_info[5]["off_time"] , neurons_info[5]["burst_freq"] , neurons_info[5]["not_burst_freq"] , input_conf["cerebellum_ctrl_a"][0] , input_conf["cerebellum_ctrl_a"][1] , input_conf["cerebellum_ctrl_a"][2] , input_conf["cerebellum_ctrl_b"][0] , input_conf["cerebellum_ctrl_b"][1] , input_conf["cerebellum_ctrl_b"][2] , input_conf["_stim_a"] , input_conf["_stim_b"] , input_conf["_start_a"] , input_conf["_start_b"] , input_conf["_stop_a"] , input_conf["_stop_b"] , input_conf["CIN"][0][0] , input_conf["CIN"][0][1] , input_conf["CIN"][0][2] , input_conf["CIN"][0][3] , input_conf["CIN"][0][4] , input_conf["CIN"][0][5] , input_conf["CIN"][0][6] , input_conf["EIN"][0][0] , input_conf["EIN"][0][1] , input_conf["EIN"][0][2] , input_conf["EIN"][0][3] , input_conf["EIN"][0][4] , input_conf["EIN"][0][5] , input_conf["EIN"][0][6] , input_conf["synapses"][0][2][0] #delay , input_conf["synapses"][0][2][1] #int , input_conf["synapses"][1][2][0] #delay , input_conf["synapses"][1][2][1] #int , input_conf["synapses"][2][2][0] #delay , input_conf["synapses"][2][2][1] #int , input_conf["synapses"][3][2][0] #delay , input_conf["synapses"][3][2][1] #int , input_conf["synapses"][4][2][0] #delay , input_conf["synapses"][4][2][1] #int , input_conf["synapses"][5][2][0] #delay , input_conf["synapses"][5][2][1] #int , steps #38 ) except KeyError: to_write = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % ( f.split("_")[0] #Save somewhere to save time, used multimple times #1 , f.split("_")[1] , 3 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , input_conf["cerebellum_ctrl_a"][0] , input_conf["cerebellum_ctrl_a"][1] , input_conf["cerebellum_ctrl_a"][2] , input_conf["cerebellum_ctrl_b"][0] , input_conf["cerebellum_ctrl_b"][1] , input_conf["cerebellum_ctrl_b"][2] , input_conf["_stim_a"] , input_conf["_stim_b"] , input_conf["_start_a"] , input_conf["_start_b"] , input_conf["_stop_a"] , input_conf["_stop_b"] , input_conf["CIN"][0][0] , input_conf["CIN"][0][1] , input_conf["CIN"][0][2] , input_conf["CIN"][0][3] , input_conf["CIN"][0][4] , input_conf["CIN"][0][5] , input_conf["CIN"][0][6] , input_conf["EIN"][0][0] , input_conf["EIN"][0][1] , input_conf["EIN"][0][2] , input_conf["EIN"][0][3] , input_conf["EIN"][0][4] , input_conf["EIN"][0][5] , input_conf["EIN"][0][6] , input_conf["synapses"][0][2][0] #delay , input_conf["synapses"][0][2][1] #int , input_conf["synapses"][1][2][0] #delay , input_conf["synapses"][1][2][1] #int , input_conf["synapses"][2][2][0] #delay , input_conf["synapses"][2][2][1] #int , input_conf["synapses"][3][2][0] #delay , input_conf["synapses"][3][2][1] #int , input_conf["synapses"][4][2][0] #delay , input_conf["synapses"][4][2][1] #int , input_conf["synapses"][5][2][0] #delay , input_conf["synapses"][5][2][1] #int , steps #29 ) cprint("Key error!","fail") return to_write