Plotting Temperature Data

 


Introduction

The purpose of this activity is to explore creating and working with two-dimensional lists in Python to process temperature data.



Exercises

  1. Create a new notebook in Google Colab for the statements and functions you will write in this activity. Then save the new notebook with a name representative of this activity.
  2. In this activity you will be exploring high and low temperatures in Kalamazoo during the month of January over several years. Using data from the files below, create 6 1-dimensional lists of high temperatures, corresponding to the 6 different years of high temperatures for the month you chose. Then create another set of 6 1-dimensional lists for the low temps for each of the 6 years.
    Files with temperature data: Alternatively, you may read the data from the file JanTemps.csv and store it in 12 separate lists, or a list of 12 elements, where each of those elements is a list of 31 temperatures.
  3. Write a function called avgTemp that takes a list of temperature values as a parameter and calculates the average value of the elements in the list. Your function should then return the average value.
  4. Test your function by calling it with one of your temperature lists and printing the result. You may have a statement such as print("The average high temp from Jan 2021 is: ", avgTemp(Jan2021HighTemps)). Double check your results by calculating the average with a calculator.
  5. Print out the average temperatures for each of your lists. You should include descriptive text with the values you print out.
  6. Write a function called medianTemp that takes a list of temperature values as a parameter and returns the median value of the list. To find the median value, you should make a clone of the list, then sort the new list (use the Python sort function for lists ), and then return the middle element of the sorted list.
  7. Print the median values for each of your temperature lists.
  8. Write a function called maxTemp that takes a list of temperatures as a parameter and calculates the maximum value of the list. It should return the maximum value. To calculate the maximum value, you may use a loop and search through list to find the largest element, or you may use the Python max function.
  9. Print out the maximum temperature for each of the 6 years of monthly data that you have, for your low temperatures as well as your high temperatures. This means you will need to call the maxTemp function with each of your lists and print the values that get returned. Include text with your printed statement to indicate what year you are reporting on, as in print("Max low temp for the month of January in the year 2005 is: " , maxTemp(Jan2005LowTemps)).
  10. Write a function called minTemp that returns the minimum value from a list of temperature values. The code for this function will be quite similar to that for the maxTemp function. You may use the Python min function.
  11. Print out the minimum temperatures for each of your lists, similar to what you did for the maximum temperatures.
  12. Write a function called numGreaterThan that takes a list of temperature values and a specific value as parameters, and returns the number of temperature values that are greater than the specifed value. To do this, create a variable called count that is initially 0. Loop through the list and check if each value is greater than the specified value. If it is, increment count by 1. Return the count at the end of the function.
  13. Test the function by calling it with one of your low temp lists and the value of 32. (This should give you the number of days with low temps over 32 degrees.)
  14. For each of your low temperature lists, print out the number of temperatures above 32 degrees.
  15. Write a similar function, numLessThan that takes a list of temperature values and a specific value as parameters, and returns the number of temperature values that are less than the specified value.
  16. For each of your high temperature lists, print the number of temperatures less than 32 degrees. For each of your low temperature lists, print both the number of temperatures less than 32 degrees and the number of temperatures less than 0 degrees.
  17. Optional Exploration: Are there other values you are interested in learning? Come up with at least one more question you would like to answer regarding these temperatures. Write that question in a new Text cell.
  18. Continued Optional Exploration: Can you use the functions you have written to determine an answer to your question(s) or would you need to write some new functions? Write the code to compute and then print out or graph an answer to your question.
  19. Plot all 6 high temperature lists on the same graph.

  20. Plot all 6 low temperature lists on the same graph.

Connections

  1. Think about how the average temperatures you calculated compare with the averages published for Kalamazoo. January weather.
  2. Read the following article: Why Record-Breaking Overnight Temperatures Are So Concerning.
  3. In a new Text cell, write several paragraphs that discuss any trends you saw in your monthly data over the six years that you looked at, and how that does or does not correspond to current trends, and what is discussed in the article.

Submit