<commit_before>import numpy as np
import requests
import json
import polyline
import matplotlib.pyplot as plt
from pprint import pprint
from sklearn import preprocessing 
from tools.WeatherFunctions import *

ORIGIN = "Hoyanger,NOR"
DESTINATION = "Brendeholten,Forde,NOR"
# ORIGIN = "Tromso,NOR"
# DESTINATION = "Oksfjord,NOR"
GOOGLE_ROUTING_URL = "https://maps.googleapis.com/maps/api/directions/json?origin={}&destination={}"


def getCoordinates(Origin, Destination):
    '''
    Queries google for map coordinates between two locations.
    '''
    try:
        url = GOOGLE_ROUTING_URL.format(Origin, Destination)
        r = requests.get(url)
        travelRoute_json = json.loads(r.text)
        polyline_json = travelRoute_json['routes'][0]['overview_polyline']['points']
        polyline_coord = polyline.decode(polyline_json)
        coordinates = np.array(polyline_coord)
        return coordinates
    except:
        print("Could not connect to google.")
        return None

def normaliseArray(Array):
    array_norm = preprocessing.MinMaxScaler().fit_transform(Array)
    return array_norm

def convSpherCoordTo2D(Array):
    '''
    Converts map/spherical coordinates to 2D coordinates
    '''
    MAP_WIDTH = 1024
    MAP_HEIGHT = 1024

    lon = [((MAP_WIDTH/360) * (180 + lon)) for lon in Array[:,1]]
    lat = [((MAP_HEIGHT/180) * (90 + lat)) for lat in Array[:,0]]
    return lon, lat

def colorCodeTemperature(Temp):
    '''
    Returns a RGBA color value from 0..1 
    '''
    MAXTEMP = 30
    MINTEMP = 24

    if Temp >= MAXTEMP:
        colorValue = 1
    elif Temp <= MINTEMP:
        colorValue = 0
    else:
        colorValue = (MAXTEMP - Temp) / (MAXTEMP - MINTEMP)
    return colorValue    

def plotLatLonColor(myCoord, ChunkNo):
    '''
    Splits the coordinates into chucks and returns 
    variables ready for ploting with ie. matplotlib
    '''
    lon, lat = convSpherCoordTo2D(myCoord)
    NoEntries = len(lon)
    CoorDistance = NoEntries / ChunkNo
    ColorArray =[]

    for ent in range(NoEntries):
        if ent % CoorDistance == 0:
            # print(myCoordinates[ent,1])
            # print(myCoordinates[ent,0])
            coordTemp = minWeatherAtLocation(myCoord[ent,1], myCoord[ent,0])
            RGBvalue = colorCodeTemperature(coordTemp)
            # print(myCoordinates[ent], RGBvalue)

        ColorArray.append(RGBvalue)

    
    return lon, lat, ColorArray



myCoordinates = getCoordinates(ORIGIN,DESTINATION)
lon, lat, colors = plotLatLonColor(myCoordinates, 5)

plt.gca().set_aspect('equal', adjustable='box')
plt.scatter(lon,lat, c=colors)
plt.show()




<commit_msg>Minor changes<commit_after>import numpy as np
import requests
import json
import polyline
import matplotlib.pyplot as plt
from pprint import pprint
from sklearn import preprocessing 
from tools.WeatherFunctions import *

ORIGIN = "Hoyanger,NOR"
DESTINATION = "Brendeholten,Forde,NOR"
# ORIGIN = "Tromso,NOR"
# DESTINATION = "Oksfjord,NOR"
GOOGLE_ROUTING_URL = "https://maps.googleapis.com/maps/api/directions/json?origin={}&destination={}"


def getCoordinates(Origin, Destination):
    '''
    Queries google for map coordinates between two locations.
    '''
    try:
        url = GOOGLE_ROUTING_URL.format(Origin, Destination)
        r = requests.get(url)
        travelRoute_json = json.loads(r.text)
        polyline_json = travelRoute_json['routes'][0]['overview_polyline']['points']
        polyline_coord = polyline.decode(polyline_json)
        coordinates = np.array(polyline_coord)
        return coordinates
    except:
        print("Could not connect to google.")
        return None

def normaliseArray(Array):
    array_norm = preprocessing.MinMaxScaler().fit_transform(Array)
    return array_norm

def convSpherCoordTo2D(Array):
    '''
    Converts map/spherical coordinates to 2D coordinates
    '''
    MAP_WIDTH = 1024
    MAP_HEIGHT = 1024

    lon = [((MAP_WIDTH/360) * (180 + lon)) for lon in Array[:,1]]
    lat = [((MAP_HEIGHT/180) * (90 + lat)) for lat in Array[:,0]]
    return lon, lat

def colorCodeTemperature(Temp):
    '''
    Returns a RGBA color value from 0..1 
    '''
    MAXTEMP = 10
    MINTEMP = 1

    if Temp >= MAXTEMP:
        colorValue = 1
    elif Temp <= MINTEMP:
        colorValue = 0
    else:
        colorValue = (MAXTEMP - Temp) / (MAXTEMP - MINTEMP)
    return colorValue    

def plotLatLonColor(myCoord, ChunkNo):
    '''
    Splits the coordinates into chucks and returns 
    variables ready for ploting with ie. matplotlib
    '''
    lon, lat = convSpherCoordTo2D(myCoord)
    NoEntries = len(lon)
    CoorDistance = int(NoEntries / ChunkNo)
    ColorArray =[]

    for ent in range(NoEntries):
        if ent % CoorDistance == 0:
            # print(myCoordinates[ent,1])
            # print(myCoordinates[ent,0])
            coordTemp = minWeatherAtLocation(myCoord[ent,1], myCoord[ent,0])
            RGBvalue = colorCodeTemperature(coordTemp)
            # print(myCoordinates[ent], RGBvalue)

        ColorArray.append(RGBvalue)

    
    return lon, lat, ColorArray



myCoordinates = getCoordinates(ORIGIN,DESTINATION)
lon, lat, colors = plotLatLonColor(myCoordinates, 5)

plt.gca().set_aspect('equal', adjustable='box')
plt.scatter(lon,lat, c=colors)
plt.show()





{'fraction_non_alphanumeric': 0.10731892301858172, 'fraction_numerical': 0.01459992415623815, 'mean_word_length': 3.1931637519872815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6051844', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1688, 'n_words': 397}