def plotcurve(self): plotx = np.linspace(self.x[0], self.x[-1], 500) plotmodel = batman.TransitModel(self.params, plotx) model = batman.TransitModel(self.params, self.x) alpha = '' dof = 3 + len(self.params.u) if self.params.ecc == self.initialecc: alpha = '_fixedecc' dof += 2 nu = len(self.y.tolist()) - dof print(nu) sigma2 = self.err**2. sum = (self.y-model.light_curve(self.params))**2. sum /= sigma2 chisq = np.sum(sum) chisq_prob = chi2.sf(chisq, nu) print(chisq) print(chisq_prob) print(chisq/nu) fig = plt.figure() ax1 = fig.add_axes((.1,.3,.8,.6)) ax2 = fig.add_axes((.1,.1,.8,.2)) ax2.set_xlabel(r'$\textrm{Days from}~t_0$') ax1.set_ylabel(r'$\textrm{Relative flux}$') ax2.set_ylabel(r"$\textrm{Residuals}$") ax1.get_xaxis().set_ticks([]) ax1.plot(plotx, plotmodel.light_curve(self.params), color='black', zorder = 10) ax2.plot(plotx, np.zeros_like(plotmodel.light_curve(self.params)), ':',color='black', zorder = 10) ax1.errorbar(self.x,self.y,yerr=self.err, fmt='o', mfc='darkgray', mec='darkgray', ecolor='darkgray', markersize=5, zorder = 0) ax2.errorbar(self.x, -(model.light_curve(self.params)-self.y), yerr = self.err, fmt='o', mfc='darkgray', mec='darkgray', ecolor='darkgray', markersize=5, zorder = 0) plt.savefig('finalplots/lightcurve_'+self.params.limb_dark+alpha+'.eps') plt.savefig('finalplots/lightcurve_'+self.params.limb_dark+alpha+'.png') plt.show()
def init_batman(t, ld_law, nresampling=None, etresampling=None): """ This function initializes the batman code. """ params = batman.TransitParams() params.t0 = 0. params.per = 1. params.rp = 0.1 params.a = 15. params.inc = 87. params.ecc = 0. params.w = 90. if ld_law == 'linear': params.u = [0.5] else: params.u = [0.1,0.3] if ld_law == 'none': params.limb_dark = 'quadratic' else: params.limb_dark = ld_law params.ac = 0.001 params.fp = 0.001 params.t_secondary = params.t0 + (params.per/2) + params.ac if nresampling is None or etresampling is None: m = [batman.TransitModel(params, t), batman.TransitModel(params, t, transittype='secondary')] else: m = [batman.TransitModel(params, t, supersample_factor=nresampling, exp_time=etresampling),\ batman.TransitModel(params, t, transittype='secondary', supersample_factor=nresampling, exp_time=etresampling)] return params,m
def DoubleTransitModel(theta, x, y, yerr): p1, t01, rp1, w1, u1, p2, t02, rp2, w2, u2, V, C = theta params1 = batman.TransitParams() #params1.t0=t01 params1.t0 = 57512.3834 params1.per = 1.6377 params1.rp = rp1 params1.a = 19.5 params1.inc = 90 params1.ecc = 0 params1.w = w1 params1.u = [u1] params1.limb_dark = "linear" m1 = batman.TransitModel(params1, x) model1 = m1.light_curve(params1) params2 = batman.TransitParams() params2.t0 = 57512.3897 params2.per = 2.0198 params2.rp = rp2 params2.a = 26.7 params2.inc = 90 params2.ecc = 0 params2.w = w2 params2.u = [u2] params2.limb_dark = "linear" m2 = batman.TransitModel(params2, x) model2 = m2.light_curve(params2) model3 = V * (x - x[0]) + C #model3=-1167273.5778*(x-x[0])+59856592.8761 #model=(model1+model2-1)*model3 model = model1 + model2 - 1 #model=model1 return model
def fit_secondary(X0, p, f, e): pm = bm.TransitParams() pm.t0 = t0 pm.per = 1. pm.rp = rp pm.a = X0[0] pm.inc = X0[1] pm.ecc = X0[2] pm.w = w pm.u = [0.3, 0.2] pm.limb_dark = "quadratic" pm.fp = fp m = bm.TransitModel(pm, p) pm.t_secondary = m.get_t_secondary(pm) m2 = bm.TransitModel(pm, p, transittype="secondary") f1 = (m.light_curve(pm) + 1) / 2 f2 = m2.light_curve(pm) / 2 F = f1 * f2 vals = np.sqrt((f - F)**2 / e**2) fit_val = np.sum(vals) / (len(vals) - 1) return fit_val
def transitModel2_white(params, t, expTime): """construct a double transit :param params: transit planet parameters :param t: time stamps in seconds :param expTime: exposure time for each frame :returns: light curve model :rtype: np.array """ transit_params.t0 = params[1] # time of inferior conjunction transit_params.per = 1.51087081 # orbital period transit_params.a = 20.4209 transit_params.inc = 89.65 transit_params.rp = params[0] # planet radius (in units of stellar radii) transit_params.u = [params[4], params[5]] # linear limb darkening coefficients m_b = batman.TransitModel( transit_params, (t - 0.5 * expTime) / 86400, exp_time=expTime / 86400) lc1 = m_b.light_curve(transit_params) transit_params.t0 = params[3] transit_params.per = 2.4218233 # orbital period transit_params.a = 27.9569 transit_params.inc = 89.67 transit_params.rp = params[2] # planet radius (in units of stellar radii) transit_params.u = [params[4], params[5]] # linear limb darkening # coefficients m_c = batman.TransitModel( transit_params, (t - 0.5 * expTime) / 86400, exp_time=expTime / 86400) lc2 = m_c.light_curve(transit_params) lc = (lc1 + lc2) - 1 # two transit, remove one baseline return lc
def init_batman(t, ld_law, nresampling=None, etresampling=None): """ This function initializes the batman code. """ params = batman.TransitParams() params.t0 = 0. params.per = 1. params.rp = 0.1 params.a = 15. params.inc = 87. params.ecc = 0. params.w = 90. if ld_law == 'linear': params.u = [0.5] else: params.u = [0.1, 0.3] params.limb_dark = ld_law if nresampling is None or etresampling is None: m = batman.TransitModel(params, t) else: m = batman.TransitModel(params, t, supersample_factor=nresampling, exp_time=etresampling) return params, m
def init_batman(t, ld_law, nresampling=None, etresampling=None): """ This function initializes the batman lightcurve generator object. Parameters ---------- t: array Array containing the times at which the lightcurve will be evaluated. Assumes units of days. ld_law: string Limb-darkening law used to compute the model. Available ld laws: uniform, linear, quadratic, logarithmic, exponential, squareroot, nonlinear, power2. nresampling: int Number of resampled points in case resampling is wanted. etresampling: float Exposure time of the resampling, same units as input time. Returns ------- params: batman object Object containing the parameters of the lightcurve model. m: batman object Object that enables the lightcurve calculation. """ params = batman.TransitParams() params.t0 = 0. params.per = 1. params.rp = 0.1 params.a = 15. params.inc = 87. params.ecc = 0. params.w = 90. if ld_law == 'linear': params.u = [0.5] elif ld_law == 'nonlinear': params.u = [0.1, 0.1, 0.1, 0.1] else: params.u = [0.1, 0.3] params.limb_dark = ld_law if nresampling is None or etresampling is None: m = batman.TransitModel(params, t) else: m = batman.TransitModel(params, t, supersample_factor=nresampling, exp_time=etresampling) return params, m
def set_no_bin_mode(self): self._bin_type = 'none' self._t_model = self.t_data self._bin_indices = np.array(range(len(self.t_data))) self._bin_res = 1 # Reset the transit model and resolution if hasattr(self, 'params'): self.m = batman.TransitModel(self.params, self._t_model) self.bss = self.m.fac self.m = batman.TransitModel(self.params, self._t_model, fac=self.bss)
def set_regular_bin_mode(self, bin_res=4, adjust_res=False): """Initialises the bin mode for model-to-data conversion. Args: bin_res (int): the number of flux points binned into each data bin (the resolution). adjust_res (bool): If True, will adjust the bin_resolution based on the duration; to make sure at least 3 points are within a duration. Returns: None """ # Adjust resolution if below the minimum if adjust_res: bin_res = self.adjust_res(bin_res, max_points=50000, points_per_dur=5) # Binning procedure # ----------------- # Bin boundaries (assumes equally spaced, minus some gaps) ts = np.median(self.t_data[1:] - self.t_data[:-1]) # time-step t_bins = np.empty(len(self.t_data) + 1, dtype=float) t_bins[0] = 1.5 * self.t_data[0] - 0.5 * self.t_data[1] t_bins[-1] = 1.5 * self.t_data[-1] - 0.5 * self.t_data[-2] t_bins[1:-1] = self.t_data[:-1] \ + 0.5*(self.t_data[1:] - self.t_data[:-1]) self._t_bins = t_bins self._bin_type = 'regular' self._bin_indices = np.sort(list(range(len(self.t_data))) * bin_res) self._bin_res = bin_res # Can't be done w.r.t t_bins, as it is irregular around gaps t_model = np.empty(len(self.t_data) * bin_res, dtype=float) for i in range(len(self.t_data)): t_model[i * bin_res:(i + 1) * bin_res] = np.linspace( self.t_data[i] - ts / 2, self.t_data[i] + ts / 2, bin_res + 1, endpoint=False)[1:] self._t_model = t_model # Reset the transit model and resolution if hasattr(self, 'params'): self.m = batman.TransitModel(self.params, self._t_model) self.bss = self.m.fac self.m = batman.TransitModel(self.params, self._t_model, fac=self.bss)
def fit_db(X0, p1, f1, e1, p2, f2, e2): pm1 = bm.TransitParams() pm2 = bm.TransitParams() t01, t02 = X0[0], X0[1] rp1 = X0[2] rp2 = 1 / rp1 fp1 = X0[3] fp2 = 1 / fp1 a1, a2 = X0[4], X0[5] inc = X0[6] ecc = X0[7] w1 = X0[8] w2 = w1 + 180 u1, u2 = X0[9], X0[10] u3, u4 = X0[11], X0[12] pm1.t0 = t01 pm1.per = 1. pm1.rp = rp1 pm1.a = a1 pm1.inc = inc pm1.ecc = ecc pm1.w = w1 pm1.u = [u1, u2] pm1.limb_dark = "quadratic" pm2.t0 = t02 pm2.per = 1. pm2.rp = rp2 pm2.a = a2 pm2.inc = inc pm2.ecc = ecc pm2.w = w2 pm2.u = [u3, u4] pm2.limb_dark = "quadratic" m1 = bm.TransitModel(pm1, p1) m2 = bm.TransitModel(pm2, p2) F1 = (m1.light_curve(pm1) + fp1) / (1 + fp1) F2 = (m2.light_curve(pm2) + fp2) / (1 + fp2) fit_vals1 = np.sqrt((f1 - F1)**2 / e1**2) fit_vals2 = np.sqrt((f2 - F2)**2 / e2**2) fit_val = (np.sum(fit_vals1) + np.sum(fit_vals2)) / (len(fit_vals1) + len(fit_vals2) - 1) return fit_val
def lnlike(theta, t_kep, f_kep, t_spit, f_spit, u1_kep=u1_KEP, u2_kep=u2_KEP, u1_spit=u1_SPIT, u2_spit=u2_SPIT): t0, per, a, b, rpKEP, rpSPIT, sigmaKEP, sigmaSPIT, offsetKEP, offsetSPIT = theta # Set up K2 transit parameters. kep_params = batman.TransitParams() kep_params.t0 = t0 kep_params.per = per kep_params.rp = rpKEP kep_params.a = a kep_params.inc = np.arccos(b / a) * (180. / np.pi) kep_params.ecc = 0. kep_params.w = 0. kep_params.u = [u1_kep, u2_kep] kep_params.limb_dark = 'quadratic' # Initialize the K2 transit model. kep_init = batman.TransitModel(kep_params, t_kep) kep_model = kep_init.light_curve(kep_params) + offsetKEP # Calculate likelihood of K2 model like_kep = -0.5 * (np.sum((f_kep - kep_model)**2 * (1 / sigmaKEP**2) - np.log(2 * np.pi * (1 / sigmaKEP**2)))) # Set up Spitzer transit parameters. spit_params = batman.TransitParams() spit_params.t0 = t0 spit_params.per = per spit_params.rp = rpSPIT spit_params.a = a spit_params.inc = np.arccos(b / a) * (180. / np.pi) spit_params.ecc = 0. spit_params.w = 0. spit_params.u = [u1_spit, u2_spit] spit_params.limb_dark = 'quadratic' # Initialize the Spitzer transit model. spit_init = batman.TransitModel(spit_params, t_spit) spit_model = spit_init.light_curve(spit_params) + offsetSPIT # Calculate likelihood of Spitzer model like_spit = -0.5 * (np.sum((f_spit - spit_model)**2 * (1 / sigmaSPIT**2) - np.log(2 * np.pi * (1 / sigmaSPIT**2)))) return like_kep + like_spit
def generate_transit_function(times, per, t0, rp, a, inc, ecc, w, limb_dark='linear', u=[0.14], phase_secondary=0.5, eclipse=False): params = batman.TransitParams() params.per = per params.rp = rp params.a = a params.inc = inc params.ecc = ecc params.w = w params.limb_dark = limb_dark params.u = u params.t0 = t0 params.fp = 1 params.t_secondary = t0 + per * 0.5 * ( 1 + 4 / np.pi * ecc * np.cos(w * np.pi / 180)) #TODO change this so it puts a lot of points near the transit/eclipse t = np.linspace(times.iloc[0] - 0.5, times.iloc[-1] + 0.5, 10000) if eclipse: #setup model to appropriate type, eclipse or primary model = batman.TransitModel(params, t, transittype='secondary') #generate lightcurve #with fp = 1, out-of-eclispe has a level of 2, so subtract this off to get eclipse variation (deltaFlux) lightcurve = model.light_curve(params) - 2 #convert lightcurve to function lightcurve = interpolate.interp1d((t - times.iloc[0]) * 24, lightcurve) return lightcurve else: #setup model to appropriate type, eclipse or primary model = batman.TransitModel(params, t) #subtract out of transit level to variation due to transit (deltaFlux) lightcurve = (model.light_curve(params) - 1) lightcurve = lightcurve / abs(np.min(lightcurve)) #convert lightcurve to function lightcurve = interpolate.interp1d((t - times.iloc[0]) * 24, lightcurve) return lightcurve
def HSTtransitLC( expTime, cRate, param, orbits=4, orbitLength=96, # min visibility=50, # min overhead=20, # s plot=False): """Simulate a transit signal observed by HST :param expTime: exposure time :param cRate: average count rate :param param: parameters describing the sinusoid, a batman dictionary :param orbits: number of orbits :param orbit: (default 96 min) length of a orbit :param visibility: (default 50 min) length of visible period per orbit :param overhead: overhead [s] per exposure :param plot: wheter to make a plot :returns: count, t :rtype: tuple """ params = batman.TransitParams() # object to store transit parameters params.t0 = param['t0'] / (24 * 60) # time of inferior conjunction params.per = param['period'] # orbital period params.rp = param['rp'] # planet radius (in units of stellar radii) params.a = param['a'] # semi-major axis (in units of stellar radii) params.ecc = 0 # eccentricity params.inc = 89.1 # inclination params.w = 90. # longitude of periastron (in degrees) params.limb_dark = "linear" # limb darkening model params.u = [0.28] # limb darkening coefficients t = HSTtiming(expTime, orbits, orbitLength, visibility, overhead) m = batman.TransitModel(params, t / (24 * 3600)) # calculate count, be careful that period in h count = cRate * expTime * m.light_curve(params) t_mod = np.linspace(t.min(), t.max(), 10 * len(t)) m = batman.TransitModel(params, t_mod / (24 * 3600)) count_mod = cRate * expTime * m.light_curve(params) if plot: fig, ax = plt.subplots() ax.plot(t / 60, count, 'o') ax.set_xlabel('Time [min]') ax.set_ylabel(r'count [$\mathsf{e^-}$]') plt.show() return count, t, count_mod, t_mod
def transit_model(self, pv, time): """ Define the transit model for a given pv vector INPUT: pv[0] - period pv[1] - epoch (0) pv[2] - Rp/Rs (sqrt(depth)) pv[3] - a/Rs (estimate from stellar density) pv[4] - impact param """ p,t0,RpRs,aRs,dur = pv ii = mt.acos(pv[4]/pv[3])*(180./np.pi) # inclination in degrees params = batman.TransitParams() params.t0 = t0 params.per = p params.inc = ii params.rp = RpRs params.a = aRs params.ecc = 0. params.w = 0. params.u = self.limbdark params.limb_dark = "quadratic" params.fp = 0.001 # supersample for K2 cadence transitmodel = batman.TransitModel(params, time, transittype='primary',supersample_factor=7,exp_time=0.020431801470066003) lc = transitmodel.light_curve(params) return lc
def transit_model( params, jd ): blockPrint() params.t0 = 0 p = batman.TransitModel(params,jd) transit_flux = p.light_curve(params) enablePrint() return transit_flux
def lc_min(params, phase, flux, err): ''' Function which calculates Chi2 value for a given set of input parameters. Function to be minimized to find best fit parameters ''' #Define the system parameters for the batman LC model pm = bm.TransitParams() pm.t0 = 0. #Time of transit centre pm.per = 1. #Orbital period = 1 as phase folded pm.rp = params[0] #Ratio of planet to stellar radius pm.a = params[1] #Semi-major axis (units of stellar radius) pm.inc = params[2] #Orbital Inclination [deg] pm.ecc = 0. #Orbital eccentricity (fix circular orbits) pm.w = 90. #Longitude of periastron [deg] (unimportant as circular orbits) pm.u = [0.1, 0.3] #Stellar LD coefficients pm.limb_dark = "quadratic" #LD model #Initialize the batman LC model and compute model LC m = bm.TransitModel(pm, phase) f_model = m.light_curve(pm) fit_vals = np.sqrt((flux - f_model)**2 / err**2) fit_val = np.sum(fit_vals) / (len(fit_vals) - 4) return fit_val
def lc_min(params, time, flux, err, spl): ''' Function which calculates Chi2 value for a given set of input parameters. Function to be minimized to find best fit parameters Uses a spline to model any Out-of-Transit variability ''' phase = ((time - (params['t0'].value)) / params['per'].value) % 1 #Produce binned data set for caclulating the spline variability_model = spl(phase) #Define the system parameters for the batman LC model pm = bm.TransitParams() pm.t0 = 0 #Time of transit centre pm.per = 1. #Orbital period = 1 as phase folded pm.rp = params['rp'].value #Ratio of planet to stellar radius pm.a = params['a'].value #Semi-major axis (units of stellar radius) pm.inc = params['inc'].value #Orbital Inclination [deg] pm.ecc = args.ecc #Orbital eccentricity (fix circular orbits) pm.w = args.w #Longitude of periastron [deg] (unimportant as circular orbits) if not args.ld == "uniform": pm.u = [args.u1, args.u2] #Stellar LD coefficients else: pm.u = [] pm.limb_dark = args.ld #LD model #Initialize the batman LC model and compute model LC m = bm.TransitModel(pm, phase) f_model = m.light_curve(pm) model_total = f_model * variability_model residuals = (flux - model_total)**2 / err**2 return residuals
def transit_model_1_plot(period): """ Function for interactive transit modeling """ # Parameters of planet model params = batman.TransitParams() params.t0 = 0. # time of inferior conjunction params.per = period # orbital period (days) params.rp = ( (1.0 * u.Rjup) / (1.203 * u.Rsun)).si.value # planet radius (in units of stellar radii) params.a = 15. # semi-major axis (in units of stellar radii) params.inc = 87. # orbital inclination (in degrees) params.ecc = 0. # eccentricity params.w = 90. # longitude of periastron (in degrees) params.u = [0.1, 0.1] # limb darkening coefficients [u1, u2] params.limb_dark = "quadratic" # limb darkening model # Defining the timeframe and calculating flux time = np.linspace(-1, 1, 10000) * 6 # Creates an array of 10000 points # over a roughly 12-day period model = batman.TransitModel(params, time) flux_model = model.light_curve(params) # Plotting results plt.figure(figsize=(14, 5)) plt.plot(time - time[0], flux_model, 'r-') plt.title( "Figure 3: Multiple Transits of a Hot Jupiter with a {:0.1f}-day Period" .format(params.per)) plt.xlabel("Time (days)") plt.ylabel("Star brightness") return
def lc_min(params, time, flux, err): ''' Function which calculates Chi2 value for a given set of input parameters. Function to be minimized to find best fit parameters ''' phase = ((time - params['t0'].value) / params['per'].value) % 1 #Define the system parameters for the batman LC model pm = bm.TransitParams() pm.t_secondary = 0 #Time of transit centre pm.per = 1. #Orbital period = 1 as phase folded pm.rp = params['rp'].value #Ratio of planet to stellar radius pm.a = params['a'].value #Semi-major axis (units of stellar radius) pm.inc = 90 #Orbital Inclination [deg] pm.fp = params['fp'].value pm.ecc = args.ecc #Orbital eccentricity (fix circular orbits) pm.w = args.w #Longitude of periastron [deg] (unimportant as circular orbits) if not args.ld == "uniform": pm.u = [args.u1, args.u2] #Stellar LD coefficients else: pm.u = [] pm.limb_dark = args.ld #LD model #Initialize the batman LC model and compute model LC m = bm.TransitModel(pm, phase, transittype="secondary") f_model = m.light_curve(pm) - params['base'].value residuals = (flux - f_model)**2 / err**2 return residuals
def make_lightcurve(r, i, width, u_type, u_param, t): ''' r: planet radius (in stellar radii) i: inclination (in degrees) width: "width parameter" a**3/p**2 u_type: type of limb darkening u_param: list of parameters for limb darkening t: timesteps that you want the fluxes at assume circular orbit ''' params = batman.TransitParams() params.rp = r #planet radius (in units of stellar radii) params.inc = i #orbital inclination (in degrees) params.w = 0 #longitude of periastron (in degrees) params.ecc = 0 #eccentricity params.per = 100 #orbital period params.t0 = 0 #time of inferior conjunction params.a = (width * 100**2)**( 1 / 3) #semi-major axis (in units of stellar radii) params.u = u_param #limb darkening coefficients [u1, u2] params.limb_dark = u_type #limb darkening model m = batman.TransitModel(params, t) #initializes model flux = m.light_curve(params) #calculates light curve return flux
def light_curve_model(t, rp, a, t0 = 0., per = 1., inc = 90., ecc = 0., w = 90., limb_dark = "quadratic", u = [0.1, 0.3]): '''Python Function to use the batman package to produce a model lightcurve using the following input parameters: t: numpy array containing the time values at which to calculate the model LC rp: radius of the planet, in units of stellar radii a semi-major axis of the planet's orbit, in units of stellar radii t0 = 0. time of the transit centre per = 1. orbital period inc = 90. orbital inclination [degrees] ecc = 0. orbital eccentricity w = 90. longitude of periastron [degrees] limb_dark = "uniform" limb darkening mechanism u = [] limb darkening coefficients NOTE: Units of t, t0, and per are not set to be a specific unit but must all be consistent OUTPUT: flux_model : a numpy array of the same dimensions as t, containing the relative for the model LC at each time point in t''' params = batman.TransitParams() params.t0 = t0 params.per = per params.rp = rp params.a = a params.inc = inc params.ecc = ecc params.w = w params.u = u params.limb_dark = limb_dark m = batman.TransitModel(params, t) flux_model = m.light_curve(params) return flux_model
def batman_model(time, p): """ Creates a batman transit model to inject into the data as not-a-flare noise. Parameters ---------- time : np.ndarray params : parameters for the batman model. params is an array of [t0, period, rp/r_star, a/r_star]. Returns ---------- flux : batman modeled flux with transit injected. """ params = batman.TransitParams() params.t0 = p[0] params.per = p[1] params.rp = p[2] params.a = p[3] params.inc = 90. params.ecc = 0. params.w = 90. params.u = [0.1, 0.3] params.limb_dark = "quadratic" m = batman.TransitModel(params, time) flux = m.light_curve(params) return flux
def make_lightcurve(t0, r, i, p, width, u_type, u_param, t): """ Generate a batman lightcurve with the given parameters. Parameters ---------- t0 (num): time of inferior conjunction r (num): planet radius (in stellar radii) i (num): orbital inclination (in degrees) p (num): orbital period width (num): width parameter (defined as a**3/p**2) u_type (str): limb darkening model u_param (list): parameters for limb darkening t: timesteps that you want the fluxes at assume circular orbit """ # Init batman model params = batman.TransitParams() params.rp = r params.inc = i params.w = 0 # longitude of periastron (degenerate with width) params.ecc = 0 # eccentricity (0 for circular orbits) params.per = p # orbital period params.t0 = t0 params.a = (width * p**2)**(1 / 3) # semi-major axis (stellar radii) params.limb_dark = u_type params.u = u_param model = batman.TransitModel(params, t) # Generate curve flux = model.light_curve(params) # compute light curve return flux
def eval(self, **kwargs): """Evaluate the function with the given values""" # Get the time if self.time is None: self.time = kwargs.get('time') # Generate with batman bm_params = batman.TransitParams() # Set all parameters for p in self.parameters.list: setattr(bm_params, p[0], p[1]) # Combine limb darkening coeffs bm_params.u = [getattr(self.parameters, u).value for u in self.coeffs] # Use batman ld_profile name if self.parameters.limb_dark.value == '4-parameter': bm_params.limb_dark = 'nonlinear' # Make the eclipse tt = self.parameters.transittype.value m_eclipse = batman.TransitModel(bm_params, self.time, transittype=tt) # Evaluate the light curve return m_eclipse.light_curve(bm_params)
def _create_data_from_model_with_trends(transit_model, noise_dev=0.01): # Given a fully set up transit model, create some fake # data with a touch of noise. # Make our own batman model and data from it model = batman.TransitModel(transit_model._batman_params, transit_model.times) data = model.light_curve(transit_model._batman_params) if transit_model.airmass is not None: data += transit_model.model.airmass_trend * (transit_model.airmass) if transit_model.width is not None: data += transit_model.model.width_trend * transit_model.width if transit_model.spp is not None: data += transit_model.model.spp_trend * transit_model.spp if noise_dev > 0: # Make some noise generator = np.random.default_rng(432132) noise = generator.normal(scale=noise_dev, size=len(data)) data += noise return data
def init_model(self, time, cadence, supersample_factor): self.update_params(self.sample_prior()[0].T) exp_time = cadence - (cadence / supersample_factor) self.model = batman.TransitModel(self.batpars, time, supersample_factor=supersample_factor, exp_time=exp_time)
def BatmanModel(t0=0.0, P=1.0, rad_pl=0.01602, a=15.0, i=87.0, e=0.0, w=90.0, coeff=[0.5, 0.1], plot=False): # Initialize the model params = batman.TransitParams() #object to store transit parameters params.t0 = t0 #76.6764 #time of inferior conjunction params.per = P #13.17562 #orbital period params.rp = rad_pl #0.01602 #planet radius (in units of stellar radii) params.a = a #13.8 #semi-major axis (in units of stellar radii) params.inc = i #88.19 #orbital inclination (in degrees) params.ecc = e #0.0 #eccentricity params.w = w #90. #longitude of periastron (in degrees) params.limb_dark = "quadratic" #limb darkening model params.u = coeff #[0.4899, 0.1809] #limb darkening coefficients [u1, u2] t = np.linspace(-.25, .25, 1000) #times at which to calculate light curve t_new = np.interp(t, (t.min(), t.max()), (0, 0.2)) m = batman.TransitModel(params, t) #initializes model flux = m.light_curve(params) #calculates light curve if plot == True: fig, ax = plt.subplots() ax.get_yaxis().get_major_formatter().set_useOffset(False) ax.plot(t_new, flux) return (t_new, flux, rad_pl)
def get_value(self, t): params.t0 = np.exp(self.log_T0) #time of inferior conjunction params.per = np.exp(self.log_per) #orbital period params.rp = np.exp( self.log_ror) #planet radius (in units of stellar radii) params.a = np.exp( self.log_aor) #semi-major axis (in units of stellar radii) #b=ars*np.cos(np.radians(inc)) params.inc = np.rad2deg( np.arccos(np.exp(self.log_b) / np.exp(self.log_aor))) #orbital inclination (in degrees) params.u = [ 0.5707, 0.1439 ] #limb darkening coefficients #SING 09 for -0.3dex, 4750K logg 3 star (Pretty damn close) params.limb_dark = "quadratic" #limb darkening model params.ecc = 0.0 #eccentricity params.w = 90 #longitude of periastron (in degrees) m = batman.TransitModel(params, t, supersample_factor=5, exp_time=0.5 / 24.) model = m.light_curve(params) model = 1e6 * (model - 1) return model
def get_tran(para, time): if fix_ecc: P, Tc, ars, rprs, inc, sig2 = para else: P, Tc, ars, rprs, inc, e, w, sig2 = para params.t0 = Tc #time of inferior conjunction params.per = P #orbital period params.rp = rprs #planet radius (in units of stellar radii) params.a = ars #semi-major axis (in units of stellar radii) params.inc = inc #orbital inclination (in degrees) params.u = [ 0.5707, 0.1439 ] #limb darkening coefficients #SING 09 for -0.3dex, 4750K logg 3 star (Pretty damn close) params.limb_dark = "quadratic" #limb darkening model if fix_ecc: params.ecc = 0.0 #eccentricity params.w = 90 #longitude of periastron (in degrees) else: params.ecc = e params.w = w m = batman.TransitModel(params, time, supersample_factor=5, exp_time=0.5 / 24.) model = m.light_curve(params) model = 1e6 * (model - 1) return model
def transit(idx, data, params): t = data.time[idx] p = batman.TransitParams() t0, per, rp, a, inc, ecc, w, u1, u2, limb_dark = params #FIXME if limb_dark == 2: p.limb_dark = "quadratic" else: print "unsupported limb darkening parameter" return 0 p.t0 = t0 p.per = per p.rp = rp p.a = a p.inc = inc p.ecc = ecc p.w = w p.u = [u1, u2] m = batman.TransitModel(p, t, supersample_factor=3, exp_time=data.exp_time / 24. / 60. / 60.) return m.light_curve(p)