def frame_generation(index_iteration): print(index_iteration); figure.clf(); figure.suptitle("Hodgkin-Huxley Network (iteration: " + str(index_iteration) +")", fontsize = 18, fontweight = 'bold'); ax1 = figure.add_subplot(121); ax2 = figure.add_subplot(122); end_iteration = index_iteration; if (end_iteration > len(dyn_peripheral)): end_iteration = len(dyn_peripheral); dynamic_length = 100; begin_iteration = end_iteration - dynamic_length; if (begin_iteration < 0): begin_iteration = 0; # Display output dynamic xlim = [dyn_time[begin_iteration], dyn_time[begin_iteration + dynamic_length]]; visualizer = dynamic_visualizer(1, x_title="Time", y_title="V", x_lim=xlim, y_lim=ylim); dyn_time_segment = [ dyn_time[i] for i in range(begin_iteration, end_iteration, 1) ]; dyn_peripheral_segment = [ dyn_peripheral[i] for i in range(begin_iteration, end_iteration, 1) ]; visualizer.append_dynamic(dyn_time_segment, dyn_peripheral_segment); visualizer.show(ax1, False); visualize_segmenetation(end_iteration, ax2, step); return [ figure.gca() ];
def frame_generation(index_iteration): print(index_iteration) figure.clf() figure.suptitle("Hodgkin-Huxley Network (iteration: " + str(index_iteration) +")", fontsize = 18, fontweight = 'bold') ax1 = figure.add_subplot(121) ax2 = figure.add_subplot(122) end_iteration = index_iteration if (end_iteration > len(dyn_peripheral)): end_iteration = len(dyn_peripheral) dynamic_length = 100 begin_iteration = end_iteration - dynamic_length if begin_iteration < 0: begin_iteration = 0 # Display output dynamic xlim = [dyn_time[begin_iteration], dyn_time[begin_iteration + dynamic_length]] visualizer = dynamic_visualizer(1, x_title="Time", y_title="V", x_lim=xlim, y_lim=ylim) dyn_time_segment = [ dyn_time[i] for i in range(begin_iteration, end_iteration, 1) ] dyn_peripheral_segment = [ dyn_peripheral[i] for i in range(begin_iteration, end_iteration, 1) ] visualizer.append_dynamic(dyn_time_segment, dyn_peripheral_segment) visualizer.show(ax1, False) visualize_segmenetation(end_iteration, ax2, step) return [ figure.gca() ]
def testVisualizeSeveralDynamicsOneCanvasNoCrash(self): t1 = [0, 1, 2, 3, 4, 5, 6, 7]; y1 = [0, 0, 1, 2, 0, 1, 2, 0]; t2 = [0, 1, 2, 3, 4, 5, 6, 7]; y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t1, y1); visualizer.append_dynamics(t2, y2);
def testVisualizeSeveralDynamicsOneCanvasNoCrash(self): t1 = [0, 1, 2, 3, 4, 5, 6, 7]; y1 = [0, 0, 1, 2, 0, 1, 2, 0]; t2 = [0, 1, 2, 3, 4, 5, 6, 7]; y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t1, y1); visualizer.append_dynamics(t2, y2);
def testVisualizeSeveralDynamicsSeveralCanvasesNoCrash(self): t1 = [0, 1, 2, 3, 4, 5, 6, 7]; y1 = [0, 0, 1, 2, 0, 1, 2, 0]; t2 = [0, 1, 2, 3, 4, 5, 6, 7]; y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(3); visualizer.append_dynamic(t1, y1, canvas=0); visualizer.append_dynamics(t2, y2, canvas=1, separate=True);
def testVisualizeSeveralDynamicsSeveralCanvasesNoCrash(self): t1 = [0, 1, 2, 3, 4, 5, 6, 7]; y1 = [0, 0, 1, 2, 0, 1, 2, 0]; t2 = [0, 1, 2, 3, 4, 5, 6, 7]; y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(3); visualizer.append_dynamic(t1, y1, canvas=0); visualizer.append_dynamics(t2, y2, canvas=1, separate=True);
def template_dynamic_hhn(num_osc, steps, time, stimulus = None, params = None, separate = False, ccore_flag = False): net = hhn_network(num_osc, stimulus, params, ccore = ccore_flag); (t, dyn_peripheral, dyn_central) = net.simulate(steps, time); amount_canvases = 1; if (isinstance(separate, list)): amount_canvases = len(separate) + 2; elif (separate is True): amount_canvases = len(dyn_peripheral[0]) + 2; visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False); visualizer.append_dynamics(t, dyn_peripheral, 0, separate); visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True); visualizer.show();
def template_dynamic_hhn(num_osc, steps, time, stimulus = None, params = None, separate = False, ccore_flag = False): net = hhn_network(num_osc, stimulus, params, ccore = ccore_flag); (t, dyn_peripheral, dyn_central) = net.simulate(steps, time); amount_canvases = 1; if (isinstance(separate, list)): amount_canvases = len(separate) + 2; elif (separate is True): amount_canvases = len(dyn_peripheral[0]) + 2; visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False); visualizer.append_dynamics(t, dyn_peripheral, 0, separate); visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True); visualizer.show();
def testVisualizeSeparateListNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(2); visualizer.append_dynamics(t, y, canvas=0, separate=[ [0], [1] ]);
def testVisualizeMultipleDynamicNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(1); visualizer.append_dynamics(t, y);
def testVisualizeSignleDynamicNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t, y);
def testVisualizeUnusedCanvasesNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(3); visualizer.append_dynamic(t, y, canvas=0, color='red');
def testVisualizeSeparateSequenceNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7] y = [[0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2]] visualizer = dynamic_visualizer(2) visualizer.append_dynamics(t, y, canvas=0, separate=True)
def testVisualizeSeparateListNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(2); visualizer.append_dynamics(t, y, canvas=0, separate=[ [0], [1] ]);
def testVisualizeMultipleDynamicNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ]; visualizer = dynamic_visualizer(1); visualizer.append_dynamics(t, y);
def testVisualizeSignleDynamicNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t, y);
def testVisualizeUnusedCanvasesNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(3); visualizer.append_dynamic(t, y, canvas=0, color='red');
def testVisualizeDynamicWithColorNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t, y, canvas=0, color='red');
def testVisualizeDynamicWithColorNoCrash(self): t = [0, 1, 2, 3, 4, 5, 6, 7]; y = [0, 0, 1, 2, 0, 1, 2, 0]; visualizer = dynamic_visualizer(1); visualizer.append_dynamic(t, y, canvas=0, color='red');
def template_image_segmentation(image_file, steps, time, dynamic_file_prefix): image = read_image(image_file) stimulus = rgb2gray(image) params = hhn_parameters() params.deltah = 650 params.w1 = 0.1 params.w2 = 9.0 params.w3 = 5.0 params.threshold = -10 stimulus = [255.0 - pixel for pixel in stimulus] divider = max(stimulus) / 50.0 stimulus = [int(pixel / divider) for pixel in stimulus] t, dyn_peripheral, dyn_central = None, None, None if (not os.path.exists(dynamic_file_prefix + 'dynamic_time.txt') or not os.path.exists(dynamic_file_prefix + 'dynamic_peripheral.txt') or not os.path.exists(dynamic_file_prefix + 'dynamic_dyn_central.txt')): print( "File with output dynamic is not found - simulation will be performed - it may take some time, be patient." ) net = hhn_network(len(stimulus), stimulus, params, ccore=True) (t, dyn_peripheral, dyn_central) = net.simulate(steps, time) print("Store dynamic to save time for simulation next time.") with open(dynamic_file_prefix + 'dynamic_time.txt', 'wb') as file_descriptor: pickle.dump(t, file_descriptor) with open(dynamic_file_prefix + 'dynamic_peripheral.txt', 'wb') as file_descriptor: pickle.dump(dyn_peripheral, file_descriptor) with open(dynamic_file_prefix + 'dynamic_dyn_central.txt', 'wb') as file_descriptor: pickle.dump(dyn_central, file_descriptor) else: print("Load output dynamic from file.") with open(dynamic_file_prefix + 'dynamic_time.txt', 'rb') as file_descriptor: t = pickle.load(file_descriptor) with open(dynamic_file_prefix + 'dynamic_peripheral.txt', 'rb') as file_descriptor: dyn_peripheral = pickle.load(file_descriptor) with open(dynamic_file_prefix + 'dynamic_dyn_central.txt', 'rb') as file_descriptor: dyn_central = pickle.load(file_descriptor) animate_segmentation(t, dyn_peripheral, image_file, 200) # just for checking correctness of results - let's use classical algorithm if (False): dbscan_instance = dbscan(image, 3, 4, True) dbscan_instance.process() trustable_clusters = dbscan_instance.get_clusters() amount_canvases = len(trustable_clusters) + 2 visualizer = dynamic_visualizer(amount_canvases, x_title="Time", y_title="V", y_labels=False) visualizer.append_dynamics(t, dyn_peripheral, 0, trustable_clusters) visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True) visualizer.show()
def template_image_segmentation(image_file, steps, time, dynamic_file_prefix): image = read_image(image_file); stimulus = rgb2gray(image); params = hhn_parameters(); params.deltah = 650; params.w1 = 0.1; params.w2 = 9.0; params.w3 = 5.0; params.threshold = -10; stimulus = [255.0 - pixel for pixel in stimulus]; divider = max(stimulus) / 50.0; stimulus = [int(pixel / divider) for pixel in stimulus]; t, dyn_peripheral, dyn_central = None, None, None; if ( not os.path.exists(dynamic_file_prefix + 'dynamic_time.txt') or not os.path.exists(dynamic_file_prefix + 'dynamic_peripheral.txt') or not os.path.exists(dynamic_file_prefix + 'dynamic_dyn_central.txt') ): print("File with output dynamic is not found - simulation will be performed - it may take some time, be patient."); net = hhn_network(len(stimulus), stimulus, params, ccore=True); (t, dyn_peripheral, dyn_central) = net.simulate(steps, time); print("Store dynamic to save time for simulation next time."); with open(dynamic_file_prefix + 'dynamic_time.txt', 'wb') as file_descriptor: pickle.dump(t, file_descriptor); with open(dynamic_file_prefix + 'dynamic_peripheral.txt', 'wb') as file_descriptor: pickle.dump(dyn_peripheral, file_descriptor); with open(dynamic_file_prefix + 'dynamic_dyn_central.txt', 'wb') as file_descriptor: pickle.dump(dyn_central, file_descriptor); else: print("Load output dynamic from file."); with open (dynamic_file_prefix + 'dynamic_time.txt', 'rb') as file_descriptor: t = pickle.load(file_descriptor); with open (dynamic_file_prefix + 'dynamic_peripheral.txt', 'rb') as file_descriptor: dyn_peripheral = pickle.load(file_descriptor); with open (dynamic_file_prefix + 'dynamic_dyn_central.txt', 'rb') as file_descriptor: dyn_central = pickle.load(file_descriptor); animate_segmentation(t, dyn_peripheral, image_file, 200); # just for checking correctness of results - let's use classical algorithm if (False): dbscan_instance = dbscan(image, 3, 4, True); dbscan_instance.process(); trustable_clusters = dbscan_instance.get_clusters(); amount_canvases = len(trustable_clusters) + 2; visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False); visualizer.append_dynamics(t, dyn_peripheral, 0, trustable_clusters); visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True); visualizer.show();