def test_track_multiple_t1_swaps_special_example_7(self): sys.setrecursionlimit(40000) first_mesh = mesh.load(path.join(dirname(__file__), 'data', 'multiple_t1_example_7_before.mesh')) second_mesh = mesh.load(path.join(dirname(__file__), 'data', 'multiple_t1_example_7_after.mesh')) # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(first_mesh.elements): ground_truth[element.id_in_frame] = second_mesh.elements[element_index].id_in_frame first_mesh.plot(path.join(dirname(__file__),'output','multiple_t1_example_7_before.pdf')) second_mesh.plot(path.join(dirname(__file__),'output','multiple_t1_example_7_after.pdf')) tracking.track(first_mesh, second_mesh) # tracking.find_maximum_common_subgraph(first_mesh, second_mesh) first_mesh.plot(path.join(dirname(__file__),'output','multiple_t1_example_7_before.pdf'), color_by_global_id = True, total_number_of_global_ids = first_mesh.get_num_elements()) second_mesh.plot(path.join(dirname(__file__),'output','multiple_t1_example_7_after.pdf'), color_by_global_id = True, total_number_of_global_ids = first_mesh.get_num_elements()) print 'evaluate tracking' tracking_success, number_tracked_cells = tracking.evaluate_tracking(first_mesh, second_mesh, ground_truth)
def test_track_division_standard_case(self): """We load a mesh where only one maximum common subgraph should be identified, and track the division event""" mesh_one = mesh.load( path.join(dirname(__file__), 'data', 'standard_simple_division_one.mesh')) mesh_two = mesh.load( path.join(dirname(__file__), 'data', 'standard_simple_division_two.mesh')) # First pick a cell in the centre mesh_centre = mesh_two.calculate_centre() mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[ element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id(most_central_element.id_in_frame) tracked_ids = tracking.track(mesh_one, mesh_two) mesh_one.plot(path.join(dirname(__file__), 'output', 'tracked_standard_mesh_before_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) mesh_two.plot(path.join(dirname(__file__), 'output', 'tracked_standard_mesh_after_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) # make sure that the entire mesh was tracked (except for the dead cell) self.assertEqual(len(tracked_ids), mesh_one.get_num_elements() - 2) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals(ground_truth[element_one.id_in_frame], element_two.id_in_frame) plt.close('all')
def make_division_II_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.load('standard_ambiguous_division_one.mesh') mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id_in_direction(most_central_element.id_in_frame, [1.0, 1.0]) subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) subgraph_finder.find_maximum_common_subgraph() post_processor = tracking.PostProcessor(mesh_one, mesh_two, [subgraph_finder.largest_mappings[1]]) post_processor.index_global_ids_from_largest_mappings() tracked_ids = post_processor.mapped_ids tracked_ids_all = tracked_ids plotname = 'division_II' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_division_resolved_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.load('standard_ambiguous_division_one.mesh') mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id_in_direction(most_central_element.id_in_frame, [1.0, 1.0]) tracked_ids = tracking.find_maximum_common_subgraph( mesh_one, mesh_two ) for element in mesh_one.elements: element.global_id = None for element in mesh_two.elements: element.global_id = None tracked_ids_all = tracking.track(mesh_one, mesh_two) plotname = 'division_all' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_division_resolved_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.load('standard_ambiguous_division_one.mesh') mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[ element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id_in_direction( most_central_element.id_in_frame, [1.0, 1.0]) tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) for element in mesh_one.elements: element.global_id = None for element in mesh_two.elements: element.global_id = None tracked_ids_all = tracking.track(mesh_one, mesh_two) plotname = 'division_all' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def test_post_processing_for_second_data_pair(self): """Load two segmented data frames and track them""" first_mesh = mesh.load( path.join(dirname(__file__), 'output', 'second_mesh_tracked_with_third_mesh_cleaned.mesh')) second_mesh = mesh.load( path.join(dirname(__file__), 'output', 'third_mesh_tracked_cleaned.mesh')) largest_mapping = {} for element in first_mesh.elements: if element.global_id != None: second_frame_id = second_mesh.get_element_with_global_id( element.global_id).id_in_frame largest_mapping[element.id_in_frame] = second_frame_id largest_mappings = [largest_mapping] post_processor = tracking.PostProcessor(first_mesh, second_mesh, largest_mappings) post_processor.index_global_ids_from_largest_mappings() post_processor.post_process_with_data() first_mesh.plot( path.join(dirname(__file__), 'output', 'second_mesh_tracked_with_third_mesh_processed.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements()) second_mesh.plot( path.join(dirname(__file__), 'output', 'third_mesh_tracked_processed.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements()) first_mesh.save( path.join( dirname(__file__), 'output', 'second_mesh_tracked_with_third_mesh_tracked_processed.mesh')) second_mesh.save( path.join(dirname(__file__), 'output', 'third_mesh_tracked_processed.mesh'))
def test_translation_special_case(self): """load first random mesh, move it, and track it. """ sys.setrecursionlimit(40000) large_mesh = mesh.load(path.join(dirname(__file__),'data','special_translation_mesh_one.mesh')) large_mesh.assign_frame_ids_in_order() mesh_one = large_mesh.copy_region_of_interest((3,10),(-1,9)) mesh_two = large_mesh.copy_region_of_interest((5,12),(-1,9)) # Build ground truth ground_truth_indices = {} for element_index, element in enumerate(mesh_one.elements): if element.id_in_frame in mesh_two.frame_id_dictionary: ground_truth_indices[element_index] = mesh_two.frame_id_dictionary[element.id_in_frame] mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() ground_truth = {} for element_index, element in enumerate(mesh_one.elements): if element_index in ground_truth_indices: ground_truth[element.id_in_frame] = mesh_two.elements[ground_truth_indices[element_index]].id_in_frame print 'call tracker' tracked_ids = tracking.track(mesh_one, mesh_two) # tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) print 'tracker returned' mesh_one.plot(path.join(dirname(__file__),'output', 'special_translation_mesh_one.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) mesh_two.plot(path.join(dirname(__file__),'output', 'special_translation_mesh_two.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() self.assertEqual( len(tracked_ids), len(ground_truth) ) # for frame_id in ground_truth: # if mesh_one.get_element_with_frame_id(frame_id).global_id == None: # print 'element with this frame id did not get tracked:' # print frame_id for global_id in tracked_ids: element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEqual(element_one.get_num_nodes(), element_two.get_num_nodes()) self.assertAlmostEqual(element_one.calculate_area(), element_two.calculate_area()) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame )
def test_save_and_load(self): """make a mesh, save, and load it""" mesh_to_save = mesh.creation.generate_random_tesselation(3,3) mesh_to_save.save(path.join(dirname(__file__),'output','test_mesh.mesh')) loaded_mesh = mesh.load(path.join(dirname(__file__),'output','test_mesh.mesh')) assert( loaded_mesh == mesh_to_save ) self.assertAlmostEqual( loaded_mesh.calculate_total_area(), mesh_to_save.calculate_total_area() )
def test_save_and_load(self): """make a mesh, save, and load it""" mesh_to_save = mesh.creation.generate_random_tesselation(3, 3) mesh_to_save.save( path.join(dirname(__file__), 'output', 'test_mesh.mesh')) loaded_mesh = mesh.load( path.join(dirname(__file__), 'output', 'test_mesh.mesh')) assert (loaded_mesh == mesh_to_save) self.assertAlmostEqual(loaded_mesh.calculate_total_area(), mesh_to_save.calculate_total_area())
def test_track_special_permutation_mesh(self): """generate a small random mesh and track it. """ mesh_one = mesh.load(path.join(dirname(__file__),'data','special_permutation_mesh.mesh')) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame mesh_one.plot(path.join(dirname(__file__),'output','special_permutation_mesh_one.pdf')) mesh_two.plot(path.join(dirname(__file__),'output','special_permutation_mesh_two_before_tracking.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) mesh_one.plot(path.join(dirname(__file__),'output','special_permutation_mesh_before.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements()) mesh_two.plot(path.join(dirname(__file__),'output','special_permutation_mesh_after.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements()) dangling_elements_one = mesh_one.get_dangling_element_ids(ground_truth.keys()) self.assertGreaterEqual(len(tracked_ids), max(mesh_one.get_num_elements() - 3, mesh_one.get_num_elements() - len(dangling_elements_one))) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() for global_id in tracked_ids: element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEqual(element_one.get_num_nodes(), element_two.get_num_nodes()) self.assertEqual(network_one.degree(element_one.id_in_frame), network_two.degree(element_two.id_in_frame)) self.assertAlmostEqual(element_one.calculate_area(), element_two.calculate_area()) np.testing.assert_almost_equal(element_one.calculate_centroid(), element_two.calculate_centroid())
def make_division_II_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.load('standard_ambiguous_division_one.mesh') mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[ element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id_in_direction( most_central_element.id_in_frame, [1.0, 1.0]) subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder( mesh_one, mesh_two) subgraph_finder.find_maximum_common_subgraph() post_processor = tracking.PostProcessor( mesh_one, mesh_two, [subgraph_finder.largest_mappings[1]]) post_processor.index_global_ids_from_largest_mappings() tracked_ids = post_processor.mapped_ids tracked_ids_all = tracked_ids plotname = 'division_II' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def test_translation_special_case_three(self): """load third random mesh, move it, and track it. """ sys.setrecursionlimit(40000) large_mesh = mesh.load(path.join(dirname(__file__),'data','special_translation_mesh_three.mesh')) large_mesh.assign_frame_ids_in_order() mesh_one = large_mesh.copy_region_of_interest((3,10),(-1,9)) mesh_two = large_mesh.copy_region_of_interest((5,12),(-1,9)) # Build ground truth ground_truth_indices = {} for element_index, element in enumerate(mesh_one.elements): if element.id_in_frame in mesh_two.frame_id_dictionary: ground_truth_indices[element_index] = mesh_two.frame_id_dictionary[element.id_in_frame] mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_reverse_order() ground_truth = {} for element_index, element in enumerate(mesh_one.elements): if element_index in ground_truth_indices: ground_truth[element.id_in_frame] = mesh_two.elements[ground_truth_indices[element_index]].id_in_frame # tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) tracked_ids = tracking.track(mesh_one, mesh_two) # subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('debug_mesh_special_before_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('debug_mesh_special_after_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_one.plot(path.join(dirname(__file__),'output', 'special_translation_mesh_three_before.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) mesh_two.plot(path.join(dirname(__file__),'output', 'special_translation_mesh_three_after.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() self.assertEqual( len(tracked_ids), len(ground_truth) ) for global_id in tracked_ids: element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEqual(element_one.get_num_nodes(), element_two.get_num_nodes()) self.assertAlmostEqual(element_one.calculate_area(), element_two.calculate_area()) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame )
def test_track_special_division_eight(self): """read a special mesh, perform a division event, and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.load( path.join(dirname(__file__), 'data', 'division_special_mesh_nine.mesh')) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_reverse_order() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[ element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() file_to_read = open( path.join(dirname(__file__), 'data', 'division_special_direction_nine.pickle'), 'r') division_direction = pickle.load(file_to_read) file_to_read.close() mesh_two.divide_element_with_frame_id_in_direction( most_central_element.id_in_frame, division_direction) mesh_one.plot( path.join(dirname(__file__), 'output', 'tracked_special_mesh_eight_before_division.pdf')) mesh_two.plot( path.join(dirname(__file__), 'output', 'tracked_special_mesh_eight_after_division.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) # tracked_ids = tracking.find_maximum_common_subgraph( mesh_one, mesh_two ) # subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('debug_mesh_special_before_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('debug_mesh_special_after_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_one.plot(path.join( dirname(__file__), 'output', 'tracked_special_mesh_eight_before_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) mesh_two.plot(path.join( dirname(__file__), 'output', 'tracked_special_mesh_eight_after_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) # make sure that the entire mesh was tracked (except for the dead cell) self.assertEqual(len(tracked_ids), mesh_one.get_num_elements() - 1) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEqual(ground_truth[element_one.id_in_frame], element_two.id_in_frame) # plt.close('all')
from OpenGL.GLU import * import cv import mesh import wx import cybvh import random import quantities as pq import sounds if not 'window' in globals(): window = PointWindow(size=(640, 480)) ROULETTE = 0.2 meshname = 'ellipse' mesh.load(meshname) mycybvh = cybvh.CyBVH(mesh.mybvh.verts[:, :3].copy(), np.array(mesh.mybvh.tris)[:, :3].copy(), mesh.mybvh.nodes) def reset_sink(): global sink, sinkrad, source sinkrad = 0.8 source = np.array([0, 0, 0], 'f') sink = np.array([0, 0, 0], 'f') if not 'sink' in globals(): reset_sink() window.Refresh()
def test_track_special_t1_swap_4(self): """generate a random mesh, copy it, perform a t1 swap on it, and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.load(path.join(dirname(__file__), 'data', 'special_t1_mesh_four.mesh')) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # Perform T1 swap on mesh two # First pick a node in the centre mesh_centre = mesh_two.calculate_centre() # pick the node closest to the centre min_distance = 3*mesh_two.calculate_height() for node in mesh_two.nodes: distance = np.linalg.norm(node.position - mesh_centre) if distance < min_distance: min_distance = distance most_central_node = node # pick a node that shares an edge with this central node for local_index, element_node in enumerate(most_central_node.adjacent_elements[0].nodes): if element_node.id == most_central_node.id: num_nodes_this_element = most_central_node.adjacent_elements[0].get_num_nodes() one_edge_node = most_central_node.adjacent_elements[0].nodes[(local_index+1)%num_nodes_this_element] break mesh_two.perform_t1_swap( most_central_node.id, one_edge_node.id ) tracked_ids = tracking.track( mesh_one, mesh_two ) # subgraph_finder = tracking.LocalisedSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # post_processor = tracking.PostProcessor(mesh_one, mesh_two, subgraph_finder.largest_mappings) # post_processor.tidy_current_mapping() # post_processor.index_global_ids_from_largest_mappings() # network_one = mesh_one.generate_network_of_unidentified_elements() # print network_one.nodes() # post_processor.altered_fill_in_by_adjacency(network_one) # post_processor.index_global_ids() # subgraph_finder = tracking.LocalisedSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_one.plot(path.join(dirname(__file__),'output','tracked_mesh_before_special_t1_swap_four.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements() ) mesh_two.plot(path.join(dirname(__file__),'output','tracked_mesh_after_special_t1_swap_four.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements() ) # # make sure that the entire mesh was tracked # self.assertEqual( len(tracked_ids), mesh_one.get_num_elements() ) # mesh_one.plot(path.join(dirname(__file__),'output','tracked_mesh_before_special_t1_swap_three.pdf')) # mesh_two.plot(path.join(dirname(__file__),'output','tracked_mesh_after_special_t1_swap_three.pdf')) # for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame ) plt.close('all')
import core import mesh import sys,time e=core.Environment(sys.argv) import discr import exporter m=mesh.Mesh_3() m = mesh.load(m,"feelpp3d.geo",0.1) Xh=discr.Pch_3D_P1(mesh=m) P0h = discr.Pdh_3D_P0(mesh=m) u=Xh.elementFromExpr("{sin(2*pi*x)*cos(pi*y)*cos(pi*z)}:x:y:z") e = exporter.exporter(mesh=m) e.addScalar("un", 1.) e.addP1c("u",u); e.addP0d("pid",discr.pid( P0h )); e.save()
def test_track_special_case(self): """track a cell death event and identify the cells that are involved in rearrangement""" sys.setrecursionlimit(40000) mesh_one = mesh.load(path.join(dirname(__file__),'data','special_death_mesh_one.mesh')) mesh_two = mesh.load(path.join(dirname(__file__),'data','special_death_mesh_two.mesh')) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.kill_element_with_frame_id(most_central_element.id_in_frame) mesh_one.plot(path.join(dirname(__file__),'output','not_tracked_mesh_before_death.pdf' )) mesh_two.plot(path.join(dirname(__file__),'output','not_tracked_mesh_after_death.pdf' )) tracked_ids = tracking.track( mesh_one, mesh_two ) # # mesh_one.plot('special_tracked_mesh_before_death.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('special_tracked_mesh_after_death.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # tracked_ids = tracking.find_maximum_common_subgraph( mesh_one, mesh_two ) # subgraph_finder = tracking.LocalisedSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) mesh_one.plot(path.join(dirname(__file__),'output','special_tracked_mesh_before_death.pdf'), color_by_global_id = True, total_number_of_global_ids = len( tracked_ids ) ) mesh_two.plot(path.join(dirname(__file__),'output','special_tracked_mesh_after_death.pdf'), color_by_global_id = True, total_number_of_global_ids = len( tracked_ids ) ) # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # # make sure that the entire mesh was tracked (except for the dead cell) self.assertEqual( len(tracked_ids), mesh_two.get_num_elements() - 2 ) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame ) plt.close('all')
import core import mesh import sys, time e = core.Environment(sys.argv) import discr import exporter m2d = mesh.Mesh_2() m2d = mesh.load(m2d, "triangle.geo", 0.1) Xh = discr.Pch_2D_P1(mesh=m2d) P0h = discr.Pdh_2D_P0(mesh=m2d) u = Xh.elementFromExpr("{sin(2*pi*x)*cos(pi*y)}:x:y") e = exporter.exporter(mesh=m2d) e.addScalar("un", 1.) e.addP1c("u", u) e.addP0d("pid", discr.pid(P0h)) e.save()
'test_on_data', 'data', 'first_few_frames', 'Segment_0_002.tif') # first_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked.mesh')) # second_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked.mesh')) # # # first_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked_cleaned.mesh')) # second_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_cleaned.mesh')) # # # first_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked_processed.mesh')) # second_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_processed.mesh')) first_mcs = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_on_data', 'output', 'second_mesh_tracked_with_third_mesh.mesh')) second_mcs = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_on_data', 'output', 'third_mesh_tracked.mesh')) sys.setrecursionlimit(40000) first_mcs_copy = copy.deepcopy(first_mcs) weakly_connected_global_ids = find_weakly_connected_cells(first_mcs_copy) first_mcs_cleaned = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_on_data', 'output', 'second_mesh_tracked_with_third_mesh_cleaned.mesh')) second_mcs_cleaned = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_on_data',
import cybvh import bvh import numpy as np import mesh import time N_RAYS = 1000 origins = np.random.rand(N_RAYS,3).astype('f') directions = np.random.rand(N_RAYS,3).astype('f')-0.5 directions /= np.sqrt(np.sum(directions*directions,1))\ .reshape(-1,1).astype('f') mesh.load('blueghost') global mycybvh mycybvh = cybvh.CyBVH(mesh.mybvh.verts[:,:3].copy(), np.array(mesh.mybvh.tris)[:,:3].copy(), mesh.mybvh.nodes) def test_intersect_triangle(): N_TRIS = 100 v0,v1,v2 = np.random.rand(3, N_TRIS, 3).astype('f') bvht = [bvh.intersect_triangle(origins[i], directions[i], v0[j], v1[j], v2[j]) for i in range(N_RAYS) for j in range(N_TRIS)] cybvht = [cybvh.intersect_triangle(origins[i], directions[i], v0[j], v1[j], v2[j]) for i in range(N_RAYS) for j in range(N_TRIS)] bvht = np.array(bvht)
import cv import mesh import wx import cybvh import random import quantities as pq import sounds if not 'window' in globals(): window = PointWindow(size=(640,480)) ROULETTE=0.2 meshname = 'ellipse' mesh.load(meshname) mycybvh = cybvh.CyBVH(mesh.mybvh.verts[:,:3].copy(), np.array(mesh.mybvh.tris)[:,:3].copy(), mesh.mybvh.nodes) def reset_sink(): global sink, sinkrad, source sinkrad = 0.8 source = np.array([0,0,0],'f') sink = np.array([0,0,0],'f') if not 'sink' in globals(): reset_sink() window.Refresh()
def test_track_special_case_seven(self): """generate a random mesh, copy it, perform a death event, and find maximum common subgraph not sure whether this one even works! """ sys.setrecursionlimit(40000) mesh_one = mesh.load( path.join(dirname(__file__), 'data', 'special_death_mesh_seven.mesh')) mesh_two = mesh.load( path.join(dirname(__file__), 'data', 'special_death_mesh_seven.mesh')) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_reverse_order() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[ element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.kill_element_with_frame_id(most_central_element.id_in_frame) tracked_ids = tracking.track(mesh_one, mesh_two) # subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) mesh_one.plot(path.join(dirname(__file__), 'output', 'special_tracked_mesh_7_before_death.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) mesh_two.plot(path.join(dirname(__file__), 'output', 'special_tracked_mesh_7_after_death.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) dangling_elements_one = mesh_one.get_dangling_element_ids( ground_truth.keys()) self.assertGreaterEqual( len(tracked_ids), max(mesh_one.get_num_elements() - 4, mesh_one.get_num_elements() - len(dangling_elements_one) - 1)) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals(ground_truth[element_one.id_in_frame], element_two.id_in_frame) plt.close('all')
import cybvh import bvh import numpy as np import mesh import time N_RAYS = 1000 origins = np.random.rand(N_RAYS, 3).astype('f') directions = np.random.rand(N_RAYS, 3).astype('f') - 0.5 directions /= np.sqrt(np.sum(directions*directions,1))\ .reshape(-1,1).astype('f') mesh.load('blueghost') global mycybvh mycybvh = cybvh.CyBVH(mesh.mybvh.verts[:, :3].copy(), np.array(mesh.mybvh.tris)[:, :3].copy(), mesh.mybvh.nodes) def test_intersect_triangle(): N_TRIS = 100 v0, v1, v2 = np.random.rand(3, N_TRIS, 3).astype('f') bvht = [ bvh.intersect_triangle(origins[i], directions[i], v0[j], v1[j], v2[j]) for i in range(N_RAYS) for j in range(N_TRIS) ] cybvht = [ cybvh.intersect_triangle(origins[i], directions[i], v0[j], v1[j], v2[j]) for i in range(N_RAYS)
def test_translation_special_case_eleven(self): """generate a random mesh, move it, and track it. """ sys.setrecursionlimit(40000) large_mesh = mesh.load(path.join(dirname(__file__),'data','special_translation_mesh_thirteen.mesh')) large_mesh.assign_frame_ids_in_order() mesh_one = large_mesh.copy_region_of_interest((3,10),(-1,9)) mesh_two = large_mesh.copy_region_of_interest((5,12),(-1,9)) # Build ground truth ground_truth_indices = {} for element_index, element in enumerate(mesh_one.elements): if element.id_in_frame in mesh_two.frame_id_dictionary: ground_truth_indices[element_index] = mesh_two.frame_id_dictionary[element.id_in_frame] mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() ground_truth = {} for element_index, element in enumerate(mesh_one.elements): if element_index in ground_truth_indices: ground_truth[element.id_in_frame] = mesh_two.elements[ground_truth_indices[element_index]].id_in_frame print 'call tracker' # tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) tracked_ids = tracking.track(mesh_one, mesh_two) print 'tracker returned' mesh_one.plot(path.join(dirname(__file__),'output','special_translation_mesh_thirteen_before.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids)) mesh_two.plot(path.join(dirname(__file__),'output','special_translation_mesh_thirteen_after.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids)) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() # Find any dangling elements that may not be identifiable through adjacency dangling_elements_counter = 0 dangling_elements = [] for element_one_id in ground_truth: element_one = mesh_one.get_element_with_frame_id(element_one_id) element_two = mesh_two.get_element_with_frame_id(ground_truth[element_one_id]) ids_adjacent_to_element_one = element_one.get_ids_of_adjacent_elements() ids_adjacent_to_element_two = element_two.get_ids_of_adjacent_elements() mappable_elements_adjacent_to_elements_one = set(ids_adjacent_to_element_one).intersection(ground_truth.keys()) mappable_elements_adjacent_to_elements_two = set(ids_adjacent_to_element_two).intersection(ground_truth.values()) if (len(mappable_elements_adjacent_to_elements_one) == 1 or len(mappable_elements_adjacent_to_elements_two) == 1): dangling_elements_counter += 1 dangling_elements.append(element_one_id) elif (len(mappable_elements_adjacent_to_elements_one) == 2): neighbouring_polygon_number_is_the_same = False for element in mappable_elements_adjacent_to_elements_one: element_polygon_number = mesh_one.get_element_with_frame_id(element).get_num_nodes() if element_polygon_number == element_one.get_num_nodes(): dangling_elements.append(element_one_id) dangling_elements_counter += 1 break elif (len(mappable_elements_adjacent_to_elements_two) == 2): neighbouring_polygon_number_is_the_same = False for element in mappable_elements_adjacent_to_elements_two: element_polygon_number = mesh_two.get_element_with_frame_id(element).get_num_nodes() if element_polygon_number == element_two.get_num_nodes(): dangling_elements.append(element_one_id) dangling_elements_counter += 1 break for global_id in tracked_ids: element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEqual(element_one.get_num_nodes(), element_two.get_num_nodes()) self.assertAlmostEqual(element_one.calculate_area(), element_two.calculate_area()) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame ) self.assertGreaterEqual( len(tracked_ids), max( len(ground_truth) - dangling_elements_counter, len(ground_truth) - 3 ) )
def test_track_special_case_seven(self): """generate a random mesh, copy it, perform a death event, and find maximum common subgraph not sure whether this one even works! """ sys.setrecursionlimit(40000) mesh_one = mesh.load(path.join(dirname(__file__),'data','special_death_mesh_seven.mesh')) mesh_two = mesh.load(path.join(dirname(__file__),'data','special_death_mesh_seven.mesh')) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_reverse_order() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.kill_element_with_frame_id(most_central_element.id_in_frame) tracked_ids = tracking.track( mesh_one, mesh_two ) # subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) mesh_one.plot(path.join(dirname(__file__),'output','special_tracked_mesh_7_before_death.pdf'), color_by_global_id = True, total_number_of_global_ids = len( tracked_ids ) ) mesh_two.plot(path.join(dirname(__file__),'output','special_tracked_mesh_7_after_death.pdf'), color_by_global_id = True, total_number_of_global_ids = len( tracked_ids ) ) dangling_elements_one = mesh_one.get_dangling_element_ids(ground_truth.keys()) self.assertGreaterEqual(len(tracked_ids), max(mesh_one.get_num_elements() - 4, mesh_one.get_num_elements() - len(dangling_elements_one) -1)) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals( ground_truth[element_one.id_in_frame], element_two.id_in_frame ) plt.close('all')
def make_three_sided_division_plot(): """We load a mesh where only one maximum common subgraph should be identified, and track the division event""" mesh_one = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_tracking', 'data', 'division_special_mesh_six.mesh')) mesh_two = mesh.load( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_tracking', 'data', 'division_special_mesh_six.mesh')) # First pick a cell in the centre mesh_centre = mesh_two.calculate_centre() mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_order() most_central_element = mesh_two.find_most_central_element() most_central_element_id = most_central_element.id_in_frame file_to_read = open( path.join(dirname(__file__), '..', '..', '..', 'test', 'test_tracking', 'data', 'division_special_direction_six.pickle'), 'r') division_direction = pickle.load(file_to_read) file_to_read.close() mesh_two.divide_element_with_frame_id_in_direction( most_central_element.id_in_frame, division_direction) daughter_cell_id_one = mesh_one.get_maximal_frame_id() + 1 daughter_cell_id_two = mesh_one.get_maximal_frame_id() + 2 cells_adjacent_to_daughter_cell_one = mesh_two.get_element_with_frame_id( daughter_cell_id_one).get_ids_of_adjacent_elements() cells_adjacent_to_daughter_cell_two = mesh_two.get_element_with_frame_id( daughter_cell_id_two).get_ids_of_adjacent_elements() bordering_cells = set.intersection( set(cells_adjacent_to_daughter_cell_one), set(cells_adjacent_to_daughter_cell_two)) first_mesh_polygon_list = [] for element in mesh_one.elements: this_polygon = mpl.patches.Polygon( [node.position for node in element.nodes], fill=True) if element.id_in_frame in bordering_cells: this_polygon.set_facecolor('slategrey') elif element.id_in_frame == most_central_element_id: this_polygon.set_facecolor('lightskyblue') else: this_polygon.set_facecolor([1.0, 1.0, 1.0]) first_mesh_polygon_list.append(this_polygon) first_mesh_polygon_collection = mpl.collections.PatchCollection( first_mesh_polygon_list, match_original=True) first_mesh_figure = plt.figure() first_mesh_figure.gca().add_collection(first_mesh_polygon_collection) first_mesh_figure.gca().set_aspect('equal') first_mesh_figure.gca().autoscale_view() plt.axis('off') first_mesh_figure.savefig('three_sided_division_first.pdf', bbox_inches='tight') plt.close(first_mesh_figure) second_mesh_polygon_list = [] for element in mesh_two.elements: this_polygon = mpl.patches.Polygon( [node.position for node in element.nodes], fill=True) if element.id_in_frame in bordering_cells: this_polygon.set_facecolor('slategrey') elif (element.id_in_frame == daughter_cell_id_one or element.id_in_frame == daughter_cell_id_two): this_polygon.set_facecolor('lightskyblue') else: this_polygon.set_facecolor('white') second_mesh_polygon_list.append(this_polygon) second_mesh_polygon_collection = mpl.collections.PatchCollection( second_mesh_polygon_list, match_original=True) second_mesh_figure = plt.figure() second_mesh_figure.gca().add_collection(second_mesh_polygon_collection) second_mesh_figure.gca().set_aspect('equal') second_mesh_figure.gca().autoscale_view() plt.axis('off') second_mesh_figure.savefig('three_sided_division_second.pdf', bbox_inches='tight') plt.close(second_mesh_figure)
def test_post_processing_for_first_data_pair(self): """Load two segmented data frames and track them""" first_mesh = mesh.load( path.join(dirname(__file__), 'output', 'first_mesh_tracked_cleaned.mesh')) second_mesh = mesh.load( path.join(dirname(__file__), 'output', 'second_mesh_tracked_cleaned.mesh')) largest_mapping = {} for element in first_mesh.elements: if element.global_id != None: second_frame_id = second_mesh.get_element_with_global_id( element.global_id).id_in_frame largest_mapping[element.id_in_frame] = second_frame_id largest_mappings = [largest_mapping] post_processor = tracking.PostProcessor(first_mesh, second_mesh, largest_mappings) post_processor.index_global_ids_from_largest_mappings() post_processor.post_process_with_data() first_mesh.plot( path.join(dirname(__file__), 'output', 'first_mesh_tracked_processed.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements()) second_mesh.plot( path.join(dirname(__file__), 'output', 'second_mesh_tracked_processed.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements()) first_mesh.save( path.join(dirname(__file__), 'output', 'first_mesh_tracked_processed.mesh')) second_mesh.save( path.join(dirname(__file__), 'output', 'second_mesh_tracked_processed.mesh')) global_ids = [] for element in second_mesh.elements: if element.global_id != None: if element.global_id in global_ids: print 'found double global id' else: global_ids.append(element.global_id) global_ids_one = [] for element in first_mesh.elements: if element.global_id != None: if element.global_id in global_ids_one: print 'found double global id' else: global_ids_one.append(element.global_id) self.assertEqual(len(global_ids_one), len(global_ids))
def test_track_special_case(self): """track a cell death event and identify the cells that are involved in rearrangement""" sys.setrecursionlimit(40000) mesh_one = mesh.load( path.join(dirname(__file__), 'data', 'special_death_mesh_one.mesh')) mesh_two = mesh.load( path.join(dirname(__file__), 'data', 'special_death_mesh_two.mesh')) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[ element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.kill_element_with_frame_id(most_central_element.id_in_frame) mesh_one.plot( path.join(dirname(__file__), 'output', 'not_tracked_mesh_before_death.pdf')) mesh_two.plot( path.join(dirname(__file__), 'output', 'not_tracked_mesh_after_death.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) # # mesh_one.plot('special_tracked_mesh_before_death.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('special_tracked_mesh_after_death.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # tracked_ids = tracking.find_maximum_common_subgraph( mesh_one, mesh_two ) # subgraph_finder = tracking.LocalisedSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # tracked_ids = tracking.find_maximum_common_subgraph(mesh_one, mesh_two) mesh_one.plot(path.join(dirname(__file__), 'output', 'special_tracked_mesh_before_death.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) mesh_two.plot(path.join(dirname(__file__), 'output', 'special_tracked_mesh_after_death.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_death_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # # make sure that the entire mesh was tracked (except for the dead cell) self.assertEqual(len(tracked_ids), mesh_two.get_num_elements() - 2) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals(ground_truth[element_one.id_in_frame], element_two.id_in_frame) plt.close('all')
second_filename = path.join(dirname(__file__),'..','..','..','test','test_on_data','data','first_few_frames', 'Segment_0_001.tif') third_filename = path.join(dirname(__file__),'..','..','..','test','test_on_data','data','first_few_frames', 'Segment_0_002.tif') # first_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked.mesh')) # second_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked.mesh')) # # # first_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked_cleaned.mesh')) # second_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_cleaned.mesh')) # # # first_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','first_mesh_tracked_processed.mesh')) # second_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_processed.mesh')) first_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_with_third_mesh.mesh')) second_mcs = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','third_mesh_tracked.mesh')) sys.setrecursionlimit(40000) first_mcs_copy = copy.deepcopy(first_mcs) weakly_connected_global_ids = find_weakly_connected_cells(first_mcs_copy) first_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_with_third_mesh_cleaned.mesh')) second_mcs_cleaned = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','third_mesh_tracked_cleaned.mesh')) first_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','second_mesh_tracked_with_third_mesh_tracked_processed.mesh')) second_mcs_tracked = mesh.load(path.join(dirname(__file__),'..','..','..','test','test_on_data','output','third_mesh_tracked_processed.mesh'))
def make_four_sided_division_plot(): """We load a mesh where only one maximum common subgraph should be identified, and track the division event""" mesh_one = mesh.load(path.join(dirname(__file__),'..','..','..', 'test','test_tracking','data', 'standard_ambiguous_division_one.mesh')) mesh_two = mesh.load(path.join(dirname(__file__),'..','..','..', 'test','test_tracking','data', 'standard_ambiguous_division_two.mesh')) # First pick a cell in the centre mesh_centre = mesh_two.calculate_centre() mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_order() most_central_element = mesh_two.find_most_central_element() most_central_element_id = most_central_element.id_in_frame mesh_two.divide_element_with_frame_id_in_direction(most_central_element.id_in_frame, [1.0,1.0]) daughter_cell_id_one = mesh_one.get_maximal_frame_id() + 1 daughter_cell_id_two = mesh_one.get_maximal_frame_id() + 2 cells_adjacent_to_daughter_cell_one = mesh_two.get_element_with_frame_id(daughter_cell_id_one).get_ids_of_adjacent_elements() cells_adjacent_to_daughter_cell_two = mesh_two.get_element_with_frame_id(daughter_cell_id_two).get_ids_of_adjacent_elements() bordering_cells = set.intersection(set(cells_adjacent_to_daughter_cell_one), set(cells_adjacent_to_daughter_cell_two)) first_mesh_polygon_list = [] for element in mesh_one.elements: this_polygon = mpl.patches.Polygon([node.position for node in element.nodes], fill = True) if element.id_in_frame in bordering_cells: this_polygon.set_facecolor('slategrey') elif element.id_in_frame == most_central_element_id: this_polygon.set_facecolor('lightskyblue') else: this_polygon.set_facecolor([1.0, 1.0, 1.0]) first_mesh_polygon_list.append(this_polygon) first_mesh_polygon_collection = mpl.collections.PatchCollection(first_mesh_polygon_list, match_original = True) first_mesh_figure = plt.figure() first_mesh_figure.gca().add_collection(first_mesh_polygon_collection) first_mesh_figure.gca().set_aspect('equal') first_mesh_figure.gca().autoscale_view() plt.axis('off') first_mesh_figure.savefig('four_sided_division_first.pdf', bbox_inches = 'tight') plt.close(first_mesh_figure) second_mesh_polygon_list = [] for element in mesh_two.elements: this_polygon = mpl.patches.Polygon([node.position for node in element.nodes], fill = True) if element.id_in_frame in bordering_cells: this_polygon.set_facecolor('slategrey') elif ( element.id_in_frame == daughter_cell_id_one or element.id_in_frame == daughter_cell_id_two): this_polygon.set_facecolor('lightskyblue') else: this_polygon.set_facecolor('white') second_mesh_polygon_list.append(this_polygon) second_mesh_polygon_collection = mpl.collections.PatchCollection(second_mesh_polygon_list, match_original = True) second_mesh_figure = plt.figure() second_mesh_figure.gca().add_collection(second_mesh_polygon_collection) second_mesh_figure.gca().set_aspect('equal') second_mesh_figure.gca().autoscale_view() plt.axis('off') second_mesh_figure.savefig('four_sided_division_second.pdf', bbox_inches = 'tight') plt.close(second_mesh_figure)
def test_track_division_standard_ambiguous_case(self): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.load( path.join(dirname(__file__), 'data', 'standard_ambiguous_division_one.mesh')) mesh_two = mesh.load( path.join(dirname(__file__), 'data', 'standard_ambiguous_division_two.mesh')) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() # build ground truth for testing the mapping ground_truth = {} for element_index, element in enumerate(mesh_one.elements): ground_truth[element.id_in_frame] = mesh_two.elements[ element_index].id_in_frame # pick the element closest to the centre most_central_element = mesh_two.find_most_central_element() mesh_two.divide_element_with_frame_id_in_direction( most_central_element.id_in_frame, [1.0, 1.0]) tracked_ids = tracking.track(mesh_one, mesh_two) # tracked_ids = tracking.find_maximum_common_subgraph( mesh_one, mesh_two ) # subgraph_finder = tracking.ReducedBacktrackingSubgraphFinder(mesh_one, mesh_two) # subgraph_finder.find_maximum_common_subgraph() # largest_mappings = subgraph_finder.largest_mappings # # for mapping_index, large_mapping in enumerate(largest_mappings): # # tracked_ids = [] # # for element_one in mesh_one.elements: # element_one.global_id = None # # for element_two in mesh_two.elements: # element_two.global_id = None # # for global_id, frame_one_id in enumerate(large_mapping): # mesh_one.get_element_with_frame_id(frame_one_id).global_id = global_id # mesh_two.get_element_with_frame_id(large_mapping[frame_one_id]).global_id = global_id # tracked_ids.append(global_id) # # mesh_one.index_global_ids() # mesh_two.index_global_ids() # # mesh_one.plot('mesh_special_before_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) # mesh_two.plot('mesh_special_after_division_' + str(mapping_index) + '.pdf', color_by_global_id = True, # total_number_of_global_ids = len( tracked_ids ) ) mesh_one.plot(path.join(dirname(__file__), 'output', 'tracked_ambiguous_mesh_before_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) mesh_two.plot(path.join(dirname(__file__), 'output', 'tracked_ambiguous_mesh_after_division.pdf'), color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) # make sure that the entire mesh was tracked (except for the dead cell) self.assertEqual(len(tracked_ids), mesh_one.get_num_elements() - 2) for global_id in tracked_ids: # and that the mapping coincides with the ground truth for all tracked ids element_one = mesh_one.get_element_with_global_id(global_id) element_two = mesh_two.get_element_with_global_id(global_id) self.assertEquals(ground_truth[element_one.id_in_frame], element_two.id_in_frame) plt.close('all')