Skip to content

Instantly share code, notes, and snippets.

@j-faria
Created November 15, 2013 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-faria/7486737 to your computer and use it in GitHub Desktop.
Save j-faria/7486737 to your computer and use it in GitHub Desktop.
Calculate and show the covariance matrix for template noise.
from numpy import *
from pylab import *
from glob import glob
from scipy.stats import nanmean
NN = '088' # change this
fileglob = 'Residuals_NN' + NN + '_Index*'
print 'Using', fileglob, '\n'
filenames = glob(fileglob)
filenames.sort()
arr = []
for f in filenames:
a = loadtxt(f, unpack=True)
#print nanmean(a)
a = a - nanmean(a)
arr.append(a)
print len(arr), '"realizations" of', shape(arr)[1], 'variables\n'
nr = len(arr)
nv = shape(arr)[1]
arr_wn = nan_to_num(arr) # replace nan with 0 (should we do this?)
R = corrcoef(arr_wn)
pcolor(R)
cb = colorbar()
yticks(arange(0.5,nr+0.5),range(1,nr+1))
xticks(arange(0.5,nr+0.5),range(1,nr+1))
xlim([0,nr])
ylim([0,nr])
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment