How to use lightkurve - 10 common examples

To help you get started, we’ve selected a few lightkurve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KeplerGO / lightkurve / lightkurve / lightcurve.py View on Github external
def __init__(self, time=None, flux=None, flux_err=None,
                 flux_unit=u.Unit('electron/second'), time_format='bkjd', time_scale='tdb',
                 centroid_col=None, centroid_row=None, quality=None, quality_bitmask=None,
                 channel=None, campaign=None, quarter=None, mission=None,
                 cadenceno=None, targetid=None, ra=None, dec=None, label=None, meta=None):
        super(KeplerLightCurve, self).__init__(time=time, flux=flux, flux_err=flux_err, flux_unit=flux_unit,
                                               time_format=time_format, time_scale=time_scale,
                                               targetid=targetid, label=label, meta=meta)
        self.centroid_col = self._validate_array(centroid_col, name='centroid_col')
        self.centroid_row = self._validate_array(centroid_row, name='centroid_row')
        self.quality = self._validate_array(quality, name='quality')
        self.cadenceno = self._validate_array(cadenceno, name='cadenceno')
        self.quality_bitmask = quality_bitmask
        self.channel = channel
        self.campaign = campaign
        self.quarter = quarter
        self.mission = mission
        self.ra = ra
        self.dec = dec
