Ejemplo n.º 1
0
def eleanor_target_download(targID, sectors='all', sc=False, lc_format='pdc'):
    import eleanor
    if sectors == 'all':
        sector_array = np.array([1, 2])

    tic_times, tic_sap_flux, tic_pdc_flux, tic_errors = [], [], [], []
    for sector in sector_array:
        try:
            ticstar = eleanor.Source(tic=targID, sector=sector)
            ticdata = eleanor.TargetData(ticstar,
                                         height=15,
                                         width=15,
                                         bkg_size=31,
                                         do_psf=True,
                                         do_pca=True)
            qflag0 = ticdata.quality == 0
            tic_time, tic_raw_flux, tic_corr_flux, tic_error = ticdata.time[
                qlfag0], ticdata.raw_flux[qflag0], ticdata.corr_flux[
                    qflag0], ticdata.flux_err[qflag0]

            tic_times.append(tic_time)
            tic_sap_flux.append(tic_raw_flux)
            tic_pdc_flux.append(tic_pdc_flux)
            tic_errors.append(tic_error)

        except:
            pass

    if lc_format == 'pdc':
        return tic_times, tic_pdc_flux, tic_errors
    elif lc_format == 'sap':
        return tic_times, tic_sap_flux, tic_errors
Ejemplo n.º 2
0
def eleanor_corr(ticid, sector, pxsize = 19):
    import eleanor
    star = eleanor.Source(tic = ticid, sector = sector)
    
    data = eleanor.TargetData(star, height=pxsize, width=pxsize, bkg_size=31, 
                              do_psf=False, do_pca=True)
    
    return data.time, data.corr_flux, data.quality
Ejemplo n.º 3
0
 def load_data(self):
     """Allows for the option to pass in multiple files.
     """
     if self.multi is True:
         self.star, self.data = [], []
         for fn in self.file:
             s = eleanor.Source(fn=fn, fn_dir=self.directory)
             d = eleanor.TargetData(s)
             self.star.append(s)
             self.data.append(d)
         self.star = np.array(self.star)
         self.data = np.array(self.data)
         self.tic = self.star[0].tic
         self.coords = self.star[0].coords
     else:
         self.star = eleanor.Source(fn=self.file, fn_dir=self.directory)
         self.data = eleanor.TargetData(self.star)
         self.tic = self.star.tic
         self.coords = self.star.coords
     return
Ejemplo n.º 4
0
def from_eleanor(ticid):
    star = eleanor.Source(tic=ticid, sector=2,
                          tc=True)  #note: update to get all Sectors
    print('data found! for: ', ticid)
    data = eleanor.TargetData(star,
                              height=15,
                              width=15,
                              bkg_size=31,
                              do_psf=True,
                              do_pca=True,
                              try_load=True)
    return data
Ejemplo n.º 5
0
def cut_ffi(tic_id:int,clip :float = 4,iter : int = 1,do_pca : bool = False, do_psf :bool = False,flux_type = 'PDCSAP') -> Tuple[LightCurve, List[Figure],List[eleanor.TargetData]]:
    """
    Extracts light curves from FFIs using TESScut and Eleanor. This function automatically combines all available
    sectors for a given target.

    :param tic_id: TIC ID of the target
    :param clip: Sigma clip range of the target.
    :param iter: Iterations of the sigma clipping
    :param do_pca: Perform pca analysis with eleanor
    :param do_psf: Perform psf analysis with eleanor
    :param flux_type: Flux type that is returned. Choose between 'PDCSAP','SAP','PSF'
    :return: Lightcurve
    """
    flux_types = ['SAP','PDCSAP', 'PSF']
    if flux_type not in flux_types:
        raise ValueError(mprint(f"Flux type {flux_type} not recognized. Possible values are: {flux_types}",error))
    f = io.StringIO()
    with redirect_stdout(f):
        stars = eleanor.multi_sectors(tic=tic_id, sectors='all',tc=True)
    mprint(f.getvalue().strip(), log)

    lc_list = []
    data_list = []
    q_list = []

    pca_flag = do_pca or flux_type == 'PDCSAP'
    psf_flag = do_psf or flux_type == 'PSF'

    for star in stars:

        f = io.StringIO()
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_pca=pca_flag, do_psf=psf_flag)
        mprint(f.getvalue().strip(), log)
        q = data.quality == 0
        if flux_type == 'SAP':
            lc_list.append(LightCurve(lk.TessLightCurve(time=data.time[q], flux=data.corr_flux[q], targetid=tic_id)))
        elif flux_type == 'PDCSAP':
            lc_list.append(LightCurve(lk.TessLightCurve(time=data.time[q], flux=data.pca_flux[q], targetid=tic_id)))
        else:
            lc_list.append(LightCurve(lk.TessLightCurve(time=data.time[q], flux=data.psf_flux[q], targetid=tic_id)))

        data_list.append(data)
        q_list.append(q)

    fig = create_validation_page(data_list, q_list, f'TIC {tic_id}',do_pca=pca_flag,do_psf=psf_flag,flux_type=flux_type)

    lc : LightCurve = combine_light_curves(lc_list,clip,iter)
    mprint(f"Extracted light curve for TIC {tic_id}!", info)
    return lc, fig,data_list
Ejemplo n.º 6
0
    def build_eleanor_lc(self):
        """
        This function constructs a `Lightkurve` object from downloaded `eleanor`
        light curves. It also stores the light curve for each object it reads in,
        a well as the full Eleanor Target Pixel File data.
        """

        datum = eleanor.TargetData(
            eleanor.Source(fn=f'lc_sector_{self.j.sectors[0]}.fits',
                           fn_dir=f'{self.j.output_path}/{self.j.gaiaid}/'))

        q = datum.quality == 0
        lc = lk.LightCurve(time=datum.time[q], flux=datum.corr_flux[q])
        self.clc = lc.normalize().remove_nans().remove_outliers()

        # Store the datum and light curve
        self.j.void[f'datum_{self.j.sectors[0]}'] = datum
        self.j.void[f'clc_{self.j.sectors[0]}'] = self.clc

        if len(self.j.sectors) > 1:
            # Looping and appending all sectors
            for s in self.j.sectors[1:]:
                datum = eleanor.TargetData(
                    eleanor.Source(
                        fn=f'lc_sector_{s}.fits',
                        fn_dir=f'{self.j.output_path}/{self.j.gaiaid}/'))
                q = datum.quality == 0
                lc = lk.LightCurve(time=datum.time[q], flux=datum.corr_flux[q])
                self.clc = self.clc.append(
                    lc.normalize().remove_nans().remove_outliers())

                # Store the datum and light curve
                self.j.void[f'datum_{s}'] = datum
                self.j.void[f'clc_{s}'] = lc.normalize().remove_nans(
                ).remove_outliers()

        self.j.void[f'clc_all'] = self.clc
def get_lc(ra, dec):
    # Collect data on target from each sector in TESS.
    # You may need to eleanor.Update(sector=##) to ensure you have all data.
    global targetname

    # https://adina.feinste.in/eleanor/api.html#eleanor.multi_sectors
    data = eleanor.multi_sectors('all', coords=(ra, dec), tc=True)

    # Extract LC data for each sector using PSF photometry
    mjd, flux, ferr = ([] for x in range(3))
    for k in data:
        # https://adina.feinste.in/eleanor/api.html#eleanor.TargetData
        d = eleanor.TargetData(k,
                               height=15,
                               width=15,
                               bkg_size=31,
                               do_psf=True,
                               do_pca=True,
                               crowded_field=True)
        quality = d.quality
        index = np.where(quality == 0)  # Keep only quality = 0 data

        # Based on fits file headers, time is Barycentric Julian Date (-2457000 days)
        t = d.time[index]
        # corr_flux = Systematics-corrected version of lightcurve derived using aperture and tpf.
        f = d.corr_flux[index]
        # flux_err = Estimated uncertainty on raw_flux.
        e = d.flux_err[index]

        # 'Append' all data from all sectors together into a 1-D array
        mjd = np.concatenate((mjd, t))
        flux = np.concatenate((flux, f / np.median(f)))
        ferr = np.concatenate((ferr, e))

        # LC's may be large. Clear space after finished.
        del (d, t, f, e)

    # Save LC to file for easy access later.
    # No reason to run eleanor everytime.
    lcname = str(targetname) + "_tess.txt"
    with open(lcname, 'w') as ofile:
        for k in range(len(mjd)):
            ofile.write(
                str(mjd[k]) + "  " + str(flux[k]) + "  " + str(ferr[k]) + "\n")

    return (mjd, flux, ferr)
Ejemplo n.º 8
0
    def download_eleanor_data(self):
        """ Download Eleanor data.
        Data may not always be available due to not being observed by TESS, or
        errors in the download (which Im still trying to solve).
        """

        coords = SkyCoord(ra=self.j.ra, dec=self.j.dec, unit=(u.deg, u.deg))
        star = eleanor.multi_sectors(coords=coords, sectors='all')

        for s in star:
            try:
                datum = eleanor.TargetData(s)
                datum.save(output_fn=f'lc_sector_{s.sector}.fits',
                           directory=f'{self.j.output_path}/{self.j.gaiaid}/')
            except TypeError:
                print(
                    f'There is some kind of Eleanor error for Sector {s.sector}'
                )
                print('Try running eleanor.Update(), or raise an issue on the '
                      'Eleanor GitHub!')
                print('Moving on the next sector... \n')
Ejemplo n.º 9
0
def get_eleanor_lightcurves(tic_id, download_dir=None):
    """This downloads light curves from the Eleanor project for a given TIC ID.

    Parameters
    ----------
    tic_id : str
        The TIC ID of the object as a string.

    Returns
    -------
    lcfiles : list or None
        List of light-curve file paths. These are saved as CSV, rather than
        FITS, by this function.

    """

    if not eleanor_dependency:
        LOGERROR("The eleanor package is required for this function to work.")
        return None

    stars = eleanor.multi_sectors(tic=np.int64(tic_id),
                                  sectors='all',
                                  tc=False)

    for star in stars:

        d = eleanor.TargetData(star,
                               height=15,
                               width=15,
                               bkg_size=31,
                               do_psf=False,
                               do_pca=False)

        d.save(directory=download_dir)

    lcfiles = glob(
        os.path.join(download_dir,
                     'hlsp_eleanor_tess_ffi_tic{}*.fits'.format(tic_id)))

    return lcfiles
Ejemplo n.º 10
0
def CPM_one_sector(ticid, tesscut_path, sector, camera, ccd, ra, dec):
    fits_file = get_fits_filenames(tesscut_path,
                                   sector,
                                   camera,
                                   ccd,
                                   ra,
                                   dec,
                                   xpix=68,
                                   ypix=68)

    # Get the Eleanor aperture
    star = eleanor.Source(tic=ticid, sector=int(sector), tc=True)
    data = eleanor.TargetData(star)
    xpixels, ypixels = get_CPM_aperture(data.aperture)

    # Create CPM light curve
    # _, _, fig = select_aperture(sector, ypixels, xpixels, fits_file, plot=False)
    x, y = make_lc_single_sector(sector,
                                 ypixels,
                                 xpixels,
                                 fits_file,
                                 plot=False,
                                 save_to_file=False)
    return x, y
Ejemplo n.º 11
0
## User inputs ##
gaia_id = np.int(sys.argv[1])
aperture = input("Which aperture type would you like?\n(Check elanor documentation to see what this implies)\nOptions are normal, small, large: ")
clip = int(input("How many standard deviations should be clipped?\n"))
#######

# Download the data for this star
star = eleanor.multi_sectors(gaia=gaia_id, sectors='all')

# Do the photometry for all sectors using the selected aperture size

data = []
for s in star:
    datum = eleanor.TargetData(s, height=15, width=15, bkg_size=31,
                               aperture_mode=aperture, regressors='corner',
                               do_psf=False, do_pca=False)
    data.append(datum)

# Create flux vector

time = []
flux = []
err = []

for sector, datum in enumerate(data):
    # Only data not flagged for bad quality
    q = datum.quality == 0
    # Time
    time_i = datum.time[q].flatten()
    time = np.hstack([time, time_i])
 def build(self, object_info):
     mission_id = object_info.mission_id()
     sherlock_id = object_info.sherlock_id()
     quarters = None
     sectors = None
     logging.info("Retrieving star catalog info...")
     mission, mission_prefix, id = super().parse_object_id(mission_id)
     transits_min_count = 1
     star_info = None
     quarters = None
     if mission_prefix not in self.star_catalogs:
         raise ValueError("Wrong object id " + mission_id)
     if mission_prefix == self.MISSION_ID_KEPLER or mission_prefix == self.MISSION_ID_KEPLER_2:
         if object_info.sectors != 'all':
             lcf = lk.search_lightcurvefile(
                 str(mission_id),
                 mission=mission,
                 cadence="long",
                 quarter=object_info.sectors).download_all()
         else:
             lcf = lk.search_lightcurvefile(str(mission_id),
                                            mission=mission,
                                            cadence="long").download_all()
         lc = lcf.PDCSAP_FLUX.stitch().remove_nans()
         transits_min_count = 1 if len(lcf) == 0 else 2
         if mission_prefix == self.MISSION_ID_KEPLER:
             quarters = [lcfile.quarter for lcfile in lcf]
         elif mission_prefix == self.MISSION_ID_KEPLER_2:
             logging.info("Correcting K2 motion in light curve...")
             quarters = [lcfile.campaign for lcfile in lcf]
             lc = lc.to_corrector("sff").correct(windows=20)
         star_info = starinfo.StarInfo(
             sherlock_id,
             *self.star_catalogs[mission_prefix].catalog_info(id))
     else:
         if isinstance(object_info, MissionFfiCoordsObjectInfo):
             coords = SkyCoord(ra=object_info.ra,
                               dec=object_info.dec,
                               unit=(u.deg, u.deg))
             star = eleanor.multi_sectors(coords=coords,
                                          sectors=object_info.sectors)
         else:
             object_id_parsed = re.search(super().NUMBERS_REGEX,
                                          object_info.id)
             object_id_parsed = object_info.id[
                 object_id_parsed.regs[0][0]:object_id_parsed.regs[0][1]]
             star = eleanor.multi_sectors(tic=object_id_parsed,
                                          sectors=object_info.sectors)
         if star[0].tic:
             # TODO FIX star info objectid
             logging.info("Assotiated TIC is " + star[0].tic)
             star_info = starinfo.StarInfo(
                 object_info.sherlock_id(),
                 *self.star_catalog.catalog_info(int(star[0].tic)))
         data = []
         for s in star:
             datum = eleanor.TargetData(s,
                                        height=15,
                                        width=15,
                                        bkg_size=31,
                                        do_pca=True)
             data.append(datum)
         quality_bitmask = np.bitwise_and(data[0].quality.astype(int), 175)
         lc = data[0].to_lightkurve(
             data[0].pca_flux,
             quality_mask=quality_bitmask).remove_nans().flatten()
         sectors = [datum.source_info.sector for datum in data]
         if len(data) > 1:
             for datum in data[1:]:
                 quality_bitmask = np.bitwise_and(datum.quality, 175)
                 lc = lc.append(
                     datum.to_lightkurve(datum.pca_flux,
                                         quality_mask=quality_bitmask).
                     remove_nans().flatten())
             transits_min_count = 2
     return lc, star_info, transits_min_count, sectors, quarters
Ejemplo n.º 13
0
##sigma_cut_lc_fig.savefig(save_path + '{} - Sector {} - 3 sigma lightcurve.png'.format(target_ID, tpf.sector))
##plt.close(sigma_cut_lc_fig)
#
## Convert to lightcurve object
#lc_30min = tpf_30min.to_lightcurve(aperture_mask = aperture_mask)
#lc_30min = lc_30min[(lc_30min.time < 1346) | (lc_30min.time > 1350)]
#lc_30min.scatter()
#plt.title('{} - 30min FFI base lc'.format(target_ID))
#
############################# eleanor lc #######################################

star = eleanor.Source(coords=(ra, dec), sector=1)
#star = eleanor.Source(coords=(49.4969, -66.9268), sector=1)

# Extract target pixel file, perform aperture photometry and complete some systematics corrections
data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_psf=False)

q = data.quality == 0

# Plot raw flux
raw_eleanor_fig = plt.figure()
plt.scatter(data.time[q],
            data.raw_flux[q] / np.median(data.raw_flux[q]),
            s=1,
            c='k')
plt.ylabel('Normalized Flux')
plt.xlabel('Time')
plt.title('{} - eleanor light curve from FFIs - raw flux'.format(target_ID))
raw_eleanor_fig.savefig(
    save_path +
    '{} - Sector {} - eleanor raw flux.png'.format(target_ID, sector))
