Beispiel #1
0
 def test_pca_eof(self):
     A = Analyzer(setup_data1(nt=70, nx=150))
     raw_eof = A.pca_eof(raw=True)
     np_eof, np_pc, np_ev = pca_numpy(A.stacked_data.T, A.npca)
     self.assertTrue(npy.allclose(npy.abs(raw_eof[:2,:2]), npy.abs(npy.array(
         [[ 0.15702435,  0.05325682],
         [ 0.14647224,  0.05082613]]))))
     eof = A.pca_eof()
     self.assertTrue(npy.allclose(npy.abs(eof[:2,:3].filled(0.)),  npy.abs(npy.array(
         [[ 0.15702435,  0., 0.14647224],
         [ 0.05325682,  0., 0.05082613]]))))
Beispiel #2
0
 def test_pca_ec(self):
     data = setup_data1(nt=70, nx=150)
     A = Analyzer(data)
     A.pca_eof()
     ec = A.pca_ec()
     pc = A.pca_pc()
     self.assertTrue(npy.allclose(ec, pc))
     ece = A.pca_ec(xeof=A.pca_eof(raw=True), xraw=True)
     self.assertTrue(npy.allclose(ece, pc))
     ecd = A.pca_ec(xdata=data)
     self.assertTrue(npy.allclose(ecd, pc))
     ecrd = A.pca_ec(xdata=A.stacked_data, xraw=True)
     self.assertTrue(npy.allclose(ecrd, pc))
     ecre = A.pca_ec(xeof=A.pca_eof(raw=True), xraw=True)
     self.assertTrue(npy.allclose(ecrd, pc))
Beispiel #3
0
 def test_pca_xrec(self):
     var = setup_data1()
     A = Analyzer(var)
     rec = A.pca_rec()
     xeof = A.pca_eof()
     xpc = A.pca_pc()
     xrec = A.pca_rec(xeof=xeof, xpc=xpc)
     self.assertTrue(npy.allclose(rec, xrec))
Beispiel #4
0
    def test_pca(self):

        # spanlib
        A = Analyzer(setup_data1(nt=70, nx=50))
        sp_eof = A.pca_eof(raw=True)
        sp_pc = A.pca_pc(raw=True)
        sp_ev = A.pca_ev(raw=True)

        # numpy
        np_eof, np_pc, np_ev = pca_numpy(A.stacked_data.T, A.npca)

        # checks
        self.assertTrue(npy.allclose(sp_ev, np_ev))
        signs = npy.sign(sp_eof[0])*npy.sign(np_eof[0])
        np_eof *= npy.resize(signs, np_eof.shape)
        np_pc *= npy.resize(signs, np_pc.shape)
        self.assertTrue(npy.allclose(sp_eof, np_eof))
        self.assertTrue(npy.allclose(sp_pc, np_pc))
        self.assertTrue(npy.allclose(sp_ev, np_ev))
Beispiel #5
0
 def test_pca_ndim3(self):
     A = Analyzer(setup_data2())
     A.pca()
     self.assertTrue(npy.allclose(
         npy.abs(A.pca_eof(raw=True)[190:193,5]),
         npy.abs(npy.array([-0.03623882, -0.02312414, -0.00942417]))))