Ejemplo n.º 1
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))
Ejemplo n.º 2
0
    def test_spht_ispht_one_added_args(self):
        """::Test spht when only nmax is passed.
        """
        c = sp.random_coefs(100, 100)
        p = sp.ispht(c)
        c2 = sp.spht(p, 5)

        res = True
        if (sp.L2_coef(c[0:5, :] - c2) / sp.L2_coef(c[0:5, :])) > 1e-13:
            res = False

        self.assertTrue(res)
Ejemplo n.º 3
0
    def test_spht_ispht_no_added_args(self):
        """::Test spht and ispht when nmax, mmax, nrows, ncols are not passed.
        """
        c = sp.random_coefs(100, 100)
        p = sp.ispht(c)
        c2 = sp.spht(p)

        res = True
        if (sp.L2_coef(c - c2) / sp.L2_coef(c)) > 1e-13:
            res = False

        self.assertTrue(res)
Ejemplo n.º 4
0
    def test_spht_with_large_random(self):
        """::Generate 100 random modes and test both spht and ispht.
        """

        c = sp.random_coefs(100, 100)
        p = sp.ispht(c, 202, 202)
        c2 = sp.spht(p, 100, 100)

        res = True
        if (sp.L2_coef(c - c2) / sp.L2_coef(c)) > 1e-13:
            res = False

        self.assertTrue(res)
Ejemplo n.º 5
0
    def test_spht(self):
        """::Compare spht within pysphi and csphi"""

        Nrows = 100
        Ncols = 200
        res = True

        for MM in xrange(2, 8, 2):
            NNcols = Ncols - MM
            p = sp.random_patt_uniform(Nrows, NNcols)

            spy = sp.spht_slow(p, 50, 46)
            sc = sp.spht(p, 50, 46)

            rerr = sp.compare_relative(spy, sc)
            if (rerr > 1e-13):
                res = False

        self.assertTrue(res)
Ejemplo n.º 6
0
    def test_with_individual_coefficients_set(self):
        """::Testing spht and ispht with single coefficients, first 5 modes.
        """
        res = True

        try:
            for n in xrange(0, 6):
                for m in xrange(-n, n + 1):
                    rnd = np.random.normal(0, 10)
                    c = sp.zeros_coefs(15, 15)
                    c[n, m] = rnd
                    p = sp.ispht(c, 50, 50)
                    c2 = sp.spht(p, 15, 15)
                    s = sp.L2_coef(c - c2) / sp.L2_coef(c)

                    if s > 1e-13:
                        res = False
        except:
            res = False

        self.assertTrue(res)
Ejemplo n.º 7
0
    def test_with_individual_coefficients_set(self):
        """::Testing spht and ispht with single coefficients, first 10 modes.
        Since these routines haven't been optimized yet, this will take about
        a minute.
        """

        res = True

        try:
            for n in xrange(0, 11):
                for m in xrange(-n, n + 1):
                    rnd = np.random.normal(0, 10)
                    c = sp.zeros_coefs(48, 48)
                    c[n, m] = rnd
                    p = sp.ispht(c, 100, 100)
                    c2 = sp.spht(p, 48, 48)
                    s = sp.L2_coef(c - c2) / sp.L2_coef(c)

                    if s > 1e-13:
                        res = False
        except:
            res = False

        self.assertTrue(res)
Ejemplo n.º 8
0
print("")

start_time = time.time()
p = sp.ispht(c, Nrows, Nrows)
elapsed = time.time() - start_time 
f1 = f1/elapsed

print("                  Elapsed Time: {0}".format(str(elapsed)))
print("")
print("                  -------------------------------------")
print("")
print("                  Running spht(patt,{0},{1})".format(str(Nmax),
                                                      str(Nmax)))

start_time = time.time()
c2 = sp.spht(p, Nmax, Nmax)
elapsed = time.time() - start_time
f2 = f2/elapsed
print("")
print("                  Elapsed Time: {0}".format(str(elapsed)))
print("")
err = sp.L2_coef(c - c2) / sp.L2_coef(c)
print("                  Relative Error:  {0}".format(err))
print("")
print("")
print("          -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
print("          -=-                                               -=-")
print("               ispht() speed up by factor:    {0}  ".format(str(f1)))
print("          -=-                                               -=-")
print("                spht() speed up by factor:    {0}   ".format(str(f2)))
print("          -=-                                               -=-")
Ejemplo n.º 9
0
    print(ssphere2.single_val)
    print(ssphere1.is_symmetric)
    print(ssphere2.is_symmetric)

    vvv1 = sp.pysphi.fc_to_sc(ssphere2._dsphere, 2, 2)

    #pysphi.fix_even_row_data_fc(d2)

    #fdata_extended = np.zeros([8,8],dtype=np.complex128)

    #pysphi.pad_rows_fdata(d2,fdata_extended)

    #pysphi.sin_fc(fdata_extended)

    #this matches Matlab
    scoef = sp.spht(ssphere2, 2, 2)

    th = scoef._array_2d_repr()

    rs = scoef._reshape_n_vecs()

    #ps.pcolor_coefs(scoef)
    sp.plot_coefs(scoef)

    print scoef[:, 2]

    sp = sp.ispht(scoef, 6, 8)

if T5:
    rr = sp.random_coefs(10, 10) + 1j * sp.random_coefs(10, 10)
Ejemplo n.º 10
0
print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")

for nm in XX:
    c = sp.random_coefs(nm, nm)
    
    start_time = time.time()
    p = sp.ispht(c, Nrows, Nrows)
    elapsed = time.time() - start_time
    est.append(elapsed)
    print("") 
    print("***Mode Number***: " + str(nm))
    print("")
    print("     Forward Elapsed: " + str(elapsed))

    start_time = time.time()
    c = sp.spht(p, nm, nm)
    elapsed = time.time() - start_time 
    eist.append(elapsed)
    print("     Backward Elapsed: " + str(elapsed))
    print("")


print("")
print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
print("             Vector")
print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
print("")

for nm in XX:
    vc  = sp.random_coefs(nm, nm, coef_type = sp.vector)
Ejemplo n.º 11
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SpherePy.  If not, see <http://www.gnu.org/licenses/>

import spherepy as sp
import numpy as np
import plot_sphere
import profile

c = sp.zeros_coefs(48, 48)
c[4, 3] = 1.0
c[3, 0] = 1.0

p = sp.ispht(c, 150, 150)
#profile.run('p = sp.ispht(c,602,602)')

c2 = sp.spht(p, 48, 48)

#profile.run('c2 = sp.spht(p,200,200)')

print(sp.L2_coef(c - c2) / sp.L2_coef(c))

T = np.abs(p.array)

plot_sphere.plot_mag_on_sphere(T)

a = raw_input()
Ejemplo n.º 12
0
import sys
sys.path.append('../spherepy')
import spherepy as sp
import numpy as np

#TODO: Change all xrange instances to range
#and do a 'from six.moves import range' here
from six.moves import xrange

c = sp.random_coefs(2,2)
p = sp.ispht(c,3,6)
c2 = sp.spht(p,2,2)

sp.pretty_coefs(c)
sp.pretty_coefs(c2)

res = True
if (sp.L2_coef(c - c2) / sp.L2_coef(c))  > 1e-13:
    print("Failed")
else:
    print("Win")

a = 1