Ejemplo n.º 14
0
    def eleanor_lc(self, plot=False):
        """ 
        retrieves + produces eleanor light curves from FFI files
        """
        import eleanor
        from astropy import units as u
        from astropy.coordinates import SkyCoord
        import warnings
        warnings.filterwarnings('ignore')
        from eleanor.utils import SearchError

        download_dir_tesscut = os.path.join(os.path.expanduser('~'),
                                            '.eleanor', 'tesscut')

        download_dir_mastdownload = os.path.join(os.path.expanduser('~'),
                                                 '.eleanor', 'mastDownload')
        print(download_dir_tesscut, download_dir_mastdownload)
        gaia_ids = []

        print(self.radecall[:10])
        for n in range(len(self.radecall)):
            #for n in range(10):
            try:

                coords = SkyCoord(ra=self.radecall[n][0],
                                  dec=self.radecall[n][1],
                                  unit=(u.deg, u.deg))
                #try:
                files = eleanor.multi_sectors(
                    coords=coords, tic=0, gaia=0, sectors='all'
                )  #by not providing a sector argument, will ONLY retrieve most recent sector
                print(len(files))
                print(
                    'Found TIC {0} (Gaia {1}), with TESS magnitude {2}, RA {3}, and Dec {4}'
                    .format(files[0].tic, files[0].gaia, files[0].tess_mag,
                            files[0].coords[0], files[0].coords[1]))
                #data = eleanor.TargetData(files)

                for file in files:
                    data = eleanor.TargetData(file)
                    q = data.quality == 0

                    fluxandtime = [
                        data.time[q], data.raw_flux[q], data.corr_flux[q]
                    ]
                    lightcurve = np.asarray(fluxandtime)

                    if plot:
                        #!!! put plotting background here
                        print("Plotting TPF + aperture")
                        fig, (ax1, ax2, ax3) = plt.subplots(ncols=3,
                                                            figsize=(15, 4))
                        ax1.imshow(data.tpf[0])
                        ax1.set_title('Target Pixel File')
                        ax2.imshow(data.bkg_tpf[0])
                        ax2.set_title('2D interpolated background')
                        ax3.imshow(data.aperture)
                        ax3.set_title('Aperture')
                        plt.savefig(self.path + self.folderlabel +
                                    self.identifiers[n] + ".png")

                    if not os.path.isfile(self.lightcurvefilepath):
                        #setting up fits file + save first one
                        hdr = fits.Header()  # >> make the header
                        hdu = fits.PrimaryHDU(lightcurve, header=hdr)
                        hdu.writeto(self.lightcurvefilepath)
                        print(int(n))

                    else:  #save the rest
                        fits.append(self.lightcurvefilepath, lightcurve)
                        print(int(n))

                    gaia_ids.append(int(file.gaia))
            except (SearchError, ValueError, LinAlgError):
                print("Search Error or ValueError or LinAlgError occurred")

            #try:
            for root, dirs, files in os.walk(download_dir_tesscut):
                for file in files:
                    try:
                        os.remove(os.path.join(root, file))
                        #print("Deleted", os.path.join(root, file))
                    except (PermissionError, OSError):
                        #print("Unable to delete", os.path.join(root, file))
                        continue
            for root, dirs, files in os.walk(download_dir_mastdownload):
                for file in files:
                    try:
                        os.remove(os.path.join(root, file))
                        #print("Deleted", os.path.join(root, file))
                    except (PermissionError, OSError):
                        #print("Deleted", os.path.join(root, file))
                        continue
        fits.append(self.lightcurvefilepath, np.asarray(gaia_ids))
        print("All light curves saved into fits file")
        return gaia_ids
Ejemplo n.º 15
0
def view_next(main, RA, DE, coord, sectors):
    def var_states():
        states[0] = typeA.get()
        states[1] = typeB.get()
        states[2] = typeC.get()
        states[3] = Data.get()

    if (len(RA) == 0):
        call_file_name()
    else:

        #window = tkinter.Tk()
        #w, h = 300, 200
        #window.title("Star Images")
        #canvas = tkinter.Canvas(window, width=w, height=h)
        #label = tkinter.Label(window, text='We have data')
        #label.pack()

        states = [0, 0, 0, 0]
        star = eleanor.Source(coords=coord, sector=sectors[0], tc=True)
        data = eleanor.TargetData(star,
                                  try_load=True,
                                  do_psf=True,
                                  do_pca=True)
        main.destroy()
        vis = eleanor.Visualize(data)
        viewer = tkinter.Tk()
        button_1 = tkinter.Button(
            viewer,
            text="Submit",
            fg="green",
            command=lambda: save_to_file_finished(viewer, RA, DE, states))
        button_2 = tkinter.Button(
            viewer,
            text="Review",
            fg="blue",
            command=lambda: save_to_file_review(viewer, RA, DE))
        button_3 = tkinter.Button(
            viewer,
            text="Save Remaining",
            fg="orange",
            command=lambda: save_remaining_and_quit(viewer, RA, DE))
        button_4 = tkinter.Button(viewer,
                                  text="Store State Values",
                                  fg="green",
                                  command=lambda: var_states())
        button_1.grid(row=5)
        button_2.grid(row=5, column=2)
        button_3.grid(row=5, column=3)
        button_4.grid(row=5, column=1)
        typeA = tkinter.IntVar()
        typeB = tkinter.IntVar()
        typeC = tkinter.IntVar()
        Data = tkinter.IntVar()
        check_1 = tkinter.Checkbutton(viewer, text="No Data", variable=Data)
        check_2 = tkinter.Checkbutton(viewer, text="Type A", variable=typeA)
        check_3 = tkinter.Checkbutton(viewer, text="Type B", variable=typeB)
        check_4 = tkinter.Checkbutton(viewer, text="Type C", variable=typeC)
        check_1.grid(row=4, column=4)
        check_2.grid(row=1, column=4)
        check_3.grid(row=2, column=4)
        check_4.grid(row=3, column=4)

        fig1 = vis.pixel_by_pixel(colrange=[4, 10],
                                  rowrange=[4, 10],
                                  data_type="periodogram",
                                  color_by_pixel=True)
        chart_type = FigureCanvasTkAgg(fig1, viewer)
        chart_type.get_tk_widget().grid(row=0, sticky=tkinter.E)
Ejemplo n.º 16
0
    def from_eleanor(self, ticid, save_postcard=False):
        """Download light curves from Eleanor for desired target. Eleanor light
        curves include:
        - raw : raw flux light curve
        - corr : corrected flux light curve
        - pca : principle component analysis light curve
        - psf : point spread function photometry light curve

        Parameters
        ----------
        ticid : int
            TIC ID of desired target

        Returns
        -------
        LightCurveCollection :
            ~lightkurve.LightCurveCollection containing raw and corrected light curves.
        """
        '''
        # BUGFIX FOR ELEANOR (DEPRICATED)
        # -------------------------------
        from astroquery.mast import Observations
        server = 'https://mast.stsci.edu'
        Observations._MAST_REQUEST_URL = server + "/api/v0/invoke"
        Observations._MAST_DOWNLOAD_URL = server + "/api/v0.1/Download/file"
        Observations._COLUMNS_CONFIG_URL = server + "/portal/Mashup/Mashup.asmx/columnsconfig"
        '''

        # search TESScut to figure out which sectors you need (there's probably a better way to do this)
        sectors = self._find_sectors(ticid)
        if isinstance(ticid, str):
            ticid = int(re.search(r'\d+', str(ticid)).group())
        self.ticid = ticid
        print(
            f'Creating light curve for target {ticid} for sectors {sectors}.')
        # download target data for the desired source for only the first available sector

        star = eleanor.Source(tic=ticid, sector=int(sectors[0]), tc=True)
        try:
            data = eleanor.TargetData(star,
                                      height=11,
                                      width=11,
                                      bkg_size=27,
                                      do_psf=True,
                                      do_pca=True,
                                      try_load=True,
                                      save_postcard=save_postcard)
        except:
            data = eleanor.TargetData(star,
                                      height=7,
                                      width=7,
                                      bkg_size=21,
                                      do_psf=True,
                                      do_pca=True,
                                      try_load=True,
                                      save_postcard=save_postcard)
        q = data.quality == 0
        # create raw flux light curve
        raw_lc = lk.LightCurve(time=data.time[q],
                               flux=data.raw_flux[q],
                               flux_err=data.flux_err[q],
                               label='raw',
                               time_format='btjd').remove_nans().normalize()
        corr_lc = lk.LightCurve(time=data.time[q],
                                flux=data.corr_flux[q],
                                flux_err=data.flux_err[q],
                                label='corr',
                                time_format='btjd').remove_nans().normalize()
        pca_lc = lk.LightCurve(time=data.time[q],
                               flux=data.pca_flux[q],
                               flux_err=data.flux_err[q],
                               label='pca',
                               time_format='btjd').remove_nans().normalize()
        psf_lc = lk.LightCurve(time=data.time[q],
                               flux=data.psf_flux[q],
                               flux_err=data.flux_err[q],
                               label='psf',
                               time_format='btjd').remove_nans().normalize()
        #track breakpoints between sectors
        self.breakpoints = [raw_lc.time[-1]]
        # iterate through extra sectors and append the light curves
        if len(sectors) > 1:
            for s in sectors[1:]:
                try:  # some sectors fail randomly
                    star = eleanor.Source(tic=ticid, sector=int(s), tc=True)
                    data = eleanor.TargetData(star,
                                              height=15,
                                              width=15,
                                              bkg_size=31,
                                              do_psf=True,
                                              do_pca=True,
                                              try_load=True)
                    q = data.quality == 0

                    raw_lc = raw_lc.append(
                        lk.LightCurve(
                            time=data.time[q],
                            flux=data.raw_flux[q],
                            flux_err=data.flux_err[q],
                            time_format='btjd').remove_nans().normalize())
                    corr_lc = corr_lc.append(
                        lk.LightCurve(
                            time=data.time[q],
                            flux=data.corr_flux[q],
                            flux_err=data.flux_err[q],
                            time_format='btjd').remove_nans().normalize())
                    pca_lc = pca_lc.append(
                        lk.LightCurve(
                            time=data.time[q],
                            flux=data.pca_flux[q],
                            flux_err=data.flux_err[q],
                            time_format='btjd').remove_nans().normalize())
                    psf_lc = psf_lc.append(
                        lk.LightCurve(
                            time=data.time[q],
                            flux=data.psf_flux[q],
                            flux_err=data.flux_err[q],
                            time_format='btjd').remove_nans().normalize())

                    self.breakpoints.append(raw_lc.time[-1])
                except:
                    continue
        # store in a LightCurveCollection object and return
        return lk.LightCurveCollection([raw_lc, corr_lc, pca_lc, psf_lc])
Ejemplo n.º 17
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
Ejemplo n.º 18
0
def get_eleanor_lightcurves(tic_id, download_dir=None, targetdata_kwargs=None):
    """This downloads light curves from the Eleanor project for a given TIC ID.

    Parameters
    ----------
    tic_id : str
        The TIC ID of the object as a string.

    download_dir : str
        The light curve FITS files will be downloaded here.

    targetdata_kwargs : dict
        Optional dictionary of keys and values to be passed
        ``eleanor.TargetData`` (see
        https://adina.feinste.in/eleanor/api.html). For instance, you might pass
        ``{'height':8, 'width':8, 'do_pca':True, 'do_psf':True,
        'crowded_field':False}`` to run these settings through to eleanor. The
        default options used if targetdata_kwargs is None are as follows::

            {
                height=15,
                width=15,
                save_postcard=True,
                do_pca=False,
                do_psf=False,
                bkg_size=31,
                crowded_field=True,
                cal_cadences=None,
                try_load=True,
                regressors=None
            }

    Returns
    -------
    lcfiles : list or None
        List of light-curve file paths. These are saved as CSV, rather than
        FITS, by this function.

    """

    if not eleanor_dependency:
        LOGERROR("The eleanor package is required for this function to work.")
        return None

    stars = eleanor.multi_sectors(tic=np.int64(tic_id),
                                  sectors='all',
                                  tc=False)

    for star in stars:

        if targetdata_kwargs is None:
            d = eleanor.TargetData(star,
                                   height=15,
                                   width=15,
                                   save_postcard=True,
                                   do_pca=False,
                                   do_psf=False,
                                   bkg_size=31,
                                   crowded_field=True,
                                   cal_cadences=None,
                                   try_load=True)
        else:
            d = eleanor.TargetData(star, **targetdata_kwargs)

        d.save(directory=download_dir)

    lcfiles = glob(
        os.path.join(download_dir,
                     'hlsp_eleanor_tess_ffi_tic{}*.fits'.format(tic_id)))

    return lcfiles
Ejemplo n.º 19
0
    print(tic_ids)
    star = eleanor.multi_sectors(tic=tic_ids, sectors='all')

    #print('Found TIC {0} (Gaia {1}), with TESS magnitude {2}, RA {3}, and Dec {4}'
    #     .format(star.tic, star.gaia, star.tess_mag, star.coords[0], star.coords[1]))

    #data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_psf=True, do_pca=True, regressors='corner')

    #plt.figure(figsize=(15,5))

    data = []
    #plot_fmt = ['k.', 'r.','k.', 'r.']

    for s in star:
        datum = eleanor.TargetData(s,
                                   do_psf=False,
                                   do_pca=False,
                                   aperture_mode='small')
        data.append(datum)

    plt.figure(num=150)
    plt.scatter(data[0].time, data[0].quality, c='k', marker='.')
    plt.show()

    #plt.imshow(data[0].aperture)
    #plt.show()

    #print(data[0].tpf[400])
    #print(data[0].cen_x, data[0].cen_y)
    #print(data[0].tpf_flux_bkg)

    time = []
