def get_mass_radius(chain, discard, source, version, cap=None): """Returns GR mass and radius given a chain containing gravity and redshift Returns ndarray of equivalent form to input chain (after slicing discard/cap) """ ref_mass = 1.4 ref_radius = 10 chain = mcmc_tools.slice_chain(chain, discard=discard, cap=cap) n_walkers, n_steps, n_dimensions = chain.shape chain_flat = chain.reshape((-1, n_dimensions)) pkeys = mcmc_versions.get_parameter(source, version, 'param_keys') if 'm_gr' in pkeys: mass_nw = ref_mass * chain_flat[:, pkeys.index('g')] mass_gr = chain_flat[:, pkeys.index('m_gr')] m_ratio = mass_gr / mass_nw xi = gravity.gr_corrections(r=ref_radius, m=mass_nw, phi=m_ratio)[0] radius_gr = ref_radius * xi else: redshift = chain_flat[:, pkeys.index('redshift')] g_reference = gravity.get_acceleration_newtonian(r=ref_radius, m=ref_mass) g = chain_flat[:, pkeys.index('g')] * g_reference mass_gr, radius_gr = gravity.get_mass_radius(g=g, redshift=redshift) mass_gr = mass_gr.value radius_gr = radius_gr.value # reshape back into chain new_shape = (n_walkers, n_steps) mass_reshape = mass_gr.reshape(new_shape) radius_reshape = radius_gr.reshape(new_shape) return np.dstack((mass_reshape, radius_reshape))
def get_gr_factors(self, params): """Returns GR factors (m_ratio, redshift) given (m_nw, m_gr)""" mass_nw = params['m_nw'] mass_gr = params['m_gr'] m_ratio = mass_gr / mass_nw redshift = gravity.gr_corrections(r=self.reference_radius, m=mass_nw, phi=m_ratio)[1] return m_ratio, redshift
def get_radius(mass_nw, mass_gr): """Returns GR radius for the given Newtonian mass and GR mass """ ref_radius = 10 m_ratio = mass_gr / mass_nw xi = gravity.gr_corrections(r=ref_radius, m=mass_nw, phi=m_ratio)[0] radius_gr = ref_radius * xi return radius_gr
def get_xi_redshift_chain(chain, discard, source, version, cap=None, r_nw=10, mass_nw=None, mass_gr=None): """Returns chain of the xi and redshift Note: xi is the radius ratio (R_gr / R_nw), not anisotropy """ mass_nw, mass_gr = get_masses(chain, discard=discard, source=source, cap=cap, version=version, mass_nw=mass_nw, mass_gr=mass_gr) mass_ratio = mass_gr / mass_nw xi_chain, redshift_chain = gravity.gr_corrections(r=r_nw, m=mass_nw, phi=mass_ratio) return xi_chain, redshift_chain-1
def gr_factors(): mass_nw = self.reference_mass * params[self.param_idxs['g']] if self.has_m_gr: mass_gr = params[self.param_idxs['m_gr']] m_ratio = mass_gr / mass_nw red = gravity.gr_corrections(r=self.reference_radius, m=mass_nw, phi=m_ratio)[1] else: red = params[self.param_idxs['redshift']] g_nw = gravity.get_acceleration_newtonian(r=self.reference_radius, m=mass_nw) mass_gr = gravity.mass(g=g_nw, redshift=red).value m_ratio = mass_gr / mass_nw return m_ratio, red
def add_redshift(kgrid, m_ratio=1.0): """Adds redshift (1+z) column to given Kgrid parameters ---------- kgrid : grid_analyser.Kgrid grid object containing model data m_ratio : flt (optional) mass ratio, M_gr / M_newton """ default_radius = 10 if 'radius' not in kgrid.params.columns: print('Using default radius=10km') kgrid.params['radius'] = default_radius radii = np.array(kgrid.params.radius) masses = np.array(kgrid.params.mass) r_ratios, redshifts = gravity.gr_corrections(r=radii, m=masses, phi=m_ratio) kgrid.params['radius_gr'] = radii * r_ratios kgrid.params['mass_gr'] = masses * m_ratio kgrid.params['redshift'] = redshifts