Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import netCDF4 as nc
import numpy as np
import pandas as pd
import chart_studio.plotly as px
import plotly.graph_objects as go
import tkinter as gui
"""
Loading in the dataset as a .nc file and then creating variables to store certain information from it
(Ozone, longitude and latitude values)
"""
in_nc = nc.Dataset(r"C:\Users\Topher\PycharmProjects\BigDataProject\ModelCombined\dataBig.nc")
en = in_nc.variables['ensemble_ozone'][:]
lon = in_nc.variables['lon'][:]
lat = in_nc.variables['lat'][:]
"""
The first 25 methods of this class are all used to set the hour value to be used in the map. Each method corresponds
to 1 of the 25 different hour subsets. The hour that is selected passes the value through to the draw method, which
uses the hour value as an index to pull all the data from the respective hour subset. Every method is static because
they do not need to act on any objects.
"""
class GUI:
@staticmethod
def get_hour_0():
hour = 0
GUI.draw_hour(hour)
@staticmethod
def get_hour_1():
hour = 1
GUI.draw_hour(hour)
@staticmethod
def get_hour_2():
hour = 2
GUI.draw_hour(hour)
@staticmethod
def get_hour_3():
hour = 3
GUI.draw_hour(hour)
@staticmethod
def get_hour_4():
hour = 4
GUI.draw_hour(hour)
@staticmethod
def get_hour_5():
hour = 5
GUI.draw_hour(hour)
@staticmethod
def get_hour_6():
hour = 6
GUI.draw_hour(hour)
@staticmethod
def get_hour_7():
hour = 7
GUI.draw_hour(hour)
@staticmethod
def get_hour_8():
hour = 8
GUI.draw_hour(hour)
@staticmethod
def get_hour_9():
hour = 9
GUI.draw_hour(hour)
@staticmethod
def get_hour_10():
hour = 10
GUI.draw_hour(hour)
@staticmethod
def get_hour_11():
hour = 11
GUI.draw_hour(hour)
@staticmethod
def get_hour_12():
hour = 12
GUI.draw_hour(hour)
@staticmethod
def get_hour_13():
hour = 13
GUI.draw_hour(hour)
@staticmethod
def get_hour_14():
hour = 14
GUI.draw_hour(hour)
@staticmethod
def get_hour_15():
hour = 15
GUI.draw_hour(hour)
@staticmethod
def get_hour_16():
hour = 16
GUI.draw_hour(hour)
@staticmethod
def get_hour_17():
hour = 17
GUI.draw_hour(hour)
@staticmethod
def get_hour_18():
hour = 18
GUI.draw_hour(hour)
@staticmethod
def get_hour_19():
hour = 19
GUI.draw_hour(hour)
@staticmethod
def get_hour_20():
hour = 20
GUI.draw_hour(hour)
@staticmethod
def get_hour_21():
hour = 21
GUI.draw_hour(hour)
@staticmethod
def get_hour_22():
hour = 22
GUI.draw_hour(hour)
@staticmethod
def get_hour_23():
hour = 23
GUI.draw_hour(hour)
@staticmethod
def get_hour_24():
hour = 24
GUI.draw_hour(hour)
@staticmethod
def draw_hour(hour):
X = [] # create empty array to store set of x values
Y = [] # create empty array to store set of y values
Z = [] # create empty array to store set of z values
for i in range(20): # loop through all latitude values (all 400)
for j in range(20): # loop through all longitude values (all 700)
z = en[hour][i][j] # set the z value to the value matching the respective hour, lat and lon values
x = lat[i] # set the x value to the respective latitude value
y = lon[j] # set the y value to the respective longitude value
X.append(x) # add this new x value to the set of all x values for that hour
Y.append(y) # add this new y value to the set of all y values for that hour
Z.append(z) # add this new z value to the set of all z values for that hour
A = np.array((X, Y, Z), dtype=float) # create a 3D array from the 3 lists of data (x,y,z)
df = pd.DataFrame(A, index=["lat", "lon", "ozone"]) # create a data frame with these labels
df = df.transpose() # flip the dataframe rows and columns
fig1 = go.Figure(go.Densitymapbox(lat=df["lat"], lon=df["lon"], z=df["ozone"], radius=3, # plot points + size
colorbar=dict(title="Ozone", # title of side bar
titleside="top", # altering side bar settings
tickmode="array",
tickvals=[0, 0.00000016],
ticktext=["Low", "High"],
ticks="outside"),
colorscale="ice")) # dataset colour
fig1.update_layout(mapbox_style="carto-positron") # world map style
fig1.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0}) # margins for world map
fig1.show() # plot the map
in_nc.close() # close the nc file
"""
This is the setup for the GUI. It will consist of an array of buttons for each hour, allowing for individual
viewing of each hour. This is done by assigning a command call to each of the buttons. The commands just call
each of the class methods defined above.
"""
def main():
window = gui.Tk() # creating the window
window.geometry("400x300") # window size
window.title("Ozone Tracker") # window title
window.configure(bg="Grey") # background colour
background_image = gui.PhotoImage(file="background.png") # custom back ground image
background_label = gui.Label(image=background_image) # creating a label to hold the image
background_label.place(x=0, y=0, relwidth=1, relheight=1) # label dimensions and position
title_label = gui.Label(window, text="Ozone Graph Drawer", bd=0, height=2, width=50)
title_label.place(x=25, y=10)
hours_label = gui.Label(window, text="HOURS", bd=0, height=3, width=9)
hours_label.place(x=45, y=120)
# setting up the group of 25 buttons for each hour
button1 = gui.Button(window, text="1", bd=0, height=1, width=5, command=GUI.get_hour_0)
button1.place(x=135, y=70)
button2 = gui.Button(window, text="2", bd=0, height=1, width=5, command=GUI.get_hour_1)
button2.place(x=180, y=70)
button3 = gui.Button(window, text="3", bd=0, height=1, width=5, command=GUI.get_hour_2)
button3.place(x=225, y=70)
button4 = gui.Button(window, text="4", bd=0, height=1, width=5, command=GUI.get_hour_3)
button4.place(x=270, y=70)
button5 = gui.Button(window, text="5", bd=0, height=1, width=5, command=GUI.get_hour_4)
button5.place(x=315, y=70)
button6 = gui.Button(window, text="6", bd=0, height=1, width=5, command=GUI.get_hour_5)
button6.place(x=135, y=100)
button7 = gui.Button(window, text="7", bd=0, height=1, width=5, command=GUI.get_hour_6)
button7.place(x=180, y=100)
button8 = gui.Button(window, text="8", bd=0, height=1, width=5, command=GUI.get_hour_7)
button8.place(x=225, y=100)
button9 = gui.Button(window, text="9", bd=0, height=1, width=5, command=GUI.get_hour_8)
button9.place(x=270, y=100)
button10 = gui.Button(window, text="10", bd=0, height=1, width=5, command=GUI.get_hour_9)
button10.place(x=315, y=100)
button11 = gui.Button(window, text="11", bd=0, height=1, width=5, command=GUI.get_hour_10)
button11.place(x=135, y=130)
button12 = gui.Button(window, text="12", bd=0, height=1, width=5, command=GUI.get_hour_11)
button12.place(x=180, y=130)
button13 = gui.Button(window, text="13", bd=0, height=1, width=5, command=GUI.get_hour_12)
button13.place(x=225, y=130)
button14 = gui.Button(window, text="14", bd=0, height=1, width=5, command=GUI.get_hour_13)
button14.place(x=270, y=130)
button15 = gui.Button(window, text="15", bd=0, height=1, width=5, command=GUI.get_hour_14)
button15.place(x=315, y=130)
button16 = gui.Button(window, text="16", bd=0, height=1, width=5, command=GUI.get_hour_15)
button16.place(x=135, y=160)
button17 = gui.Button(window, text="17", bd=0, height=1, width=5, command=GUI.get_hour_16)
button17.place(x=180, y=160)
button18 = gui.Button(window, text="18", bd=0, height=1, width=5, command=GUI.get_hour_17)
button18.place(x=225, y=160)
button19 = gui.Button(window, text="19", bd=0, height=1, width=5, command=GUI.get_hour_18)
button19.place(x=270, y=160)
button20 = gui.Button(window, text="20", bd=0, height=1, width=5, command=GUI.get_hour_19)
button20.place(x=315, y=160)
button21 = gui.Button(window, text="21", bd=0, height=1, width=5, command=GUI.get_hour_21)
button21.place(x=135, y=190)
button22 = gui.Button(window, text="22", bd=0, height=1, width=5, command=GUI.get_hour_21)
button22.place(x=180, y=190)
button23 = gui.Button(window, text="23", bd=0, height=1, width=5, command=GUI.get_hour_22)
button23.place(x=225, y=190)
button24 = gui.Button(window, text="24", bd=0, height=1, width=5, command=GUI.get_hour_23)
button24.place(x=270, y=190)
button25 = gui.Button(window, text="25", bd=0, height=1, width=5, command=GUI.get_hour_24)
button25.place(x=315, y=190)
window.mainloop() # loop for window so that it runs
if __name__ == '__main__':
main()