github KeplerGO / lightkurve / lightkurve / prf / tpfmodel.py View on Github external
def plot_diagnostics(self, data, figsize=(12, 4), *params, **kwargs):
        """Plots an image of the model for a given point in the parameter space."""
        fig, ax = plt.subplots(nrows=1, ncols=3, figsize=figsize)
        fit = self.fit(data)
        extent = (self.prfmodel.column, self.prfmodel.column + self.prfmodel.shape[1],
                  self.prfmodel.row, self.prfmodel.row + self.prfmodel.shape[0])
        plot_image(data, ax=ax[0],
                   title='Observed Data, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.predicted_image, ax=ax[1],
                   title='Predicted Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.residual_image, ax=ax[2],
                   title='Residual Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        return fit
github KeplerGO / lightkurve / lightkurve / prf / tpfmodel.py View on Github external
def plot_diagnostics(self, data, figsize=(12, 4), *params, **kwargs):
        """Plots an image of the model for a given point in the parameter space."""
        fig, ax = plt.subplots(nrows=1, ncols=3, figsize=figsize)
        fit = self.fit(data)
        extent = (self.prfmodel.column, self.prfmodel.column + self.prfmodel.shape[1],
                  self.prfmodel.row, self.prfmodel.row + self.prfmodel.shape[0])
        plot_image(data, ax=ax[0],
                   title='Observed Data, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.predicted_image, ax=ax[1],
                   title='Predicted Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.residual_image, ax=ax[2],
                   title='Residual Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        return fit
github KeplerGO / lightkurve / lightkurve / prf / tpfmodel.py View on Github external
def plot_diagnostics(self, data, figsize=(12, 4), *params, **kwargs):
        """Plots an image of the model for a given point in the parameter space."""
        fig, ax = plt.subplots(nrows=1, ncols=3, figsize=figsize)
        fit = self.fit(data)
        extent = (self.prfmodel.column, self.prfmodel.column + self.prfmodel.shape[1],
                  self.prfmodel.row, self.prfmodel.row + self.prfmodel.shape[0])
        plot_image(data, ax=ax[0],
                   title='Observed Data, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.predicted_image, ax=ax[1],
                   title='Predicted Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        plot_image(fit.residual_image, ax=ax[2],
                   title='Residual Image, Channel: {}'.format(self.prfmodel.channel),
                   extent=extent, **kwargs)
        return fit
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
description_string = "{} Long".format(filetype)
    mask &= np.array([description_string in desc for desc in products['description']])

    # Identify quarter by the description.
    if quarter is not None:
        quarter_mask = np.zeros(len(products), dtype=bool)
        for q in np.atleast_1d(quarter):
            quarter_mask |= np.array([desc.lower().replace('-', '').endswith('q{}'.format(q))
                                      for desc in products['description']])
        mask &= quarter_mask

    # For Kepler short cadence data the month can be specified
    if month is not None:
        month = np.atleast_1d(month)
        # Get the short cadence date lookup table.
        table = ascii.read(os.path.join(PACKAGEDIR, 'data', 'short_cadence_month_lookup.csv'))
        # The following line is needed for systems where the default integer type
        # is int32 (e.g. Windows/Appveyor), the column will then be interpreted
        # as string which makes the test fail.
        table['StartTime'] = table['StartTime'].astype(str)
        # Grab the dates of each of the short cadence files.
        # Make sure every entry has the correct month
        is_shortcadence = mask & np.asarray(['Short' in desc for desc in products['description']])
        for idx in np.where(is_shortcadence)[0]:
            quarter = int(products['description'][idx].split(' - ')[-1][1:].replace('-', ''))
            date = products['dataURI'][idx].split('/')[-1].split('-')[1].split('_')[0]
            permitted_dates = []
            for m in month:
                try:
                    permitted_dates.append(table['StartTime'][
                        np.where((table['Month'] == m) & (table['Quarter'] == quarter))[0][0]
                                    ])
github KeplerGO / lightkurve / lightkurve / interact_bls.py View on Github external
f = lc.fold(best_period, best_t0)
            inwindow = (f.time > minphase) & (f.time < maxphase)
            nb = int(np.ceil(inwindow.sum()/10000))
            f_source.data = {'phase': f[inwindow].time[::nb],
                             'flux': f[inwindow].flux[::nb]}

            mf = model.model(lc.time, best_period, duration_slider.value, best_t0)
            mf /= np.median(mf)
            mask = ~(convolve(np.asarray(mf == np.median(mf)), Box1DKernel(2)) > 0.9)
            model_lc = LightCurve(lc.time[mask], mf[mask])

            model_lc_source.data = {'time': np.sort(model_lc.time),
                                    'flux': model_lc.flux[np.argsort(model_lc.time)]}

            f_model_lc = model_lc.fold(best_period, best_t0)
            f_model_lc = LightCurve([-0.5], [1]).append(f_model_lc)
            f_model_lc = f_model_lc.append(LightCurve([0.5], [1]))

            f_model_lc_source.data = {'phase': f_model_lc.time,
                                      'flux': f_model_lc.flux}

            vertical_line.update(location=best_period)
            fig_folded.title.text = 'Period: {} days \t T0: {}{}'.format(
                                        np.round(best_period, 7),
                                        np.round(best_t0, 7), time_format)
            text_output.text = "Period: {} days, \t T0: {}{}".format(
                                        np.round(best_period, 7),
                                        np.round(best_t0, 7), time_format)
github KeplerGO / lightkurve / lightkurve / interact_bls.py View on Github external
minpow, maxpow = bls_source.data['power'].min()*0.95,  bls_source.data['power'].max()*1.05
                fig_bls.y_range.start = minpow
                fig_bls.y_range.end = maxpow

            # Otherwise, we can just update the best_period index
            minphase, maxphase = fig_folded.x_range.start, fig_folded.x_range.end
            f = lc.fold(best_period, best_t0)
            inwindow = (f.time > minphase) & (f.time < maxphase)
            nb = int(np.ceil(inwindow.sum()/10000))
            f_source.data = {'phase': f[inwindow].time[::nb],
                             'flux': f[inwindow].flux[::nb]}

            mf = model.model(lc.time, best_period, duration_slider.value, best_t0)
            mf /= np.median(mf)
            mask = ~(convolve(np.asarray(mf == np.median(mf)), Box1DKernel(2)) > 0.9)
            model_lc = LightCurve(lc.time[mask], mf[mask])

            model_lc_source.data = {'time': np.sort(model_lc.time),
                                    'flux': model_lc.flux[np.argsort(model_lc.time)]}

            f_model_lc = model_lc.fold(best_period, best_t0)
            f_model_lc = LightCurve([-0.5], [1]).append(f_model_lc)
            f_model_lc = f_model_lc.append(LightCurve([0.5], [1]))

            f_model_lc_source.data = {'phase': f_model_lc.time,
                                      'flux': f_model_lc.flux}

            vertical_line.update(location=best_period)
            fig_folded.title.text = 'Period: {} days \t T0: {}{}'.format(
                                        np.round(best_period, 7),
                                        np.round(best_t0, 7), time_format)
            text_output.text = "Period: {} days, \t T0: {}{}".format(
github KeplerGO / lightkurve / lightkurve / interact_bls.py View on Github external
inwindow = (f.time > minphase) & (f.time < maxphase)
            nb = int(np.ceil(inwindow.sum()/10000))
            f_source.data = {'phase': f[inwindow].time[::nb],
                             'flux': f[inwindow].flux[::nb]}

            mf = model.model(lc.time, best_period, duration_slider.value, best_t0)
            mf /= np.median(mf)
            mask = ~(convolve(np.asarray(mf == np.median(mf)), Box1DKernel(2)) > 0.9)
            model_lc = LightCurve(lc.time[mask], mf[mask])

            model_lc_source.data = {'time': np.sort(model_lc.time),
                                    'flux': model_lc.flux[np.argsort(model_lc.time)]}

            f_model_lc = model_lc.fold(best_period, best_t0)
            f_model_lc = LightCurve([-0.5], [1]).append(f_model_lc)
            f_model_lc = f_model_lc.append(LightCurve([0.5], [1]))

            f_model_lc_source.data = {'phase': f_model_lc.time,
                                      'flux': f_model_lc.flux}

            vertical_line.update(location=best_period)
            fig_folded.title.text = 'Period: {} days \t T0: {}{}'.format(
                                        np.round(best_period, 7),
                                        np.round(best_t0, 7), time_format)
            text_output.text = "Period: {} days, \t T0: {}{}".format(
                                        np.round(best_period, 7),
                                        np.round(best_t0, 7), time_format)
github KeplerGO / lightkurve / lightkurve / interact_bls.py View on Github external
half_button = Button(label="Half Period", button_type="danger", width=100)
        text_output = Paragraph(text="Period: {} days, T0: {}{}".format(
                                                    np.round(best_period, 7),
                                                    np.round(best_t0, 7), time_format),
                                width=350, height=40)

        # Set up BLS source
        bls_source = prepare_bls_datasource(result, loc)
        bls_help_source = prepare_bls_help_source(bls_source, npoints_slider.value)

        # Set up the model LC
        mf = model.model(lc.time, best_period, duration_slider.value, best_t0)
        mf /= np.median(mf)
        mask = ~(convolve(np.asarray(mf == np.median(mf)), Box1DKernel(2)) > 0.9)
        model_lc = LightCurve(lc.time[mask], mf[mask])
        model_lc = model_lc.append(LightCurve([(lc.time[0] - best_t0) + best_period/2], [1]))
        model_lc = model_lc.append(LightCurve([(lc.time[0] - best_t0) + 3*best_period/2], [1]))

        model_lc_source = ColumnDataSource(data=dict(
                                     time=np.sort(model_lc.time),
                                     flux=model_lc.flux[np.argsort(model_lc.time)]))

        # Set up the LC
        nb = int(np.ceil(len(lc.flux)/5000))
        lc_source = prepare_lightcurve_datasource(lc[::nb])
        lc_help_source = prepare_lc_help_source(lc)

        # Set up folded LC
        nb = int(np.ceil(len(lc.flux)/10000))
        f = lc.fold(best_period, best_t0)
        f_source = prepare_folded_datasource(f[::nb])
        f_help_source = prepare_f_help_source(f)
github afeinstein20 / eleanor / eleanor / targetdata.py View on Github external
lc_obj_tpf = lightcurve.LightCurve(time = self.time[q][self.cal_cadences[0]:self.cal_cadences[1]],
                                               flux = all_corr_lc_tpf_sub[a][q][self.cal_cadences[0]:self.cal_cadences[1]])

            flat_lc_tpf = lc_obj_tpf.flatten(polyorder=2, window_length=51).remove_outliers(sigma=4)

            tpf_stds[a] =  np.std(flat_lc_tpf.flux)

            lc_obj_pc = lightcurve.LightCurve(time = self.time[q][self.cal_cadences[0]:self.cal_cadences[1]],
                                              flux = all_corr_lc_pc_sub[a][q][self.cal_cadences[0]:self.cal_cadences[1]])
            flat_lc_pc = lc_obj_pc.flatten(polyorder=2, window_length=51).remove_outliers(sigma=4)
            pc_stds[a] = np.std(flat_lc_pc.flux)


            if self.source_info.tc == False:
                lc_2d_tpf = lightcurve.LightCurve(time = self.time[q][self.cal_cadences[0]:self.cal_cadences[1]],
                                                  flux = all_corr_lc_tpf_2d_sub[a][q][self.cal_cadences[0]:self.cal_cadences[1]])
                flat_lc_2d = lc_2d_tpf.flatten(polyorder=2, window_length=51).remove_outliers(sigma=4)

                stds_2d[a] = np.std(flat_lc_2d.flux)

                all_corr_lc_tpf_2d_sub[a] = all_corr_lc_tpf_2d_sub[a] * np.nanmedian(all_raw_lc_tpf_2d_sub[a])


            all_corr_lc_pc_sub[a]  = all_corr_lc_pc_sub[a]  * np.nanmedian(all_raw_lc_pc_sub[a])
            all_corr_lc_tpf_sub[a] = all_corr_lc_tpf_sub[a] * np.nanmedian(all_raw_lc_tpf_sub[a])




        if self.crowded_field > 0.15:
            tpf_stds[ap_size > 8] = 1.0