def get_m1m2_grid(m1_range, m2_range, filtering_criteria): """Return a meshgrid of m1, m2, z points based on filtering criteria. The returned meshgrid can be used to create a contour plot based on the filtering criteria :param m1_range: :param m2_range: :param filtering_criteria: :return: """ xs = np.linspace(m1_range[0], m1_range[1], 1000) ys = np.linspace(m2_range[0], m2_range[1], 1000)[::-1] m1, m2 = np.meshgrid(xs, ys) z = np.zeros(shape=(len(xs), len(ys))) for nrx, loop_m1 in enumerate(tqdm(xs)): for nry, loop_m2 in enumerate(ys): if loop_m2 > loop_m1: pass # by definition, we choose only m2 smaller than m1 if loop_m2 < loop_m1: mc = conversion.component_masses_to_chirp_mass(loop_m1, loop_m2) M = conversion.component_masses_to_total_mass(loop_m1, loop_m2) q = conversion.component_masses_to_mass_ratio(loop_m1, loop_m2) if filtering_criteria(loop_m1, loop_m2, mc, q, M) == 1: z[nry][nrx] = 1 return m1, m2, z
def setUp(self): self.search_keys = [] self.parameters = dict() self.component_mass_pars = dict(mass_1=1.4, mass_2=1.4) self.mass_parameters = self.component_mass_pars.copy() self.mass_parameters[ "mass_ratio"] = conversion.component_masses_to_mass_ratio( **self.component_mass_pars) self.mass_parameters[ "symmetric_mass_ratio"] = conversion.component_masses_to_symmetric_mass_ratio( **self.component_mass_pars) self.mass_parameters[ "chirp_mass"] = conversion.component_masses_to_chirp_mass( **self.component_mass_pars) self.mass_parameters[ "total_mass"] = conversion.component_masses_to_total_mass( **self.component_mass_pars) self.component_tidal_parameters = dict(lambda_1=300, lambda_2=300) self.all_component_pars = self.component_tidal_parameters.copy() self.all_component_pars.update(self.component_mass_pars) self.tidal_parameters = self.component_tidal_parameters.copy() self.tidal_parameters[ "lambda_tilde"] = conversion.lambda_1_lambda_2_to_lambda_tilde( **self.all_component_pars) self.tidal_parameters[ "delta_lambda_tilde"] = conversion.lambda_1_lambda_2_to_delta_lambda_tilde( **self.all_component_pars)
def get_m1m2_grid(m1_range, m2_range, prior, resolution): """Generate a grid of m1 and m2 and mark point if in prior space.""" xs = np.linspace(m1_range[0], m1_range[1], resolution) ys = np.linspace(m2_range[0], m2_range[1], resolution)[::-1] m1, m2 = np.meshgrid(xs, ys) in_prior = np.zeros(shape=(len(xs), len(ys))) for nrx, loop_m1 in enumerate(tqdm(xs)): for nry, loop_m2 in enumerate(ys): if loop_m2 > loop_m1: pass # by definition, we choose only m2 smaller than m1 if loop_m2 < loop_m1: mc = component_masses_to_chirp_mass(loop_m1, loop_m2) q = component_masses_to_mass_ratio(loop_m1, loop_m2) in_prior[nry][nrx] = prior.prob( dict(chirp_mass=mc, mass_ratio=q, mass_2=loop_m2)) return m1, m2, in_prior
def get_event_status(catalogue_df): data = [] for rowid, event in catalogue_df.iterrows(): m1 = event.mass_1_source m2 = event.mass_2_source mc = conversion.component_masses_to_chirp_mass(m1, m2) M = conversion.component_masses_to_total_mass(m1, m2) q = conversion.component_masses_to_mass_ratio(m1, m2) data.append( { "event": event.commonName, "catalog": event["catalog.shortName"], "in_prior": contour_condition(m1, m2, mc, q, M) == 1, "m1_source": m1, "m2_source": m2, "M": M, } ) return pd.DataFrame(data)
def test_component_masses_to_mass_ratio(self): mass_ratio = conversion.component_masses_to_mass_ratio(self.mass_1, self.mass_2) self.assertAlmostEqual(self.mass_ratio, mass_ratio)