Example #1
0
    def test_misc(self):
        """::exercise misc functions"""

        z1 = sp.random_patt_uniform(11, 10, patt_type=sp.scalar)

        _ = sp.abs(z1)
        _ = sp.mag(z1)
        _ = sp.mag2(z1)
        _ = sp.L2_patt(z1)
        _ = sp.LInf_patt(z1)

        z1 = sp.random_patt_uniform(11, 10, patt_type=sp.vector)

        _ = sp.mag(z1)
        _ = sp.mag2(z1)
        _ = sp.L2_patt(z1)
        _ = sp.LInf_patt(z1)

        z1 = sp.random_coefs(11, 10, coef_type=sp.scalar)

        _ = sp.abs(z1)
        _ = sp.mag(z1)
        _ = sp.mag2(z1)
        _ = sp.L2_coef(z1)
        _ = sp.LInf_coef(z1)

        z1 = sp.random_coefs(11, 10, coef_type=sp.vector)

        _ = sp.mag(z1)
        _ = sp.mag2(z1)
        _ = sp.L2_coef(z1)
        _ = sp.LInf_coef(z1)

        self.assertTrue(True)
Example #2
0
def verify_spht(pattfile, scoeffile):

    fpatt = fl.load_patt(pattfile)
    fsc = fl.load_coef(scoeffile)
    sc = sp.spht(fpatt, fsc.nmax, fsc.mmax)

    diff = fsc - sc

    return (sp.L2_coef(diff),
            sp.LInf_coef(diff), sp.L2_coef(diff) / sp.L2_coef(fsc),
            sp.LInf_coef(diff) / sp.LInf_coef(fsc))
Example #3
0
def verify_vspht(pattf1, pattf2, scoeff1, scoeff2):

    vfpatt = fl.load_vpatt(pattf1, pattf2)

    fsc1 = fl.load_coef(scoeff1)
    fsc2 = fl.load_coef(scoeff2)

    vfsc = sp.VectorCoefs(fsc1._vec, fsc2._vec, fsc1.nmax, fsc1.mmax)

    vsc = sp.vspht(vfpatt, fsc1.nmax, fsc1.mmax)

    diff = vfsc - vsc

    return (sp.L2_coef(diff),
            sp.LInf_coef(diff), sp.L2_coef(diff) / sp.L2_coef(vfsc),
            sp.LInf_coef(diff) / sp.LInf_coef(vfsc))
Example #4
0
    def test_reciprocity_matlab(self):
        """:: Test reciprocity from matlab output
        
        The test compares the output to the same routine written in Matlab
        """

        print(" ")

        for Nmax in range(6, 8):
            for Mmax in range(Nmax - 1, Nmax + 1):
                filename_c = "coeffs_%d_%d.tst" % (Nmax, Mmax)
                filename_rc = "coeffs_rec_%d_%d.tst" % (Nmax, Mmax)
                path_c = os.path.join(path, test_path,
                                      test_reciprocity_directivity_path,
                                      filename_c)
                path_rc = os.path.join(path, test_path,
                                       test_reciprocity_directivity_path,
                                       filename_rc)

                print(filename_rc)

                (c_m, d) = fl.load_vcoef(path_c)
                (rc_m, d) = fl.load_vcoef(path_rc)

                rc = nss.reciprocity(c_m)

                diff = sp.LInf_coef(rc - rc_m)
                self.assertAlmostEqual(diff, 0, places=14, msg=msg1)
Example #5
0
    def test_probe_correct_and_probe_response(self):
        """:: Test probe_correct and probe_response based on inverses
        
        probe_response is the inverse of probe_correct, this tests that to make
        sure it's true.
        """

        p_m = sp.random_coefs(5, 1, coef_type=sp.vector)

        for Nmax in range(10, 14):
            for Mmax in range(Nmax - 1, Nmax + 1):

                c_m = sp.random_coefs(Nmax, Mmax, coef_type=sp.vector)

                R_python = nss.translate_symmetric_probe(60,
                                                         p_m,
                                                         27,
                                                         region=nss.external)

                # Do probe response and probe correct here
                dnm_response = nss.probe_response(c_m, R_python)
                dnm_corrected = nss.probe_correct(dnm_response, R_python)

                diff = sp.LInf_coef(dnm_corrected - c_m)

                self.assertLess(diff, 1e-12)
