import matplotlib.pyplot as plt
import numpy as np
import pickle
%matplotlib inline

"""
Explanation: Tuples and Dictionaries Exercise
End of explanation
"""


def read_weather():
    with open('data/weather.pkl', 'rb') as f:
        return pickle.load(f)

# The file weather.pkl contains a list of dictionaries 
Data = read_weather()
Data[0]

"""
Explanation: The purpose of the exersise is to manipulate and plot the current weather of a number of European cities. The data has been downloaded from Openweather, and has been loaded for you below using the given function read_weather.
The function returns a list of dictionaries, each of which contains the name of the cities along with a large number of the weather parameters. Before you start the exercise, print various parts of Data familiarise yourself with the content.
End of explanation
"""


# Implement Q1 part 1 here:
# -------------------------
# tempr_dict = ...

# Run this cell to tests if you have completed part 1 correctly:
assert(all(key in tempr_dict for key in ['Berlin', 'Kiev', 'London', 'Moscow', 'Southampton'])),\
    'keys of your weather dictionary should be Berlin, Kiev, London, Moscow, Southampton'

assert(len(tempr_dict['Moscow']) == 2), "Entries in your dictionary should be a tuple of two values"

# Part 2:



"""
Explanation: Part 1: Temperature


We want to manipulate the data so it is easier to plot. Create a new dictionary with the country names as keys (name entries in Data) and the values being the tuple of (lattitude, temperature) corresponding to that country.

You will need a for loop



Plot the temperature of the cities (y) vs lattitude (x)

You could either do this by scattering the data or using a for loop. The easier approach would be to use a for loop and the 'x' marker.
Also try to add the city names to the scattered markers using ax.annotate
End of explanation
"""


# Implement Q2 pt 1 here
# -----------------------
# weather_dict = ...

# Implement Q2 pt 2 here
# -----------------------
def plot_weather_lattitude(weather_dictionary, var_name):
#     YOUR CODE HERE
    
    
    return None

# Here are the variables that should be in your data
weather_vars = ['temp', 'temp_max', 'temp_min', 'pressure', 'humidity']

# Loop over the variable strings above and plot them using your
#   plot_weather_lattitude function:
for var_name in weather_vars:
    plot_weather_lattitude(weather_dict, var_name)

"""
Explanation: Optional extension: Weather
Temperature is not the only parameter in the data. By extending the code you wrote above, plot the remaining variables 


Instead of storing the value in your dictionary as (lattitude, temp), use the tuple (lattitude, main) where main is the dictionary containing temp, pressure and humidity etc. entries from the original Data list


Write a function which takes the weather dictionary and a string variable name (e.g. 'temp', 'pressure'...) as arguments and plots the chosen variable against lattitude for all countries in the weather dictionary

Start from your plotting code in the previous question
End of explanation
"""


