Пример #1
0
 def test_create_new_tree_from_old_node_link_save_load(self):
     first_tree = TestImageTree.create_one_high_tree()
     first_tree_filename = 'tcntfonlsl.tsv'
     second_tree_filename = 'saveload_nl.tsv'
     if os.path.isfile(first_tree_filename):
         os.remove(first_tree_filename)
     if os.path.isfile(second_tree_filename):
         os.remove(second_tree_filename)
     first_tree.set_filename(first_tree_filename)
     serializer.save_tree(first_tree)
     quad_key = '321'
     new_link = first_tree.get_link()
     new_tree_result = tree_creator.create_new_from_old_insert_node_link(
         old_tree=first_tree,
         link_to_insert=new_link,
         quad_key=quad_key,
         new_tree_name='sln',
         filename=second_tree_filename)
     new_tree = new_tree_result.value
     serializer.save_tree_only_filename(new_tree, new_tree.filename)
     self.assertTrue(os.path.isfile(second_tree_filename))
     self.assertTrue(os.path.isfile(first_tree.filename))
     loaded_tree = serializer.load_link_new_serializer(new_tree.get_link())
     self.assertEqual(loaded_tree, new_tree)
     os.remove(second_tree_filename)
     os.remove(first_tree_filename)
Пример #2
0
 def test_lowest_set_node(self):
     node_link = 'start@https://artmapstore.blob.core.windows.net/firstnodes/user/abhishek/start.ver_10.tsv'
     root_tree = serializer.load_link_new_serializer(node_link)
     quad_key = '001023020031111023210'
     lowest_set_node, relative_quad_key = root_tree.lowest_set_node(
         quad_key)
     self.assertEqual(relative_quad_key, '0')
     self.assertTrue(lowest_set_node.is_set())
Пример #3
0
 def test_save_load_compact(self):
     filename = 'test_compact.tsv.gzip'
     tree = TestImageTree.create_one_high_tree(filename)
     serializer.save_tree(tree)
     loaded_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename, node_name=tree.name))
     self.assertEqual(tree, loaded_tree)
     os.remove(filename)
Пример #4
0
 def test_image_at_quadkey_child_same(self):
     fruits_link = constants.FRUITS_LINK
     fruit_tree = serializer.load_link_new_serializer(fruits_link)
     test_resolution = 256
     own_image = fruit_tree.get_np_array(test_resolution)
     child_pil_image = fruit_tree.get_pil_image_at_quadkey(
         resolution=test_resolution, quad_key='33')
     self.assertLess(utilities.mse(own_image, np.array(child_pil_image)),
                     0.1)
Пример #5
0
 def test_image_at_quadkey_resolution(self):
     fruits_link = constants.FRUITS_LINK
     fruit_tree = serializer.load_link_new_serializer(fruits_link)
     test_resolution = 256
     for quad_key in ['', '3', '33', '33313']:
         pil_image = fruit_tree.get_pil_image_at_quadkey(
             quad_key=quad_key, resolution=test_resolution)
         self.assertEqual((test_resolution, test_resolution),
                          pil_image.size)
Пример #6
0
 def test_load_root_name(self):
     filename = 'test_load_root.tsv.gz'
     tree = TestImageTree.create_one_high_tree(filename=filename)
     serializer.save_tree(tree)
     loaded_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename=filename, node_name='son'))
     self.assertEqual('son', loaded_tree.name)
     self.assertEqual(1, loaded_tree.height(max_height=7))
     os.remove(filename)
Пример #7
0
 def test_fruits(self):
     fruit_relative_filename = 'fruits.tsv'
     current_dir = os.path.dirname(os.path.realpath(__file__))
     fruit_filename = os.path.join(current_dir, fruit_relative_filename)
     self.assertTrue(os.path.isfile(fruit_filename))
     link = utilities.format_node_address(node_name='fruits',
                                          filename=fruit_filename)
     fruit_tree = serializer.load_link_new_serializer(link=link)
     rendered = fruit_tree.get_np_array(128)
     self.assertEqual(rendered.shape[0], 128)
Пример #8
0
 def test_save_load_infinite(self):
     tree = TestImageTree.create_one_high_tree()
     tree.get_children()[0] = tree
     filename = 'test_infinite.tsv.gz'
     tree.set_filename(filename)
     serializer.save_tree(tree)
     new_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename=filename,
                                       node_name='father'))
     self.assertEqual('father', new_tree.name)
     os.remove(filename)
Пример #9
0
 def test_save_load_random(self):
     tree = treegenerator.TreeGenerator.create_random_tree('ra',
                                                           4,
                                                           pixel=(0, 0, 0),
                                                           variance=1)
     filename = 'rat.tsv.gz'
     tree.set_filename(filename)
     root_link = utilities.format_node_address(filename, node=tree.name)
     serializer.save_tree(tree)
     another_tree = serializer.load_link_new_serializer(link=root_link)
     self.assertEqual(tree, another_tree)
     os.remove(filename)
