**CS152 Project3 by Velan Nandhakumaran**

Goal:

The purpose of this project was to create a variety of functions and programs to help with computing simple statistical functions.

Abstract:

The main lecture concepts in this lab were learning how to create loops, use loops, utilize lists, and store and access data. We also worked on calling programs from different files to utilize in the current program. For example, in our computeStats.py file, we imported and called the stats.py program to calculate mean, min, max, and standard deviation. The stats.py called to calculate those specific categories

Importing programs is much more easy and clear than re-writing a program.

Tasks:

Temperature Conversion:

The first task was to add a function to our stats.py file that converts Celsius to Fahrenheit. It used Celsius as the input and outputted Fahrenheit through an algebraic equation.

Temperature Statistics:

In this task, a program called computeStats.py was created that read a single stream of numbers, stores them in a list, then calls the functions from stats.py to calculate the min, max, mean, and standard deviation. Using grep and cut commands on the terminal and computeStats.py, the mean, max, min, and standard deviation of the temperatures at 1m, 5m, and 7m were calculated. The Celsius to Fahrenheit function was also used to display the temperature in two different forms. Figures 1, 2, and 3 represent the outputs of our program for the first week of June, I did not include the screenshots of the July and August data because it would make the report look messy. That said, please find the commands and program in my project 3 file.

Figure 1 illustrates the mean, min, and max temperatures in Celsius and Fahrenheit for the first week of June at 1m in depth. It also shows the standard deviation in Celsius.

Figure 2 illustrates the mean, min, and max temperatures in Celsius and Fahrenheit for the first week of June at 5m in depth. It also shows the standard deviation in Celsius.

Figure 3 illustrates the mean, min, and max temperatures in Celsius and Fahrenheit for the first week of June at 7m in depth. It also shows the standard deviation in Celsius.

**Thermocline Depth Calculation:**

The next task was to write a function that computes the depth of the maximum change in density, and a function that reads in a stream of data and sets up the computations. A file called thermocline.py was created. A function called density was created with one parameter, temps (a list of temperatures). The function looped over the temps list and for each temperature value, t, it computed the density using a formula. Then a function was added to thermocline.py that computes the derivative of density with respect to depth. The function takes 2 lists-- the set of temperatures and the corresponding depths--and it will return the depth of the maximum change in density. Next the main function was written such that it reads all the buoy data through stdin, extracts all the temperature fields in order, computes the thermocline depth, and prints it out. The program keeps track of and prints out the minimum and maximum depth of the thermocline and when the minimum and maximum events occurred. Throughout all the functions in the thermocline.py file, loops (while or for) and ‘if’ statements were utilized such that we could go through all the data and update our desired variables. For example, in the main function, a ‘for loop’ was used to go through the data and if statements were used to update the value of maxdepth. This was because if the depth was greater than our current maxdepth, the max depth would now be updated to that certain depth.

The final task to complete was to use unix commands to compute the thermocline depth on hourly intervals for the month of June. The following command was used to get the desired information and redirect the output to a new file called 2016-06-thermo.csv:

curl -s http://cs.colby.edu/courses/F18/cs152-labs/3100_iSIC.csv | grep '6 /[[:digit:]]\+/2016' | grep ':00' | python3 thermocline.py >2016-06-thermo.csv. The new file was then redirected using cat, then the second field was cut, and it was piped to computeStats.py to get the min, max, mean, and standard deviation of thermocline for June.

cat 2016-06-thermo.csv | cut -d ',' -f 2 | python3 computeStats.py

Figure4: shows the min, mean, standard deviation, and max in Celsius, and the min, mean and max in Fahrenheit

Reflection: The lecture concepts on loops and conditional statements were extremely helpful because the computer could go through the data and update values such that we could gather our desired information. Learning how to access functions in different files was also helpful because re-writing the same function would be a waste of time and could cause an error.

Sources: I got help from the TA’s, I believe the person who helped me the most is named Jackie. She was very helpful and knowledgeable.