view attached files for assignment
Microsoft Word - Homework9.docx ENGR 102 - Homework 9 Problems 1-3 are to be completed on Mimir. You will need to develop your code in https://repl.it/ or another IDE such as Spyder. You will then be required to save the file to your local computer and then upload your code into Mimir. Be careful to follow the naming convention described in the problem. If you have trouble, please do not hesitate to contact the teaching team. Problem 4 is to be done separately and submitted to the appropriate submission box on eCampus. Please submit the following files to Mimir: • Lab9a_write.py • Lab9a_read.py • Lab9a_interpolate.py You have been tasked to build a program for performing interpolation calculations on select properties of water. This will be done in three different parts: Problem 1 is to write and store data in a file, Problem 2 is to read data from the file, and Problem 3 to interpolate and answer queries. If you plan to take a thermodynamics course in the future, this program may prove helpful to future you. https://en.wikipedia.org/wiki/Linear_interpolation Problem 1: Writing the file Open the file “WaterData.py” which contains lists of the data you need. The data are thermodynamic properties of liquid water at varying temperatures and two different pressures. The properties listed are as follows: • Specific volume (?) in units of ?3/?? • Specific internal energy (?) in units of ??/?? • Specific enthalpy (ℎ) in units of ??/?? • Specific entropy (?) in units of ??/(?? · ?) It is common to use linear interpolation for temperatures not listed. So, for example, if you need the properties at ? = 25℃, you could interpolate between the property values listed for ? = 20℃ and ? = 40℃ as a good estimate. Create a program named Lab9a_write.py that will write the water data to a new file. You may copy the lists of data into your program file. Name the new file that your code creates Lab9a_ThermoProperties.csv. Write the data to the file in the “comma separated” format shown below. The format for each pressure is the temperature value followed by the corresponding property values for that temperature all on one line with the values separated by commas. There are no spaces between the numbers, only commas. 5 MPa Data 0,0.0009977,0.04,5.03,0.0001 20,0.0009996,83.61,88.61,0.2954 40,0.0010057,166.92,171.95,0.5705 ... 10 MPa Data 0,0.0009952,0.12,10.07,0.0003 ... Open the file your code created in a text editor (like Notepad) or in Spyder, and verify that the first several lines look like the sample lines above. Open the file your code created in Excel. The commas will not be shown and the data will be listed in columns. Excel is able to recognize and import comma separated variable files (.csv) even though it is just a simple text file. Problem 2: Reading a file Create a program named Lab9a_read.py that will read the CSV file you created in Part A. Prompt the user for the filename of the data file to read, then read all the data in the file, and print a nicely formatted table, using the output format shown below. Example output: Enter the filename: Lab9a_ThermoProperties.csv 5 MPa Data Temp [C] v [m3/kg] u [kJ/kg] h [kJ/kg] s [kJ/kgK] 0.0 0.0009977 0.04 5.03 0.0001 20.0 0.0009996 83.61 88.61 0.2954 40.0 0.0010057 166.92 171.95 0.5705 ... 10 MPa Data Temp [C] v [m3/kg] u [kJ/kg] h [kJ/kg] s [kJ/kgK] 0.0 0.0009952 0.12 10.07 0.0003 20.0 0.0009973 83.31 93.28 0.2943 ... Problem 3: Interpolate the data Now you will add some useful features to your code from above. Rather than hardcode the database in Python as lists, you want to be able to read in the data from a file, then perform calculations with it. Your program should perform the following tasks: • Open and read in the data from the created file in Problem 1 (reuse code from Problem 2) • Take as input from the user a temperature value and a pressure value o Check to make sure the user entered values within the temperature and pressure ranges of the dataset • Interpolate to estimate the property values o You will need to do a double interpolation, in other words, interpolate between two temperatures and two pressures • Format your output as shown below o Use seven (7) decimal places for specific volume o Use two (2) decimal places for specific internal energy and specific enthalpy o Use four (4) decimal places for specific entropy • Name your program Lab9a_interpolate.py for submission Example output (using input 50 and 8): Enter a temperature between 0 and 260 C: 50 Enter a pressure between 5 and 10 MPa: 8 Properties at 50.0 C and 8.0 MPa are: Specific volume (m^3/kg): 0.0010090 Specific internal energy (kJ/kg): 208.17 Specific enthalpy (kJ/kg): 216.24 Specific entropy (kJ/kgK): 0.6982 Problem 4: Weather or not it is important On the class website is a CSV file containing weather data from Coulter Field (in Bryan) for 3 years (1 day is missing for some reason!); the data was taken from Weather Underground (wunderground.com). There are different versions of the file for Windows and Mac; the only difference is whether the end of a line contains just a new-line character, or both a new-line and a carriage return (you don’t need to worry about the difference). Open the file in any text browser and you should see what it is. Note that the first line of the file contains the column headers explaining what each column is. Download the file to your system, and write a program that will read in the file and do the following: a) Output the maximum and minimum temperature seen over the 3 year period b) Output the average daily precipitation c) Pick any 3 other “interesting” data analysis questions (of your choice) and output the answer to that question. For at least one, make use of the date information. Here are some ideas, but you can pick whatever you want: d) For some particular day, such as December 25, find the maximum and minimum temperatures reached among the 3 years of data. e) For some particular month, such as July 2015, calculate the average high temperature. f) Calculate how frequently the pressure increases from one day to another vs. how frequently it decreases. g) Calculate the annual percentage of days when the humidity was above 90%. h) Calculate the mean and standard deviation of precipitation levels. Be sure to include a descriptive sentence for what you are printing out in each case. Note that the “interesting” analysis questions you choose should be different analyses from each other; for example, you should not find the min/max temperature for just 3 different dates, or find the min/max pressure for December 25, since those are essentially the identical computation. Save your file as a pdf titled [Last Name]_[First Name]_[Section]_Hmk9-4.pdf. An example file uploaded to eCampus would be Doe_John_501_ Hmk9-4.pdf.