def __init__(self, lcdata, tmodel=None, **kwargs): self.tmodel = tmodel or Gimenez() self.lcdata = lcdata self.group = None self.pid_ar = None self.pid_ld = None self.pid_private = None ## Precalculate the likelihood constants ## ===================================== self.lln = -0.5 * self.lcdata.npt * m.log(2 * m.pi) ## Define priors ## ============= pr = kwargs.get('priors', {}) self.priors = [] self.priors.extend([ UP(0.2, 5.0, 'e', 'Error multiplier') for i in range(self.lcdata.npb) ]) self.priors.extend([ UP(0.0, 0.01, 'c', 'Contamination') for i in range(self.lcdata.npb) ]) self.ps = PriorSet(self.priors) self.np = len(self.priors) self.pv_start_idx = None
def __init__(self, npop=70, orbit_priors={}, ar_priors={}, ld_priors={}): self.npop = npop self.lc_lpfunctions = [] self.rv_lpfunctions = [] self.lclp = self.lc_lpfunctions self.rvlp = self.rv_lpfunctions self.ar_pdef = ar_priors self.ld_pdef = ld_priors pr = orbit_priors self.orbit_priors = [pr.get( 'tc'), ## 0 - Transit center pr.get( 'p'), ## 1 - Period pr.get('rho', UP( 0.5, 2.0, 'rho', 'stellar density', 'g/cm^3')), ## 2 - Stellar density pr.get( 'b', UP( 0, 0.99, 'b', 'impact parameter')), ## 3 - Impact parameter pr.get( 'e', UP( 0, 0.001, 'e', 'Eccentricity')), ## 4 - Eccentricity pr.get( 'w', UP( 0, 0.001, 'w', 'Argument of periastron'))] ## 5 - Argument of periastron self.orbit_ps = PriorSet(self.orbit_priors) self.lc_passbands = [] self.nor = 6 self.nar = None self.nld = None self.nlc = None self.nrv = None self.ar_start_idx = self.nor self.ld_start_idx = None self.lc_start_idx = None self.rv_start_idx = None
def __init__(self, lcdata, tmodel=None, **kwargs): self.tmodel = tmodel or Gimenez() self.lcdata = lcdata self.group = None self.pid_ar = None self.pid_ld = None self.pid_private = None ## Precalculate the likelihood constants ## ===================================== self.lln = -0.5*self.lcdata.npt * m.log(2*m.pi) ## Define priors ## ============= pr = kwargs.get('priors', {}) self.priors = [] self.priors.extend([UP(0.2, 5.0, 'e', 'Error multiplier') for i in range(self.lcdata.npb)]) self.priors.extend([UP(0.0, 0.01, 'c', 'Contamination') for i in range(self.lcdata.npb)]) self.ps = PriorSet(self.priors) self.np = len(self.priors) self.pv_start_idx = None
class LCLogPosteriorFunction(object): def __init__(self, lcdata, tmodel=None, **kwargs): self.tmodel = tmodel or Gimenez() self.lcdata = lcdata self.group = None self.pid_ar = None self.pid_ld = None self.pid_private = None ## Precalculate the likelihood constants ## ===================================== self.lln = -0.5 * self.lcdata.npt * m.log(2 * m.pi) ## Define priors ## ============= pr = kwargs.get('priors', {}) self.priors = [] self.priors.extend([ UP(0.2, 5.0, 'e', 'Error multiplier') for i in range(self.lcdata.npb) ]) self.priors.extend([ UP(0.0, 0.01, 'c', 'Contamination') for i in range(self.lcdata.npb) ]) self.ps = PriorSet(self.priors) self.np = len(self.priors) self.pv_start_idx = None def compute_continuum(self, pv): raise NotImplementedError def compute_transit(self, pv): print(self.group._pv_o_physical) z = of.z_eccentric(self.lcdata.time, *self.group._pv_o_physical, nthreads=0) f = self.tmodel(z, m.sqrt(pv[self.pid_ar[0]]), pv[self.pid_ld], 0.0) return f def compute_lc_model(self, pv): return self.compute_transit(pv) def log_posterior(self, pv): log_prior = self.ps.c_log_prior(pv[self.pid_private]) flux_m = self.compute_lc_model(pv) err = self.lcdata.errors * pv[self.pid_err] chisqr = (((self.lcdata.fluxes - flux_m) / err)**2).sum() log_likelihood = self.lln - 0.5 * (np.log(err)).sum() - 0.5 * chisqr return log_prior + log_likelihood
class LCLogPosteriorFunction(object): def __init__(self, lcdata, tmodel=None, **kwargs): self.tmodel = tmodel or Gimenez() self.lcdata = lcdata self.group = None self.pid_ar = None self.pid_ld = None self.pid_private = None ## Precalculate the likelihood constants ## ===================================== self.lln = -0.5*self.lcdata.npt * m.log(2*m.pi) ## Define priors ## ============= pr = kwargs.get('priors', {}) self.priors = [] self.priors.extend([UP(0.2, 5.0, 'e', 'Error multiplier') for i in range(self.lcdata.npb)]) self.priors.extend([UP(0.0, 0.01, 'c', 'Contamination') for i in range(self.lcdata.npb)]) self.ps = PriorSet(self.priors) self.np = len(self.priors) self.pv_start_idx = None def compute_continuum(self, pv): raise NotImplementedError def compute_transit(self, pv): print (self.group._pv_o_physical) z = of.z_eccentric(self.lcdata.time, *self.group._pv_o_physical, nthreads=0) f = self.tmodel(z, m.sqrt(pv[self.pid_ar[0]]), pv[self.pid_ld], 0.0) return f def compute_lc_model(self, pv): return self.compute_transit(pv) def log_posterior(self, pv): log_prior = self.ps.c_log_prior(pv[self.pid_private]) flux_m = self.compute_lc_model(pv) err = self.lcdata.errors*pv[self.pid_err] chisqr = (((self.lcdata.fluxes - flux_m)/err)**2).sum() log_likelihood = self.lln - 0.5*(np.log(err)).sum() -0.5*chisqr return log_prior + log_likelihood
class LPFGroup(object): def __init__(self, npop=70, orbit_priors={}, ar_priors={}, ld_priors={}): self.npop = npop self.lc_lpfunctions = [] self.rv_lpfunctions = [] self.lclp = self.lc_lpfunctions self.rvlp = self.rv_lpfunctions self.ar_pdef = ar_priors self.ld_pdef = ld_priors pr = orbit_priors self.orbit_priors = [pr.get( 'tc'), ## 0 - Transit center pr.get( 'p'), ## 1 - Period pr.get('rho', UP( 0.5, 2.0, 'rho', 'stellar density', 'g/cm^3')), ## 2 - Stellar density pr.get( 'b', UP( 0, 0.99, 'b', 'impact parameter')), ## 3 - Impact parameter pr.get( 'e', UP( 0, 0.001, 'e', 'Eccentricity')), ## 4 - Eccentricity pr.get( 'w', UP( 0, 0.001, 'w', 'Argument of periastron'))] ## 5 - Argument of periastron self.orbit_ps = PriorSet(self.orbit_priors) self.lc_passbands = [] self.nor = 6 self.nar = None self.nld = None self.nlc = None self.nrv = None self.ar_start_idx = self.nor self.ld_start_idx = None self.lc_start_idx = None self.rv_start_idx = None def add_lpfunction(self, lpfunction): lpfunction.group = self if isinstance(lpfunction, LCLogPosteriorFunction): self.lc_lpfunctions.append(lpfunction) self.lc_passbands.extend(lpfunction.lcdata.passbands) elif isinstance(lpfunction, RVLogPosteriorFunction): self.rv_lpfunctions.append(lpfunction) else: raise NotImplementedError def finalize(self): ## Optimise the area ratio access ## ============================== ar_groups = list(np.unique(np.concatenate([[pb.kgroup for pb in lpf.lcdata.passbands] for lpf in self.lclp]))) for lpf in self.lclp: lpf.pid_ar = [self.ar_start_idx + ar_groups.index(pb.kgroup) for pb in lpf.lcdata.passbands] self.nar = len(ar_groups) self.ld_start_idx = self.ar_start_idx + self.nar ## Optimise the limb darkening coefficient access ## ============================================== lds = self.ld_start_idx self.lclp[0].pid_ld = np.s_[lds:lds+2*self.lclp[0].lcdata.npb] final_pb_set = self.lc_passbands[:self.lclp[0].lcdata.npb] for i,lpf in enumerate(self.lc_lpfunctions[1:]): lp_indices = [] for j,pb in enumerate(lpf.lcdata.passbands): try: lp_indices.append(final_pb_set.index(pb)) except ValueError: final_pb_set.append(pb) lp_indices.append(len(final_pb_set)-1) if np.all(np.diff(lp_indices) == 1): lpf.pid_lc = np.s_[lds+lp_indices[0] : lds+2*(lp_indices[-1]+1)] else: lpf.pid_lc = np.concatenate([(lds+2*li, lds+2*li+1) for li in lp_indices]) self.lc_passbands = final_pb_set self.nld = 2*len(self.lc_passbands) ## Setup the private space for log-posterior functions ## =================================================== self.lc_start_idx = self.ld_start_idx+self.nld+np.cumsum([0]+[lpf.np for lpf in self.lclp[:-1]]) for i,lpf in enumerate(self.lclp): lpf.pv_start_idx = self.lc_start_idx[i] self.nlc = sum([lpf.np for lpf in self.lclp]) ## Generate rest of the prior sets ## =============================== self.ar_priors = [self.ar_pdef.get('ar {:d}'.format(ai), UP(0.05**2, 0.15**2, 'ar', 'area ratio', '1/As')) for ai in ar_groups] self.ar_pset = PriorSet(self.ar_priors) self.ld_priors = [] for pb in self.lc_passbands: self.ld_priors.append(self.ld_pdef.get('u {:s}'.format(pb.name), UP( 0.0,1.3, 'u {:s}'.format(pb.name), 'Linear limb darkening coefficient'))) self.ld_priors.append(self.ld_pdef.get('v {:s}'.format(pb.name), UP(-0.3,0.7, 'v {:s}'.format(pb.name), 'Quadratic limb darkening coefficient'))) self.ld_pset = PriorSet(self.ld_priors) pv0_basic = np.hstack([ps.generate_pv_population(self.npop) for ps in [self.orbit_ps, self.ar_pset, self.ld_pset]]) pv0_lc_private = np.hstack([lpf.ps.generate_pv_population(self.npop) for lpf in self.lclp]) self.pv0 = np.hstack([pv0_basic, pv0_lc_private]) def map_orbit(self, pv): a = AC*((pv[1]*DTOS)**2 * 1e3*pv[2])**(1/3) i = math.acos(pv[4]/a) self._pv_o_physical = pv[:6].copy() self._pv_o_physical[2] = a self._pv_o_physical[3] = i return self._pv_o_physical def __call__(self, pv): self.map_orbit(pv) return self.orbit_ps.c_log_prior(pv[0:7])