Example #1
0
def _from_path_LC(path, mission, flux_type="PDCSAP_FLUX"):

    origins = {"Kepler": "KLC", "K2": "KLC", "TESS": "TLC"}

    if ((mission == "Kepler") | (mission == "K2")):
        lcf = KeplerLightCurveFile(path)
    elif mission == "TESS":
        lcf = TessLightCurveFile(path)

    else:
        raise KeyError("Invalid mission. Pass 'Kepler', 'K2', or 'TESS'.")

    lc = lcf.get_lightcurve(flux_type)
    flc = _convert_LC_to_FLC(lc, origin=origins[mission])
    return flc
Example #2
0
def from_KeplerLightCurve_source(target, lctype='SAP_FLUX', **kwargs):
    """
    Accepts paths and EPIC IDs as targets. Either fetches a ``KeplerLightCurveFile``
    from MAST via ID or directly from a path, then creates a ``FlareLightCurve``
    preserving all data from ``KeplerLightCurve``.

    Parameters
    ------------
    target : str or int
        EPIC ID (e.g., 211119999) or path to zipped ``KeplerLightCurveFile``
    lctype: 'SAP_FLUX' or 'PDCSAP_FLUX'
        takes in either raw or PDC flux, default is 'SAP_FLUX' because it seems
        to work best with the K2SC detrending pipeline
    kwargs : dict
        Keyword arguments to pass to `KeplerLightCurveFile.from_archive
        <https://lightkurve.keplerscience.org/api/lightkurve.lightcurvefile.KeplerLightCurveFile.html#lightkurve.lightcurvefile.KeplerLightCurveFile.from_archive>`_

    Returns
    --------
    FlareLightCurve
    """

    lcf = KeplerLightCurveFile.from_archive(target, **kwargs)
    lc = lcf.get_lightcurve(lctype)

    return from_KeplerLightCurve(lc)
Example #3
0
def get_lightcurve(target):
    lcs = KeplerLightCurveFile.from_archive(target,
                                            quarter='all',
                                            cadence='long')
    lc = lcs[0].PDCSAP_FLUX.remove_nans()
    lc.flux = -2.5 * np.log10(lc.flux)
    lc.flux = lc.flux - np.average(lc.flux)
    for i in lcs[1:]:
        i = i.PDCSAP_FLUX.remove_nans()
        i.flux = -2.5 * np.log10(i.flux)
        i.flux = i.flux - np.average(i.flux)
        lc = lc.append(i)
    return lc.time, lc.flux
Example #4
0
    #             if (x == self.peakFlare):
    #                 break
    #             i += 1
    #         print(time[i])

    def reduceandplot(self):

        p = [self.peakTime, 0.05, self.peakFlare]
        print('First values of peakTime, peakFlare, and fwhm' +
              str(self.peakTime) + " " + str(self.peakFlare) + " " + str(0.05))
        result = minimize(ng_ln_like, p, args=[self.time, self.flux])
        print(result)
        self.peakTime, fwhm, flarePeak = result.x
        print(self.peakTime, fwhm, flarePeak)
        pl.plot(
            self.time,
            ap.aflare1(self.time,
                       tpeak=self.peakTime,
                       fwhm=fwhm,
                       ampl=flarePeak,
                       upsample=True,
                       uptime=10))
        pl.plot(self.time, self.flux)
        pl.show()


w359 = KeplerLightCurveFile.from_archive(201885041)
flare1 = strPlot(w359, 250, 280, 2)
#flare1.peaks()
flare1.reduceandplot()
Example #5
0
i, j, k = [5, 4, 3]
print(k)


def neg_ln_like(p):
    gp.set_parameter_vector(p)
    return -gp.log_likelihood(y)


def grad_neg_ln_like(p):
    gp.set_parameter_vector(p)
    return -gp.grad_log_likelihood(y)


strLC = KeplerLightCurveFile.from_archive(206208968)
strPDC = strLC.PDCSAP_FLUX.remove_outliers()

y = strPDC.flux[:300]
x = strPDC.time[:300]
y = (y / np.median(y)) - 1  # sets the function to begin at 0
x = x[np.isfinite(y)]
y = y[np.isfinite(y)]  # removes NaN values

pl.plot(x, y)
#pl.show()
print(median_absolute_deviation(y))
print(np.var(y))

kernel = np.var(y) * kernels.ExpSquaredKernel(0.5) * kernels.ExpSine2Kernel(
    log_period=0.5, gamma=1)
