def mr_convert(self, meas): """Runs conversion from mass to radius""" if self.config_parameters["mass_radius"] == "mrexo": return pfm(meas, predict="radius", dataset="kepler")[0] elif self.config_parameters["mass_radius"] == "otegi": return self.otegi_mr(meas, "radius")
def syssim_pers(self, per, rad, P, M_star): """Generates probability of periods using clustered periods from He, Ford, and Ragozzine (2019)""" sigmap = 0.2 Np = len(per) PR = [per[i] / per[i - 1] for i in range(1, len(per))] bools = [] for i in range(len(PR)): if PR[i] > spst.lognorm.ppf(0.95, Np * sigmap): bools.append(1) else: bools.append(0) def calc_bools_dict_value(bl): kt_planets = [p for p in range(1, len(bl) + 2)] kt_cluster = {} kt_cluster_count = 0 for i in range(0, len(bl)): if bl[i] == 0: if kt_planets[i] not in [ v for sl in kt_cluster.values() for v in sl ]: kt_cluster_count += 1 kt_cluster[kt_cluster_count] = [ kt_planets[i], kt_planets[i + 1] ] else: found_in_key = [ k for (k, v) in kt_cluster.items() if kt_planets[i] in v ][0] kt_cluster[found_in_key].append(kt_planets[i + 1]) else: if kt_planets[i] not in [ v for sl in kt_cluster.values() for v in sl ]: kt_cluster_count += 1 kt_cluster[kt_cluster_count] = [kt_planets[i]] kt_cluster_count += 1 kt_cluster[kt_cluster_count] = [kt_planets[i + 1]] else: kt_cluster_count += 1 kt_cluster[kt_cluster_count] = [kt_planets[i + 1]] return len(kt_cluster), list(kt_cluster.values()) Nc, Np = calc_bools_dict_value(bools) if Nc == 1: Pcb = 0 Pcbs = [] fPcb = [] for i in range(len(P)): test = 0 for k in range(len(per)): test += spst.lognorm.pdf(per[k] / P[i], len(per) * sigmap) Pcbs.append(P[i]) fPcb.append(test) Pcb = round(Pcbs[np.where(fPcb == max(fPcb))[0][0]], 1) else: Pcb = [] for i in range(Nc): Pcbs = [] fPcb = [] for k in range(len(P)): test = 0 for j in Np[i]: test += spst.lognorm.pdf(per[j - 1] / P[k], len(Np[i]) * sigmap) Pcbs.append(P[k]) fPcb.append(test) Pcb.append(Pcbs[np.where(fPcb == max(fPcb))[0][0]]) Pcb = np.array([round(Pcb[i], 1) for i in range(len(Pcb))]) Pip = np.linspace(math.sqrt(min(P) / max(P)), math.sqrt(max(P) / min(P)), 1001) fPip = [] for i in range(Nc): fPip.append( spst.lognorm.pdf(Pip, (len(per) if Nc == 1 else len(Np[i])) * sigmap)) fP = np.zeros(len(P)) fD = np.zeros(len(P)) for i in range(len(fP)): f = [] for j in range(Nc): f.append( np.interp(P[i], (Pcb if Nc == 1 else Pcb[j]) * Pip, fPip[j])) fP[i] = max(f) m = np.zeros(len(per)) for k in range(len(per)): if self.config_parameters["mass_radius"] == "mrexo": m[k] = pfm(measurement=rad[k], predict='mass', dataset='kepler')[0] elif self.config_parameters["mass_radius"] == "otegi": m[k] = self.otegi_mr(rad[k], "mass") m2 = np.mean(m) GMfp213 = (self.G * M_star * self.M_sun / (4 * math.pi**2))**(1 / 3) dc = 8 rats = [math.sqrt(per[k + 1] / per[k]) for k in range(len(per) - 1)] k = 0 for i in range(len(P)): if k < len(per) - 1 and P[i] > per[k] * rats[k] and P[i] < per[k + 1]: k += 1 a1 = GMfp213 * (P[i] * self.seconds_per_day if P[i] < per[k] else per[k] * self.seconds_per_day)**(2 / 3) a2 = GMfp213 * (per[k] * self.seconds_per_day if P[i] < per[k] else P[i] * self.seconds_per_day)**(2 / 3) fD[i] = 2 * (a2 - a1) / (a2 + a1) * ( (m[k] + m2) * self.M_earth / (3 * M_star * self.M_sun))**(-1 / 3) if fD[i] < dc: fP[i] = 0 Du = np.arange(0, max(fD) + 1) fDu = np.zeros(len(Du)) trap = np.trapz(fP, P) cdfp = np.zeros(len(fP)) for i in range(len(fD)): j = int(fD[i]) fDu[j] += fP[i] / trap for i in range(len(fP)): cdfP[i] = np.trapz(fP[:i + 1], P[:i + 1]) / trap return fP / trap, fDu, cdfP
def epos_pers(self, p0, per, rad, P, M_star): """Generates probability of periods using dimensionless spacing in period ratios from EPOS (Mulders et al. 2018)""" fP = np.zeros(len(P)) cdfP = np.zeros(len(P)) fD = np.zeros(len(P)) ind = 0 for i in range(len(P)): if P[i] < p0: fP[i] = ((P[i] / 12)**1.6 if P[i] < 12 else (P[i] / 12)**-0.9) else: ind = i break logD = -0.9 sigma = 0.41 PRgrid = np.logspace(0, 1) with np.errstate(divide='ignore'): Dgrid = np.log(2. * (PRgrid**(2. / 3.) - 1.) / (PRgrid**(2. / 3.) + 1.)) Dgrid[0] = -4 pdfPR = spst.norm(logD, sigma).pdf(Dgrid) cdfPR = spst.norm(logD, sigma).cdf(Dgrid) j = 0 for i in range(ind, len(fP)): if j < len(per) - 1 and P[i] > per[j + 1]: j += 1 fP[i] = np.interp(P[i] / per[j], PRgrid, pdfPR) if j != len(per) - 1: fP[i] *= np.interp(per[j + 1] / P[i], PRgrid, pdfPR) m = np.zeros(len(per)) for k in range(len(per)): if self.config_parameters["mass_radius"] == "mrexo": m[k] = pfm(measurement=rad[k], predict='mass', dataset='kepler')[0] elif self.config_parameters["mass_radius"] == "otegi": m[k] = self.otegi_mr(rad[k], "mass") m2 = np.mean(m) GMfp213 = (self.G * M_star * self.M_sun / (4 * math.pi**2))**(1 / 3) dc = 8 rats = [math.sqrt(per[k + 1] / per[k]) for k in range(len(per) - 1)] k = 0 for i in range(len(P)): if k < len(per) - 1 and P[i] > per[k] * rats[k] and P[i] < per[k + 1]: k += 1 a1 = GMfp213 * (P[i] * self.seconds_per_day if P[i] < per[k] else per[k] * self.seconds_per_day)**(2 / 3) a2 = GMfp213 * (per[k] * self.seconds_per_day if P[i] < per[k] else P[i] * self.seconds_per_day)**(2 / 3) fD[i] = 2 * (a2 - a1) / (a2 + a1) * ( (m[k] + m2) * self.M_earth / (3 * M_star * self.M_sun))**(-1 / 3) if fD[i] < dc: fP[i] = 0 Du = np.arange(0, max(fD) + 1) fDu = np.zeros(len(Du)) trap = np.trapz(fP, P) for i in range(len(fD)): j = int(fD[i]) fDu[j] += fP[i] / trap for i in range(len(cdfP)): cdfP[i] = np.trapz(fP[:i + 1], P[:i + 1]) / trap return fP / trap, fDu, cdfP
def epos_pers(self, p0, per, rad, P, M_star): """Generates probability of periods using dimensionless spacing in period ratios from EPOS (Mulders et al. 2018)""" fP = np.zeros(len(P)) fD = np.zeros(len(P)) ind = 0 for i in range(len(P)): if P[i] < p0: fP[i] = ((P[i] / 12)**1.6 if P[i] < 12 else (P[i] / 12)**-0.9) else: ind = i break logD = -0.9 sigma = 0.41 PRgrid = np.logspace(0, 1) with np.errstate(divide='ignore'): Dgrid = np.log(2. * (PRgrid**(2. / 3.) - 1.) / (PRgrid**(2. / 3.) + 1.)) Dgrid[0] = -4 pdfP = spst.norm(logD, sigma).pdf(Dgrid) cdfP = spst.norm(logD, sigma).cdf(Dgrid) for i in range(ind, len(fP)): for j in range(len(per)): if P[i] > per[j]: fP[i] = np.interp(P[i] / per[j], PRgrid, pdfP) if j < len(per) - 1 and P[i] < per[j + 1]: fP[i] *= np.interp(per[j + 1] / P[i], PRgrid, pdfP) elif j < len(per) - 1 and P[i] >= per[j + 1]: fP[i] = 0 m = np.zeros(len(per)) for k in range(len(per)): if self.config_parameters["mass_radius"] == "mrexo": m[k] = pfm(measurement=rad[k], predict='mass', dataset='kepler')[0] elif self.config_parameters["mass_radius"] == "otegi": m[k] = self.otegi_mr(rad[k], "mass") for i in range(len(P)): for k in range(len(per)): m1 = m[k] m2 = np.mean(m) dc = 8 a1 = self.K3(P[i], M_star) if P[i] < per[k] else self.K3( per[k], M_star) a2 = self.K3(per[k], M_star) if P[i] < per[k] else self.K3( P[i], M_star) fD[i] = 2 * (a2 - a1) / (a2 + a1) * ( (m1 + m2) * const.M_earth.cgs.value / (3 * M_star * const.M_sun.cgs.value))**(-1 / 3) if fD[i] < dc: fP[i] = 0 Du = np.arange(0, max(fD) + 1) fDu = np.zeros(len(Du)) for i in range(len(fD)): j = int(fD[i]) fDu[j] += fP[i] / np.trapz(fP, P) return fP / np.trapz(fP, P), fDu