Пример #1
0
def process():
    parser = ArgumentParser(
        description="Generating a greengraph by using a start point, an end point, number of steps and the name of the file you want the graph to be stored at."
    )

    """
    Parameters
    """
    parser.add_argument("--from", "-f", dest="fromCity")
    parser.add_argument("--to", "-t", dest="toCity")
    parser.add_argument("--steps", "-s")
    parser.add_argument("--out", "-o")

    """
    Print help message even if no flag is provided
    """
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()

    myGraph = Greengraph(args.fromCity, args.toCity)
    data = myGraph.green_between(args.steps)
    plt.plot(data)
    plt.savefig(args.out)
Пример #2
0
def build_greengraph(args):
    graph = Greengraph(args.startLoc, args.endLoc)
    data = graph.green_between(args.steps)
    plt.plot(data)

    # Labelling of plot
    plt.xlabel("Step")
    plt.ylabel("Number of green pixels (Max 160000)")
    plt.title("Green pixels in geographical images between " +
              "".join(args.startLoc) + " and " + "".join(args.endLoc))
    plt.savefig(args.out + '.png')
    plt.show()
Пример #3
0
def build_greengraph(args):
    graph = Greengraph(args.startLoc,args.endLoc)
    data = graph.green_between(args.steps)
    plt.plot(data)
    
    # Labelling of plot 
    plt.xlabel("Step")
    plt.ylabel("Number of green pixels (Max 160000)")
    plt.title("Green pixels in geographical images between "+
              "".join(args.startLoc)+ " and " + "".join(args.endLoc))
    plt.savefig(args.out+'.png')
    plt.show()
Пример #4
0
def process():
    parser = ArgumentParser(description = "Generating a greengraph by using a start point, an end point, number of steps and the name of the file you want the graph to be stored at.")
    
    parser.add_argument('--from', '-f', dest = 'fromCity')
    parser.add_argument('--to', '-t', dest = 'toCity')
    parser.add_argument('--steps', '-s')
    parser.add_argument('--out', '-o')

    # Print help message even if no flag is provided
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()

    myGraph = Greengraph(args.fromCity, args.toCity)
    data = myGraph.green_between(args.steps)
    plt.plot(data)
    plt.savefig(args.out)
Пример #5
0
 def setup(self):
     self.london_location = [51.5073509,-0.1277583]
     self.oxford_location = [51.7520209,-1.2577263]
     self.start = 'London'
     self.end = 'Oxford'
     self.mygraph = Greengraph(self.start,self.end)
     self.mygraph.geocoder.geocode = MagicMock(side_effect=side_effect)
     self.test_location_result = [[51.5073509,-0.1277583],[51.5685184,-0.4102503],[51.6296859,-0.6927423],[51.6908534,-0.9752343],[51.7520209,-1.2577263]]
     raw_data_location = path.join(path.dirname(__file__), 'fixtures\london.raw')
     print raw_data_location;
     with open(raw_data_location, 'rb') as f:
         data = f.read();
     returndata = type('',(object,),{"content": data})()
     requests.get = MagicMock(return_value = returndata) 
Пример #6
0
class test_graph():
    def setup(self):
        self.london_location = [51.5073509,-0.1277583]
        self.oxford_location = [51.7520209,-1.2577263]
        self.start = 'London'
        self.end = 'Oxford'
        self.mygraph = Greengraph(self.start,self.end)
        self.mygraph.geocoder.geocode = MagicMock(side_effect=side_effect)
        self.test_location_result = [[51.5073509,-0.1277583],[51.5685184,-0.4102503],[51.6296859,-0.6927423],[51.6908534,-0.9752343],[51.7520209,-1.2577263]]
        raw_data_location = path.join(path.dirname(__file__), 'fixtures\london.raw')
        print raw_data_location;
        with open(raw_data_location, 'rb') as f:
            data = f.read();
        returndata = type('',(object,),{"content": data})()
        requests.get = MagicMock(return_value = returndata) 
       
    @with_setup(setup)
    def test_geolocate_London(self):
        location = 'London';
        result = self.mygraph.geolocate(location)
        assert_equal(values[location][0][1],result)
    
    @with_setup(setup)
    def test_geolocate_Oxford(self):
        location = 'Oxford';
        result = self.mygraph.geolocate(location)
        assert_equal(values[location][0][1],result)
       
    @with_setup(setup)
    def test_location_sequence_London_To_Oxford(self):
        testresult = self.mygraph.location_sequence(self.london_location, self.oxford_location,5)
        assert_allclose(self.test_location_result,testresult,rtol=1e-5,atol=1e-8)

    @with_setup(setup)
    def test_location_sequence_Oxford_To_London(self):
        reversed_results = self.test_location_result[::-1]
        testresult = self.mygraph.location_sequence(self.oxford_location,self.london_location,5)
        assert_allclose(reversed_results,testresult,rtol=1e-5,atol=1e-8)
      
    @with_setup(setup)
    def test_location_sequence_Oxford_To_London_2steps(self):
        testresult = self.mygraph.location_sequence(self.oxford_location,self.london_location,2)
        assert_allclose([self.oxford_location, self.london_location],testresult,rtol=1e-5,atol=1e-8)
    
    @with_setup(setup)
    def test_graph_init_start_end(self):
        assert_equal(self.start,self.mygraph.start)
        assert_equal(self.end,self.mygraph.end)
    
    @with_setup(setup)
    def test_green_between_2_step(self):
        expected = [106725, 106725]
        result = self.mygraph.green_between(2)
        assert_equal(expected,result)
Пример #7
0
def do_the_thing(args):
    graph = Greengraph(args.start, args.end)
    if args.save_png:
        points = graph.location_sequence(graph.geolocate(graph.start),
                                         graph.geolocate(graph.end),
                                         args.steps)
        green = []
        for n, point in enumerate(points):
            _m = Map(*point)
            green.append(_m.count_green())
            with open(args.filename+'_'+str(n)+'.png','w') as f:
                f.write(_m.show_green())
    else:
        green = graph.green_between(args.steps)
    plt.plot(graph.green_between(args.steps))
    plt.savefig(args.filename+'.png')
    plt.show()