Exemple #1
0
def get_all_TESS_data(object_name, radius = ".02 deg", get_PDC = True, get_all = False):
    """ 
    Given a planet name, this function returns a dictionary of times, fluxes and 
    errors on fluxes in a juliet-friendly format for usage. The function does an 
    astroquery to MAST using a default radius of .02 deg around the target name. If get_PDC is True, 
    this function returns PDC fluxes. False returns SAP fluxes. If get_all is true, this function 
    returns a dictionary that in addition to the times, fluxes and errors, returns other 
    metadata.
    """
    if not has_astroquery:
        print("Error on using juliet function `get_all_TESS_data`: astroquery.mast not found.")
    obs_table = Observations.query_object(object_name,radius=radius)
    out_dict = {}
    times = {}
    fluxes = {}
    fluxes_errors = {}
    for i in range(len(obs_table['dataURL'])):
        if 's_lc.fits' in obs_table['dataURL'][i]:
            fname = obs_table['dataURL'][i].split('/')[-1]
            metadata = fname.split('-')
            if len(metadata) == 5:
                # Extract metadata:
                sector = np.int(metadata[1].split('s')[-1])
                ticid = np.int(metadata[2])
                # Download files:
                data_products = Observations.get_product_list(obs_table[i])
                manifest = Observations.download_products(data_products)
                # Read lightcurve file:
                d,h = fits.getdata('mastDownload/TESS/'+fname[:-8]+'/'+fname,header=True)
                t,fs,fserr,f,ferr = d['TIME']+h['BJDREFI'],d['SAP_FLUX'],d['SAP_FLUX_ERR'],\
                                    d['PDCSAP_FLUX'],d['PDCSAP_FLUX_ERR']
                idx_goodpdc = np.where((f != 0.)&(~np.isnan(f)))[0]
                idx_goodsap = np.where((fs != 0.)&(~np.isnan(fs)))[0]
                # Save to output dictionary:
                if 'TIC' not in out_dict.keys():
                    out_dict['TIC'] = ticid
                out_dict[sector] = {}
                out_dict[sector]['TIME_PDCSAP_FLUX'] = t[idx_goodpdc]
                out_dict[sector]['PDCSAP_FLUX'] = f[idx_goodpdc]
                out_dict[sector]['PDCSAP_FLUX_ERR'] = ferr[idx_goodpdc]
                out_dict[sector]['TIME_SAP_FLUX'] = t[idx_goodsap]
                out_dict[sector]['SAP_FLUX'] = fs[idx_goodsap]
                out_dict[sector]['SAP_FLUX_ERR'] = fserr[idx_goodsap]
                if get_PDC:
                    times['TESS'+str(sector)] = t[idx_goodpdc]
                    med = np.median(f[idx_goodpdc])
                    fluxes['TESS'+str(sector)] = f[idx_goodpdc]/med
                    fluxes_errors['TESS'+str(sector)] = ferr[idx_goodpdc]/med
                else:
                    times['TESS'+str(sector)] = t[idx_goodsap]
                    med = np.median(fs[idx_goodsap])
                    fluxes['TESS'+str(sector)] = fs[idx_goodsap]/med
                    fluxes_errors['TESS'+str(sector)] = fserr[idx_goodsap]/med
                # Remove downloaded folder:
                os.system('rm -r mastDownload')
    if get_all:
        return out_dict, times, fluxes, fluxes_errors
    else:
        return times, fluxes, fluxes_errors
Exemple #2
0
def getTPF(object_name, radius=".02 deg", P=None, t0=None, tdur=None):
    """
    Given an object name, a period, a transit-time and a transit duration for an exoplanet, this function gets you a PLD corrected 
    lightcurve. PLD coefficients are trained on the out-of-transit data.
    """
    obs_table = Observations.query_object(object_name, radius=radius)
    for i in range(len(obs_table['dataURL'])):

        print(obs_table['dataURL'][i])
