Skip to main content

np_exercise_bradford_data.py


"""
Solution for Numpy exercise : Bradford weather
a. read in weather data from Bradford station
skip rows and specify missing_values string as appropriate
b. calculate monthly mean temperature (tmean)
as the average of tmin and tmax
Author: L J Gregoire
"""
import numpy as np
###
# read in Bradford weather data
###
filename='bradforddata.txt'  # put full path to data if needed
data=np.genfromtxt(filename,
           skip_header=7,usecols=(0,1,2,3),
           missing_values='---')
tmin=data[:,2]
tmax=data[:,3]
##########
# caculate mean monthly temperature
# as the average of min and max tempeartures
tmean=(tmin+tmax)/2.
##########
# Print some values to check the results
print tmin[:5]
print tmax[:5]
print tmean[:5]