def test_get_best_from_chain(): # Triplicate sphere pars (are copies) # Represents a chain with 2 walkers and 3 steps intern_sphere_pars = SphereComponent.internalise(SPHERE_PARS) dummy_chain = np.array( [[intern_sphere_pars, intern_sphere_pars, intern_sphere_pars], [intern_sphere_pars, intern_sphere_pars, intern_sphere_pars]]) dummy_lnprob = np.zeros(dummy_chain.shape[:2]) # Incorporate identifying marker at desired index true_best_ix = (1, 1) dummy_chain[true_best_ix][0] = 10. dummy_lnprob[true_best_ix] = 1. best_comp = SphereComponent.get_best_from_chain(dummy_chain, dummy_lnprob) assert np.allclose(dummy_chain[true_best_ix], best_comp.get_emcee_pars())
def test_externalise_and_internalise_pars(): """Check that pars are successfully converted from internal form (used by emcee) to external form (interacted with by user) successfully""" # Check SphereComponent internal_sphere_pars = np.copy(SPHERE_PARS) internal_sphere_pars[6:8] = np.log(internal_sphere_pars[6:8]) sphere_comp = SphereComponent(emcee_pars=internal_sphere_pars) external_sphere_pars = sphere_comp.get_pars() assert np.allclose(SPHERE_PARS, external_sphere_pars) re_internal_sphere_pars = sphere_comp.internalise(external_sphere_pars) assert np.allclose(internal_sphere_pars, re_internal_sphere_pars) # Check EllipComponent internal_ellip_pars = np.copy(ELLIP_PARS) internal_ellip_pars[6:10] = np.log(internal_ellip_pars[6:10]) ellip_comp = EllipComponent(emcee_pars=internal_ellip_pars) external_ellip_pars = ellip_comp.get_pars() assert np.allclose(ELLIP_PARS, external_ellip_pars) re_internal_ellip_pars = ellip_comp.internalise(external_ellip_pars) assert np.allclose(internal_ellip_pars, re_internal_ellip_pars)
def test_externalise_and_internalise_pars(): """Check that pars are successfully converted from internal form (used by emcee) to external form (interacted with by user) successfully""" # Check SphereComponent internal_sphere_pars = np.copy(SPHERE_PARS) internal_sphere_pars[6:8] = np.log(internal_sphere_pars[6:8]) sphere_comp = SphereComponent(emcee_pars=internal_sphere_pars) external_sphere_pars = sphere_comp.get_pars() assert np.allclose(SPHERE_PARS, external_sphere_pars) re_internal_sphere_pars = sphere_comp.internalise(external_sphere_pars) assert np.allclose(internal_sphere_pars, re_internal_sphere_pars) # Check EllipComponent internal_ellip_pars = np.copy(ELLIP_PARS) internal_ellip_pars[6:10] = np.log(internal_ellip_pars[6:10]) ellip_comp = EllipComponent(emcee_pars=internal_ellip_pars) external_ellip_pars = ellip_comp.get_pars() assert np.allclose(ELLIP_PARS, external_ellip_pars) re_internal_ellip_pars = ellip_comp.internalise(external_ellip_pars) assert np.allclose(internal_ellip_pars, re_internal_ellip_pars)