Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Python Program to Calculate Annual Temperature Statistics

Problem

One of the objectives of the Oman Meteorological Office is to provide statistics on annual temperatures.Assume that at the end of each month only four values of temperature are considered.The first value corresponds to the average temperature of the first week; the second value corresponds to the average temperature of the second week, and so on. The temperature values are stored in a text file named 'temeperatures.txt'.

The latter is composed of thirteen (13) lines as shown in Table 1 (first column). The first line contains the number of months considered, while each of the following twelve (12) lines contains the average weekly temperatures preceded by the number of the corresponding month (e.g. 1 for January,2 for February, …etc).

Note that, sometimes some missing (erroneous) temperature values are entered by mistake or maybe not available at all. The 2nd temperature of the 6th month (‘3a’); and the 3rd temperature of the 8th month (‘-‘) are two examples of missing temperatures. These missing values must be corrected before calculating the average temperatures. One way to correct missing values is to replace them with random numbers generated from a history of min and max temperatures computed from previous years (using another input file 'minmaxTemperartures.txt' as shown in the 2nd column of Table 1).

For example, in order to compute the average temperature of the 6th month, the erroneous temperature (‘3a’) will be replaced by a random number generated from the interval [min, max] (i.e., [32, 36]). At the end of the year, the Meteorological Office reports, in an output text file named 'outFileTemperatures.txt', the min, max and average temperature values for each month and the annual min, max and mean temperature, as shown in Table 1 (3rd column). It is also important to plot the curve of temperature change during the year as shown in Figure 1.

1. Your Python program should have the following functions:

a. main(fname1, fname2, fname3): the main function where fname1, fname2 are the parameter variables corresponding, respectively, to the names of the input files ‘temperatures.txt’ and ‘minmaxTemperatures.txt’; and fname3 is the parameter variable corresponding to the output file name ‘outFileTemperatures.txt’. The main function reads data from fname1 (i.e. ‘temperatures.txt’), validates errors using fname2 (i.e. ‘minmaxTemperatures.txt’) then produces the output file fname3 (i.e., ‘outFileTemperatures.txt’) as shown in the 3rd column of Table 1.

2. printHeader(outfile): prints the header of the output file outfile (i.e., ‘outFileTemperatures.txt’ as shown in the 3rd column of Table 1.)

3. validateTemp(t, month, f2): validates the temperature value t. If t is not a valid temperature value, it will be replaced by a random value generated by the function getRandTemp(month, f2), which is described in (d).

4. getRandTemp(month, f2): reads, from the temperature history file f2 (i.e., 'minmaxTemperartures.txt'), the min and max temperatures of the month defined by the number month and returns a random value in the range [min, max]

5. Plot the temperature changes:

To plot the annual min, max and average temperatures in one figure (see Figure 1 (a,b)), a function plotTemperature() is provided to you. The function plotTemperature() has three parameters variables: (i) ‘inFile’, which receives the name of the file containing min, max and average temperatures, (ii) ‘fromMnth’ and (iii) ‘toMnth’ are the lowest and highest month indices used to plot the temperature change. For instance: •

6. plotTemperature(‘outTemperatures.txt’, 1, 12) is used to read min, max and average temperatures from the text file ‘outTemperatures.txt’ and then plot the temperature change from the first (1) to the twelfth (12) month as shown in Figure 1 (a). By default, ‘fromMnth’and ‘toMnth’ can be omitted, i.e.,

7. plotTemperature(‘outTemperatures.txt’).

8. plotTemperature(‘outTemperatures.txt’, 3, 10) is used to read min and max temperatures from the text file ‘outTemperatures.txt’ and then plot the temperature change from the third (3) to the tenth (10) month as shown in Figure 1 (b).

9. The generated plot (or graph) is saved as an image (i.e., ‘TemperaturePlot.png’).Using the function plotTemperature(), plot the annual change in temperature and also for each season (i.e. from January to April, from May to August and from September to December).

support
close