Ejemplo n.º 20
0
import numpy as np
import matplotlib.pyplot as plt
import eleanor
from astropy.coordinates import SkyCoord, Angle
from astropy import units as u
import sys, os

ra = 11.096438  # In degrees
dec = -63.56094  # In degrees
coords = SkyCoord(Angle(ra, u.deg), Angle(dec, u.deg))

star = eleanor.Source(coords=coords)
data0 = eleanor.TargetData(star, bkg_type='2d_bkg')
data1 = eleanor.TargetData(star, bkg_type='constant')

q = data0.quality == 0

plt.plot(data0.time[q],
         data0.corr_flux[q] / np.nanmedian(data0.corr_flux[q]),
         'k.',
         label=str(data0.bkg_type))
plt.plot(data1.time[q],
         data1.corr_flux[q] / np.nanmedian(data1.corr_flux[q]),
         'r.',
         label=str(data1.bkg_type))
plt.title('The labels in the legend should be 2D_BKG and CONSTANT.')
plt.legend()
plt.show()
plt.close()

print("Is FFIINDEX working?")
		index = target_id.index(flare)
		good_shot_ra.append(target_ra[index])
		good_shot_dec.append(target_dec[index])
		good_shot_sector.append(target_sector[index])
		good_shot_start.append(target_start_mjd[index])
		good_shot_end.append(target_end_mjd[index])
	except Exception as e:
		print(e)
      
###  
for index, target in enumerate(good_shot_flares):
	try:
		print(target)
		coords = SkyCoord(ra=float(good_shot_ra[index]), dec=float(good_shot_dec[index]), unit=(u.deg,u.deg))
		source = eleanor.Source(coords=coords, sector=good_shot_sector[index])
		data = eleanor.TargetData(source, aperture_mode='small')

		time = []
		flux = []
		background = []
		tpf_qual = []

		q = data.quality == 0
		time.append(data.time[q])
		flux.append(data.corr_flux[q]/np.median(data.corr_flux[q]))
		background.append(data.flux_bkg[q])
		tpf_qual.append(data.tpf[q])

		time = time[0]
		flux = flux[0]
		background = background[0]
Ejemplo n.º 22
0
#%%

for i, this_id in enumerate(ids):
    if duration[i] > 0.32:
        print(i)
        print(this_id)
        print(sector[i])
        star = eleanor.Source(tic=int(this_id), sector=int(sector[i]))
        print(
            'Found TIC {0} (Gaia {1}), with TESS magnitude {2}, RA {3}, and Dec {4}'
            .format(star.tic, star.gaia, star.tess_mag, star.coords[0],
                    star.coords[1]))
        data = eleanor.TargetData(star,
                                  height=15,
                                  width=15,
                                  bkg_size=31,
                                  do_psf=True,
                                  do_pca=True)
        plt.figure(figsize=(15, 5))

        q = data.quality == 0

        #plt.plot(data.time[q], data.raw_flux[q]/np.nanmedian(data.raw_flux[q])+0.06, 'k')
        #plt.plot(data.time[q], data.corr_flux[q]/np.nanmedian(data.corr_flux[q]) + 0.03, 'r')

        #plt.plot(data.time[q], data.psf_flux[q]/np.nanmedian(data.psf_flux[q]) - 0.02, 'b')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time [BJD - 2457000]')
        plt.title('TIC ' + this_id)

        flux_norm = np.average(data.pca_flux[q])
Ejemplo n.º 23
0
def eleanor_lc_download(target_ID, sector, plot_raw = False, plot_corr = False, plot_pca = False, from_file = False, save_path = ''):
    """
    Downloads and returns the various lightcurves produced by the eleanor pipeline:
        raw_lc = lc with flux from simple aperture photometry
        corr_lc = lc with flux 'corrected' for poitning errors etc (though often not trustworthy)
        pca_lc = lc with flux based on principal component analysis
        psf_lc = lc with flux based on point spread function modelling - n.b. sometimes has problems depending on tensorflow version in python
    """
    ra, dec, tic = find_tic(target_ID, from_file = from_file) 
    
    # Locates star in data
    star = eleanor.Source(tic, sector = sector)
    #star = eleanor.Source(coords=(49.4969, -66.9268), sector=1)
    
    # Extract target pixel file, perform aperture photometry and complete some systematics corrections
    data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_psf=False)
    
    q = data.quality == 0
    
    # Plot raw flux
    raw_lc = lightkurve.LightCurve(data.time[q],flux = data.raw_flux[q]/np.median(data.raw_flux[q]), flux_err = data.flux_err[q], targetid = target_ID)
    if plot_raw == True:
        raw_eleanor_fig = plt.figure()
        plt.scatter(data.time[q], data.raw_flux[q]/np.median(data.raw_flux[q]), s=1, c = 'k')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title('{} - eleanor light curve from FFIs - raw flux'.format(target_ID))
#        raw_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor raw flux.png'.format(target_ID, sector))
        #plt.close(raw_eleanor_fig)
        plt.show()
    
    # Plot corrected flux
    corr_lc = lightkurve.LightCurve(data.time[q],flux = data.corr_flux[q]/np.median(data.corr_flux[q]), flux_err = data.flux_err[q], targetid = target_ID)
    if plot_corr == True:
        corr_eleanor_fig = plt.figure()
        plt.scatter(data.time[q], data.corr_flux[q]/np.median(data.corr_flux[q]), s=1, c= 'r')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title('{} - eleanor light curve from FFIs - corr flux'.format(target_ID))
        #corr_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor corr flux.png'.format(target_ID, sector))
        #plt.close(corr_eleanor_fig)
        plt.show()
    
    # Plot pca flux
    eleanor.TargetData.pca(data, flux=data.raw_flux, modes=4)
    pca_lc = lightkurve.LightCurve(data.time[q], flux = data.pca_flux[q]/np.median(data.pca_flux[q]), flux_err = data.flux_err[q], targetid = target_ID)
    if plot_pca == True:
        pca_eleanor_fig = plt.figure()
        plt.scatter(data.time[q], data.pca_flux[q]/np.median(data.pca_flux[q]), s=1, c= 'g')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title('{} - eleanor light curve from FFIs - pca flux'.format(target_ID))
        #pca_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor pca flux.png'.format(target_ID, sector))
        #plt.close(pca_eleanor_fig)
        plt.show()
    
    # Plot psf flux
    #eleanor.TargetData.psf_lightcurve(data, model='gaussian', likelihood='poisson')
    #psf_lc = lightkurve.LightCurve(data.time[q], flux = data.psf_flux[q]/np.median(data.psf_flux[q]), flux_err = data.flux_err[q], targetid = target_ID)
    #psf_eleanor_fig = plt.figure()
    #plt.scatter(data.time[q], data.psf_flux[q]/np.median(data.psf_flux[q]), s=1, c= 'g')
    #plt.ylabel('Normalized Flux')
    #plt.xlabel('Time')
    #plt.title('{} - eleanor light curve from FFIs - psf flux'.format(target_ID))
    #psf_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor psf flux.png'.format(target_ID, sector))
    #plt.show()
    
    return raw_lc, corr_lc, pca_lc #,psf_lc
