def __init__(self, path, transit_params=None): self.path = path self.default_figsize = (12, 8)#(20, 8) times, fluxes_kepler, errors, fluxes_model, flags = np.loadtxt(path, unpack=True) self.times = times if times.mean() > 2450000 else times + 2454833. self.fluxes_kepler = fluxes_kepler self.errors = errors self.fluxes_model = fluxes_model self.flags = flags self.kepler_lc = LightCurve(times=self.times, fluxes=fluxes_kepler, errors=errors) self.model_lc = LightCurve(times=self.times, fluxes=fluxes_model) self.transit_params = transit_params
class BestLightCurve(object): def __init__(self, path, transit_params=None): self.path = path self.default_figsize = (12, 8)#(20, 8) times, fluxes_kepler, errors, fluxes_model, flags = np.loadtxt(path, unpack=True) self.times = times if times.mean() > 2450000 else times + 2454833. self.fluxes_kepler = fluxes_kepler self.errors = errors self.fluxes_model = fluxes_model self.flags = flags self.kepler_lc = LightCurve(times=self.times, fluxes=fluxes_kepler, errors=errors) self.model_lc = LightCurve(times=self.times, fluxes=fluxes_model) self.transit_params = transit_params def plot_whole_lc(self): # Whole light curve fig, ax = plt.subplots(2, 1, figsize=self.default_figsize, sharex='col') ax[0].plot_date(self.kepler_lc.times.plot_date, self.fluxes_kepler, 'k.', label='Kepler') ax[0].plot_date(self.model_lc.times.plot_date, self.fluxes_model, 'r', label='STSP') #ax[0].legend(loc='lower left') ax[0].set(ylabel='Flux') ax[1].plot_date(self.kepler_lc.times.plot_date, self.fluxes_kepler - self.fluxes_model, 'k.') ax[1].set(ylabel='Residuals') ax[1].axhline(0, color='r') label_times = Time(ax[1].get_xticks(), format='plot_date') ax[1].set_xticklabels([lt.strftime("%H:%M") for lt in label_times.datetime]) ax[1].set_xlabel('Time on {0} UTC'.format(label_times[0].datetime.date())) ax[0].set_title(os.path.basename(self.path)) # for l in ax[1].get_xticklabels(): # l.set_rotation(45) # l.set_ha('right') return fig, ax def plot_whole_lc(self): # Whole light curve errorbar_color = '#b3b3b3' fig, ax = plt.subplots(2, 1, figsize=self.default_figsize, sharex='col') ax[0].errorbar(self.kepler_lc.times.plot_date, self.fluxes_kepler, self.kepler_lc.errors, fmt='.', color='k', ecolor=errorbar_color, capsize=0, label='Kepler') ax[0].plot(self.model_lc.times.plot_date, self.fluxes_model, 'r', label='STSP') #ax[0].legend(loc='lower left') ax[0].set(ylabel='Flux') ax[1].errorbar(self.kepler_lc.times.plot_date, self.fluxes_kepler - self.fluxes_model, self.kepler_lc.errors, fmt='.', color='k', ecolor=errorbar_color, capsize=0) ax[1].set(ylabel='Residuals') ax[1].axhline(0, color='r') label_times = Time(ax[1].get_xticks(), format='plot_date') ax[1].set_xticklabels([lt.strftime("%H:%M") for lt in label_times.datetime]) ax[1].set_xlabel('Time on {0} UTC'.format(label_times[0].datetime.date())) ax[0].set_title(os.path.basename(self.path)) # for l in ax[1].get_xticklabels(): # l.set_rotation(45) # l.set_ha('right') return fig, ax # def plot_whole_lc(self): # # # Whole light curve # fig, ax = plt.subplots(2, 1, figsize=self.default_figsize, # sharex='col') # ax[0].plot_date(self.kepler_lc.times.plot_date, self.fluxes_kepler, # 'k.', label='Kepler') # ax[0].plot_date(self.model_lc.times.plot_date, self.fluxes_model, # 'r', label='STSP') # #ax[0].legend(loc='lower left') # ax[0].set(ylabel='Flux') # # ax[1].plot_date(self.kepler_lc.times.plot_date, # self.fluxes_kepler - self.fluxes_model, 'k.') # ax[1].set(ylabel='Residuals') # ax[1].axhline(0, color='r') # # label_times = Time(ax[1].get_xticks(), format='plot_date') # ax[1].set_xticklabels([lt.strftime("%H:%M") for lt in label_times.datetime]) # # ax[1].set_xlabel('Time on {0} UTC'.format(label_times[0].datetime.date())) # # ax[0].set_title(os.path.basename(self.path)) # # # for l in ax[1].get_xticklabels(): # # l.set_rotation(45) # # l.set_ha('right') # # return fig, ax def plot_transits(self): if self.transit_params is not None: kepler_transits = LightCurve(**self.kepler_lc.mask_out_of_transit(params=self.transit_params) ).get_transit_light_curves(params=self.transit_params) model_transits = LightCurve(**self.model_lc.mask_out_of_transit(params=self.transit_params) ).get_transit_light_curves(params=self.transit_params) else: kepler_transits = LightCurve(**self.kepler_lc.mask_out_of_transit() ).get_transit_light_curves() model_transits = LightCurve(**self.model_lc.mask_out_of_transit() ).get_transit_light_curves() # Whole light curve if len(kepler_transits) > 0: fig, ax = plt.subplots(2, len(kepler_transits), figsize=self.default_figsize, sharex='col') scale_factor = 0.4e-6 for i in range(len(kepler_transits)): ax[0, i].plot_date(kepler_transits[i].times.plot_date, scale_factor*kepler_transits[i].fluxes, 'k.', label='Kepler') ax[0, i].plot_date(model_transits[i].times.plot_date, scale_factor*model_transits[i].fluxes, 'r', label='STSP') ax[0, i].set(yticks=[]) ax[1, i].axhline(0, color='r', lw=2) ax[1, i].plot_date(kepler_transits[i].times.plot_date, scale_factor*(kepler_transits[i].fluxes - model_transits[i].fluxes), 'k.') xtick = Time(kepler_transits[i].times.jd.mean(), format='jd') #ax[1, i].set(xticks=[xtick.plot_date], xticklabels=[xtick.iso.split('.')[0]], # yticks=[]) #ax[1, i].set(xlabel='Time') #ax[0, 0].legend(loc='lower left') ax[0, 0].set(ylabel=r'Flux')# $\times \, 10^{{{0:.1f}}}$'.format(np.log10(scale_factor))) ax[1, 0].set(ylabel=r'Residuals')# $\times \, 10^{{{0:.1f}}}$'.format(np.log10(scale_factor))) #fig.subplots_adjust(wspace=0.5) fig.tight_layout() return fig, ax else: return None, None