Starting from:

$35

Honors Programming Project 12 Solution

Assignment Overview
The project will give you experience of analyzing data and plotting using Matplotlib. This task is not very complicated. However in your future study or research, many tasks you may come cross may be like this one. For problems like this, you may not have to use too complicated data structure or algorithms or advanced concepts like class or inheritance. You just want to have a fast and efficient solution. Python and the powerful third-party modules like Matplotlib will be handy tools to do this. You can develop an efficient and versatile solution in a relatively short time.

Problem Statement and Background
From this website (http://agebb.missouri.edu/weather/history/index.asp), we can get the historical weather data in some locations in Missouri. In this project, we will play with such data to have some interesting analysis results.

Firstly, from that website we can get the hourly temperature records for each day in several years. We can use such data to calculate the average high temperature and average low temperature for every month. This information is very important for people to learn about the climate of a specific location.

Secondly, we can also get the hourly solar radiation records for each day in several years. We all know that the solar radiation is the most important resource of the heat on earth. So it is reasonable that the temperature is related to the solar radiation. However, what the relation will be is an interesting question. We all have some idea that the sunlight is the strongest at noon. Does that mean the temperature is the highest at noon either? We will examine that in this project. We will calculate the average solar radiation and average temperature at different time in a day in certain month. Then we can plot a figure to show the relation between them.


Project Outlines:

First task:
    1. Download the data file from the project directory (temperature.txt). This file contains the hourly temperature records in Charleston,MO from Jan.1st,2012 to Dec.31st,2012. For each day, there are 24 lines of records of temperature for each hour time.

    2. For each day, you should find the highest temperature and the lowest temperature.
    3. For each month, you should calculate the average high temperature and average low temperature using the highest temperature and lowest temperature of all the days in that month. For example, for January, there are 31 days to calculate. You can get the January average high temperature by calculating the average of the highest temperature in the 31 days in January 2012.

    4. Plot a figure to display the result using matplotlib module. (More details will be discussed later)

Second task:
    1. You have got the temperature.txt. Now you can download the solar_radition.txt file from the project directory. This file contains the hourly solar radiation records in Charleston,MO from Jan.1st,2012 to Dec.31st,2012. For each day, there are 24 lines of records of solar radiation for each hour.

    2. Here we will only focus on June, since the daytime is relatively longer in June.
    3. For each hour time, calculate the average temperature for the 30 days in June. For example, for 11AM, calculate the average of the temperature at that time in 30 days. You also need to calculate the average temperature for 1AM, 2AM …10PM,11PM.

    4. For each hour time, calculate the average solar radiation for the 30 days in June. The calculation is almost the same as the 3rd step above.
    5. Plot a figure to show the relation between temperature and solar radiation using matplotlib module.(More details will be discussed later)




Notes and Discussion:
    1. You can consider to use max() and min() functions to get the high and low temperatures in each day.

    2. For the first task, a 'floating bar' figure should be plotted, as shown below. So the top of the bar is average high temperature, and the bottom of the bar is average low temperature.

        a. Use title
        b. Use “ticks” like “January' 'February' to label x-axis.
        c. Check section 9.9 in textbook for example of a bar graph.(page 426) and Appendix C.2.3/C.2.4

        d. You can also check this:
http://matplotlib.org/examples/pylab_examples/custom_ticker1.html
        e. To make the bar “floating”, check “bottom” option of bar() method.
Like:
plt.bar([1,2,3,4], [2,2.5,5,3], bottom=[0,-1,1,2])

    3. For the second task, a dot-line figure with two y-scales should be plotted, as below. The left y-scale and blue dots are for average temperature, the right y-scale and red dots are for average solar radiation.
        a. Using title
        b. Using two colors for two y-scale labels and two curves(points).
        c. Check this for reference, your code should be pretty similar to this example. http://matplotlib.org/examples/api/two_scales.html

    4. You should write one program to plot the two figures. You are free to use functions. You don't need to implement the user interface. (Don't need to ask user for the name of data file)

        a. Use savefig() method to save a plot as a file, like plt.savefig('temp.png'). Use show() method just for testing. Finally your program will generate two figure files in the working directory.

        b. After the first figure is finished and saved, use close() method to remove the old figure, like plt.close(). Otherwise you will mess the new figure with old one.

        c. Your program don't need to print out the analysis result to the screen (although it will be helpful for testing), just plot the figures directly.

    5. It's Ok if you use python2.7 if you have difficulty in installing matplotlib for python3. Just mention this at the beginning of your program.

    6. For the second task, when you have your figure finished, what conclusion can be drawn about the relation between temperature and solar radiation? Can you answer the question in “Problem Statement and Background” above?



Deliverables
proj12.py -- your source code solution (include section, date, project number and comments). One program to generate two figures.

More products