Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

# Marshall Korankye-Taylor

# Index 3163720
# AERO 4

# importing relevant python libraries


import matplotlib.pyplot as plt
import csv

# Enter the name of your airport


print("Follow the steps to use the Report Generator")
print("""Before you proceed, make sure that your data file is saved with the name north.csv for the northen hermisphere, and south.csv for the southern hermisphere.
Any variation from these names will render the code useless.
Also, ensure that both the code and the data files (CSV files) are in the same folder.""")
print("\nOpen your CSV file and delete the first 11 lines, thus from the -BEGIN HEADER- to -END HEADER-. Leave everything else...")

northern = input("Enter the name of your airport in the north: ")


southern = input("Enter the name of your airport in the south: ")

if not (bool(northern) and bool(southern)):


print("No name was provided for at least one of the airports. Please re-run.")
exit()

## file names
Cape_Town_file = "south.csv" # Change the file name
London_file = "north.csv" # Change the file name

## Title of graphs
Cape_Town_title = f"A LINE GRAPH TO PLOT THE DAILY\n SURFACE TEMPERATURE, PRESSURE AND DENSITY AT {southern.upper()} AERODROME"
London_title = f"A LINE GRAPH TO PLOT THE DAILY\n SURFACE TEMPERATURE, PRESSURE AND DENSITY AT {northern.upper()} AERODROME"

## Defining a data structure for the data.


T_k, P_k, rho_k = list(), list(), list()
T_p, P_p, rho_p = list(), list(), list()

# reading Cape_Town data


with open(Cape_Town_file) as k_file: # ignore the underlined.
Cape_Town_data = csv.DictReader(k_file)

for i in Cape_Town_data:
_, _, Temp, Pres, _ = i.values()
T_k.append(float(Temp))
P_k.append(float(Pres))
rho_k.append(float(Pres)*1000/(287*(float(Temp)+273)))

# reading London data


with open(London_file) as p_file: # ignore the underlined.
London_data = csv.DictReader(p_file)

for i in London_data:
_, _, Temp, Pres, _ = i.values()
T_p.append(float(Temp))
P_p.append(float(Pres))
rho_p.append(float(Pres)*1000/(287*(float(Temp)+273)))

print("Cape_Town density counts:", len(rho_k))


print("London density counts:", len(rho_p))

# Plotting of data
fig, (grf1, ax1) = plt.subplots(2, 1, figsize=(12, 6))

color = "tab:red"
ax1.set_title(Cape_Town_title)
ax1.set_xlabel("Time (day)")
ax1.set_ylabel("Temperature (K)", color = color)
ax1.plot(range(1, 366), T_k, color= color)
ax1.tick_params(axis="y", labelcolor= color)

ax2 = ax1.twinx()
color = "tab:blue"
# ax2.spines["right"].set_position(("outward", ))
ax2.set_ylabel("Pressure (C)", color = color)
ax2.plot(range(1, 366), P_k, color= color)
ax2.tick_params(axis="y", labelcolor= color)

ax3 = ax1.twinx()
color = "tab:green"
ax3.spines["right"].set_position(("outward", 50))
ax3.set_ylabel("Density (Kg/m^3)", color = color)
ax3.plot(range(1, 366), rho_k, color= color)
ax3.tick_params(axis="y", labelcolor= color)

# --------------------------------------------------------------------
grf1.set_title(London_title)
color = "tab:red"
grf1.set_xlabel("Time (day)")
grf1.set_ylabel("Temperature (K)", color = color)
grf1.plot(range(1, 366), T_p, color= color)
grf1.tick_params(axis="y", labelcolor= color)

grf2 = grf1.twinx()
color = "tab:blue"
# ax2.spines["right"].set_position(("outward", ))
grf2.set_ylabel("Pressure (C)", color = color)
grf2.plot(range(1, 366), P_p, color= color)
grf2.tick_params(axis="y", labelcolor= color)

grf3 = grf1.twinx()
color = "tab:green"
grf3.spines["right"].set_position(("outward", 50))
grf3.set_ylabel("Density (Kg/m^3)", color = color)
grf3.plot(range(1, 366), rho_p, color= color)
grf3.tick_params(axis="y", labelcolor= color)

fig.tight_layout()
plt.show()
Follow the steps to use the Report Generator
Before you proceed, make sure that your data file is saved with the name north.csv for the northen hermisphere, and south.csv for the southern hermisphere.
Any variation from these names will render the code useless.
Also, ensure that both the code and the data files (CSV files) are in the same folder.

Open your CSV file and delete the first 11 lines, thus from the -BEGIN HEADER- to -END HEADER-. Leave everything else...
Enter the name of your airport in the north: London-Gatwick
Enter the name of your airport in the south: Cape Town
Cape_Town density counts: 365
London density counts: 365

You might also like