Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. def map_plotter(longvals,latvals,meanvals,title,filename):
  2. plt.scatter(longvals,latvals, c=meanvals)
  3. plt.xlabel("Longitude")
  4. plt.ylabel("Latitude")
  5. plt.colorbar()
  6. plt.title(title)
  7. plt.savefig(filename)
  8. plt.show()
  9.  
  10. def october_anomoly(longvals,latvals,octvals,meanvals,title,filename):
  11. index = 0
  12. anomoly = []
  13. while index < len(longvals):
  14. anom = meanvals[index] - octvals[index]
  15. anomoly.append(anom)
  16. index = index + 1
  17. plt.scatter(longvals,latvals, c=anomoly)
  18. plt.xlabel("Longitude")
  19. plt.ylabel("Latitude")
  20. plt.colorbar()
  21. plt.title(title)
  22. plt.savefig(filename)
  23. plt.show()
  24.  
  25. def main():
  26. user_year = ask_year()
  27. if user_year < 2015 and user_year > 1899:
  28. print("Thank you for selecting the year", user_year)
  29. air_temp_data = read_data("data/air_temp_2014/air_temp." + str(user_year))
  30. precip_data = read_data("data/precip_2014/precip." + str(user_year))
  31. index = 0
  32. verify_climatology_data(air_temp_data,precip_data)
  33. menu_choice = get_menu_choice()
  34. if menu_choice == 1:
  35. #The following code creates the temperature line graph
  36. xs = get_month_names()
  37. is1 = get_located_between(air_temp_data,1,23.5,90)
  38. is2 = get_located_between(air_temp_data,1,-23.5,23.5)
  39. is3 = get_located_between(air_temp_data,1,-90,-23.5)
  40. index = 2
  41. ys = []
  42. ys2 = []
  43. ys3 = []
  44. while index < 14:
  45. month_val_N = statistics.mean(get_column_values(is1,index))
  46. month_val_C = statistics.mean(get_column_values(is2,index))
  47. month_val_S = statistics.mean(get_column_values(is3,index))
  48. ys.append(month_val_N)
  49. ys2.append(month_val_C)
  50. ys3.append(month_val_S)
  51. index += 1
  52. title = "Graph of global mean temperature values over 12 months in year " + str(user_year)
  53. y_axis = "Temperature in degrees Celcius"
  54. file_name = "global_mean_temp_" + str(user_year) + ".pdf"
  55. global_mean_plotter(xs,ys,ys2,ys3,y_axis,"Month",title,file_name)
  56. #This section of code creates the line graph of precip values
  57. is1 = get_located_between(precip_data,1,23.5,90)
  58. is2 = get_located_between(precip_data,1,-23.5,23.5)
  59. is3 = get_located_between(precip_data,1,-90,-23.5)
  60. index = 2
  61. ys = []
  62. ys2 = []
  63. ys3 = []
  64. while index < 14:
  65. month_val_N = statistics.mean(get_column_values(is1,index))
  66. month_val_C = statistics.mean(get_column_values(is2,index))
  67. month_val_S = statistics.mean(get_column_values(is3,index))
  68. ys.append(month_val_N)
  69. ys2.append(month_val_C)
  70. ys3.append(month_val_S)
  71. index += 1
  72. y_axis = "Precipitation"
  73. title = "Graph of global mean precipitation values over 12 months in year " + str(user_year)
  74. file_name = "global_mean_precip_" + str(user_year) + ".pdf"
  75. global_mean_plotter(xs,ys,ys2,ys3,y_axis,"Month",title,file_name)
  76. if menu_choice == 2:
  77. #The code below creates both the histogram for temperature and precip after
  78. #prompting the user for the amount of bins they would like.
  79. bin_count = int(input("How many bins would you like in your histograms?"))
  80. min_temp = get_column_values(air_temp_data, 14)
  81. min_precip = get_column_values(precip_data, 14)
  82. max_temp = get_column_values(air_temp_data, 15)
  83. max_precip = get_column_values(air_temp_data, 15)
  84.  
  85. title_temp = "Histogram of max/min global temperature in " + str(user_year)
  86. title_precip = "Histogram of max/min global precipitation in " + str(user_year)
  87.  
  88. ylabel = "Number of locations"
  89. xlabel_temp = "Temperature"
  90. xlabel_precip = "Precipitation"
  91. file_name_temp = "histogram_temperature_" + str(user_year) + ".pdf"
  92. file_name_precip = "histogram_precip_" + str(user_year) + ".pdf"
  93.  
  94. global_histogram(bin_count,min_temp,max_temp, ylabel, xlabel_temp, title_temp, file_name_temp)
  95. global_histogram(bin_count, min_precip,max_precip, ylabel, xlabel_precip, title_precip, file_name_precip)
  96. if menu_choice == 3:
  97. print("Run option 3")
  98. if menu_choice == 4:
  99. longvals = get_column_values(air_temp_data, 0)
  100. latvals = get_column_values(air_temp_data, 1)
  101. meanvals = get_column_values(air_temp_data, 16)
  102. title = "Heat map of temperature values in year " + str(user_year)
  103. filename = "heat_map_temp_" + str(user_year) + ".pdf"
  104. map_plotter(longvals,latvals,meanvals,title,filename)
  105. #precipitation
  106. longvalsp = get_column_values(precip_data, 0)
  107. latvalsp = get_column_values(precip_data, 1)
  108. sumvalsp = get_column_values(precip_data, 17)
  109. title = "Heat map of precipitation values in year " + str(user_year)
  110. filename = "heat_map_precip_" + str(user_year) + ".pdf"
  111. map_plotter(longvalsp,latvalsp,sumvalsp,title,filename)
  112. if menu_choice == 5:
  113. #This function will find the temperature and precipitation anomoly in October and create a heatmap.
  114. #This type of map is used quite a bit in climatology.
  115. longvals = get_column_values(air_temp_data, 0)
  116. latvals = get_column_values(air_temp_data, 1)
  117. octtemp = get_column_values(air_temp_data, 11)
  118. meanvals = get_column_values(air_temp_data, 16)
  119. title = "Temperature anomoly in October " + str(user_year)
  120. filename = "oct_anom_temp_" + str(user_year) + ".pdf"
  121. october_anomoly(longvals,latvals,octtemp,meanvals,title,filename)
  122. #precipitation
  123. longvalsp = get_column_values(precip_data, 0)
  124. latvalsp = get_column_values(precip_data, 1)
  125. octprecip = get_column_values(precip_data, 11)
  126. meanvalsp = get_column_values(precip_data, 16)
  127. title = "Precipitation anomoly in October " + str(user_year)
  128. filename = "oct_anom_temp_" + str(user_year) + ".pdf"
  129. october_anomoly(longvalsp,latvalsp,octprecip,meanvals,title,filename)
  130. if menu_choice == 6:
  131. print("Pie Chart of Precip as compared to mean")
  132. if menu_choice == 0:
  133. return
  134. else:
  135. print("Try again next time!")
  136. return
  137.  
  138. if __name__ == "__main__":
  139. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement