# The correlation between air pressure and temperature

The Cambridge University Digital Technology Group have been recording the weather from the roof of their department building since 1995 and make the data available to download in a single CSV file.

The following program determines the correlation coefficient between pressure and temperature at this site.

import numpy as np
import matplotlib.pyplot as plt

data = np.genfromtxt('weather-raw.csv', delimiter=',', usecols=(1,4))
# Remove any rows with either missing T or missing p
data = data[~np.any(np.isnan(data), axis=1)]
# Temperatures are reported after multiplication by a factor of 10 so remove
# this factor
data[:,0] /= 10

# Get the correlation coefficient
corr = np.corrcoef(data, rowvar=0)[0,1]
print('p-T correlation coefficient: {:.4f}'.format(corr))

# Plot the data on a scatter plot: T on x-axis, p on y-axis.
plt.scatter(*data.T, marker='.')
plt.xlabel('$T$ /$\mathrm{^\circ C}$')
plt.ylabel('$p$ /mbar')
plt.show()


The output gives a correlation coefficient of 0.0260: as expected, there is little correlation between air temperature and pressure (since the air density also varies). 