Ejemplo n.º 24
0
def eleanor_lc(savepath, RADECfile, plotting=True):
    """ 
    retrieves + produces eleanor light curves from FFI files
    """
    import eleanor
    from astropy import units as u
    from astropy.coordinates import SkyCoord
    import warnings
    warnings.filterwarnings('ignore')
    from eleanor.utils import SearchError
    from scipy.linalg.misc import LinAlgError

    download_dir_tesscut = os.path.join(os.path.expanduser('~'), '.eleanor',
                                        'tesscut')

    download_dir_mastdownload = os.path.join(os.path.expanduser('~'),
                                             '.eleanor', 'mastDownload')
    print(download_dir_tesscut, download_dir_mastdownload)

    with open(RADECfile, 'r') as f:
        lines = f.readlines()
        for line in lines:
            ID, RA, DEC, sector = line.split(',')
            print(ID, RA, DEC, sector)
            sector_int = int(sector)

            filepath = savepath + ID + "_s" + str(sector_int) + "_lc.txt"

            if not os.path.isfile(filepath):
                try:
                    coords = SkyCoord(ra=RA, dec=DEC, unit=(u.deg, u.deg))
                    files = eleanor.Source(coords=coords,
                                           tic=0,
                                           gaia=0,
                                           sector=sector_int)
                    #print("files found: ", len(files))
                    print(
                        'Found TIC {0} (Gaia {1}), with TESS magnitude {2}, RA {3}, and Dec {4}'
                        .format(files.tic, files.gaia, files.tess_mag,
                                files.coords[0], files.coords[1]))
                    #try:
                    data = eleanor.TargetData(files, do_pca=True)
                    q = data.quality == 0

                    timeandflux = np.asarray((data.time[q], data.corr_flux[q]))

                    plt.scatter(data.time[q], data.raw_flux[q], label="raw")
                    plt.scatter(data.time[q], data.corr_flux[q], label="corr")
                    plt.legend(loc="upper left")
                    plt.show()

                    np.savetxt(filepath, timeandflux)

                except (SearchError, ValueError):
                    print("******************************")
                    print("Search Error or ValueError occurred")
                    print("******************************")

                except OSError:
                    print("******************************")
                    print("Empty or corrupt FITS file")
                    print("******************************")
                except LinAlgError:
                    print("******************************")
                    print("SVD did not converge")
                    print("******************************")
                except IndexError:
                    print("******************************")
                    print("Couldn't find these coordinates in")
                    print("******************************")
                #except TypeError:
                #   print("******************************")
                #  print("Issue with internal function while trying to read file")
                # print("******************************")
            else:
                print("Already found this target")

            for root, dirs, files in os.walk(download_dir_tesscut):
                for file in files:
                    try:
                        os.remove(os.path.join(root, file))
                        print("Deleted")
                    except (PermissionError, OSError):
                        #print("Unable to delete", os.path.join(root, file))
                        continue
            for root, dirs, files in os.walk(download_dir_mastdownload):
                for file in files:
                    try:
                        os.remove(os.path.join(root, file))
                        print("Deleted")
                    except (PermissionError, OSError):
                        #print("Deleted", os.path.join(root, file))
                        continue

    return
Ejemplo n.º 25
0
    return binned_lc


###############################################################################
# Main

log = logging.getLogger(__name__)

# Assign star of interest
#star = eleanor.Source(tic=29857954, sector=1)
star = eleanor.Source(coords=(319.94962, -58.1489), sector=1)
#star = eleanor.Source(gaia=4675352109658261376, sector=1)

# Extract target pixel file, perform aperture photometry and complete some systematics corrections
#data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_psf=False)
data = eleanor.TargetData(star)

q = data.quality == 0

# Plot a lightcurve or a few...
plt.figure()
plt.plot(data.time[q], data.raw_flux[q] / np.median(data.raw_flux[q]) - 0.01,
         'k')
plt.plot(data.time[q], data.corr_flux[q] / np.median(data.corr_flux[q]) + 0.01,
         'r')
#plt.plot(data.time[q], data.pca_flux[q]/np.median(data.pca_flux[q]) + 0.03, 'y')

