コード例 #1
0
def get_eleanor(sectors='all',
                tic=None,
                coords=None,
                out_sec=False,
                height=15,
                width=15,
                bkg_size=31,
                do_psf=False,
                do_pca=False,
                out_flux='corr_flux',
                norm=True,
                errorcalc=True,
                qual_flag=True):
    #!!Add more docstrings for all keywords!!
    #!!Add common name processing instead of just tic!!
    """
    Function to get a light curve from the TESS full frame images (FFIs) using
    the Python package eleanor.

    Parameters
    ----------
    sectors : str or array or list
       The sectors that eleanor will use to produce the light curve. If set to 
       'all', then all available sectors will be used in the light curve
       production.
    tic : int or None
       TIC ID for the object that a light curve is desired for. If set to None,
       coords must have a valid input.
    coords : tuple of floats
       The RA and Dec of the object that a light curve is desired for. Must be
       of the form (RA, Dec) in decimal degrees. If set to None, the tic 
       argument cannot be None.
    out_sec : bool
       Flag controlling whether an array containing the sectors used to extract
       the light curve will be output. If True, an additional output will be 
       expected.
    height : int
       Height in pixels of the postage stamp with which to extract the light 
       curve.
    width : int
       Height in pixels of the postage stamp with which to extract the light
       curve.
    bkg_size : int
       Background size to be considered for the background subtraction from the
       light curve.
    do_psf : bool
       Flag to determine whether a PSF-corrected light curve will be generated
       as an additional option to the corrected light curve.
    do_pca : bool
       Flag to deteremine whether a PCA-corrected light curve will be generated
       as an additional option to the corrected light curve.
    out_flux : str
       Which of the light curves to output. Options are 'corr_flux', 'psf_flux',
       and 'pca_flux'. Only one may be selected. If either 'psf_flux' or 
       'pca_flux' are selected, the do_psf and do_pca flags must be set to True,
       respectively.
    norm : bool
       Flag determining whether the light curve will be normalized prior to 
       output.
    errorcalc : bool
       Flag determining whether the RMS errors will be calculated for the light
       curve.
    qual_flag : bool
       Flag determining whether the timestamps with bad quality flags will be 
       excluded automatically.

    Returns
    -------
    lc : 'LightCurve' object
       The combined light curve from each sector for the coordinates or TIC ID 
       requested.
    sectors : array
       Optional output array containing the sectors that the combined light 
       curve was extracted from.
    """
    import eleanor

    if tic is None and coords is None:
        raise ValueError('Please make sure either tic or coords have valid ' +
                         'input')

    if tic:
        star = eleanor.multi_sectors(tic=tic, sectors=sectors)
    else:
        star = eleanor.multi_sectors(coords=coords, sectors=sectors)

    secs = []
    data = []

    for s in star:
        datum = eleanor.TargetData(s,
                                   height=height,
                                   width=width,
                                   bkg_size=bkg_size,
                                   do_psf=do_psf,
                                   do_pca=do_pca)
        data.append(datum)

        sec = s.sector
        secs.append(sec)

    for i in range(len(data)):
        q = data[i].quality == 0
        time = data[i].time

        if out_flux == 'corr_flux':
            flux = data[i].corr_flux
        elif out_flux == 'pca_flux':
            flux = data[i].pca_flux
        elif out_flux == 'psf_flux':
            flux = data[i].psf_flux

        if qual_flag:
            time = time[q]
            flux = flux[q]

        if norm:
            flux = flux / np.median(flux)

        flux_err = None
        if errorcalc:
            flux_err = np.ones(len(flux)) * rms(flux)

        if i == 0:
            lc = LightCurve(time, flux, flux_err=flux_err)
        else:
            sec_lc = LightCurve(time, flux, flux_err=flux_err)
            lc = lc.append(lc)

    if out_sec:
        return lc, secs
    else:
        return lc
コード例 #2
0
def get_mlffi(tic=None,
              ra=None,
              dec=None,
              sectors='all',
              flux_type='corr',
              out_sec=False):
    """
    For use on tesseract only. Fetches FFI light curves made by Brian Powell.

    Parameters
    ----------
    tic : int or None
       TIC ID of target. If None, both ra and dec must not be None.
    ra : float or None
       RA of target. If None, tic must not be None. If not None, dec must also
       not be None.
    dec : float or None
       Dec of target. If None, tic must not be None. If not None, ra must also 
       not be None.
    sectors : str or list or array
       The desired sectors to make the light curve from. May be set to 'all' to
       use all available light curves.
    flux_type : str
       The type of correction applied to the light curve. Options are 'raw', 
       'corr', and 'pca'.
    out_sec : bool
       Flag determining whether or not the sectors that the light curve was
       generated from are output. If True, an additional output will be 
       expected.

    Returns
    -------
    lc : 'LightCurve' object
       The combined light curve.
    sectors : array
       The sectors from which the output light curve was generated.
    """
    if not tic and not ra and not dec:
        raise ValueError('Please provide valid input for either tic or ra/dec')

    if sectors == 'all':
        if not ra and not dec:
            info = tessobs_info(tic=tic)
        else:
            info = tessobs_info(ra=ra, dec=dec)

        sectors = list(set(info['sector']))

    if not isinstance(sectors, list):
        raise ValueError('Sectors must be a list!')

    if not tic:
        tic = coord_to_tic(ra, dec)

    camera_arr = []
    chip_arr = []
    Tmag_arr = []

    sects = sectors

    if not os.path.isdir('/data/tessraid/bppowel1/'):
        raise ValueError('Not on tesseract')

    for i in range(len(sects)):
        path = '/data/tessraid/bppowel1/tesslcs_sector_' + str(
            sects[i]) + '_104'
        lc_files = []

        for (dirpath, dirnames, filenames) in os.walk(path):
            for name in filenames:
                lc_files.append(os.path.join(dirpath, name))

        lc_files = [t for t in lc_files if 'tesslc_' in t]
        tics = [int(t.split('.')[0].split('_')[-1]) for t in lc_files]

        path = [s for s in lc_files if str(tic) in s]

        try:
            fp = open(str(path[0]), 'rb')
        except:
            print('Target not found in Sector %s' % sects[i])
            sects.remove(sects[i])  #trouble line, may cause silent error
            continue

        data = pickle.load(fp)
        fp.close()

        Tmag_arr.append(data[2])
        camera_arr.append(data[4])
        chip_arr.append(data[5])

        time = data[6]
        flux_err = data[10]

        if flux_type == 'corr':
            flux = data[8]
        elif flux_type == 'raw':
            flux = data[7]
        elif flux_type == 'pca':
            flux = data[9]

        if i == 0:
            lc = LightCurve(time, flux, flux_err=flux_err)
        else:
            sec_lc = LightCurve(time, flux, flux_err=flux_err)
            lc.append(sec_lc)

    lc = lc.normalize()

    lc.Tmag = Tmag_arr
    lc.camera = camera_arr
    lc.chip = chip_arr

    if out_sec:
        return lc, sects
    else:
        return lc