Example #6
0
    def test_rotate_around_y_by_pi_on_large_random_coefs(self):
        """:: Test rotate_around_y_by_pi using large randomly generated coeff
        sets.
        
        Large coefficient sets are generated and rotate_around_y_by_pi is
        applied twice two the set of coefficients to return the set back to 
        its original form. 
        """

        print(" ")

        #generate five sets of random variabls

        for nmax in range(100, 104):
            for mmax in range(nmax - 2, nmax + 1):
                c = sp.random_coefs(nmax, mmax, coef_type=sp.vector)

                print("Nmax = %d, Mmax = %d" % (nmax, mmax))

                rc = nss.rotate_around_y_by_pi(c)
                rcc = nss.rotate_around_y_by_pi(rc)

                diff = sp.LInf_coef(rcc - c)
                print("WARNING: This should be 0: err = %.16e" % diff)
                #TODO: I don't understand something here. The difference
                #between rcc and c should be exactly zero but I am
                #getting an error roughly 1e-13. I am not doing any
                #arithmetic so I shouldn't have any error???
                #NEED TO UNDERSTAND THIS
                self.assertAlmostEqual(diff, 0, places=10)
Example #7
0
    def test_reciprocity_on_large_random_coefs(self):
        """:: Test reciprocity using large randomly generated coeff sets.
        
        Large coefficient sets are generated and reciprocity is applied 
        twice two the set of coefficients to return the set back to its
        original form. 
        """

        print(" ")

        #generate five sets of random variabls
        for nmax in range(100, 104):
            for mmax in range(nmax - 2, nmax + 1):
                c = sp.random_coefs(nmax, mmax, coef_type=sp.vector)

                print("Nmax = %d, Mmax = %d" % (nmax, mmax))

                rc = nss.reciprocity(c)
                rcc = nss.reciprocity(rc)

                diff = sp.LInf_coef(rcc - c)
                self.assertAlmostEqual(diff, 0, places=14)
Example #8
0
    def test_probe_correct_compare_matlab(self):
        """:: Test probe_correct and probe_response from matlab output
        
        The test compares the output to the same routine written in Matlab
        """

        print(" ")

        # PROBE CORRECT

        for Nmax in range(6, 8):
            for Mmax in range(Nmax - 1, Nmax + 1):
                filename_c = "coeffs5_a_%d_%d.tst" % (Nmax, Mmax)
                filename_rc = "coeffs5_a_pcorrect_%d_%d.tst" % (Nmax, Mmax)
                filename_p = "coeffs5_p.tst"
                path_c = os.path.join(path, test_path, test_p_correct_response,
                                      filename_c)
                path_rc = os.path.join(path, test_path,
                                       test_p_correct_response, filename_rc)
                path_p = os.path.join(path, test_path, test_p_correct_response,
                                      filename_p)

                print(filename_rc)

                (c_m, d) = fl.load_vcoef(path_c)
                (rc_m, d) = fl.load_vcoef(path_rc)
                (p_m, d) = fl.load_vcoef(path_p)

                # Last flag makes this the EXTERNAL case
                R_python = nss.translate_symmetric_probe(60,
                                                         p_m,
                                                         27,
                                                         region=nss.external)

                dnm = nss.probe_correct(c_m, R_python)

                diff = sp.LInf_coef(dnm - rc_m)

                self.assertLess(diff, 1e-12)

        # PROBE RESPONSE

        for Nmax in range(6, 8):
            for Mmax in range(Nmax - 1, Nmax + 1):
                filename_c = "coeffs6_a_%d_%d.tst" % (Nmax, Mmax)
                filename_rc = "coeffs6_a_presponse_%d_%d.tst" % (Nmax, Mmax)
                filename_p = "coeffs6_p.tst"
                path_c = os.path.join(path, test_path, test_p_correct_response,
                                      filename_c)
                path_rc = os.path.join(path, test_path,
                                       test_p_correct_response, filename_rc)
                path_p = os.path.join(path, test_path, test_p_correct_response,
                                      filename_p)

                print(filename_rc)

                (c_m, d) = fl.load_vcoef(path_c)
                (rc_m, d) = fl.load_vcoef(path_rc)
                (p_m, d) = fl.load_vcoef(path_p)

                # Last flag makes this the EXTERNAL case
                R_python = nss.translate_symmetric_probe(60,
                                                         p_m,
                                                         27,
                                                         region=nss.external)

                dnm = nss.probe_response(c_m, R_python)

                diff = sp.LInf_coef(dnm - rc_m)

                self.assertLess(diff, 1e-12)