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)
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))
def test_vspht_vispht_no_added_args(self): """::Test spht and ispht when nmax, mmax, nrows, ncols are not passed. """ c = sp.random_coefs(100, 100, coef_type=sp.vector) p = sp.vispht(c) c2 = sp.vspht(p) res = True if (sp.L2_coef(c - c2) / sp.L2_coef(c)) > 1e-13: res = False self.assertTrue(res)
def test_vspht_vispht_one_added_args(self): """::Test vspht when only nmax is passed. """ c = sp.random_coefs(100, 100, coef_type=sp.vector) p = sp.vispht(c) c2 = sp.vspht(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)
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)
def test_div_same_sizes(self): """::can add two VectorCoefs that are same sized """ z1 = sp.random_coefs(11, 10, coef_type=sp.vector) z2 = sp.random_coefs(11, 10, coef_type=sp.vector) a = z1 / (z2 + 0.0001) b = z1 / (z2 + 0.0001) c = a - b res = True if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False self.assertTrue(res)
def test_mult_same_sizes(self): """::can multiply two VectorCoefs that are same sized """ z1 = sp.random_coefs(11, 10, coef_type=sp.vector) z2 = sp.random_coefs(11, 10, coef_type=sp.vector) a = z1 * z2 b = z1 * z2 c = a - b res = True if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False self.assertTrue(res)
def test_sub_same_sizes(self): """::can sub two ScalarCoefs that are same sized """ z1 = sp.random_coefs(11, 10) z2 = sp.random_coefs(11, 10) a = z1 - z2 b = z1 - z2 c = a - b res = True if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False self.assertTrue(res)
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))
def test_vec_with_individual_coefficients_set(self): """::Testing vspht and vispht with single coefficients, first 5 modes. """ res = True for n in xrange(1, 6): for m in xrange(-n, n + 1): rnd1 = np.random.normal(0, 10) rnd2 = np.random.normal(0, 10) vc = sp.zeros_coefs(15, 15, coef_type=sp.vector) vc[n, m] = (rnd1, rnd2) p = sp.vispht(vc, 50, 50) vc2 = sp.vspht(p, 15, 15) s = sp.L2_coef(vc - vc2) / sp.L2_coef(vc) if s > 1e-10: res = False self.assertTrue(res)
def test_mult_constant_left_right(self): """::can mult a scalar to ScalarCoefs from both sides""" z1 = sp.random_coefs(11, 10) a = z1 * 1j * 1.1 b = z1 * 1j * 1.1 c = a - b res = True if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False a = 1j * 1.1 * z1 b = 1j * 1.1 * z1 c = a - b if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False self.assertTrue(res)
def test_div_constant_left_right(self): """::can mult a scalar to VectorCoefs from both sides""" z1 = sp.random_coefs(11, 10, coef_type=sp.vector) a = z1 / 1j * 1.1 b = z1 / 1j * 1.1 c = a - b res = True if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False a = 1j * 1.1 / z1 b = 1j * 1.1 / z1 c = a - b if sp.L2_coef(c) / sp.L2_coef(b) > 1e-13: res = False self.assertTrue(res)
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)
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)
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
# 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()
print(" Elapsed Time: {0}".format(str(elapsed))) print("") print(" -------------------------------------") print("") print(" Running spht_slow(patt,{0},{1})".format(str(Nmax), str(Nmax))) start_time = time.time() c2 = sp.spht_slow(p, Nmax, Nmax) elapsed = time.time() - start_time 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)) #transforms using the c extensions print("") print(" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-") print(" -=- -=-") print(" -=- C version of the code -=-") print(" -=- -=-") print(" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-") print("") print(" Running ispht(scoef,{0},{1})".format(str(Nrows), str(Nrows))) print("")
import sys sys.path.append('../spherepy') import spherepy as sp #TODO: Change all xrange instances to range #and do a 'from six.moves import range' here from six.moves import xrange patt1 = sp.random_patt_uniform(5, 10, patt_type=sp.scalar) sp.file.save_patt(patt1, 't1.txt') patt2 = sp.file.load_patt('t1.txt') a = sp.L2_patt(patt1 - patt2) scoef1 = sp.random_coefs(10, 7) sp.file.save_coef(scoef1, 't2.txt') scoef2 = sp.file.load_coef('t2.txt') a = sp.L2_coef(scoef1 - scoef2) a = 1