Esempio n. 1
0
def main_function(origin, destination, depart_time=None):
    if depart_time is None:
        depart_time = get_current_time()
    result = comparison.comparison(origin, destination, depart_time)
    if result['best'] == 1:
        target_list = transform_output(result, 'only_bike')
    elif result['best'] == 2:
        target_list = transform_output(result, 'use_google')
    else:
        target_list = transform_output(result, 'bike_metro')
    draw_map.draw_map(target_list)
Esempio n. 2
0
def plot_electric_field(E_theta, E_phi):
	#Variables for plotting purposes
	x = np.arange(0, 360)
	y = np.arange(60, 90)
	X , Y = np.meshgrid(x, y)

	#Quiver plot of the electric field E = -grad(Phi), to show the direction in weak areas, all the arrows should have the same length and the magnitude should be given by the color below
	#Getting the magnitude and normalizing
	magnitude = np.sqrt((E_theta*E_theta) + (E_phi*E_phi))
	E_phi_norm = np.zeros(E_phi.shape)
	E_phi_norm[1:-1,1:-1] = E_phi[1:-1,1:-1]/magnitude[1:-1,1:-1]
	E_theta_norm = np.zeros(E_theta.shape)
	E_theta_norm[1:-1,1:-1] = E_theta[1:-1,1:-1]/magnitude[1:-1,1:-1]

	plt.figure()
	x = np.arange(0,potential.shape[1])
	y = 60 + np.arange(0,potential.shape[0])
	X, Y = np.meshgrid(x,y)

	skipArrows = 10
	eArrows = plt.contourf(X,Y, magnitude)
	plt.quiver(X[:,::skipArrows],Y[:,::skipArrows], E_phi_norm[:,::skipArrows], E_theta_norm[:,::skipArrows], angles = 'uv', scale = 40)

	cbar = plt.colorbar(eArrows)

	#Labels
	plt.title('Electric field in the higher latitudes')
	cbar.set_label('$|\\vec{E}|$')
	plt.xlabel('Longitude [ $ ^\circ$]')
	plt.ylabel('Latitude  [ $ ^\circ$]')

	plt.savefig('eArrows.eps')

	#Let's plot the electric field on the map as well
	fig = plt.figure()
	my_map = draw_map()

	longitude, latitude = my_map(X, Y)

	my_map.contourf(longitude, latitude, magnitude)
	my_map.quiver(longitude[:,::skipArrows],latitude[:,::skipArrows], E_phi_norm[:,::skipArrows], E_theta_norm[:,::skipArrows], angles = 'uv', scale = 40)
	plt.savefig('map_efield')

	#Plotting it on as a stereographic projection


	fig = plt.figure()
	X2 = (90 - Y)*np.sin(np.deg2rad(X))
	Y2 = (90 - Y)*np.cos(np.deg2rad(X))
	quiver = pl.quiver(X2[2:-2,::skipArrows],Y2[2:-2,::skipArrows],E_phi[2:-2,::skipArrows], E_theta[2:-2,::skipArrows])
	quiver.set_label(' $\Phi$  [V]')#, rotation = 0)
	pl.title('Electric Field')

	plt.savefig('other_proj.eps')

	return 