Exemple #3
0
 def scrape_HST(self):
     """
     Checks MAST for the target's relevant HST proposals/data.
     Modifies hst_approved: if there are observations, sets it to True; otherwise False.
     Appends links to relevant HST data to hst_data.
     """
     obs = Observations.query_object(self.input_name, radius=".02 deg") # should work. waliases
     HST_obs = obs[obs['obs_collection']=='HST']
     if len(HST_obs) > 0:
         self.hst_approved = True
         for ob in HST_obs:
             self.hst_data[ob['obs_title']] = ob['dataURL']
     if self.hst_approved is None:
         self.hst_approved = False
Exemple #4
0
 def scrape_webb_MAST(self):
     """
     Checks MAST for the target's relevant JWST proposals/data.
     Modifies webb_approved: if there are relevant proposals, sets it to True; otherwise False.
     Appends the names of these proposals to webb_proposal_names.
     """
     obs = Observations.query_object(self.input_name, radius=".02 deg") # should work. waliases
     JWST_obs = obs[obs['obs_collection']=='JWST']
     if len(JWST_obs) > 0:
         self.webb_approved = True
         for ob in JWST_obs:
             self.webb_proposal_names.append(ob['obs_title'])
     if self.webb_approved is None:
         self.webb_approved = False
     return
Exemple #5
0
    def download(self, products=['LC'], download_dir=None):
        """
        Dowload, reorganize, and simple rename desired data products.
        Updates:
            - get SPOC_df and product list ONLY option (maybe separate query() function)
            - simple rename function
        """
        self.target_path = None
        self.parent_folder = download_dir
        if self.tic != "tic issue":
            if self.tic != None:
                if download_dir != None:
                    self.folder_name = os.path.join(download_dir, self.tic)

        if products == "all":
            self.products = ['LC', 'DVM', 'TP', 'DVT', 'DVS', 'DVR']
        else:
            self.products = products

        def reorganize():  #bring all files to top level
            print("Reorganizing...")
            ### EXTRACT ALL FILES
            #get down to where sector folders are, get list of folder names
            get_down = os.path.join(self.folder_name, 'mastDownload', 'TESS')
            sub_folders = os.listdir(get_down)

            for sub in sub_folders:
                #get file list of subfolder
                sub_path = os.path.join(get_down, sub)
                file_list = os.listdir(sub_path)

                #copy files into parent self.folder_name
                for file in file_list:
                    file_path = os.path.join(sub_path, file)
                    new_loc = os.path.join(self.folder_name, file)
                    shutil.copyfile(src=file_path, dst=new_loc)

            ### DELETE 'mastDownload' FOLDER
            delete_dir = os.path.join(self.folder_name, 'mastDownload')
            shutil.rmtree(delete_dir)

        #def rename(): simple rename for all data products: tic#######_sector####_'type'.'type'

        def LC_extract():  #extract LC data from all sectors, label by sector
            print("Extracting LC...")

            # IDENTIFY LC files

            file_list = os.listdir(self.folder_name)
            LC_list = []
            for file in file_list:
                file_type = os.path.splitext(file)[-2].split("_")[-1]
                if file_type == 'lc':
                    LC_list.append(file)
            self.LC_list = LC_list
            # COMBINE LC'S INTO SINGLE DATAFRAME
            temp_df_list = []
            for lc in LC_list:
                # append LC data
                lc_path = os.path.join(self.folder_name, lc)
                temp_df = self.get_LC_data(lc_path)
                # add sector label column
                sect = lc.split("-")[1].split("s")[-1][-2:]
                temp_sector = np.repeat(a=sect, repeats=len(temp_df['time']))
                temp_df['sector'] = temp_sector

                temp_df_list.append(temp_df)

            lc_df = pd.concat(temp_df_list, ignore_index=True)
            self.spoc_lc = lc_df

        ### DO THE DOWNLOADING
        query_string = "tic " + self.tic
        try:
            obs_table = Observations.query_object(query_string,
                                                  radius=0.0005 * u.deg)
            self.SPOC_table = obs_table[obs_table['provenance_name'] == 'SPOC']
            self.SPOC_df = self.SPOC_table.to_pandas()
            self.FFI_ids = self.SPOC_df[self.SPOC_df['dataproduct_type'] ==
                                        'image']['obsid'].to_numpy(dtype='str')
            self.timeseries_ids = self.SPOC_df[
                self.SPOC_df['dataproduct_type'] ==
                'timeseries']['obsid'].to_numpy(dtype='str')
            Observations.download_products(
                self.timeseries_ids,
                download_dir=self.folder_name,
                productSubGroupDescription=self.products)
            reorganize()
            LC_extract()

            self.query_success = "success"
        except:
            self.query_success = "fail"
