Example #1
0
def simple_plot(n, m):

    c = sp.zeros_coefs(48, 48)
    c[n, m] = 1.0
    p = sp.ispht(c, 100, 100)
    T = np.abs(p.array)

    plot_mag_on_sphere(T)
Example #2
0
def verify_ispht(pattfile, scoeffile):

    fsc = fl.load_coef(scoeffile)
    fpatt = fl.load_patt(pattfile)
    patt = sp.ispht(fsc, fpatt.nrows, fpatt.ncols)

    diff = fpatt - patt

    return (sp.L2_patt(diff),
            sp.LInf_patt(diff), sp.L2_patt(diff) / sp.L2_patt(fpatt),
            sp.LInf_patt(diff) / sp.LInf_patt(fpatt))
Example #3
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)
Example #4
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)
Example #5
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)
Example #6
0
    def test_ispht(self):
        """::Compare ispht within pysphi and csphi"""

        Nmax = 50
        Nrows = 102
        res = True

        for MM in xrange(1, 3):
            Mmax = Nmax - MM
            c = sp.random_coefs(Nmax, Mmax)

            ppy = sp.ispht_slow(c, Nrows / 2, Nrows)
            pc = sp.ispht(c, Nrows / 2, Nrows)

            rerr = np.sum(sp.abs(ppy - pc)) / np.sum(sp.abs(ppy))

            if (rerr > 1e-13):
                res = False

        self.assertTrue(res)
Example #7
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)
Example #8
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)
Example #9
0
 def test_ispht_size_error2(self):
     """::Test ispht error when ncols is too small.
     """
     c = sp.random_coefs(100, 100)
     with self.assertRaises(ValueError):
         _ = sp.ispht(c, 104, 198)
Example #10
0
ISPHT = 0
SPHT = 1
VISPHT = 2
VSPHT = 3
FFT = 4

ctrl = SPHT

c = sp.random_coefs(Nmax, Nmax)
vc  = sp.random_coefs(Nmax, Nmax, coef_type = sp.vector)

if ctrl == ISPHT:
    profile.run('p = sp.ispht(c,Nrows,Nrows)',sort=1)

if ctrl == SPHT:
    p = sp.ispht(c, Nrows, Nrows)
    profile.run('c2 = sp.spht(p,Nmax,Nmax)',sort=1)

if ctrl == VISPHT:
    profile.run('p = sp.vispht(vc,Nrows,Nrows)',sort=1)

if ctrl == VSPHT:
    vp = sp.vispht(vc, Nrows, Nrows)
    profile.run('vc2 = sp.vspht(vp,Nmax,Nmax)',sort=1)

if ctrl == FFT:
    """Interesting, fft2 calls cfft twice"""

    data = np.ones([Nrows,Nrows],dtype = np.complex128)

    profile.run('fdata = np.fft.fft2(data) / (Nrows * Nrows)',sort=1)
Example #11
0
    #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)

    ss = 1j - 2 / (sp.zeros_coefs(5,4) + .001) + \
            4* sp.random_coefs(5,4) / 6.0
    ss += sp.ones_coefs(5, 4, coef_type=sp.scalar)

    qq = 1 + 2 * sp.ones_coefs(3, 3) / 4 * sp.ones_coefs(3, 3) - 2

    ds1 =1j + 4*sp.ones_patt_uniform(5,8)/3 - \
        sp.ones_patt_uniform(5,8) -1 + \
        10*sp.random_patt_uniform(5,8)

    print ds1.single_val
Example #12
0
import spherepy as sp
from mayavi import mlab

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


def plot_mag_on_sphere(T):

    (nrows, ncols) = T.shape

    phi, theta = np.meshgrid(np.linspace(0, 2 * np.pi, ncols),
                             np.linspace(0, np.pi, nrows))
    X = T * np.cos(phi) * np.sin(theta)
    Y = T * np.sin(phi) * np.sin(theta)
    Z = T * np.cos(theta)

    s = mlab.mesh(X, Y, Z, colormap='prism')
    mlab.show()


c = sp.zeros_coefs(10, 10)
c[5, 1] = 1.0

p = sp.ispht(c, 100, 100)

T = np.abs(p.array)

plot_mag_on_sphere(T)
Example #13
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()
Example #14
0
def _tiny_rep(c):
    sr = "{0:.2}".format(c)
    if sr[0] == '(':
        sr = sr[1:-1]
    return sr


c = sp.random_coefs(4, 4)
c[0, 0] = 1

sa = []
cfit = c[0:2, :]
cvec = cfit._vec

for val in cvec:
    sa.append(_tiny_rep(val))

while len(sa) < 9:
    sa.append("")

for n in range(0, 9):
    sa[n] = sa[n].center(13)

print fs.format(sa[0], sa[1], sa[2], sa[3], sa[4], sa[5], sa[6], sa[7], sa[8])

c = sp.random_coefs(4, 1)
cc = c[0:2, :]
p = sp.ispht(cc, 50, 60)

#sp.plot_sphere_mag(p)
Example #15
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