Example #6
0
def from_KeplerLightCurve_source(target):

    lcf = KeplerLightCurveFile.from_archive(target)
    lc = lcf.get_lightcurve('SAP_FLUX')
    return from_KeplerLightCurve(lc)
def retreive_data(num_periods=4,
                  KIC=4570949,
                  drop_outliers=False,
                  downloaded=True,
                  base_dir="../mastDownload/Kepler/",
                  params=None,
                  which_quarters=None):
    """
    Retreives and conditions data for the given KIC object

    Args:
        num_periods (int, optional) - window size for median filter
        KIC (optional, int) - KIC number
        drop_outliers (optional, boolean) - drop outliers?
        downloaded (optional, boolean) - whether data are DLed
        base_dir (optional, str) - directory under which to find data files
        params (optional, dict) - if not None, the routine masks
            points in transit (as indicated by the params values)
            while conditioning the data
        which_quarters (optional, list) - which quarters to return

    Returns:
        time (float array) - observational times
        flux (float array) - unconditioned light curve data
        filtered_time (float array) - observational times, conditioned
        filtered_flux (float array) - observational data, conditioned

    """

    if (not downloaded):
        for q in range(0, 18):
            try:
                lc = KeplerLightCurveFile.from_archive(
                    str(KIC), quarter=q, verbose=False).PDCSAP_FLUX
                tpf = KeplerTargetPixelFile.from_archive(str(KIC), quarter=q)

            except:
                pass

    time = np.array([])
    flux = np.array([])

    filtered_time = np.array([])
    filtered_flux = np.array([])

    # Return the filter
    returned_filter = np.array([])

    # Collect all data files
    ls = glob(base_dir + "kplr*" + str(KIC) + "_lc_Q*/*.fits")
    tpfs = glob(base_dir + "kplr*" + str(KIC) + "_lc_Q*/*targ.fits.gz")

    if (which_quarters is None):
        which_quarters = range(len(ls))

    for i in which_quarters:
        # PDCSAP_FLUX supposedly takes care of the flux fraction -
        # _Data Processing Handbook_, p. 129
        # https://archive.stsci.edu/kepler/manuals/KSCI-19081-002-KDPH.pdf
        lc = KeplerLightCurveFile(ls[i]).PDCSAP_FLUX
        lc.remove_nans()

        cur_time = lc.time
        cur_flux = lc.flux

        # Remove nans since remove_nans above doesn't seem to work.
        ind = ~np.isnan(cur_flux)
        cur_time = cur_time[ind]
        cur_flux = cur_flux[ind]

        time = np.append(time, cur_time)
        flux = np.append(flux, cur_flux)

        cur_filtered_time, cur_filtered_flux, cur_filter =\
                filter_data(cur_time, cur_flux, num_periods=num_periods,
                        drop_outliers=drop_outliers, params=params)

        filtered_time = np.append(filtered_time, cur_filtered_time)
        filtered_flux = np.append(filtered_flux, cur_filtered_flux)
        returned_filter = np.append(returned_filter, cur_filter)

    # Finally remove any NaNs that snuck through
    ind = ~np.isnan(filtered_flux)
    filtered_time = filtered_time[ind]
    filtered_flux = filtered_flux[ind]

    return time, flux, filtered_time, filtered_flux, returned_filter
Example #8
0
      int(quarter), '\nHost Star Mass in Solar Masses: ', starmass,
      '\nRadius of Host Star in Solar Radii: ', starradius,
      '\nTemperature of Host Star in Kelvin: ', startemp)

# Importing our data (target pixel file)
tpf = KeplerTargetPixelFile.from_archive(int(stellarsystem),
                                         quarter=int(quarter))
tpf.plot(aperture_mask=tpf.pipeline_mask)

# Convert the target pixel file into a light curve using the pipeline-defined aperture mask
lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)
lc.plot()
plt.title("Light Curve from TPF")

# Use Kepler Light Curve File now (rather than being generated by us using a Target Pixel File, these files have been pregenerated using NASA’s Kepler Data Processing Pipeline - contains SAP and PDCSAP flux)
lcf = KeplerLightCurveFile.from_archive(
    int(stellarsystem), quarter=int(quarter)).PDCSAP_FLUX.remove_nans()
lcf.plot()
plt.title('PDCSAP Flux Light Curve From Archive of Kepler ' +
          str(stellarsystem))
# lcf.scatter()

print('----------------------------------------')

# Convert light curve file to a periodogram and find orbital period

pg = lcf.to_periodogram()
pg.plot()
pg.plot(format='period', scale='log')

pg = lcf.to_periodogram(
    oversample_factor=30