コード例 #1
0
 def test_node_object_is_clean(self):
     graph = LocationGraph([[0.1, 0.2]])
     node = graph.highest
     self.assertEqual(
         set(node.__dict__.keys()),
         {'outflow', 'altitude', 'flow', 'is_border', 'above', 'below', 'position'}
     )
コード例 #2
0
 def test_4_merged_points(self):
     graph = LocationGraph([[2, 2], [2, 2]])
     self.assertEqual(len(graph), 1)
     self.assertEqual(graph.highest, graph.lowest)
     self.assertIsNone(graph.highest.above)
     self.assertIsNone(graph.highest.below)
     self.assertEqual(graph.highest.outflow, [])
コード例 #3
0
    def test_node_conversion(self):
        graph = LocationGraph([[0.1, 0.2]])
        node = graph.highest

        self.assertEqual(node.altitude, 0.2)
        self.assertEqual(node.flow, 0.0)
        self.assertEqual(len(node.outflow), 1)
        self.assertEqual(graph.lowest, next(iter(node.outflow)))
コード例 #4
0
 def flow(self, data):
     graph = LocationGraph(data)
     num_points = sum([len(i) for i in data])
     self.assertEqual(num_points, len(graph))
     writer = DummyWriter()
     writer.update = MagicMock()
     nodes_with_flow = flow(graph, writer)
     self.assertEqual(writer.update.call_count, num_points)
     return [i.flow for i in nodes_with_flow.ascending()]
コード例 #5
0
    def test_multiple_merged_points(self):
        graph = LocationGraph([[2, 2, 2], [2, 1, 2], [2, 2, 2]])
        self.assertEqual(len(graph), 2)

        top = graph.highest
        self.assertEqual(
            top.position,
            {(0,0),(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)}
        )
        self.assertEqual(top.altitude, 2)
        self.assertEqual(len(top.outflow), 1)
        self.assertEqual(top.is_border, True)

        bottom = graph.lowest
        self.assertEqual(bottom.position, {(1, 1)})
        self.assertEqual(bottom.altitude, 1)
        self.assertEqual(len(bottom.outflow), 0)
        self.assertEqual(bottom.is_border, False)
コード例 #6
0
    def test_node_merging(self):
        graph = LocationGraph([[0.1, 0.2], [0.1, 0.3]])
        self.assertEqual(len(graph), 3)

        top = graph.highest
        self.assertEqual(top.position, {(1,1)})
        self.assertEqual(len(top.outflow), 2)
        self.assertEqual(top.altitude, 0.3)
        self.assertEqual(top.is_border, True)

        middle = top.below
        self.assertEqual(middle.position, {(0, 1)})
        self.assertEqual(len(middle.outflow), 1)
        self.assertEqual(middle.altitude, 0.2)
        self.assertEqual(middle.is_border, True)

        bottom = graph.lowest
        self.assertEqual(bottom.position, {(0, 0), (1,0)})
        self.assertEqual(bottom.altitude, 0.1)
        self.assertEqual(bottom.position, {(0, 0), (1, 0)})
        self.assertEqual(len(bottom.outflow), 0)
コード例 #7
0
import pickle
from data_structures.location_graph import LocationGraph
from utils.load_image import load_and_crop_data
from utils.report_settings import report_settings

config = {
    'size': (1000, 1000),
    'offset': (0, 0),
    'frequency': 8000,
    'job_name': "run_scripts"
}

report_settings(config)
height_map = load_and_crop_data(config).tolist()

graph = LocationGraph(height_map, config)


def save(graph):
    print('Saving graph.pkl')
    import resource
    import sys
    print(resource.getrlimit(resource.RLIMIT_STACK))
    print(sys.getrecursionlimit())
    size = graph.config['size']
    max_rec = 10 * size[0] * size[1]
    resource.setrlimit(resource.RLIMIT_STACK,
                       [0x100 * max_rec, resource.RLIM_INFINITY])
    sys.setrecursionlimit(max_rec)
    pickle.dump(graph, open('graph.pkl', 'wb'))
コード例 #8
0
 def test_graph_node_ordering(self):
     graph = LocationGraph(load_data())
     node_list = list(graph.ascending())
     for i in range(len(node_list) - 1):
         self.assertLessEqual(node_list[i].altitude, node_list[i + 1].altitude)
コード例 #9
0
 def test_create_graph(self):
     graph = LocationGraph(load_data())
     self.assertEqual(len(graph), 4, "All items should be converted to graph")
コード例 #10
0
from utils.image_writer import ImageWriter
from utils.const_writer import ConstWriter
from utils.report_settings import report_settings
from utils.load_image import load_and_crop_data
from utils.colour import get_colour_function
from utils.publish import make_video, make_image

# Params
size = (890, 890)
offset = (0, 0)
frequency = 8000
job_name = "run_scripts"
report_settings(size, frequency, job_name)
height_map = load_and_crop_data(size, offset).tolist()

graph = LocationGraph(height_map)


def colour_func(num_points):
    return (0, 0, min(num_points * 20 - 20, 255))


constWriter = ConstWriter(size, job_name, colour_func)

for node in tqdm(graph.descending(), total=len(graph), unit=" nodes"):
    constWriter.update(node)

constWriter.save()
im = load_and_crop_data(size, offset)
im = im - im.min()
make_image(job_name, im)