- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindchillcomp.py
More file actions
Latest commit
53 lines (44 loc) · 1.53 KB
/
Copy pathwindchillcomp.py
File metadata and controls
53 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Column names and column indices to read
columns= {'date': 0, 'time': 1, 'tempout': 2, 'windspeed': 7,
'windchill': 12}
# Data types for each column (only if non-string)
types= {'tempout': float, 'windspeed': float, 'windchill': float}
# Initialize my data variable
data= {}
forcolumnincolumns:
data[column] = []
# Read and parse the data file
filename="data/wxobs20170821.txt"
withopen(filename, 'r') asdatafile:
# Read the first three lines (header)
for_inrange(3):
datafile.readline()
# Read and parse the rest of the file
forlineindatafile:
split_line=line.split()
forcolumnincolumns:
i=columns[column]
t=types.get(column, str)
value=t(split_line[i])
data[column].append(value)
# Compute the wind chill temperature
defcompute_windchill(t, v):
a=35.74
b=0.6215
c=35.75
d=0.4275
v2=v**2
wci=a+ (b*t) - (c*v2) + (d*t*v2)
returnwci
# Compute the wind chill factor
windchill= []
fortemp, windspeedinzip(data['tempout'], data['windspeed']):
windchill.append(compute_windchill(temp, windspeed))
# Output comparison of data
print(' ORIGINAL COMPUTED')
print(' DATE TIME WINDCHILL WINDCHILL DIFFERENCE')
print('------- ------ --------- --------- ----------')
zip_data=zip(data['date'], data['time'], data['windchill'], windchill)
fordate, time, wc_orig, wc_compinzip_data:
wc_diff=wc_orig-wc_comp
print(f'{date}{time:>6}{wc_orig:9.6f}{wc_comp:9.6f}{wc_diff:10.6f}')