Esempio n. 3
0
def plot_drift(v_theta, v_phi):

	# plt.figure()
	x = np.arange(0,v_theta.shape[1])
	y = 60 + np.arange(0,v_theta.shape[0])
	X, Y = np.meshgrid(x,y)

	skipArrows = 10
	
	#Let's normalize the plt.t as well
	plt.figure()

	magnitude = np.sqrt((v_theta*v_theta) + (v_phi*v_phi))
	v_phi_norm = v_phi[1:-1,1:-1]/magnitude[1:-1,1:-1]
	v_theta_norm = v_theta[1:-1,1:-1]/magnitude[1:-1,1:-1]

	eArrows = plt.contourf(X,Y, magnitude)
	Q = plt.quiver(X[:,::skipArrows],Y[:,::skipArrows], v_phi_norm[:,::skipArrows], v_theta_norm[:,::skipArrows], angles= 'uv',  scale = 40)
	cbar = plt.colorbar(eArrows)
	cbar.set_label('$m/s$')

	#Labels
	plt.title('Drift the higher latitudes')
	plt.xlabel('Longitude [ $ ^\circ$]')
	plt.ylabel('Latitude  [ $ ^\circ$]')

	plt.savefig('vArrows.eps')

	#Let us also draw the currents on a map
	fig = plt.figure()
	my_map = draw_map()

	longitude, latitude = my_map(X, Y)

	contour = my_map.contourf(longitude, latitude, magnitude)
	my_map.quiver(longitude[:,::skipArrows],latitude[:,::skipArrows], v_phi_norm[:,::skipArrows], v_theta_norm[:,::skipArrows], angles = 'uv', scale = 40)
	cbar = plt.colorbar(contour)
	cbar.set_label('m/s')

	plt.savefig('map_drift.eps')





	return
Esempio n. 4
0
            if char == player_char:
                return x, y


def move(level, direction):
    """Handles moves on the level"""
    oldx, oldy = get_player_pos(level)
    newx, newy = oldx, oldy
    if direction == 'LEFT':
        newx = newx - 1
    if direction == 'RIGHT':
        newx = newx + 1
    if direction == 'UP':
        newy = newy - 1
    if direction == 'DOWN':
        newy = newy + 1
    if level[newy][newx] == 'x':
        sys.exit(0)
    if level[newy][newx] != '#':
        level[oldy][oldx] = ' '
        level[newy][newx] = '*'


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    mm = MAP_DATA
    for direction in ['RIGHT', 'RIGHT', 'UP', 'UP', 'LEFT']:
        move(mm, direction)
    img = draw_map(mm, tile_img, tiles)
    image.save(img, 'moved.png')
Esempio n. 5
0
        for x, char in enumerate(row):
            if char == player_char:
                return x, y

def move(level, direction):
    """Handles moves on the level"""
    oldx, oldy = get_player_pos(level)
    newx, newy = oldx, oldy
    if direction == 'LEFT':
        newx = newx - 1
    if direction == 'RIGHT':
        newx = newx + 1
    if direction == 'UP':
        newy = newy - 1
    if direction == 'DOWN':
        newy = newy + 1
    if level[newy][newx] == 'x':
        sys.exit(0)
    if level[newy][newx] != '#':
        level[oldy][oldx] = ' '
        level[newy][newx] = '*'


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    mm = MAP_DATA
    for direction in ['RIGHT', 'RIGHT', 'UP', 'UP', 'LEFT']:
        move(mm, direction)
    img = draw_map(mm, tile_img, tiles)
    image.save(img, 'moved.png')
Esempio n. 6
0
def game(key):
    """Handles key events in the game"""
    move(level, DIRECTIONS.get(key, 0))
    map_img = draw_map(level, tile_img, tiles)
    display.blit(map_img, Rect((0, 0, 224, 224)), Rect((0, 0, 224, 224)))
    pygame.display.update()
Esempio n. 7
0
# .gitignore and requirements.pip could be added to the repo
import pygame
from pygame import Rect

from draw_map import draw_map, level
from event_loop import event_loop
from load_tiles import load_tiles
from moves import move

pygame.init()
pygame.display.set_mode((640, 400))
display = pygame.display.get_surface()

DIRECTIONS = {276: 'LEFT', 275: 'RIGHT', 273: 'UP', 274: 'DOWN'}


def game(key):
    """Handles key events in the game"""
    move(level, DIRECTIONS.get(key, 0))
    map_img = draw_map(level, tile_img, tiles)
    display.blit(map_img, Rect((0, 0, 224, 224)), Rect((0, 0, 224, 224)))
    pygame.display.update()


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    map_img = draw_map(level, tile_img, tiles)
    display.blit(map_img, Rect((0, 0, 224, 224)), Rect((0, 0, 224, 224)))
    pygame.display.update()
    event_loop(game)