plt.ylabel('Normalized Flux')
plt.xlabel('Time')
plt.show()
Ejemplo n.º 26
0
def eleanor_lc_download(target_ID,
                        sector,
                        plot_raw=False,
                        plot_corr=False,
                        plot_pca=False,
                        from_file=False,
                        save_path=''):
    """
    Downloads and returns the various lightcurves produced by the eleanor pipeline:
        raw_lc = lc with flux from simple aperture photometry
        corr_lc = lc with flux 'corrected' for poitning errors etc (though often not trustworthy)
        pca_lc = lc with flux based on principal component analysis
        psf_lc = lc with flux based on point spread function modelling - n.b. sometimes has problems depending on tensorflow version in python
    """
    if from_file == True:
        table_data = Table.read("BANYAN_XI-III_members_with_TIC.csv",
                                format='ascii.csv')

        # Obtains ra and dec for object from target_ID
        i = list(table_data['main_id']).index(target_ID)
        ra = table_data['ra'][i]
        dec = table_data['dec'][i]
        tic = table_data['MatchID'][i]
    else:
        # Find ra, dec and tic # via the TIC (typically based on Gaia DR2)
        TIC_table = Catalogs.query_object(target_ID, catalog="TIC")
        #        ra = TIC_table['ra'][0]
        #        dec = TIC_table['dec'][0]
        #        tic = TIC_table['ID'][0]
        tic = target_ID

    # Locates star in data
    star = eleanor.Source(tic, sector=sector)
    #star = eleanor.Source(coords=(49.4969, -66.9268), sector=1)

    # Extract target pixel file, perform aperture photometry and complete some systematics corrections
    data = eleanor.TargetData(star,
                              height=15,
                              width=15,
                              bkg_size=31,
                              do_psf=False)

    q = data.quality == 0

    # Plot raw flux
    raw_lc = lightkurve.LightCurve(data.time[q],
                                   flux=data.raw_flux[q] /
                                   np.median(data.raw_flux[q]),
                                   flux_err=data.flux_err[q],
                                   targetid=target_ID)
    if plot_raw == True:
        raw_eleanor_fig = plt.figure()
        plt.scatter(data.time[q],
                    data.raw_flux[q] / np.median(data.raw_flux[q]),
                    s=1,
                    c='k')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title(
            '{} - eleanor light curve from FFIs - raw flux'.format(target_ID))
        #        raw_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor raw flux.png'.format(target_ID, sector))
        #plt.close(raw_eleanor_fig)
        plt.show()

    # Plot corrected flux
    corr_lc = lightkurve.LightCurve(data.time[q],
                                    flux=data.corr_flux[q] /
                                    np.median(data.corr_flux[q]),
                                    flux_err=data.flux_err[q],
                                    targetid=target_ID)
    if plot_corr == True:
        corr_eleanor_fig = plt.figure()
        plt.scatter(data.time[q],
                    data.corr_flux[q] / np.median(data.corr_flux[q]),
                    s=1,
                    c='r')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title(
            '{} - eleanor light curve from FFIs - corr flux'.format(target_ID))
        #corr_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor corr flux.png'.format(target_ID, sector))
        #plt.close(corr_eleanor_fig)
        plt.show()

    # Plot pca flux
    eleanor.TargetData.pca(data, flux=data.raw_flux, modes=4)
    pca_lc = lightkurve.LightCurve(data.time[q],
                                   flux=data.pca_flux[q] /
                                   np.median(data.pca_flux[q]),
                                   flux_err=data.flux_err[q],
                                   targetid=target_ID)
    if plot_pca == True:
        pca_eleanor_fig = plt.figure()
        plt.scatter(data.time[q],
                    data.pca_flux[q] / np.median(data.pca_flux[q]),
                    s=1,
                    c='g')
        plt.ylabel('Normalized Flux')
        plt.xlabel('Time')
        plt.title(
            '{} - eleanor light curve from FFIs - pca flux'.format(target_ID))
        pca_eleanor_fig.savefig(
            save_path +
            '{} - Sector {} - eleanor pca flux.png'.format(target_ID, sector))
        plt.close(pca_eleanor_fig)
        #plt.show()

    # Plot psf flux
    #eleanor.TargetData.psf_lightcurve(data, model='gaussian', likelihood='poisson')
    #psf_lc = lightkurve.LightCurve(data.time[q], flux = data.psf_flux[q]/np.median(data.psf_flux[q]), flux_err = data.flux_err[q], targetid = target_ID)
    #psf_eleanor_fig = plt.figure()
    #plt.scatter(data.time[q], data.psf_flux[q]/np.median(data.psf_flux[q]), s=1, c= 'g')
    #plt.ylabel('Normalized Flux')
    #plt.xlabel('Time')
    #plt.title('{} - eleanor light curve from FFIs - psf flux'.format(target_ID))
    #psf_eleanor_fig.savefig(save_path + '{} - Sector {} - eleanor psf flux.png'.format(target_ID, sector))
    #plt.show()

    return raw_lc, corr_lc, pca_lc  #, psf_lc
Ejemplo n.º 27
0
	try:
		print(i)
		star = eleanor.multi_sectors(tic=i, sectors='all')

		#print('Found TIC {0} (Gaia {1}), with TESS magnitude {2}, RA {3}, and Dec {4}'
		#     .format(star.tic, star.gaia, star.tess_mag, star.coords[0], star.coords[1]))

		#data = eleanor.TargetData(star, height=15, width=15, bkg_size=31, do_psf=True, do_pca=True, regressors='corner')

		#plt.figure(figsize=(15,5))

		data = []
		#plot_fmt = ['k.', 'r.','k.', 'r.']

		for s in star:
		    datum = eleanor.TargetData(s, height=15, width=15, bkg_size=31, do_psf=False, do_pca=False, aperture_mode='small')
		    data.append(datum)

		time = []
		#time_1 = []
		#time_2 = []
		flux = []
		#flux_1 = []
		#flux_2 = []
		#half_1 = []
		#half_2 = []
		background = []
		for sector, datum in enumerate(data):
		    q = datum.quality == 0
		    #plt.plot(datum.time[q], datum.corr_flux[q]/np.median(datum.corr_flux[q]), plot_fmt[sector])
		    #half_1 = datum[int(0.025*len(datum)):int(0.475*len(datum))]
Ejemplo n.º 28
0
import eleanor
import numpy as np
from astropy import units as u
import matplotlib.pyplot as plt
from astropy.coordinates import SkyCoord
import lightkurve as lk

#eleanor.Update(sector=1)

star = eleanor.Source(name='WASP-100', sector=3)
print(star.gaia)

data = eleanor.TargetData(star, do_psf=True, do_pca=True)

#plt.title('2D background')
#plt.imshow(data.post_obj.background2d[100], vmin=0, vmax=20)
#plt.colorbar()
#plt.show()

#print(data.bkg_type)

#plt.figure(figsize=[14,4])
#plt.plot(data.time, data.post_obj.bkg, 'b', lw=3)
#plt.xlabel('time [bjd-2457000]')
#plt.ylabel('background flux')
#plt.show()

#plt.imshow(data.tpf[100])
#plt.imshow(data.aperture, alpha =0.4, cmap='Greys_r')
#plt.show()