def main(): params = parameters.Parameters() params.read(sys.argv[1:]) sim = False for task in params.task: if task == "app": dash_ui.launcher.launch_app(params) elif task == "help": if (len(sys.argv) > 2): params.help(sys.argv[2]) else: params.help() elif task == "track": tracking.track(params) elif task == "simulate": simulation.simulate(params) sim = True elif task == "postprocess": postprocessing.postprocess(params, simulated=sim) elif task == "view": visualisation.render(params) elif task == "compare": trajectories.compare_trajectories(params) else: sys.exit(f"ERROR: Task {task} is not yet implemented. Aborting...")
def movie_menu(title, imdb_id): tracking.track('/Movies/Movie', { 'Title': title }) torrent_infos = [] torrent_provider = SharedCodeService.metaprovider.MetaProvider() torrent_provider.movies_get_specific_torrents(imdb_id, torrent_infos) torrent_infos.sort(key=lambda torrent_info: torrent_info.seeders, reverse=True) object_container = ObjectContainer(title2=title) for torrent_info in torrent_infos: seeders_leechers_line = '{0}\nSeeders: {1}, Leechers: {2}'.format(torrent_info.size, torrent_info.seeders, torrent_info.leechers) movie_object = MovieObject() SharedCodeService.trakt.movies_fill_movie_object(movie_object, imdb_id) object_container.title2 = movie_object.title movie_object.title = torrent_info.release movie_object.summary = '{0}\n\n{1}'.format(seeders_leechers_line, movie_object.summary) movie_object.url = torrent_info.url object_container.add(movie_object) return object_container
def menu(): tracking.track('/Anime') object_container = ObjectContainer(title2='Anime') object_container.add(DirectoryObject(key=Callback(popular_menu, title='Popular', per_page=31), title='Popular', summary='Browse popular anime')) object_container.add(InputDirectoryObject(key=Callback(search_menu, title='Search', per_page=31), title='Search', summary='Search anime', thumb=R('search.png'), prompt='Search for anime')) return object_container
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 episode_menu(show_title, tvdb_id, season_index, episode_index, first_aired_iso): tracking.track('/TV Shows/Episode', { 'Title': show_title, 'Season': season_index, 'Episode': episode_index }) torrent_provider = SharedCodeService.metaprovider.MetaProvider() torrent_infos = [] torrent_provider.tvshows_get_specific_torrents(tvdb_id, season_index, episode_index, first_aired_iso, torrent_infos) torrent_infos.sort(key=lambda torrent_info: torrent_info.seeders, reverse=True) object_container = ObjectContainer() for torrent_info in torrent_infos: seeders_leechers_line = '{0}\nSeeders: {1}, Leechers: {2}'.format(torrent_info.size, torrent_info.seeders, torrent_info.leechers) episode_object = EpisodeObject() SharedCodeService.trakt.tvshows_fill_episode_object(episode_object, tvdb_id, season_index, episode_index) object_container.title2 = episode_object.title episode_object.title = torrent_info.release episode_object.summary = '{0}\n\n{1}'.format(seeders_leechers_line, episode_object.summary) episode_object.url = torrent_info.url object_container.add(episode_object) return object_container
def movie_menu(title, imdb_id): tracking.track('/Movies/Movie', {'Title': title}) torrent_infos = [] torrent_provider = SharedCodeService.metaprovider.MetaProvider() torrent_provider.movies_get_specific_torrents(imdb_id, torrent_infos) torrent_infos.sort(key=lambda torrent_info: torrent_info.seeders, reverse=True) object_container = ObjectContainer(title2=title) for torrent_info in torrent_infos: seeders_leechers_line = '{0}\nSeeders: {1}, Leechers: {2}'.format( torrent_info.size, torrent_info.seeders, torrent_info.leechers) movie_object = MovieObject() SharedCodeService.trakt.movies_fill_movie_object(movie_object, imdb_id) object_container.title2 = movie_object.title movie_object.title = torrent_info.release movie_object.summary = '{0}\n\n{1}'.format(seeders_leechers_line, movie_object.summary) movie_object.url = torrent_info.url object_container.add(movie_object) return object_container
def favorites_menu(title): tracking.track('/TV Shows/' + title) ids = Dict['tvshows_favorites'] if 'tvshows_favorites' in Dict else [] object_container = ObjectContainer(title2=title) fill_object_container(object_container, ids) return object_container
def about_menu(): tracking.track('/About') object_container = ObjectContainer(title2='About') object_container.add(DirectoryObject(key=Callback(empty_menu), title='Channel version: {0}'.format(SharedCodeService.common.VERSION), summary='Current version of the BitTorrent channel')) object_container.add(DirectoryObject(key=Callback(empty_menu), title='Local IP: {0}'.format(Network.Address), summary='Plex Media Server Local IP')) object_container.add(DirectoryObject(key=Callback(empty_menu), title='Public IP: {0}'.format(Network.PublicAddress), summary='Plex Media Server Public IP')) return object_container
def run_tracking_task(nclicks, active_file, params_json): params = Parameters(json.loads(params_json)) params._params = json.loads(params_json) if ".tif" in active_file: params.name = active_file.replace('.tif','') tracking.track(params) return ["", 1, True, 'render-current-trajectories']
def onChange(self, trackbarValue): #set video to starting frame self.video.set(cv2.CAP_PROP_POS_FRAMES, self.start) cnts, image_edged3, image_contours = imagePros(self.fileName, option='vid') cells = [] bboxes = [] global x global y global w global h global counter counter = 0 cellTags = [] #Ignore contours that do not satisfy size criteria for i in cnts: if cv2.contourArea(i) < 700 or cv2.contourArea(i) > 6000: continue hull = cv2.convexHull(i) cv2.drawContours(image_contours, [hull], 0, (34, 255, 34), 2) x, y, w, h = cv2.boundingRect(i) #save coordinates in bboxes array bboxes.append([x, y, w, h]) M = cv2.moments(i) cx = int(M['m10'] / M['m00']) cy = int(M['m01'] / M['m00']) #save centers in cells array cells.append([cx, cy]) cellLet = chr(counter + 67) cellTags.append(counter + 67) cv2.putText(image_contours, cellLet, (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (225, 0, 255), 2) counter = counter + 1 cv2.putText(image_contours, "cell count: " + str(counter), (10, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2) #show starting video frame with each cell tagged cv2.imshow("cellVid", image_contours) k = cv2.waitKey() print(cellTags) print(k) if k == 27: pass elif k in cellTags: #selected cell's coordinates are sent to tracking print("key") cellnumber = k - 67 print(len(bboxes)) print(cellnumber) tracking.track(bboxes[cellnumber][0], bboxes[cellnumber][1], bboxes[cellnumber][2], bboxes[cellnumber][3], cv2.CAP_PROP_POS_FRAMES, self.fileName) pass
def menu(): tracking.track('/Movies') object_container = ObjectContainer(title2='Movies') object_container.add(DirectoryObject(key=Callback(movies_menu, title='Popular', page='/movies/trending', per_page=31), title='Popular', summary='Browse popular movies')) object_container.add(DirectoryObject(key=Callback(movies_menu, title='Rating', page='/movies/popular', per_page=31), title='Rating', summary='Browse highly-rated movies')) object_container.add(DirectoryObject(key=Callback(genres_menu, title='Genres'), title='Genres', summary='Browse movies by genre')) object_container.add(InputDirectoryObject(key=Callback(search_menu, title='Search', per_page=31), title='Search', summary='Search movies', thumb=R('search.png'), prompt='Search for movies')) return object_container
def genres_menu(title): tracking.track('/Movies/' + title) genres = SharedCodeService.trakt.movies_genres() object_container = ObjectContainer(title2=title) for genre in genres: object_container.add(DirectoryObject(key=Callback(genre_menu, title=genre[0], genre=genre[1], per_page=31), title=genre[0])) return object_container
def search_menu(title, query, per_page, count=0): tracking.track('/Movies/Search', { 'Query': query }) ids = [] count = SharedCodeService.trakt.movies_search(query, ids) object_container = ObjectContainer(title2=title) fill_object_container(object_container, ids) return object_container
def menu(): tracking.track('/TV Shows') object_container = ObjectContainer(title2='TV Shows') object_container.add(DirectoryObject(key=Callback(shows_menu, title='Popular', page='/shows/trending', per_page=31), title='Popular', summary='Browse popular TV shows')) object_container.add(DirectoryObject(key=Callback(shows_menu, title='Rating', page='/shows/popular', per_page=31), title='Rating', summary='Browse highly-rated TV shows')) object_container.add(DirectoryObject(key=Callback(genres_menu, title='Genres'), title='Genres', summary='Browse TV shows by genre')) object_container.add(DirectoryObject(key=Callback(favorites_menu, title='Favorites'), title='Favorites', summary='Browse your favorite TV shows', thumb=R('favorites.png'))) object_container.add(InputDirectoryObject(key=Callback(search_menu, title='Search', per_page=31), title='Search', summary='Search TV shows', thumb=R('search.png'), prompt='Search for TV shows')) return object_container
def remove_from_favorites(title, show_title, tvdb_id): tracking.track('/TV Shows/FavRemove', { 'Title': show_title }) if 'tvshows_favorites' in Dict and tvdb_id in Dict['tvshows_favorites']: Dict['tvshows_favorites'].remove(tvdb_id) Dict.Save() object_container = ObjectContainer(title2=title) object_container.header = 'Remove from Favorites' object_container.message = '{0} removed from Favorites'.format(show_title) return object_container
def genre_menu(title, genre, per_page, count=0): tracking.track('/Movies/Genre', { 'Genre': title }) ids = [] count = SharedCodeService.trakt.get_ids_from_page('/movies/popular/' + genre, ids, count, per_page) object_container = ObjectContainer(title2=title) fill_object_container(object_container, ids) object_container.add(NextPageObject(key=Callback(genre_menu, title=title, genre=genre, per_page=per_page, count=count), title="More...")) return object_container
def movies_menu(title, page, per_page, count=0): tracking.track('/Movies/' + title) ids = [] count = SharedCodeService.trakt.get_ids_from_page(page, ids, count, per_page) object_container = ObjectContainer(title2=title) fill_object_container(object_container, ids) object_container.add(NextPageObject(key=Callback(movies_menu, title=title, page=page, per_page=per_page, count=count), title="More...")) return object_container
def main(): cap = cv2.VideoCapture(1) # mask while (True): ret, frame = cap.read() if frame is None: #print("frame is None") continue img = processImage(frame) cv2.imshow('Image', img) key = cv2.waitKey(1) & 0xFF if doneBuilding(): if key == ord('m'): toggleMask(img) if key == ord('p'): break print("made mask") print("searching for bot...") # plan botLoc = None while (botLoc is None): ret, frame = cap.read() botLoc = tracking.track(frame) print("found bot at", botLoc) print("initializing bot...") bot = robot(botLoc) print("initialized bot!") print("finding path...") ret, frame = cap.read() img = processImage(frame) path = findPath(img, botLoc) print("found it") bot.followLine(path) # move while (True): ret, frame = cap.read() img = processImage(frame) botLoc = tracking.track(frame) # print("bot location:", botLoc) if botLoc == (None, None): continue bot.update(botLoc)
def season_menu(title, show_title, tvdb_id, season_index): tracking.track('/TV Shows/Season', { 'Title': show_title, 'Season': season_index }) object_container = ObjectContainer(title2=title) for episode_index in SharedCodeService.trakt.tvshows_get_season_episode_index_list(tvdb_id, season_index): directory_object = DirectoryObject() episode_data = SharedCodeService.trakt.tvshows_fill_episode_object(directory_object, tvdb_id, season_index, episode_index) directory_object.title = str(episode_index) + '. ' + directory_object.title directory_object.key = Callback(episode_menu, show_title=show_title, tvdb_id=tvdb_id, season_index=season_index, episode_index=episode_index, first_aired_iso=episode_data['first_aired_iso']) object_container.add(directory_object) return object_container
def add_to_favorites(title, show_title, tvdb_id): tracking.track('/TV Shows/FavAdd', { 'Title': show_title }) if 'tvshows_favorites' not in Dict: Dict['tvshows_favorites'] = [] if tvdb_id not in Dict['tvshows_favorites']: Dict['tvshows_favorites'].append(tvdb_id) Dict.Save() object_container = ObjectContainer(title2=title) object_container.header = 'Add to Favorites' object_container.message = '{0} added to Favorites'.format(show_title) return object_container
def test_plot_collection_into_separate_figure(self): """plot a polygon collection into a figure designed by us """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(5, 5) print 'start to copy' mesh_two = copy.deepcopy(mesh_one) print 'stop to copy' mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() tracked_ids = tracking.track(mesh_one, mesh_two) # figure properties figuresize = (4, 2.75) font = {'size': 10} plt.rc('font', **font) mesh_figure = plt.figure(figsize=figuresize) ax = plt.axes([0, 0, 1, 1]) polygon_collection = mesh_two.get_polygon_collection( color_by_global_id=True, total_number_of_global_ids=mesh_one.get_num_elements()) mesh_figure.gca().add_collection(polygon_collection) mesh_figure.gca().set_aspect('equal') mesh_figure.gca().autoscale_view() plt.axis('off') filename = path.join(dirname(__file__), 'output', 'own_visualisation_figure.pdf') mesh_figure.savefig(filename, bbox_inches='tight')
def make_permutation_plot(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9,9) 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 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 = 'permutation' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_general_division_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.creation.generate_random_tesselation(9,9) 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_general' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_death_plots(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9, 9) mesh_two = copy.deepcopy(mesh_one) # 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() 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.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 = 'cell_death' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_death_plots(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9,9) mesh_two = copy.deepcopy(mesh_one) # 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() 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.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 = 'cell_death' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_permutation_plot(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9, 9) 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 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 = 'permutation' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_general_division_plot(figuresize): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.creation.generate_random_tesselation(9, 9) 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_general' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def runme(input_vid_path, background_image_path, s_initial): # 1 - stabilize the input vid stabilized_vid = st.stabilize(input_vid_path) # 2 - subtract background from stabilized video print("Starting trimap") trimap_folder, trimap_vid = tri.trimap(stabilized_vid) print("Done with trimap") # 3 - apply matting print("Starting matting") matted_vid = mt.add_background_image(trimap_folder, stabilized_vid, background_image_path) print("Done with matting") # generate frames folder ut.save_video_frames(matted_vid, folder_name="matted_vid_4_frames") # 4 - apply tracking print("Starting tracking") output_vid = tr.track("matted_vid_4_frames", s_initial) # 5 - generate the output video from the tracked frames ut.create_video_from_image_folder("tracked_images", "OUTPUT.avi", shape=(555, 416)) print("Done tracking") return output_vid
def test_plot_collection_into_separate_figure(self): """plot a polygon collection into a figure designed by us """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(5,5) print 'start to copy' mesh_two = copy.deepcopy(mesh_one) print 'stop to copy' mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() tracked_ids = tracking.track(mesh_one, mesh_two) # figure properties figuresize = (4,2.75) font = {'size' : 10} plt.rc('font', **font) mesh_figure = plt.figure(figsize = figuresize) ax = plt.axes([0,0,1,1]) polygon_collection = mesh_two.get_polygon_collection(color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements()) mesh_figure.gca().add_collection(polygon_collection) mesh_figure.gca().set_aspect('equal') mesh_figure.gca().autoscale_view() plt.axis('off') filename = path.join(dirname(__file__),'output','own_visualisation_figure.pdf') mesh_figure.savefig(filename, bbox_inches = 'tight')
def main(model=Model.DECISION_TREE, seed=None): original_train, original_validate = load_data() train, validate = encode(original_train, original_validate) with tracking.track() as track: track.set_model(model) model, params = train_model(train, model, seed) track.log_params(params) validation_predictions = make_predictions(model, validate) print("Calculating metrics") evaluation_metrics = { 'nwrmsle': evaluation.nwrmsle(validation_predictions, validate['unit_sales'].values, validate['perishable'].values), 'r2_score': metrics.r2_score(y_true=validate['unit_sales'].values, y_pred=validation_predictions) } track.log_metrics(evaluation_metrics) write_predictions_and_score(evaluation_metrics, model, original_train.columns) print("Evaluation done with metrics {}.".format( json.dumps(evaluation_metrics)))
def xest_track_shuffled_2_by_2_mesh(self): """ This tests whether we can identify cells after they got shuffled (2 by 2) This test is known to fail: due to the symmetry of the problem cells tend to be mapped in the wrong order. """ mesh_one = mesh.creation.generate_hexagonal(2,2) mesh_two = mesh.creation.generate_hexagonal(2,2) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_in_reverse_order() id_map = tracking.track(mesh_one, mesh_two) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() subgraph_network = tracking.generate_subgraph_network(mesh_two, id_map) self.assertEqual(len(id_map), 4) for index_one in id_map: element_one = mesh_one.get_element_with_frame_id(index_one) element_two = mesh_two.get_element_with_global_id(id_map[index_one]) self.assertEqual(element_one.get_num_nodes(), element_two.get_num_nodes()) self.assertEqual(network_one.degree(index_one), network_two.degree(id_map[index_one])) self.assertAlmostEqual(element_one.calculate_area(), element_two.calculate_area()) np.testing.assert_almost_equal(element_one.calculate_centroid(), element_two.calculate_centroid())
def xest_track_shuffled_3_by_3_mesh(self): """ This tests whether we can identify cells after they got shuffled (3 by 3) """ mesh_one = mesh.creation.generate_hexagonal(3,3) mesh_two = mesh.creation.generate_hexagonal(3,3) mesh_one.assign_frame_ids_in_order() mesh_one.plot(path.join(dirname(__file__),'output','mesh_one.pdf')) mesh_two.assign_frame_ids_randomly() mesh_two.plot(path.join(dirname(__file__),'output','mesh_two_before_tracking.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) mesh_two.plot(path.join(dirname(__file__),'output','mesh_two_after_tracking.pdf'), color_by_global_id = True, total_number_of_global_ids = 9) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() subgraph_network = tracking.generate_subgraph_network(mesh_two, tracked_ids) self.assertEqual(len(tracked_ids), 9) for global_id in tracked_ids: element_one = mesh_one.get_element_with_frame_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 test_track_function_on_second_data(self): """Test tracking function on second data pair""" mesh_sequence = mesh.read_sequence_from_data( path.join(dirname(__file__), 'data', 'first_few_frames')) first_mesh = mesh_sequence[1] second_mesh = mesh_sequence[2] start_time = time.clock() tracked_ids = tracking.track(first_mesh, second_mesh) end_time = time.clock() print 'total time for second data pair is:' print end_time - start_time first_mesh.plot( path.join(dirname(__file__), 'output', 'second_mesh_tracked_with_third_total.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_total.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements())
def test_track_very_large_random_mesh(self): """generate a small random mesh and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(30,30) print 'start to copy' mesh_two = copy.deepcopy(mesh_one) print 'stop to copy' mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() mesh_one.plot(path.join(dirname(__file__),'output','very_large_random_mesh_one.pdf')) mesh_two.plot(path.join(dirname(__file__),'output','very_large_random_mesh_two_before_tracking.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) mesh_two.plot(path.join(dirname(__file__),'output','very_large_random_mesh_after_tracking.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements()) network_one = mesh_one.generate_network() network_two = mesh_two.generate_network() self.assertEqual( len(tracked_ids), mesh_one.get_num_elements()) for global_id in tracked_ids: element_one = mesh_one.get_element_with_frame_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 test_track_function_on_first_data(self): """See whether we can fully track the mesh using the track function of the tracking module""" mesh_sequence = mesh.read_sequence_from_data( path.join(dirname(__file__), 'data', 'first_few_frames')) first_mesh = mesh_sequence[0] second_mesh = mesh_sequence[1] start_time = time.clock() tracked_ids = tracking.track(first_mesh, second_mesh) end_time = time.clock() print 'total time for first data pair is:' print end_time - start_time first_mesh.plot( path.join(dirname(__file__), 'output', 'first_mesh_tracked_total.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_total.pdf'), color_by_global_id=True, total_number_of_global_ids=first_mesh.get_num_elements())
def xest_track_cell_death(self): """track a cell death event and identify the cells that are involved in rearrangement""" sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(9, 9) mesh_one.save( path.join(dirname(__file__), 'output', 'death_mesh_one.mesh')) mesh_two = copy.deepcopy(mesh_one) # mesh_one = mesh.load('death_mesh_one.mesh') # mesh_two = mesh.load('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(path.join(dirname(__file__), 'output', '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', 'tracked_mesh_after_death.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) 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 Main(): Log.Info('============================================') Log.Info('Client:') Log.Info(' - Product: {0}'.format(Client.Product)) Log.Info(' - Platform: {0}'.format(Client.Platform)) Log.Info('============================================') tracking.track('/') object_container = ObjectContainer(title2=TITLE) object_container.add(DirectoryObject(key=Callback(anime_menu.menu), title='Anime', summary='Browse anime')) object_container.add(DirectoryObject(key=Callback(movies_menu.menu), title='Movies', summary='Browse movies')) object_container.add(DirectoryObject(key=Callback(tvshows_menu.menu), title='TV Shows', summary="Browse TV shows")) object_container.add(PrefsObject(title='Preferences', summary='Preferences for BitTorrent channel')) object_container.add(DirectoryObject(key=Callback(about_menu), title='About', summary='About BitTorrent channel', thumb=R('about.png'))) return object_container
def tvshow_menu(title, tvdb_id): tracking.track('/TV Shows/TV Show', { 'Title': title }) object_container = ObjectContainer(title2=title) if 'tvshows_favorites' in Dict and tvdb_id in Dict['tvshows_favorites']: object_container.add(DirectoryObject(key=Callback(remove_from_favorites, title='Remove from Favorites', show_title=title, tvdb_id=tvdb_id), title='Remove from Favorites', summary='Remove TV show from Favorites', thumb=R('favorites.png'))) else: object_container.add(DirectoryObject(key=Callback(add_to_favorites, title='Add to Favorites', show_title=title, tvdb_id=tvdb_id), title='Add to Favorites', summary='Add TV show to Favorites', thumb=R('favorites.png'))) for season_index in SharedCodeService.trakt.tvshows_get_season_index_list(tvdb_id): season_object = SeasonObject() SharedCodeService.trakt.tvshows_fill_season_object(season_object, tvdb_id, season_index) season_object.key = Callback(season_menu, title=season_object.title, show_title=title, tvdb_id=tvdb_id, season_index=season_object.index) season_object.rating_key = '{0}-{1}-{2}'.format(title, tvdb_id, season_index) object_container.add(season_object) return object_container
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 make_t1_plots(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9, 9) 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.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 = 't1_swap' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def episode_menu(show_title, tvshow_id, season_index, episode_index, first_aired_iso): tracking.track('/TV Shows/Episode', { 'Title': show_title, 'Season': season_index, 'Episode': episode_index }) torrent_provider = SharedCodeService.metaprovider.MetaProvider() torrent_infos = [] torrent_provider.tvshows_get_specific_torrents(tvshow_id, season_index, episode_index, first_aired_iso, torrent_infos) torrent_infos.sort(key=lambda torrent_info: torrent_info.seeders, reverse=True) object_container = ObjectContainer() for torrent_info in torrent_infos: seeders_leechers_line = '{0}\nSeeders: {1}, Leechers: {2}'.format( torrent_info.size, torrent_info.seeders, torrent_info.leechers) episode_object = EpisodeObject() SharedCodeService.trakt.tvshows_fill_episode_object( episode_object, tvshow_id, season_index, episode_index) object_container.title2 = episode_object.title episode_object.title = torrent_info.release episode_object.summary = '{0}\n\n{1}'.format(seeders_leechers_line, episode_object.summary) episode_object.url = torrent_info.url object_container.add(episode_object) return object_container
def search_menu(title, query, per_page, movie_count=0): tracking.track('/Anime/Search', { 'Query': query }) torrent_infos = [] torrent_provider = SharedCodeService.metaprovider.MetaProvider() torrent_provider.anime_search(query, torrent_infos) torrent_infos.sort(key=lambda torrent_info: torrent_info.seeders, reverse=True) object_container = ObjectContainer(title2=title) for torrent_info in torrent_infos: seeders_leechers_line = '{0}\nSeeders: {1}, Leechers: {2}'.format(torrent_info.size, torrent_info.seeders, torrent_info.leechers) videoclip_object = VideoClipObject() videoclip_object.title = torrent_info.title videoclip_object.summary = seeders_leechers_line videoclip_object.url = torrent_info.url object_container.add(videoclip_object) return object_container
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 test_visualise_search(self): """generate a small random mesh and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(5,5) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() tracked_ids = tracking.track(mesh_one, mesh_two) mesh_two.plot(path.join(dirname(__file__),'output','visualisation_mesh_after_tracking.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements())
def make_t1_plots(figuresize): mesh_one = mesh.creation.generate_random_tesselation(9,9) 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.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 = 't1_swap' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def xest_track_cell_death(self): """track a cell death event and identify the cells that are involved in rearrangement""" sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(9,9) mesh_one.save(path.join(dirname(__file__),'output','death_mesh_one.mesh')) mesh_two = copy.deepcopy(mesh_one) # mesh_one = mesh.load('death_mesh_one.mesh') # mesh_two = mesh.load('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(path.join(dirname(__file__),'output','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','tracked_mesh_after_death.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) 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 test_visualise_search(self): """generate a small random mesh and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(5, 5) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() tracked_ids = tracking.track(mesh_one, mesh_two) mesh_two.plot(path.join(dirname(__file__), 'output', 'visualisation_mesh_after_tracking.pdf'), color_by_global_id=True, total_number_of_global_ids=mesh_one.get_num_elements())
def xest_track_9_by_9_random_mesh(self): """generate a small random mesh and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(9,9) mesh_one.save(path.join(dirname(__file__),'output','nine_by_nine_permutation_mesh_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 mesh_one.plot(path.join(dirname(__file__),'output','larger_random_mesh_one.pdf')) mesh_two.plot(path.join(dirname(__file__),'output','larger_random_mesh_two_before_tracking.pdf')) tracked_ids = tracking.track(mesh_one, mesh_two) 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))) mesh_one.plot(path.join(dirname(__file__),'output','nine_by_nine_permuation_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','nine_by_nine_permuation_mesh_after.pdf'), color_by_global_id = True, total_number_of_global_ids = mesh_one.get_num_elements()) 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()) plt.close('all')
def make_translation_plots(figuresize): sys.setrecursionlimit(40000) large_mesh = mesh.creation.generate_random_tesselation(15, 8) 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)) 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]] 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 mesh_one.index_global_ids() mesh_two.index_global_ids() tracked_ids_all = [] tracked_ids_all = tracking.track(mesh_one, mesh_two) plotname = 'translation' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
def make_translation_plots(figuresize): sys.setrecursionlimit(40000) large_mesh = mesh.creation.generate_random_tesselation(15,8) 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)) 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]] 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 mesh_one.index_global_ids() mesh_two.index_global_ids() tracked_ids_all = [] tracked_ids_all = tracking.track( mesh_one, mesh_two ) plotname = 'translation' make_difference_plot(mesh_one, mesh_two, tracked_ids, tracked_ids_all, plotname, figuresize)
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')
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_double_division_plot(): """We load a mesh where two maximum common subgraphs will be identified, and track the division event""" mesh_one = mesh.creation.generate_random_tesselation(9, 9) 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() # get adjacent element ids adjacent_elements = most_central_element.get_ids_of_adjacent_elements() # pick one second_dividing_cell = adjacent_elements[0] mesh_two.divide_element_with_frame_id(most_central_element.id_in_frame) mesh_two.divide_element_with_frame_id(second_dividing_cell) tracked_ids = tracking.track(mesh_one, mesh_two) plotname = 'double_division' figuresize = (4, 2.75) figure_1 = plt.figure(figsize=figuresize) first_polygon_collection = mesh_one.get_polygon_collection( color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) figure_1.gca().add_collection(first_polygon_collection) figure_1.gca().set_aspect('equal') figure_1.gca().autoscale_view() plt.axis('off') this_filename = plotname + '_before_all_colors.pdf' figure_1.savefig(this_filename, bbox_inches='tight') plt.close(figure_1) figure_2 = plt.figure(figsize=figuresize) second_polygon_collection = mesh_two.get_polygon_collection( color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) figure_2.gca().add_collection(second_polygon_collection) figure_2.gca().set_aspect('equal') figure_2.gca().autoscale_view() plt.axis('off') this_filename = plotname + '_after_all_colors.pdf' figure_2.savefig(this_filename, bbox_inches='tight') plt.close(figure_2) figure_3 = plt.figure(figsize=figuresize) third_polygon_collection = mesh_one.get_polygon_collection( color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) polygon_list = [] for element in mesh_one.elements: this_polygon = mpl.patches.Polygon( [node.position for node in element.nodes], fill=True) if element.global_id == None: this_polygon.set_facecolor([1.0, 1.0, 1.0]) else: if element.id_in_frame in ground_truth: second_element = mesh_two.get_element_with_global_id( element.global_id).id_in_frame if ground_truth[element.id_in_frame] == second_element: this_polygon.set_facecolor('#2dec34') else: this_polygon.set_facecolor('red') else: this_polygon.set_facecolor('red') polygon_list.append(this_polygon) third_polygon_collection = mpl.collections.PatchCollection( polygon_list, match_original=True) figure_3.gca().add_collection(third_polygon_collection) figure_3.gca().set_aspect('equal') figure_3.gca().autoscale_view() plt.axis('off') this_filename = plotname + '_before.pdf' figure_3.savefig(this_filename, bbox_inches='tight') plt.close(figure_3) figure_4 = plt.figure(figsize=figuresize) fourth_polygon_collection = mesh_two.get_polygon_collection( color_by_global_id=True, total_number_of_global_ids=len(tracked_ids)) polygon_list = [] for element in mesh_two.elements: this_polygon = mpl.patches.Polygon( [node.position for node in element.nodes], fill=True) if element.global_id == None: this_polygon.set_facecolor([1.0, 1.0, 1.0]) else: if element.id_in_frame in ground_truth.values(): first_element = mesh_one.get_element_with_global_id( element.global_id).id_in_frame if first_element in ground_truth: if ground_truth[first_element] == element.id_in_frame: this_polygon.set_facecolor('#2dec34') else: this_polygon.set_facecolor('red') else: this_polygon.set_facecolor('red') else: this_polygon.set_facecolor('red') polygon_list.append(this_polygon) fourth_polygon_collection = mpl.collections.PatchCollection( polygon_list, match_original=True) figure_4.gca().add_collection(fourth_polygon_collection) figure_4.gca().set_aspect('equal') figure_4.gca().autoscale_view() plt.axis('off') this_filename = plotname + '_after.pdf' figure_4.savefig(this_filename, bbox_inches='tight') plt.close(figure_4)
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')
def xest_track_t1_swap(self): """generate a random mesh, copy it, perform a t1 swap on it, and track it. """ sys.setrecursionlimit(40000) mesh_one = mesh.creation.generate_random_tesselation(9,9) mesh_two = copy.deepcopy(mesh_one) mesh_one.assign_frame_ids_in_order() mesh_two.assign_frame_ids_randomly() mesh_one.save(path.join(dirname(__file__),'output','mesh_t1_one.mesh')) mesh_one.save(path.join(dirname(__file__),'output','mesh_t1_two.mesh')) # 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 ) mesh_one.plot(path.join(dirname(__file__),'output','tracked_mesh_before_t1_swap.pdf')) mesh_two.plot(path.join(dirname(__file__),'output','tracked_mesh_after_t1_swap.pdf')) tracked_ids = tracking.track( mesh_one, mesh_two ) mesh_one.plot(path.join(dirname(__file__),'output','tracked_mesh_before_t1_swap.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) mesh_two.plot(path.join(dirname(__file__),'output','tracked_mesh_after_t1_swap.pdf'), color_by_global_id = True, total_number_of_global_ids = len(tracked_ids) ) # make sure that the entire mesh was tracked 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))) 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')
channel[7].codePhase = 26519 channel[7].status = 'T' showChannelStatus(channel, settings) #Track the acquired satellites trackSamples = getSamples.int8( settings.fileName, settings.msToProcess, 11 * samplesPerCode ) #11*samplesPerCode is number of samples used in acquisition if settings.skipTracking: print "\nLoading old tracking results ... ", (trackResults, channel) = pickle.load(open("trackResults.pickle", "rb")) print "done" else: startTime = datetime.now() print "\nTracking started at", startTime (trackResults, channel) = track(trackSamples, channel, settings) pickle.dump((trackResults, channel), open("trackResults.pickle", "wb")) print "Tracking Done. Elapsed time =", (datetime.now() - startTime) if settings.plotTrackingLow: trackLowFigures = plotTrackingLow(trackResults, settings) if settings.plotTrackingHigh: trackHighFigure = plotTrackingHigh(channel, trackResults, settings) #Do navigation if settings.skipNavigation: print "\nLoading old navigation results ... ", (navSolutions, eph) = pickle.load(open("navResults.pickle", "rb")) print "done" else: startTime = datetime.now() print "\nNavigation started at", startTime