def test_sol_values(self): fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) bms.add_eqs(catalog_flux=fluxval, bvals=np.zeros((31, 31))) sol = bms.solve() nt.assert_true(sol[1]['b{}'.format(bms.unravel_pix(31, (15, 15)))], 1.0)
def test_build_solver(self): fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) bms.add_eqs(catalog_flux=fluxval, bvals=np.ones((31, 31))) bms._build_solver(norm_weight=100) nt.assert_true(isinstance(bms.ls, linsolve.LinProductSolver))
def test_eqs(self): fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) bms.add_eqs(catalog_flux=fluxval, bvals=np.ones((31, 31))) eq_keys = list(bms.eqs.keys()) nt.assert_almost_equal(bms.eqs[eq_keys[0]], 2.0)
def test_consts(self): bms = bs.BeamCat(cat=catd, bm_pix=31) ps, ws = bms.get_weights(np.array([[np.pi/2], [np.pi/2]]), 0, 1) bms._mk_eq(ps, ws, 1, 1, 0.1, 0, 0, bvals=np.ones((31, 31)), equal_wgts=False) cns_keys = bms.consts.keys() nt.assert_almost_equal(len(cns_keys), 4) px0 = bms.unravel_pix(31, (15, 15)) nt.assert_almost_equal(bms.consts['w%s_s0_t0'%px0], 1.0)
def test_add_constrain(self): fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) bms.add_eqs(catalog_flux=fluxval, bvals=np.ones((31, 31))) bms.add_constrain(0, 20) keys = list(bms.eqs.keys()) nt.assert_equal(len(keys), 2) nt.assert_equal(bms.eqs[keys[1]], 20)
def test_solve_src(self): fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) bms.add_eqs(catalog_flux=fluxval, bvals=np.zeros((31, 31))) sol = bms.solve() outflux, obsbeam = bms.eval_sol(sol) ansbeam = np.zeros((31, 31)) ansbeam[15, 15] = 1 np.testing.assert_almost_equal(obsbeam, ansbeam) np.testing.assert_almost_equal(outflux, np.array([[0], [2.0]]))
def test_mk_eq(self): bms = bs.BeamCat(cat=catd, bm_pix=31) ps, ws = bms.get_weights(np.array([[np.pi/2], [np.pi/2]]), 0, 1) bms._mk_eq(ps, ws, 1, 1, 0.1, 0, 0, equal_wgts=False, bvals=np.ones((31, 31))) eq_keys = bms.eqs.keys() cns_keys = bms.consts.keys() nt.assert_almost_equal(len(eq_keys), 1) px0 = bms.unravel_pix(31, (15, 15)) px1 = bms.unravel_pix(31, (15, 16)) px2 = bms.unravel_pix(31, (16, 15)) px3 = bms.unravel_pix(31, (16, 16)) eq0 = 'w%s_s0_t0*b%s*I0 + w%s_s0_t0*b%s*I0 + w%s_s0_t0*b%s*I0 + w%s_s0_t0*b%s*I0'%(px0, px0, px1, px1, px2, px2, px3, px3) nt.assert_equal(list(eq_keys)[0], eq0)
def test_eval_sol(self): sol = ({'chisq': 0.0, 'conv_crit': 0.0, 'iter': 1}, {'b1': 1, 'I0':2}) fluxval = np.array([2.0]) catd = gen_catdata_zensrc(fluxval, sigma=2) bms = bs.BeamCat(cat=catd, bm_pix=31) fluxval, obsbeam = bms.eval_sol(sol) ansbeam = np.zeros((31, 31)) ansbeam.flat[1] = 1 np.testing.assert_equal(obsbeam, ansbeam) np.testing.assert_almost_equal(fluxval, np.array([[0], [2.0]])) sol0 = {'b%d'%i:1 for i in range(31**2)} sol0['I0'] = 2 sol = ({'chisq': 0.0, 'conv_crit': 0.0, 'iter': 1}, sol0) fluxval, obsbeam = bms.eval_sol(sol) ansbeam = np.ones((31, 31)) np.testing.assert_almost_equal(obsbeam, ansbeam) np.testing.assert_almost_equal(fluxval, np.array([[0], [2.0]]))