Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def map_plotter(longvals,latvals,meanvals,title,filename):
- plt.scatter(longvals,latvals, c=meanvals)
- plt.xlabel("Longitude")
- plt.ylabel("Latitude")
- plt.colorbar()
- plt.title(title)
- plt.savefig(filename)
- plt.show()
- def october_anomoly(longvals,latvals,octvals,meanvals,title,filename):
- index = 0
- anomoly = []
- while index < len(longvals):
- anom = meanvals[index] - octvals[index]
- anomoly.append(anom)
- index = index + 1
- plt.scatter(longvals,latvals, c=anomoly)
- plt.xlabel("Longitude")
- plt.ylabel("Latitude")
- plt.colorbar()
- plt.title(title)
- plt.savefig(filename)
- plt.show()
- def main():
- user_year = ask_year()
- if user_year < 2015 and user_year > 1899:
- print("Thank you for selecting the year", user_year)
- air_temp_data = read_data("data/air_temp_2014/air_temp." + str(user_year))
- precip_data = read_data("data/precip_2014/precip." + str(user_year))
- index = 0
- verify_climatology_data(air_temp_data,precip_data)
- menu_choice = get_menu_choice()
- if menu_choice == 1:
- #The following code creates the temperature line graph
- xs = get_month_names()
- is1 = get_located_between(air_temp_data,1,23.5,90)
- is2 = get_located_between(air_temp_data,1,-23.5,23.5)
- is3 = get_located_between(air_temp_data,1,-90,-23.5)
- index = 2
- ys = []
- ys2 = []
- ys3 = []
- while index < 14:
- month_val_N = statistics.mean(get_column_values(is1,index))
- month_val_C = statistics.mean(get_column_values(is2,index))
- month_val_S = statistics.mean(get_column_values(is3,index))
- ys.append(month_val_N)
- ys2.append(month_val_C)
- ys3.append(month_val_S)
- index += 1
- title = "Graph of global mean temperature values over 12 months in year " + str(user_year)
- y_axis = "Temperature in degrees Celcius"
- file_name = "global_mean_temp_" + str(user_year) + ".pdf"
- global_mean_plotter(xs,ys,ys2,ys3,y_axis,"Month",title,file_name)
- #This section of code creates the line graph of precip values
- is1 = get_located_between(precip_data,1,23.5,90)
- is2 = get_located_between(precip_data,1,-23.5,23.5)
- is3 = get_located_between(precip_data,1,-90,-23.5)
- index = 2
- ys = []
- ys2 = []
- ys3 = []
- while index < 14:
- month_val_N = statistics.mean(get_column_values(is1,index))
- month_val_C = statistics.mean(get_column_values(is2,index))
- month_val_S = statistics.mean(get_column_values(is3,index))
- ys.append(month_val_N)
- ys2.append(month_val_C)
- ys3.append(month_val_S)
- index += 1
- y_axis = "Precipitation"
- title = "Graph of global mean precipitation values over 12 months in year " + str(user_year)
- file_name = "global_mean_precip_" + str(user_year) + ".pdf"
- global_mean_plotter(xs,ys,ys2,ys3,y_axis,"Month",title,file_name)
- if menu_choice == 2:
- #The code below creates both the histogram for temperature and precip after
- #prompting the user for the amount of bins they would like.
- bin_count = int(input("How many bins would you like in your histograms?"))
- min_temp = get_column_values(air_temp_data, 14)
- min_precip = get_column_values(precip_data, 14)
- max_temp = get_column_values(air_temp_data, 15)
- max_precip = get_column_values(air_temp_data, 15)
- title_temp = "Histogram of max/min global temperature in " + str(user_year)
- title_precip = "Histogram of max/min global precipitation in " + str(user_year)
- ylabel = "Number of locations"
- xlabel_temp = "Temperature"
- xlabel_precip = "Precipitation"
- file_name_temp = "histogram_temperature_" + str(user_year) + ".pdf"
- file_name_precip = "histogram_precip_" + str(user_year) + ".pdf"
- global_histogram(bin_count,min_temp,max_temp, ylabel, xlabel_temp, title_temp, file_name_temp)
- global_histogram(bin_count, min_precip,max_precip, ylabel, xlabel_precip, title_precip, file_name_precip)
- if menu_choice == 3:
- print("Run option 3")
- if menu_choice == 4:
- longvals = get_column_values(air_temp_data, 0)
- latvals = get_column_values(air_temp_data, 1)
- meanvals = get_column_values(air_temp_data, 16)
- title = "Heat map of temperature values in year " + str(user_year)
- filename = "heat_map_temp_" + str(user_year) + ".pdf"
- map_plotter(longvals,latvals,meanvals,title,filename)
- #precipitation
- longvalsp = get_column_values(precip_data, 0)
- latvalsp = get_column_values(precip_data, 1)
- sumvalsp = get_column_values(precip_data, 17)
- title = "Heat map of precipitation values in year " + str(user_year)
- filename = "heat_map_precip_" + str(user_year) + ".pdf"
- map_plotter(longvalsp,latvalsp,sumvalsp,title,filename)
- if menu_choice == 5:
- #This function will find the temperature and precipitation anomoly in October and create a heatmap.
- #This type of map is used quite a bit in climatology.
- longvals = get_column_values(air_temp_data, 0)
- latvals = get_column_values(air_temp_data, 1)
- octtemp = get_column_values(air_temp_data, 11)
- meanvals = get_column_values(air_temp_data, 16)
- title = "Temperature anomoly in October " + str(user_year)
- filename = "oct_anom_temp_" + str(user_year) + ".pdf"
- october_anomoly(longvals,latvals,octtemp,meanvals,title,filename)
- #precipitation
- longvalsp = get_column_values(precip_data, 0)
- latvalsp = get_column_values(precip_data, 1)
- octprecip = get_column_values(precip_data, 11)
- meanvalsp = get_column_values(precip_data, 16)
- title = "Precipitation anomoly in October " + str(user_year)
- filename = "oct_anom_temp_" + str(user_year) + ".pdf"
- october_anomoly(longvalsp,latvalsp,octprecip,meanvals,title,filename)
- if menu_choice == 6:
- print("Pie Chart of Precip as compared to mean")
- if menu_choice == 0:
- return
- else:
- print("Try again next time!")
- return
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement