Php.scripts.psu.edu



CMPSC-122 – Intermediate Programming1/31/18PROJECT-1: Global Temperature AnalysisName: Jonan GonzalezIntroduction:The change in temperature over the past 150 years is used by climate scientists as evidence to show that humans might have an increasingly devastating effect on the Earth's environment. Advances in computer modeling are allowing for climatologists to tease out both the causes and impacts of increasing Earth temperatures. In this recent Star Tribune article, researchers ran computer simulations that compared natural weather fluctuations for today's CO2 and greenhouse gas levels to pre-Industrial Revolution levels.Although thinking about climate change can sometimes be daunting, it is an issue that is increasingly important to understand culturally and scientifically. You have probably seen many graphs showing the temperature over x number of years, but have you ever had the chance to examine the data yourself? In this activity, you are provided with a data set of monthly average global temperatures worldwide from January 1881 to December 2012. The goals of this project are to allow you to work with meaningful climate change data so as to draw your own conclusions and become better acquainted with Python data structures and some useful functions. Learning these skills to analyze the change in temperature over the past 131 years are extremely useful, and temperature is just the "tip of the iceberg" when it comes to computer modeling of weather-related data.Note: For each exercise, paste codes or a screenshot of codes and resultsStartup python codes:import requestsimport matplotlib.pyplot as pltlink = ""f = requests.get(link)data =f.textlines=data.split('\n')'''for more about plots, visit '''import requestsimport matplotlib.pyplot as pltimport numpy as nplink = ""f = requests.get(link)data =f.textlines = data.split(' ')lines = list(filter(None, lines))lines = lines[40:-33]numbers = []months = ['Jan', 'Feb', 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec', 'J-D' , 'D-N' ,'DJF' , 'MAM' , 'JJA' , 'SON', 'Year\n1901', 'Year\n1921','Year\n1941','Year\n1961','Year\n1981','Year\n2001']for i in lines: if i in months: lines.remove(i) else: numbers.append(i)for i in numbers: if '\n' in i: numbers.remove(i)for n, i in enumerate(numbers): if i == '***': numbers[n] = 0for n, i in enumerate(numbers): if i == '****': numbers[n] = 0**Exercise 1**Convert the data from scaled change in Celsius to absolute temperature in Fahrenheit. What is the mean temperature in Fahrenheit over the entire data set? Confirm that your result is reasonable.print('____________________________________________________Exercise 1_________________________________________________')fahrenheit = []avenums = 0total = len(numbers)for i in numbers: a = round((int(i)/100)*1.8 + 57.2, 2) fahrenheit.append(a) avenums = avenums + aaverage = round(avenums/total, 2)print("List of values in Fahrenheit: " + str(fahrenheit))print("Mean Temperture: " + str(average))**Exercise 2**Find the mean average temperature of each month, as well as the lowest and highest average temperatures for each month. This is easiest if you create new list or dictionary that have all January temperatures, all February temperatures, and so on. When did the lowest and highest occur for each month? Are the highest temperatures generally more recent than the lowest temperatures?jan = []feb = []mar = []apr = []may = []jun = []jul = []aug = []sep = []oct = []nov = []dec = []i = 0while i <= len(fahrenheit): jan.append(fahrenheit[i]) i+= 18#print(jan)i = 1while i <= len(fahrenheit): feb.append(fahrenheit[i]) i+= 18#print(feb)i = 2while i <= len(fahrenheit): mar.append(fahrenheit[i]) i+= 18#print(mar)i = 3while i <= len(fahrenheit): apr.append(fahrenheit[i]) i+= 18#print(apr)i = 4while i <= len(fahrenheit): may.append(fahrenheit[i]) i+= 18#print(may)i = 5while i <= len(fahrenheit): jun.append(fahrenheit[i]) i+= 18#print(jun)i = 6while i <= len(fahrenheit): jul.append(fahrenheit[i]) i+= 18#print(jul)i = 7while i <= len(fahrenheit): aug.append(fahrenheit[i]) i+= 18#print(aug)i = 8while i <= len(fahrenheit): sep.append(fahrenheit[i]) i+= 18#print(sep)i = 9while i <= len(fahrenheit): oct.append(fahrenheit[i]) i+= 18#print(oct)i = 10while i <= len(fahrenheit): nov.append(fahrenheit[i]) i+= 18#print(nov)i = 11while i <= len(fahrenheit): dec.append(fahrenheit[i]) i+= 18#print(dec)print('_________________________________________________Exercise 2_____________________________________________________')print("The Average for January is: " + str(sum(jan)/len(jan)))print("The minimum of January is: " + str(min(jan)))print("The maximum of January is: " + str(max(jan)))print('\n')print("The Average for February is: " + str(sum(feb)/len(feb)))print("The minimum of February is: " + str(min(feb)))print("The maximum of February is: " + str(max(feb)))print('\n')print("The Average for March is: " + str(sum(mar)/len(mar)))print("The minimum of March is: " + str(min(mar)))print("The maximum of March is: " + str(max(mar)))print('\n')print("The Average for April is: " + str(sum(apr)/len(apr)))print("The minimum of April is: " + str(min(apr)))print("The maximum of April is: " + str(max(apr)))print('\n')print("The Average for May is: " + str(sum(may)/len(may)))print("The minimum of May is: " + str(min(may)))print("The maximum of May is: " + str(max(may)))print('\n')print("The Average for June is: " + str(sum(jun)/len(jun)))print("The minimum of June is: " + str(min(jun)))print("The maximum of June is: " + str(max(jun)))print('\n')print("The Average for July is: " + str(sum(jul)/len(jul)))print("The minimum of July is: " + str(min(jul)))print("The maximum of July is: " + str(max(jul)))print('\n')print("The Average for August is: " + str(sum(aug)/len(aug)))print("The minimum of August is: " + str(min(aug)))print("The maximum of August is: " + str(max(aug)))print('\n')print("The Average for September is: " + str(sum(sep)/len(sep)))print("The minimum of September is: " + str(min(sep)))print("The maximum of September is: " + str(max(sep)))print('\n')print("The Average for October is: " + str(sum(oct)/len(oct)))print("The minimum of October is: " + str(min(oct)))print("The maximum of october is: " + str(max(oct)))print('\n')print("The Average for November is: " + str(sum(nov)/len(nov)))print("The minimum of November is: " + str(min(nov)))print("The maximum of November is: " + str(max(nov)))print('\n')print("The Average for December is: " + str(sum(dec)/len(dec)))print("The minimum of December is: " + str(min(dec)))print("The maximum of December is: " + str(max(dec)))print('\n')**Exercise 3**For the rest of the project, it will be helpful to define two functions. Define one function that takes the month and year as input and outputs the index for that given month and year. Define another function that takes the index as the input and outputs the month and year.# def findMY(a,b): if a >1880 and a <= 2017: a = a-1880 if b >1 and b<=12: b = b return a,bdef findI(a,b): a += 1880 return [a][b]codes**Exercise 4**Create plots of the monthly average temperature over time for each month: one plot for all January average temperatures, one plot for all February average temperatures, etc. The plots should have Years on the horizontal (x) axis, and Temperature on the vertical (y) axis. The previously defined functions will be helpful here. Your code should plot all months (separately).years=[]b=1880for i in jan: i=b years.append(b) b += 1#Janx=yearsy= janplt.plot(x,y)plt.title("Jan")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Febx=yearsy= febplt.plot(x,y)plt.title("Feb")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Marchx=yearsy= marplt.plot(x,y)plt.title("Mar")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Aprilx=yearsy= aprplt.plot(x,y)plt.title("Apr")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Mayx=yearsy= mayplt.plot(x,y)plt.title("May")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Junex=yearsy= junplt.plot(x,y)plt.title("Jun")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Julyx=yearsy= julplt.plot(x,y)plt.title("Jul")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Augx=yearsy= augplt.plot(x,y)plt.title("Aug")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Sepx=yearsy= sepplt.plot(x,y)plt.title("Sep")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Octx=yearsy= octplt.plot(x,y)plt.title("Oct")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Novx=yearsy= novplt.plot(x,y)plt.title("Nov")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()#Decx=yearsy= decplt.plot(x,y)plt.title("Dec")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()**Exercise 5**Create a plot that shows the average annual temperature over all years. (That is, create one plot where each data point corresponds to the average temperature for a year.) (HINT: This is easiest if you create a new list with elements representing average temperature).def avgTemp(fahrenheit): return [fahrenheit[i] for i in range(0, len(fahrenheit), 18)]x = yearsy = avgTemp(fahrenheit)plt.plot(x,y)plt.title("Average per Year")plt.xlabel("Years")plt.ylabel("Temperature")plt.show()print('Graph')**Exercise 6**Create a plot showing the monthly average temperature starting at January 2000 (one plot showing all data points from January 2000 through December 2012). The previously defined functions will be helpful here.x= yearsplt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.title("2000-2012 Temperature")plt.xlabel("Years")plt.ylabel("Temperature")plt.ylim(57,59)plt.xlim(2000,2012)plt.plot(avgTemp(fahrenheit),'*k')plt.legend(['-r = Jan', '-b = Feb', '-g = Mar', '-c = Apr','-m = May', '-y = Jun','-k = Jul', '--r = Aug', '--b = Sep', '--g = Oct', '--C = Nov', '--k =Dec'], loc='lower right')plt.show()print('Graph')**Exercise 7**Plot the annual average temperature from 2000-2012.def avgTemp(fahrenheit): return [fahrenheit[i] for i in range(0, len(fahrenheit), 18)]x = yearsy = avgTemp(fahrenheit)plt.plot(x,y)plt.title("Average 2000-2012")plt.xlabel("Years")plt.ylabel("Temperature")plt.xlim(2000,2012)plt.show()print('Graph')print("_________**Exercise 8**Create a plot of the monthly average temperatures starting at January 1990 and ending on December 1999.x= yearsplt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.title("1990s Temperature")plt.xlabel("Years")plt.ylabel("Temperature")plt.ylim(57,59)plt.xlim(1990,1999)plt.legend(['-r = Jan', '-b = Feb', '-g = Mar', '-c = Apr','-m = May', '-y = Jun','-k = Jul', '--r = Aug', '--b = Sep', '--g = Oct', '--C = Nov', '--k =Dec'], loc='lower right')plt.show()print('Graph')Do you see any pattern to the data? Are temperatures rising? Which months had the highest and lowest temperatures?Yes, there’s a pattern to the data that the winter months are getting warmer than what they should be. Yes, temperatures rising. Highest Temperatures Months- Jan, Jun, Jul, Aug, Nov, Sep Lowest Temperatures Months- Oct, May, Apr, Feb, Mar, Dec**Exercise 9**Plot the annual average temperature of every year from 1990 to 1999.def avgTemp(fahrenheit): return [fahrenheit[i] for i in range(0, len(fahrenheit), 18)]x = yearsy = avgTemp(fahrenheit)plt.plot(x,y)plt.title("Average 1990s")plt.xlabel("Years")plt.ylabel("Temperature")plt.xlim(1990,1999)plt.show()print('Graph')Is it easier to see a warming trend? What is the average temperature of the 1990s?Yes, it easier to see a warming trend because if you see the average in 1990 and then 1998 you can see a drastic change in the temperature as it goes up 2°F. The average temperature in the 1990s is 58.0°F.**Exercise 10**Plot the monthly average temperature of every month in the 1890s.x= yearsplt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.plot(x,avgTemp(fahrenheit),'*k')plt.title("1890 Temperature")plt.xlabel("Years")plt.ylabel("Temperature")plt.ylim(55,59)plt.xlim(1890,1899)plt.legend(['-r = Jan', '-b = Feb', '-g = Mar', '-c = Apr','-m = May', '-y = Jun','-k = Jul', '--r = Aug', '--b = Sep', '--g = Oct', '--C = Nov', '--k =Dec'], loc='lower right')plt.show()print('Graph')What is the mean temperature of this decade? How does this decade compare to the 1990s?The mean temperature of this decade is 56.5-57.5°F. The way this compare to the 1990s is that it much lower than recent years because this shows that Global warming exist.**Exercise 11**Create plots of the monthly averages of the first 44 years, the second 44 years, and the last 43 years. Remember to use the previously defined functions!fig1=plt.figure(3)plt.subplot(311)plt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.xlim(1880,1924)plt.subplot(312)plt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.xlim((1925,1968))plt.subplot(313)plt.plot(x,jan,'-r')plt.plot(x,feb,'-b')plt.plot(x,mar,'-g')plt.plot(x,apr,'-c')plt.plot(x,may,'-m')plt.plot(x,jun,'-y')plt.plot(x,jul,'-k')plt.plot(x,aug,'--r')plt.plot(x,sep,'--b')plt.plot(x,oct,'--g')plt.plot(x,nov,'--c')plt.plot(x,dec,'--k')plt.xlim((1969,2017))plt.show()Do you see any warming trends in any of these plots? What is the average temperature of each of these time periods? You can see a warming trend in the timeline 1969-2018. Especially between 2000-2018. The average temperature between 1880-1920 was mostly 56°F. Between 1925-1968 it was 57°F. Between 1969-2018 it was 60°FAnalysis:Overall, the data points to an obvious increase in global temperature. The graphs help prove that more so than a chart of numbers. Average yearly temperature as well as average monthly temperatures have increased drastically since 1880. CO2 emissions and green house effects in the last 50 years have attributed to the increase. Prior to the 1900, there was minimal increase but the chart shows a much steeper increase now. Each student should submit their code and a word file which shows the outputs with appropriate screenshots. /* All students are expected to use appropriate amount of comments to explain their program. */Due Date: 2/16/18 ****************************************Read Me*****************************************Technical information on GISTEMP data (about the data given to you)GLOBAL Land-Ocean Temperature Index in 0.01 degrees Celsius base period: 1951-1980 sources: GHCN-v3 1880-01/2014 + SST: ERSST 1880-01/2014 using elimination of outliers and homogeneity adjustment Notes: 1950 DJF = Dec 1949 - Feb 1950 ; ***** = missingDivide by 100 to get changes in degrees Celsius (deg-C).Multiply that result by 1.8(=9/5) to get changes in degrees Fahrenheit (deg-F).Best estimate for absolute global mean for 1951-1980 is 14.0 deg-C or 57.2 deg-F,so add that to the temperature change if you want to use an absolute scale(this note applies to global annual means only, J-D and D-N !)Example -- Lets take a Table Value : 40 i.e. from the data you have loaded change : 0.40 deg-C or 0.72 deg-F (Divide by 100 to get changes in degrees Celsius (deg-C))abs. scale if global annual mean: 14.40 deg-C or 57.92 deg-F (i.e. change+absolute global mean)Try to incorporate this data (i.e. absolute Fahrenheit data) as asked in exercise-1 to get a real feel about the global temperature.Project-1 data have been gathered from through this document to have a better understanding of the data: interested to know more about Global Temperatures, read further:Dr. young’s excel spread sheet of New England and Global temperatures.The excel spread sheet uses two data sets:New England Data: U.S. Historical Climatological Network (USHCN) data set. This data set was downloaded from NOAA's National Climatic Data Center (NCDC) website. United States Historical Climatology Network (USHCN) is a high quality data set of daily and monthly records of basic meteorological variables from 1218 observing stations across the 48 contiguous United States.Global Data: The Goddard Institute for Space Studies (GISS) Surface Temperature Analysis (GISTEMP) data set from the NASA Goddard Institute. GISS data (Hansen) Land-Surface Air and Sea-Surface Water Temperature Anomalies (Land-Ocean Temperature Index, LOTI)Global-mean monthly, seasonal, and annual means, 1880-present, updated through most recent monthNorthern Hemisphere-mean monthly, seasonal, and annual means, 1880-present, updated through most recent month ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download