Пример #10
0
 def test_save_load_different_format(self):
     filename_extensions = ['.tsv', '.tsv.gz', '.itpb', '.itpb.gz']
     base_filename = 'sldf'
     for extension in filename_extensions:
         filename = base_filename + extension
         tree = TestImageTree.create_one_high_tree(filename)
         serializer.save_tree(tree)
         loaded_tree = serializer.load_link_new_serializer(
             utilities.format_node_address(filename, node_name=tree.name))
         self.assertEqual(tree.select(lambda x: x.name),
                          loaded_tree.select(lambda x: x.name))
         os.remove(filename)
Пример #11
0
 def test_multiple_file_link_load(self):
     tree = TestImageTree.create_one_high_tree()
     second_filename = 'second.tsv.gz'
     tree._children_links[2] = utilities.format_node_address(
         filename=second_filename, node_name=tree.get_children()[2].name)
     tree.get_children()[2].filename = second_filename
     serializer.save_tree(tree)
     self.assertTrue(os.path.isfile(second_filename))
     link = tree.get_link()
     loaded_tree = serializer.load_link_new_serializer(link=link)
     self.assertEqual(loaded_tree, tree)
     os.remove(second_filename)
Пример #12
0
 def test_performance_deep_quad_key_500ms(self):
     quad_key = '001023020031110131'
     node_link = 'start@https://artmapstore.blob.core.windows.net/firstnodes/user/abhishek/start.ver_10.tsv'
     root_tree = serializer.load_link_new_serializer(node_link)
     pil_image0 = root_tree.get_pil_image_at_quadkey(
         resolution=256, quad_key=quad_key)  # warm it up
     start_time = time.time()
     pil_image1 = root_tree.get_pil_image_at_quadkey(resolution=256,
                                                     quad_key=quad_key)
     end_time = time.time()
     duration_ms = 1000 * (end_time - start_time)
     time_limit_ms = 50
     self.assertLess(
         duration_ms, time_limit_ms, 'Time taken to create image ' +
         str(duration_ms) + ' is not less than ' + str(time_limit_ms))
Пример #13
0
 def test_create_new_tree_from_old_jpg_save_load(self):
     if os.path.isfile(TestImageTree.father_filename):
         os.remove(TestImageTree.father_filename)
     first_tree = TestImageTree.create_one_high_tree()
     serializer.save_tree(first_tree)
     quad_key = '021'
     new_link = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Maquette_EDM_salon_du_Bourget_2013_DSC_0192.JPG/273px-Maquette_EDM_salon_du_Bourget_2013_DSC_0192.JPG'
     filename = 'saveload_jpg.tsv'
     new_tree = tree_creator.create_new_from_old_insert_jpg(
         old_tree=first_tree,
         link_to_insert=new_link,
         quad_key=quad_key,
         new_tree_name='slj',
         filename=filename).value
     serializer.save_tree_only_filename(new_tree, new_tree.filename)
     self.assertTrue(os.path.isfile(filename))
     self.assertTrue(os.path.isfile(first_tree.filename))
     loaded_tree = serializer.load_link_new_serializer(new_tree.get_link())
     self.assertEqual(loaded_tree, new_tree)
     os.remove(filename)
     os.remove(first_tree.filename)
Пример #14
0
 def test_descendant_consistent_image_render_at_quadkey(self):
     fruits_link = constants.FRUITS_LINK
     fruit_tree = serializer.load_link_new_serializer(fruits_link)
     lowest_quad_keys = ['333133', '312312', '131231']
     for lowest_quad_key in lowest_quad_keys:
         start_resolution = 64
         expected_same_images = []
         for i in range(len(lowest_quad_key) + 1):
             node_quad_key = lowest_quad_key[:i]
             resolution = 2**(len(lowest_quad_key) - i) * 32
             node_image = fruit_tree.get_np_array_at_quad_key(
                 quad_key=node_quad_key, resolution=resolution)
             image_quad_key = lowest_quad_key[i:]
             expected_same_image = imagetree.image_at_quad_key(
                 node_image,
                 resolution=start_resolution,
                 quad_key=image_quad_key)
             expected_same_images.append(expected_same_image)
         for expected_same_image in expected_same_images:
             self.assertLess(
                 utilities.mse(expected_same_image,
                               expected_same_images[0]), 0.1)
Пример #15
0
 def test_sparse_link(self):
     node_link = 'start0010@https://artmapstore.blob.core.windows.net/firstnodes/user/abhishek/start.ver_10.tsv'
     sparse_tree = serializer.load_link_new_serializer(node_link)
     pil_image = sparse_tree.get_pil_image_at_quadkey(resolution=512,
                                                      quad_key='1')
     self.assertEqual((512, 512), pil_image.size)
Пример #16
0
 def test_not_found_link(self):
     not_found_tree = serializer.load_link_new_serializer('bababaaskjfalj')
     self.assertEqual(not_found_tree.name,
                      standard_nodes.not_found_node(None, None).name)