Exemple #6
0
"""
Example 10
++++++++++
Retrieve Hubble archival data of M83 and make a figure
"""

from astropy.io import fits
from astropy.visualization import make_lupton_rgb, ImageNormalize
import matplotlib.pyplot as plt
import reproject

from astroquery.mast import Observations

result = Observations.query_object('M83')
selected_bands = result[(result['obs_collection'] == 'HST')
                        & (result['instrument_name'] == 'WFC3/UVIS') &
                        ((result['filters'] == 'F657N') |
                         (result['filters'] == 'F487N') |
                         (result['filters'] == 'F336W')) &
                        (result['target_name'] == 'MESSIER-083')]
prodlist = Observations.get_product_list(selected_bands)
filtered_prodlist = Observations.filter_products(prodlist)

downloaded = Observations.download_products(filtered_prodlist)

blue = fits.open(downloaded['Local Path'][2])
red = fits.open(downloaded['Local Path'][5])
green = fits.open(downloaded['Local Path'][8])

target_header = red['SCI'].header
green_repr, _ = reproject.reproject_interp(green['SCI'], target_header)
Exemple #7
0
    def tasoc_lc(self):
        """
        Grabs the T'DA available light curves for your target.
        For more information, see the TASOC light curve documentation: https://tasoc.dk/code/.

        Parameters
        ----------

        Attributes
        ----------
        tasoc_header : 
        tasoc_tpf : np.2darray
        tasoc_aperture : np.2darray
        tasoc_time : np.array
        tasoc_quality : np.array
        tasoc_timecorr : np.array
        tasoc_cadenceno : np.array
        tasoc_flux_raw : np.array
        tasoc_flux_raw_err : np.array
        tasoc_flux_corr : np.array
        tasoc_flux_corr_err : np.array
        tasoc_flux_bkg : np.array
        tasoc_pixel_quality : np.array
             Quality flags for the data; use these not `tasoc_quality`.
        tasoc_pos_corr1 : np.array
        tasoc_pos_corr2 : np.array
        tasoc_mom_centr1 : np.array
        tasoc_mom_centr2 : np.array
        """
        products = Observations.query_object(objectname="TIC" + str(self.tic))

        column = np.where((products['provenance_name'] == 'TASOC')
                          & (products['target_name'] == str(self.tic))
                          & (products['sequence_number'] == self.sector))[0]

        if len(column) > 0:
            download = Observations.get_product_list(products[column])
            manifest = Observations.download_products(
                download, download_dir=self.download_dir)
            self.tasoc_path = manifest["Local Path"].data[0]

            hdu = fits.open(self.tasoc_path)

            self.tasoc_header = hdu[0].header
            self.tasoc_tpf = hdu[2].data
            self.tasoc_aperture = hdu[3].data
            self.tasoc_time = hdu[1].data['TIME']
            self.tasoc_quality = hdu[1].data['QUALITY']
            self.tasoc_timecorr = hdu[1].data['TIMECORR']
            self.tasoc_cadenceno = hdu[1].data['CADENCENO']
            self.tasoc_flux_raw = hdu[1].data['FLUX_RAW']
            self.tasoc_flux_bkg = hdu[1].data['FLUX_BKG']
            self.tasoc_flux_corr = hdu[1].data['FLUX_CORR']
            self.tasoc_pos_corr1 = hdu[1].data['POS_CORR1']
            self.tasoc_pos_corr2 = hdu[1].data['POS_CORR2']
            self.tasoc_mom_centr1 = hdu[1].data['MOM_CENTR1']
            self.tasoc_mom_centr2 = hdu[1].data['MOM_CENTR2']
            self.tasoc_pixel_quality = hdu[1].data['PIXEL_QUALITY']
            self.tasoc_flux_raw_err = hdu[1].data['FLUX_RAW_ERR']
            self.tasoc_flux_corr_err = hdu[1].data['FLUX_CORR_ERR']

        else:
            raise SearchError("No TASOC light curve found.")
