In [7]:
import numpy as np
import matplotlib.pyplot as pl
import seaborn as sn
%matplotlib inline
sn.set_style('dark')
In [3]:
stI=np.load('../data/stokesI_sunspot.npy')
stI.shape
Out[3]:
In [8]:
pl.imshow(stI[0,:,:], aspect='auto')
Out[8]:
In [51]:
U, Sigma, Vt = np.linalg.svd(stI[0,:,:])
In [23]:
pl.semilogy(Sigma)
Out[23]:
In [52]:
S = np.zeros(stI[0,:,:].shape)
SigmaNew = Sigma.copy()
SigmaNew[15:] = 0.0
n = len(Sigma)
S[:n,:n] = np.diag(SigmaNew)
In [53]:
reconstructed = U.dot(S).dot(Vt)
pl.imshow(reconstructed, aspect='auto')
Out[53]:
In [57]:
f, ax = pl.subplots(nrows=2, ncols=4, figsize=(17,8))
ax[0,0].imshow(stI[0,:,:], aspect='auto')
ax[1,0].imshow(stI[0,:,:]-stI[0,:,:], aspect='auto')
threshold = [1,7,35]
for i in range(3):
S = np.zeros(stI[0,:,:].shape)
SigmaNew = Sigma.copy()
SigmaNew[threshold[i]:] = 0.0
n = len(Sigma)
S[:n,:n] = np.diag(SigmaNew)
reconstructed = U.dot(S).dot(Vt)
ax[0,i+1].imshow(reconstructed, aspect='auto')
ax[0,i+1].set_title('Keeping {0}'.format(threshold[i]))
ax[1,i+1].imshow(stI[0,:,:]-reconstructed, aspect='auto')
In [ ]: