Exemplo n.º 1
0
    def test_fit_real_numpy(self):
        log = logging.getLogger('TestFitZern.test_fit_real_numpy')
        z = RZern(4)
        F = FitZern(z, self.L, self.K)
        theta_i = F.theta_i
        rho_j = F.rho_j

        c = normal(size=z.nk)
        Phi = [z.eval_a(c, rh, th) for rh in rho_j for th in theta_i]

        time1 = time()
        ce = F._fit_slow(Phi)
        time2 = time()
        log.debug('elapsed FIT_LIST {:.6f}'.format(time2 - time1))

        time1 = time()
        ce2 = F.fit(np.array(Phi, order='F'))
        time2 = time()
        log.debug('elapsed FIT_NUMPY {:.6f}'.format(time2 - time1))

        enorm = norm(ce2 - np.array(ce, order='F'))
        log.debug('enorm {:e}'.format(enorm))
        self.assertTrue(enorm < self.max_enorm)
Exemplo n.º 2
0
        def do_test(cls, complex_a):
            z = cls(4)
            F = FitZern(z, self.L, self.K)
            theta_i = F.theta_i
            rho_j = F.rho_j
            z.make_pol_grid(rho_j, theta_i)

            if complex_a:
                c = normal(size=z.nk) + 1j*normal(size=z.nk)
            else:
                c = normal(size=z.nk)

            PhiN = np.array(
                [z.eval_a(c, rh, th) for rh in rho_j for th in theta_i],
                order='F')

            ce1 = F.fit(PhiN)

            # create tmp path
            tmpfile = NamedTemporaryFile()
            tmppath = tmpfile.name
            tmpfile.close()

            F.save(tmppath)

            F2 = FitZern.load(tmppath)

            PhiN1 = np.array(
                [F.z.eval_a(c, rh, th) for rh in rho_j for th in theta_i],
                order='F')
            PhiN2 = np.array(
                [F2.z.eval_a(c, rh, th) for rh in rho_j for th in theta_i],
                order='F')

            self.assertTrue(isinstance(F, FitZern))
            self.assertTrue(isinstance(F2, FitZern))
            if complex_a:
                self.assertTrue(isinstance(F.z, CZern))
                self.assertTrue(isinstance(F2.z, CZern))
            else:
                self.assertTrue(isinstance(F.z, RZern))
                self.assertTrue(isinstance(F2.z, RZern))
            self.assertTrue(norm(PhiN - PhiN1) == 0)
            self.assertTrue(norm(PhiN - PhiN2) == 0)

            self.assertTrue(norm(F.z.coefnorm - F2.z.coefnorm) == 0)
            self.assertTrue(norm(F.z.ntab - F2.z.ntab) == 0)
            self.assertTrue(norm(F.z.mtab - F2.z.mtab) == 0)
            self.assertTrue(F.z.n == F2.z.n)
            self.assertTrue(F.z.nk == F2.z.nk)
            self.assertTrue(F.z.normalise == F2.z.normalise)
            self.assertTrue(norm(F.z.rhoitab - F2.z.rhoitab) == 0)
            self.assertTrue(norm(F.z.rhotab - F2.z.rhotab) == 0)
            self.assertTrue(F.z.numpy_dtype == F2.z.numpy_dtype)
            self.assertTrue(norm(F.z.ZZ - F2.z.ZZ) == 0)

            self.assertTrue(norm(F.A - F2.A) == 0)
            self.assertTrue(norm(F.I_cosm - F2.I_cosm) == 0)
            self.assertTrue(norm(F.I_sinm - F2.I_sinm) == 0)
            self.assertTrue(norm(F.I_Rnmrho - F2.I_Rnmrho) == 0)
            self.assertTrue(F.K == F2.K)
            self.assertTrue(F.L == F2.L)
            self.assertTrue(norm(F.rho_a - F2.rho_a) == 0)
            self.assertTrue(norm(F.rho_b - F2.rho_b) == 0)
            self.assertTrue(norm(F.rho_j - F2.rho_j) == 0)
            self.assertTrue(norm(F.theta_a - F2.theta_a) == 0)
            self.assertTrue(norm(F.theta_b - F2.theta_b) == 0)
            self.assertTrue(norm(F.theta_i - F2.theta_i) == 0)

            ce2 = F2.fit(PhiN)
            self.assertTrue(norm(ce2 - ce1) < self.max_enorm)

            os.unlink(tmppath)
            del z, F, F2, c, ce1, ce2, PhiN, PhiN1, PhiN2