Exemple #8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 19:31:11 2020

@author: smullally
"""

from astroquery.mast import Observations

Observations.enable_cloud_dataset(provider='AWS')

target = "Kepler-10"

#Do a cone search and find the Kepler long cadence data for your target
obs = Observations.query_object(target, radius="0s")
want = (obs['obs_collection'] == "Kepler") & (obs['t_exptime'] == 1800.0)

#Pick which data you want to retrieve
data_prod = Observations.get_product_list(obs[want])
filt_prod = Observations.filter_products(
    data_prod, description="Lightcurve Long Cadence (CLC) - Q4")

#Move data from the S3 bucket to the default astroquery location.
#cloud_only=True means that data will only be retrieved if available on AWS S3
manifest = Observations.download_products(filt_prod)

#%%
import pdb

from lightkurve import search_targetpixelfile
Exemple #9
0
def tess_target_download(targID,
                         sectors='all',
                         sc=True,
                         lc_format='pdc',
                         delete_fits='n'):
    ### this function interfaces with MASS to download light curves based on the TIC #.
    if os.path.exists(moonpydir + '/TESS_lcs'):
        pass
    else:
        os.system('mkdir ' + moonpydir + '/TESS_lcs')

    ### first try a simple curl script!

    all_times = []
    all_fluxes = []
    all_errors = []
    all_flags = []
    sectors = []
    lcfiles = []

    try:
        if targID.startswith('TIC'):
            ticnum = str(targID)[3:]
            if ticnum.startswith(' '):
                ticnum = str(ticnum)[1:]
        else:
            ticnum = str(targID)  ### you've already handled the TOI already!
            if ticnum.startswith(' '):
                ticnum = ticnum[1:]

        ### prepare for the query
        query_num = ticnum
        while len(query_num) < 16:
            query_num = '0' + query_num
        assert len(query_num) == 16

        sector_prefixes, sector_suffixes = {}, {}

        ### these can be found at archive.stsci.edu/tess/bulk_downloads/bulk_downloads_ffi-tp-lc-dv.html,
        ### in the tesscurl_sector_NN_lc.sh files.

        nsectors = 99
        nactual_sectors = 0
        for sector in np.arange(1, nsectors, 1):
            ### get the curl script... then extract the prefixes and suffixes from the first line.

            try:
                if os.path.exists(moonpydir + '/sector' + str(sector) +
                                  "_curlscript.txt"):
                    pass
                else:
                    sector_curl_URL = 'http://archive.stsci.edu/missions/tess/download_scripts/sector/tesscurl_sector_' + str(
                        sector) + '_lc.sh'
                    os.system('wget --tries=1 -N "' + sector_curl_URL +
                              '" -O ' + moonpydir + '/sector' + str(sector) +
                              "_curlscript.txt")

                curltxt = open(moonpydir + '/sector' + str(sector) +
                               '_curlscript.txt',
                               mode='r')
                first_line = curltxt.readline()
                second_line = curltxt.readline()
                sector_prefix = second_line[16:40]
                sector_suffix = second_line[56:71]
                ### now read the first line of that
                sector_prefixes[sector], sector_suffixes[
                    sector] = sector_prefix, sector_suffix
                if len(sector_prefix) > 0:
                    print("sector_prefix, sector_suffix = ", sector_prefix,
                          sector_suffix)
                    nactual_sectors += 1
                else:
                    break
            except:
                traceback.print_exc()
                break
        nsectors = nactual_sectors
        print('nsectors = ', nsectors)
        """
		sector_prefixes[1], sector_suffixes[1] = 'tess2018206045859-s0001-', '-0120-s_lc.fits'
		sector_prefixes[2], sector_suffixes[2] = 'tess2018234235059-s002-', '-0121-s_lc.fits'
		sector_prefixes[3], sector_suffixes[3] = 'tess2018263035959-s0003-', '-0123-s_lc.fits'
		sector_prefixes[4], sector_suffixes[4] = 'tess2018292075959-s0004-', '-0124-s_lc.fits'
		sector_prefixes[5], sector_suffixes[5] = 'tess2018319095959-s0005-', '-0125-s_lc.fits'
		sector_prefixes[6], sector_suffixes[6] = 'tess2018349182459-s0006-', '-0126-s_lc.fits'
		sector_prefixes[7], sector_suffixes[7] = 'tess2019006130736-s0007-', '-0131-s_lc.fits'
		sector_prefixes[8], sector_suffixes[8] = 'tess2019032160000-s0008-', '-0136-s_lc.fits'
		sector_prefixes[9], sector_suffixes[9] = 'tess2019058134432-s0009-', '-0139-s_lc.fits'
		sector_prefixes[10], sector_suffixes[10] = 'tess2019085135100-s0010-', '-0140-s_lc.fits'
		sector_prefixes[11], sector_suffixes[11] = 'tess2019112060037-s0011-', '-0143-s_lc.fits'
		sector_prefixes[12], sector_suffixes[12] = 'tess2019140104343-s0012-', '-0144-s_lc.fits'
		sector_prefixes[13], sector_suffixes[13] = 'tess2019169103026-s0013-', '-0146-s_lc.fits'
		sector_prefixes[14], sector_suffixes[14] = 'tess2019198215352-s0014-', '-0150-s_lc.fits'
		sector_prefixes[15], sector_suffixes[15] = 'tess2019226182529-s0015-', '-0151-s_lc.fits'
		sector
		nsectors = 28
		"""

        for sector in np.arange(1, nsectors + 1, 1):

            download_directory = central_data_dir + 'TESS_lightcurves/TIC' + str(
                ticnum)
            if os.path.exists(download_directory):
                pass
            else:
                os.system('mkdir ' + download_directory)

            lcdownload_name = 'TIC' + ticnum + '_sector' + str(
                sector) + '-s_lc.fits'
            os.system(
                'curl -C - -L -o ' + download_directory + '/' +
                lcdownload_name +
                ' https://mast.stsci.edu/api/v0.1/Download/file/?uri=mast:TESS/product/'
                + sector_prefixes[sector] + query_num +
                sector_suffixes[sector])
            print(
                'downloading the light curve for ' + str(targID) +
                ' in sector ', sector)

            try:
                lcfile = pyfits.open(moonpydir + '/TESS_lcs/' +
                                     lcdownload_name)
            except:
                os.system('rm -rf ' + moonpydir + '/TESS_lcs/' +
                          lcdownload_name)
                continue

            lcfiles.append(lcfile)
            lcdata = lcfile[1].data
            lctimes = np.array(lcdata['TIME'])
            if lc_format == 'pdc':
                lcfluxes = np.array(lcdata['PDCSAP_FLUX'])
                lcerrors = np.array(lcdata['PDCSAP_FLUX_ERR'])
            elif lc_format == 'sap':
                lcfluxes = np.array(lcdata['SAP_FLUX'])
                lcerrors = np.array(lcdata['SAP_FLUX_ERR'])
            lcflags = np.array(lcdata['QUALITY'])
            sector = lcfile[0].header['SECTOR']

            all_times.append(lctimes)
            all_fluxes.append(lcfluxes)
            all_errors.append(lcerrors)
            all_flags.append(lcflags)
            sectors.append(sector)

            if delete_fits == 'y':
                os.system('rm -rf ' + moonpydir + '/TESS_lcs/' +
                          lcdownload_name)

    except:
        traceback.print_exc()
        time.sleep(60)

        obsTable = Observations.query_object(targID, radius='0.001 deg')
        TESS_idxs = np.where(np.array(obsTable['obs_collection']) == 'TESS')[0]
        minTESSidx, maxTESSidx = np.nanmin(TESS_idxs), np.nanmax(TESS_idxs) + 1
        dataproducts = Observations.get_product_list(
            obsTable[minTESSidx:maxTESSidx])
        timeseries_idxs = np.where(
            np.array(dataproducts['dataproduct_type']) == 'timeseries')[0]
        obsids = np.array(dataproducts)['obsID'][timeseries_idxs]

        for obsid in np.unique(obsids):
            print("obsid = ", obsid)
            dataproductsbyID = Observations.get_product_list(obsid)
            manifest = Observations.download_products(
                dataproductsbyID,
                download_dir=moonpydir + '/TESS_lcs',
                dataproduct_type='timeseries',
                extension='lc.fits',
                mrp_only=True)

            for nmanfile, manfile in enumerate(manifest):
                manfilepath = manfile[0]
                if "_lc.fits" in manfilepath:
                    print('found the light curve!')
                    ### this is the only one you want to save!
                    lcpath = manfilepath
                    print("lcpath = ", lcpath)

                    ### open the file, grab the data!
                    lcfile = pyfits.open(lcpath)
                    lcfiles.append(lcfile)
                    lcdata = lcfile[1].data
                    lctimes = np.array(lcdata['TIME'])
                    if lc_format == 'pdc':
                        lcfluxes = np.array(lcdata['PDCSAP_FLUX'])
                        lcerrors = np.array(lcdata['PDCSAP_FLUX_ERR'])
                    elif lc_format == 'sap':
                        lcfluxes = np.array(lcdata['SAP_FLUX'])
                        lcerrors = np.array(lcdata['SAP_FLUX_ERR'])
                    lcflags = np.array(lcdata['QUALITY'])
                    sector = lcfile[0].header['SECTOR']

                    all_times.append(lctimes)
                    all_fluxes.append(lcfluxes)
                    all_errors.append(lcerrors)
                    all_flags.append(lcflags)
                    sectors.append(sector)

                    if delete_fits == 'y':
                        os.system('rm ' + lcpath)
                    break

                else:
                    pass
                    #os.system('rm -rf '+manfilepath)

            print(" ")
            print(" ")

    all_times, all_fluxes, all_errors, all_flags, sectors = np.array(
        all_times), np.array(all_fluxes), np.array(all_errors), np.array(
            all_flags), np.array(sectors)

    return all_times, all_fluxes, all_errors, all_flags, sectors
Exemple #10
0
"""
Example 10
++++++++++
Retrieve Hubble archival data of M83 and make a figure
"""
from astroquery.mast import Mast, Observations
from astropy.visualization import make_lupton_rgb, ImageNormalize
import matplotlib.pyplot as plt
import reproject

result = Observations.query_object('M83')
selected_bands = result[(result['obs_collection'] == 'HST') &
                        (result['instrument_name'] == 'WFC3/UVIS') &
                        ((result['filters'] == 'F657N') |
                         (result['filters'] == 'F487N') |
                         (result['filters'] == 'F336W')) &
                        (result['target_name'] == 'MESSIER-083')]
prodlist = Observations.get_product_list(selected_bands)
filtered_prodlist = Observations.filter_products(prodlist)

downloaded = Observations.download_products(filtered_prodlist)

blue = fits.open(downloaded['Local Path'][2])
red = fits.open(downloaded['Local Path'][5])
green = fits.open(downloaded['Local Path'][8])

target_header = red['SCI'].header
green_repr, _ = reproject.reproject_interp(green['SCI'], target_header)
blue_repr, _ = reproject.reproject_interp(blue['SCI'], target_header)

Exemple #11
0
def get_tess_data(u_ticid, max_flag=16, out_dir='./download'):
    """Given a TIC-ID, return time,flux,ferr,itime
    u_ticid : (int) TIC ID

    returns lc_time,flux,ferr,int_time
    """
    tic_str = 'TIC' + str(u_ticid)
    #out_dir='/data/rowe/TESS/download/'

    # Search MAST for TIC ID
    obs_table = Observations.query_object(tic_str, radius=".002 deg")

    # Identify TESS timeseries data sets (i.e. ignore FFIs)
    oti=(obs_table["obs_collection"] == "TESS") & \
            (obs_table["dataproduct_type"] == "timeseries")
    if oti.any() == True:
        data_products = Observations.get_product_list(obs_table[oti])
        dpi = [
            j for j, s in enumerate(data_products["productFilename"])
            if "lc.fits" in s
        ]
        manifest = Observations.download_products(data_products[dpi],
                                                  download_dir=out_dir)
    else:
        manifest = []

    lc_time = []
    flux = []
    ferr = []
    int_time = []
    for j in range(0, len(manifest)):
        fits_fname = str(manifest["Local Path"][j])
        print(fits_fname)
        hdu = fits.open(fits_fname)
        tmp_bjd = hdu[1].data['TIME']
        tmp_flux = hdu[1].data['PDCSAP_FLUX']
        tmp_ferr = hdu[1].data['PDCSAP_FLUX_ERR']
        tmp_int_time = hdu[1].header['INT_TIME'] + np.zeros(len(tmp_bjd))
        tmp_flag = hdu[1].data['QUALITY']

        ii = (tmp_flag <= max_flag) & (~np.isnan(tmp_flux))
        tmp_bjd = tmp_bjd[ii]
        tmp_flux = tmp_flux[ii]
        tmp_ferr = tmp_ferr[ii]
        tmp_int_time = tmp_int_time[ii]
        # Shift flux measurements
        median_flux = np.median(tmp_flux)
        tmp_flux = tmp_flux / median_flux
        tmp_ferr = tmp_ferr / median_flux
        # Append to output columns
        lc_time = np.append(lc_time, tmp_bjd)
        flux = np.append(flux, tmp_flux)
        ferr = np.append(ferr, tmp_ferr)
        int_time = np.append(int_time, tmp_int_time)

        hdu.close()

    # Sort by time
    si = np.argsort(lc_time)
    lc_time = np.asarray(lc_time)[si]
    flux = np.asarray(flux)[si]
    ferr = np.asarray(ferr)[si]
    int_time = np.asarray(int_time)[si]

    phot = phot_class()
    phot.time = np.copy(lc_time)
    phot.flux = np.copy(flux)
    phot.ferr = np.copy(ferr)
    phot.itime = np.copy(int_time)

    phot.itime = phot.itime / (60 * 24)  #convert minutes to days

    return phot
Exemple #12
0
from astroquery.mast import Catalogs
from astropy.io import fits
from astropy import table
import matplotlib.pyplot as plt
import numpy as np
from copy import deepcopy
#%%
#Goals: Obtain all time series data from Kepler and TESS on a given target
#using astroquery.

star_name = "L98-59"

#Use Astroquery to find all dvt products
#Start by getting all time series observations at exactly the coordinates of our star.

observations = Observations.query_object(star_name, radius="0 deg")
obs_wanted = observations['dataproduct_type'] == 'timeseries'
print(observations[obs_wanted]['obs_collection', 'project', 'obs_id'])

#Get all Products and determine which have DV files.
#Then plot the time series for each that has DVT files.

data_products = Observations.get_product_list(observations[obs_wanted])

files_wanted = (data_products["productSubGroupDescription"] == "DVT") | \
                (data_products["productSubGroupDescription"] == "DVM") | \
                (data_products["productSubGroupDescription"] == "DVS") | \
                (data_products["productSubGroupDescription"] == "DVR")

#files_wanted = list(
#        map( lambda x: x[-8:] == 'dvt.fits', data_products['productFilename'] ))