Tutorial#
[1]:
from lksearch import MASTSearch, KeplerSearch, K2Search, TESSSearch
Welcome to the new lksearch module! This package allows users to peruse available data products for the TESS, Kepler, and K2 missions. This notebook will guide you through several examples of how to use search functions.
The result of the search is a MASTSearch object, which contains among other things a full list of results stored in a pandas dataframe.
NOTE: While MASTSearch is a usable class, it does not have all of the functionality or nicities of the mission-specific searches (TESSSearch/KeplerSearch/K2Search). It is therefore recommended you as the user interact with these instead.
Basic Searches#
Data Exploration#
The lksearch package provides a user-friendly wrapper to search the MAST data archive. The most generic search is to use MASTsearch, which checks for mission products from three missions (Kepler, K2, and TESS). This search can be useful for data exploration, but does not have full functionality, as discussed below.
In addition, you can specify
search_radius: a search radius (assumes arcsec by default, but you can specify anything by using astropy units)
exptime: the exposure time of the observation. Either a number or a range in the form of a tuple
mission: the mission - only Kepler, K2, and TESS are directly supported
pipline: the pipeline(s) used to create the product, eg. Kepler, K2, SPOC, QLP, KBONUS-BKG, etc
and in the case of mission-specific searches
a sequence number*
sector for TESS
quarter/month for Kepler
campaign for K2
**NOTE* MASTSearch allows a sequence number, but it will result in selecting the same sequence for all mission. For example, if you provide sequence = 5, it will return only data from TESS sector 5, K2 campaign 5, or Kepler quarter 5.
For data exploration, it is suggested users search with the default setting (ie, providing only the target). You can use the provided class functions to extract the data products you want to download, as demonstrated throughout this tutorial.
[2]:
# First, we can check what data is available by any mission (TESS, Kepler, or K2)
# TOI-1161 is the same as Kepler-13. You can search using either name to get the same results
search_result = MASTSearch("TOI 1161")
search_result
[2]:
target_name | pipeline | mission | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 120.0 | 0.0 | 2019 | full data validation report |
1 | 158324245 | SPOC | TESS | 120.0 | 0.0 | 2019 | Light curves |
2 | 158324245 | SPOC | TESS | 120.0 | 0.0 | 2019 | TCE summary report |
3 | 158324245 | SPOC | TESS | 120.0 | 0.0 | 2019 | Data validation mini report |
4 | 158324245 | SPOC | TESS | 120.0 | 0.0 | 2019 | Target pixel files |
... | ... | ... | ... | ... | ... | ... | ... |
239 | kplr009941662 | Kepler | Kepler | 60.0 | 0.0 | 2012 | Lightcurve Short Cadence (CSC) - Q14 |
240 | kplr009941662 | Kepler | Kepler | 60.0 | 0.0 | 2012 | Target Pixel Short Cadence (TPS) - Q14 |
241 | kplr009941662 | Kepler | Kepler | 60.0 | 0.0 | 2013 | Lightcurve Short Cadence (CSC) - Q17 |
242 | kplr009941662 | Kepler | Kepler | 60.0 | 0.0 | 2011 | Target Pixel Short Cadence (TPS) - Q11 |
243 | kplr009941662 | Kepler | Kepler | 60.0 | 0.0 | 2009 | Target Pixel Short Cadence (TPS) - Q2 |
244 rows × 7 columns
Note that search_result is a MASTSearch object. When calling the object, a summary of the contents (MASTSearch object containing X data products) is printed to the screen along with a subset of the observation table.
The returned MASTSearch object has several properties to easily access specific observation characteristics. These include
target name (target_name)
right ascension (ra)
declination (dec)
exposure time (exptime)
mission
obsrvation year (year)
reduction pipeline (pipeline)
data location URI (uris)
data location in cloud storage (cloud_uris)
[3]:
# Let's use this to check what mission(s) have observed this target
print(search_result.mission)
['TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS'
'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'TESS' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler' 'Kepler'
'Kepler' 'Kepler']
[4]:
print(f"There are {sum(search_result.mission == 'TESS')} observations by TESS and {sum(search_result.mission == 'Kepler')} by Kepler")
There are 128 observations by TESS and 116 by Kepler
Accessing the full result table#
To view all of the results, you can access the ‘table’ variable. This table is a pandas dataframe that contains the full results of the MAST search as well as a few added parameters such as year, start_time, and end_time.
[5]:
search_result.table
[5]:
intentType | obs_collection_obs | provenance_name | instrument_name | project_obs | filters_obs | wavelength_region | target_name | target_classification | obs_id | ... | size | parent_obsid | dataRights | calib_level_prod | filters_prod | pipeline | mission | year | start_time | end_time | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | science | TESS | SPOC | Photometer | TESS | TESS | Optical | 158324245 | NaN | tess2019198215352-s0014-0000000158324245-0150-s | ... | 16426251 | 27448285 | PUBLIC | 3 | TESS | SPOC | TESS | 2019 | 2019-07-18 20:30:33.624 | 2019-08-14 16:56:23.634 |
1 | science | TESS | SPOC | Photometer | TESS | TESS | Optical | 158324245 | NaN | tess2019198215352-s0014-0000000158324245-0150-s | ... | 1964160 | 27448285 | PUBLIC | 3 | TESS | SPOC | TESS | 2019 | 2019-07-18 20:30:33.624 | 2019-08-14 16:56:23.634 |
2 | science | TESS | SPOC | Photometer | TESS | TESS | Optical | 158324245 | NaN | tess2019198215352-s0014-0000000158324245-0150-s | ... | 1322689 | 27448285 | PUBLIC | 3 | TESS | SPOC | TESS | 2019 | 2019-07-18 20:30:33.624 | 2019-08-14 16:56:23.634 |
3 | science | TESS | SPOC | Photometer | TESS | TESS | Optical | 158324245 | NaN | tess2019198215352-s0014-0000000158324245-0150-s | ... | 5082604 | 27448285 | PUBLIC | 3 | TESS | SPOC | TESS | 2019 | 2019-07-18 20:30:33.624 | 2019-08-14 16:56:23.634 |
4 | science | TESS | SPOC | Photometer | TESS | TESS | Optical | 158324245 | NaN | tess2019198215352-s0014-0000000158324245-0150-s | ... | 47376000 | 27448285 | PUBLIC | 2 | TESS | SPOC | TESS | 2019 | 2019-07-18 20:30:33.624 | 2019-08-14 16:56:23.634 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
239 | science | Kepler | Kepler | Kepler | Kepler | KEPLER | OPTICAL | kplr009941662 | NaN | kplr009941662_sc_Q003300033333333332 | ... | 5045760 | 599738 | PUBLIC | 2 | KEPLER | Kepler | Kepler | 2012 | 2009-05-02 00:54:00.000 | 2013-05-11 12:15:00.000 |
240 | science | Kepler | Kepler | Kepler | Kepler | KEPLER | OPTICAL | kplr009941662 | NaN | kplr009941662_sc_Q003300033333333332 | ... | 76302956 | 599738 | PUBLIC | 2 | KEPLER | Kepler | Kepler | 2012 | 2009-05-02 00:54:00.000 | 2013-05-11 12:15:00.000 |
241 | science | Kepler | Kepler | Kepler | Kepler | KEPLER | OPTICAL | kplr009941662 | NaN | kplr009941662_sc_Q003300033333333332 | ... | 648000 | 599738 | PUBLIC | 2 | KEPLER | Kepler | Kepler | 2013 | 2009-05-02 00:54:00.000 | 2013-05-11 12:15:00.000 |
242 | science | Kepler | Kepler | Kepler | Kepler | KEPLER | OPTICAL | kplr009941662 | NaN | kplr009941662_sc_Q003300033333333332 | ... | 130764115 | 599738 | PUBLIC | 2 | KEPLER | Kepler | Kepler | 2011 | 2009-05-02 00:54:00.000 | 2013-05-11 12:15:00.000 |
243 | science | Kepler | Kepler | Kepler | Kepler | KEPLER | OPTICAL | kplr009941662 | NaN | kplr009941662_sc_Q003300033333333332 | ... | 64708791 | 599738 | PUBLIC | 2 | KEPLER | Kepler | Kepler | 2009 | 2009-05-02 00:54:00.000 | 2013-05-11 12:15:00.000 |
244 rows × 59 columns
By default, MASTSearch returns any available data provided by an official mission pipeline. This means that any available High Level Science Products (HLSPs) are NOT returned. Additonally, TESS full frame images (FFIs) are not returned by MASTSearch. To search for these data types, we recommend using the mission-specific searches.
TESS search#
[6]:
# Search for TESS data only. This by default includes both HLSPs and FFI cutouts.
toi = TESSSearch('TOI 1161')
toi
[6]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Target pixel files |
1 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
2 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
3 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
4 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
... | ... | ... | ... | ... | ... | ... | ... | ... |
231 | 1717079071 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
232 | 1717079066 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
233 | 158324245 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
234 | 1717079066 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
235 | 1717079071 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
236 rows × 8 columns
There are 200+ TESS data products available for this target. Note that this is more than were returned by our first MASTsearch. These ‘extra’ data products come from non-mission sources. The ‘pipeline’ column shows what pipeline was used to generate the data product. The ‘mission’ column simply reports if the data is a mission product or HLSP. Another addition for the TESSSearch is the ‘sector’ column. This column is only populated in the TESSSearch call, so is not available when using MASTSearch.
Now that we know that TESS has observed this target, we may want to restrict our search to match our needs. Below we demonstrate some common filtering examples.
[7]:
# Only return timeseries (lightcurve) products
toi_lc = toi.timeseries
toi_lc
[7]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
1 | 158324245 | SPOC | TESS | 15 | 120.0 | 0.0 | 2019 | Light curves |
2 | 158324245 | SPOC | TESS | 26 | 120.0 | 0.0 | 2020 | Light curves |
3 | 1717079071 | SPOC | TESS | 26 | 120.0 | 0.0 | 2020 | Light curves |
4 | 1717079066 | SPOC | TESS | 40 | 120.0 | 0.0 | 2021 | Light curves |
... | ... | ... | ... | ... | ... | ... | ... | ... |
81 | 1717079071 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
82 | 1717079066 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
83 | 158324245 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
84 | 1717079066 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
85 | 1717079071 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
86 rows × 8 columns
[8]:
# Only return cubedata (TPF) products
# NOTE: Only TESS provides FFI cutouts
toi_cube = toi.cubedata
toi_cube
[8]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Target pixel files |
1 | 158324245 | SPOC | TESS | 15 | 120.0 | 0.0 | 2019 | Target pixel files |
2 | 158324245 | SPOC | TESS | 26 | 120.0 | 0.0 | 2020 | Target pixel files |
3 | 1717079071 | SPOC | TESS | 26 | 120.0 | 0.0 | 2020 | Target pixel files |
4 | 1717079066 | SPOC | TESS | 40 | 120.0 | 0.0 | 2021 | Target pixel files |
... | ... | ... | ... | ... | ... | ... | ... | ... |
41 | TOI 1161 | TESScut | TESS Sector 53 | 53 | 600.0 | 0.0 | 2022 | TESS FFI Cutout (sector 53) |
42 | TOI 1161 | TESScut | TESS Sector 54 | 54 | 600.0 | 0.0 | 2022 | TESS FFI Cutout (sector 54) |
43 | TOI 1161 | TESScut | TESS Sector 55 | 55 | 600.0 | 0.0 | 2022 | TESS FFI Cutout (sector 55) |
44 | TOI 1161 | TESScut | TESS Sector 74 | 74 | 200.0 | 0.0 | 2024 | TESS FFI Cutout (sector 74) |
45 | TOI 1161 | TESScut | TESS Sector 75 | 75 | 200.0 | 0.0 | 2024 | TESS FFI Cutout (sector 75) |
46 rows × 8 columns
[9]:
# Only return data validation products. These are PDFs generated automatically during transit searches.
toi_dv = toi.dvreports
toi_dv
[9]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
1 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
2 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
3 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
4 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
... | ... | ... | ... | ... | ... | ... | ... | ... |
99 | 1717079066 | TESS-SPOC | HLSP | 54 | 600.0 | 0.0 | 2022 | Informational PDF |
100 | 158324245 | TESS-SPOC | HLSP | 55 | 600.0 | 0.0 | 2022 | Informational PDF |
101 | 158324245 | TESS-SPOC | HLSP | 55 | 600.0 | 0.0 | 2022 | |
102 | 1717079066 | TESS-SPOC | HLSP | 55 | 600.0 | 0.0 | 2022 | |
103 | 1717079066 | TESS-SPOC | HLSP | 55 | 600.0 | 0.0 | 2022 | Informational PDF |
104 rows × 8 columns
[10]:
# Only return High Level Science Products
toi_hlsp = toi.HLSPs
toi_hlsp
[10]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | TESS-SPOC | HLSP | 14 | 1800.0 | 0.0 | 2019 | FITS |
1 | 158324245 | TESS-SPOC | HLSP | 14 | 1800.0 | 0.0 | 2019 | FITS |
2 | 158324245 | TESS-SPOC | HLSP | 15 | 1800.0 | 0.0 | 2019 | FITS |
3 | 158324245 | TESS-SPOC | HLSP | 15 | 1800.0 | 0.0 | 2019 | FITS |
4 | 1717079071 | TESS-SPOC | HLSP | 26 | 1800.0 | 0.0 | 2020 | FITS |
... | ... | ... | ... | ... | ... | ... | ... | ... |
103 | 1717079071 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
104 | 1717079066 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
105 | 158324245 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
106 | 1717079066 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
107 | 1717079071 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
108 rows × 8 columns
[11]:
# Only return official mission products
toi_mission = toi.mission_products
toi_mission
[11]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Target pixel files |
1 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
2 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
3 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
4 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
... | ... | ... | ... | ... | ... | ... | ... | ... |
123 | 158324245 | SPOC | TESS | 75 | 120.0 | 0.0 | 2024 | TCE summary report |
124 | 158324245 | SPOC | TESS | 75 | 120.0 | 0.0 | 2024 | Data validation mini report |
125 | 158324245 | SPOC | TESS | 75 | 120.0 | 0.0 | 2024 | full data validation report |
126 | 158324245 | SPOC | TESS | 75 | 120.0 | 0.0 | 2024 | Light curves |
127 | 158324245 | SPOC | TESS | 75 | 120.0 | 0.0 | 2024 | Target pixel files |
128 rows × 8 columns
Even after limiting results by data type, there are a lot of results for this target. The filter_table function allows you to filter by several additional parameters. These are: - exposure time (exptime) - the data pipline (pipeline) - the total number of results (limit).
In addition, KeplerSearch objects can be filtered by quarter/month, TESSSearch objects by sector, and K2Search objects by campaign.
[12]:
# Keep any data type, but only the shortest cadence available, which in this case is 2-minute data
toi_shortest = toi.filter_table(exptime='shortest')
toi_shortest
[12]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 74 | 20.0 | 0.0 | 2024 | Target pixel files |
1 | 158324245 | SPOC | TESS | 74 | 20.0 | 0.0 | 2024 | Light curves |
2 | 1717079066 | SPOC | TESS | 74 | 20.0 | 0.0 | 2024 | Light curves |
3 | 1717079066 | SPOC | TESS | 74 | 20.0 | 0.0 | 2024 | Target pixel files |
4 | 1717079066 | SPOC | TESS | 75 | 20.0 | 0.0 | 2024 | Light curves |
5 | 1717079066 | SPOC | TESS | 75 | 20.0 | 0.0 | 2024 | Target pixel files |
6 | 158324245 | SPOC | TESS | 75 | 20.0 | 0.0 | 2024 | Target pixel files |
7 | 158324245 | SPOC | TESS | 75 | 20.0 | 0.0 | 2024 | Light curves |
[13]:
# You could also specify an exact exposure time or range in the form of a tuple (eg, (100,500))
toi_trange = toi.filter_table(exptime=(100,500))
toi_trange
[13]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Target pixel files |
1 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
2 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
3 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
4 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
... | ... | ... | ... | ... | ... | ... | ... | ... |
123 | 158324245 | TASOC | HLSP | 15 | 120.0 | 0.0 | 2019 | FITS |
124 | 158324245 | TASOC | HLSP | 26 | 120.0 | 0.0 | 2020 | FITS |
125 | 158324245 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
126 | 1717079066 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
127 | 1717079071 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
128 rows × 8 columns
[14]:
toi_lim = toi.filter_table(limit=2)
toi_lim
[14]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Target pixel files |
1 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
Keep in mind, you can chain these commands
[15]:
toi_short_lcs = toi.timeseries.filter_table(exptime=120, sector=14)
toi_short_lcs
[15]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
1 | 158324245 | TASOC | HLSP | 14 | 120.0 | 0.0 | 2019 | FITS |
Once your search result contains the files you want, you can download the files directly to your machine.
[16]:
toi_short_lcs.download()
pipeline products: 100%|████████████████████████████████████████████| 2/2 [00:00<00:00, 4.27it/s]
[16]:
Local Path | Status | Message | URL | |
---|---|---|---|---|
0 | /Users/tapritc2/.lksearch/cache/mastDownload/T... | COMPLETE | None | None |
1 | /Users/tapritc2/.lksearch/cache/mastDownload/H... | COMPLETE | None | None |
You can also query the pandas Dataframe back end to perform more complicated searches. For example, the above could also be perfomed via:
[17]:
toi_short_lcs = toi.timeseries.query_table('sector == 14 & exptime == 120')
toi_short_lcs
[17]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 158324245 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Light curves |
1 | 158324245 | TASOC | HLSP | 14 | 120.0 | 0.0 | 2019 | FITS |
TESScut FFI Cutouts#
In addition to lightcurves and target pixel files, TESS provides Full Frame Image (FFI) data. This data was taken at a cadence of 30 minutes during the primary mission, 10 minutes during the first extension, and 200-seconds beginning in the second mission extension.
lksearch allows users to download entire FFIs, or make smaller cutouts around a target of interest using TESScut. All of this functionality if available with the TESSSearch object.
Find and download TESScut TPFs#
[18]:
search_result = TESSSearch("TOI 270", hlsp=False)
# You can filter two different ways to get the same result.
#search_result.filter_table(pipeline='TESScut')
search_result.tesscut
[18]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | TOI 270 | TESScut | TESS Sector 03 | 3 | 1800.0 | 0.0 | 2018 | TESS FFI Cutout (sector 3) |
1 | TOI 270 | TESScut | TESS Sector 04 | 4 | 1800.0 | 0.0 | 2018 | TESS FFI Cutout (sector 4) |
2 | TOI 270 | TESScut | TESS Sector 05 | 5 | 1800.0 | 0.0 | 2018 | TESS FFI Cutout (sector 5) |
3 | TOI 270 | TESScut | TESS Sector 30 | 30 | 600.0 | 0.0 | 2020 | TESS FFI Cutout (sector 30) |
4 | TOI 270 | TESScut | TESS Sector 31 | 31 | 600.0 | 0.0 | 2020 | TESS FFI Cutout (sector 31) |
5 | TOI 270 | TESScut | TESS Sector 32 | 32 | 600.0 | 0.0 | 2020 | TESS FFI Cutout (sector 32) |
For TESScut images, you can specify how large you want the cutout to be in pixels when you download the data using the TESScut_size keyword. By default, it will download a 10-pixel square image. If you use set this keyword when downloading non-TESScut data, it will be ignored.
[19]:
search_result.tesscut.filter_table(sector=3).download(TESScut_size=20)
TESScut : 100%|████████████████████████████████████████████| 1/1 [00:08<00:00, 8.03s/it]
[19]:
Local Path | Status | |
---|---|---|
0 | /Users/tapritc2/.lksearch/cache/mastDownload/T... | COMPLETE |
Find and download full frame images#
In some cases, users may want to access an FFI, for example to see if any artifacts exist on a CCD level. TESSSearch objects use the location of the target to find what camera/ccd the target was observed and access the FFIs.
Note that FFI files are large, so downloading a full sector to your hard drive is not recommended. The FFI search therefore allows you to limit the search by providing a start and stop time. Times can be provided as astropy Time objects. If a number is provided with no units, it assume MJD.
[20]:
search_result = TESSSearch("Kepler 16b")
search_result
[20]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | 299096355 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
1 | 299096355 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | full data validation report |
2 | 299096355 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
3 | 299096355 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | Data validation mini report |
4 | 299096355 | SPOC | TESS | 14 | 120.0 | 0.0 | 2019 | TCE summary report |
... | ... | ... | ... | ... | ... | ... | ... | ... |
157 | 299096355 | CDIPS | HLSP | 55 | 1800.0 | 0.0 | 2022 | FITS |
158 | 299096355 | QLP | HLSP | 55 | 600.0 | 0.0 | 2022 | FITS |
159 | 299096355 | QLP | HLSP | 56 | 200.0 | 0.0 | 2022 | FITS |
160 | 299096355 | QLP | HLSP | 73 | 200.0 | 0.0 | 2023 | FITS |
161 | 299096355 | QLP | HLSP | 74 | 200.0 | 0.0 | 2024 | FITS |
162 rows × 8 columns
[21]:
# Search for a list of FFIs in Sector 14
ffis = search_result.search_sector_ffis(14)
ffis
[21]:
target_name | pipeline | mission | sector | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | tess2019220045929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1 | tess2019200195929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
2 | tess2019219202929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
3 | tess2019220002929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
4 | tess2019201155929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
... | ... | ... | ... | ... | ... | ... | ... | ... |
1236 | tess2019220162929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1237 | tess2019205002929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1238 | tess2019205125929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1239 | tess2019222162929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1240 | tess2019216132929-s0014-2-4-0150-s | SPOC | TESS | 14 | 1800 | NaN | 2019 | Calibrated full frame image |
1241 rows × 8 columns
This produces more than 1000 FFI files, which likely we don’t want. Let’s limit it to just one.
[22]:
ffis.filter_table(limit=1).download()
pipeline products: 100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 2.76it/s]
[22]:
Local Path | Status | Message | URL | |
---|---|---|---|---|
0 | /Users/tapritc2/.lksearch/cache/mastDownload/T... | COMPLETE | None | None |
Kepler Search#
The call to KeplerSearch saves all availabe data products for the target as a table. Like with the other search objects, there are several convenient functions to limit the results to timeseries (lighcurve), cubedata (target pixel files and, in the case of TESS only, full frame image cutouts), dvreports (PDF data validation reports generated by the data pipelines), mission_products, and HLSPs. Calling these functions returns a new search object.
[23]:
# What timeseries data is available?
kep = KeplerSearch('Kepler 137')
kep
[23]:
target_name | pipeline | mission | quarter | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | kplr007419318 | Kepler | Kepler | 0 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q0 |
1 | kplr007419318 | Kepler | Kepler | 0 | 1800.000 | 0.0 | 2009 | Target Pixel Long Cadence (TPL) - Q0 |
2 | kplr007419318 | Kepler | Kepler | 1 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q1 |
3 | kplr007419318 | Kepler | Kepler | 1 | 1800.000 | 0.0 | 2009 | Target Pixel Long Cadence (TPL) - Q1 |
4 | kplr007419318 | Kepler | Kepler | 2 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q2 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
77 | kplr007419318 | Kepler | Kepler | 17 | 1800.000 | 0.0 | 2013 | Target Pixel Long Cadence (TPL) - Q17 |
78 | kplr007419318 | Kepler | Kepler | 99 | 1800.000 | 0.0 | 2009 | Data Validation full report |
79 | kplr007419318 | Kepler | Kepler | 99 | 1800.000 | 0.0 | 2009 | Data Validation summary report |
80 | kplr007419318 | Kepler | Kepler | 99 | 1800.000 | 0.0 | 2009 | Data Validation summary report |
81 | Gaia DR3 2104847370214740352 | KBONUS-BKG | HLSP | 99 | 1765.464 | 0.0 | 2009 | FITS |
82 rows × 8 columns
[24]:
kep_lc = kep.timeseries
kep_lc
[24]:
target_name | pipeline | mission | quarter | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | kplr007419318 | Kepler | Kepler | 0 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q0 |
1 | kplr007419318 | Kepler | Kepler | 1 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q1 |
2 | kplr007419318 | Kepler | Kepler | 2 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q2 |
3 | kplr007419318 | Kepler | Kepler | 3 | 1800.000 | 0.0 | 2009 | Lightcurve Long Cadence (CLC) - Q3 |
4 | kplr007419318 | Kepler | Kepler | 4 | 1800.000 | 0.0 | 2010 | Lightcurve Long Cadence (CLC) - Q4 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
35 | kplr007419318 | Kepler | Kepler | 14 | 1800.000 | 0.0 | 2012 | Lightcurve Long Cadence (CLC) - Q14 |
36 | kplr007419318 | Kepler | Kepler | 15 | 1800.000 | 0.0 | 2013 | Lightcurve Long Cadence (CLC) - Q15 |
37 | kplr007419318 | Kepler | Kepler | 16 | 1800.000 | 0.0 | 2013 | Lightcurve Long Cadence (CLC) - Q16 |
38 | kplr007419318 | Kepler | Kepler | 17 | 1800.000 | 0.0 | 2013 | Lightcurve Long Cadence (CLC) - Q17 |
39 | Gaia DR3 2104847370214740352 | KBONUS-BKG | HLSP | 99 | 1765.464 | 0.0 | 2009 | FITS |
40 rows × 8 columns
[25]:
# You can download a subsection of results directly
kep_lc[:2].download()
pipeline products: 100%|████████████████████████████████████████████| 2/2 [00:00<00:00, 3.32it/s]
[25]:
Local Path | Status | Message | URL | |
---|---|---|---|---|
0 | /Users/tapritc2/.lksearch/cache/mastDownload/K... | COMPLETE | None | None |
1 | /Users/tapritc2/.lksearch/cache/mastDownload/K... | COMPLETE | None | None |
Notice that when downloading, a table is printed out showing the status of the download. You can save this table and explore it in more detail, if desired.
[26]:
# You can download a subsection of results directly
manifest = kep[:2].download()
print(manifest['Local Path'].values)
pipeline products: 100%|████████████████████████████████████████████| 2/2 [00:00<00:00, 3.98it/s]
['/Users/tapritc2/.lksearch/cache/mastDownload/Kepler/kplr007419318_lc_Q111111111111111111/kplr007419318-2009131105131_llc.fits'
'/Users/tapritc2/.lksearch/cache/mastDownload/Kepler/kplr007419318_lc_Q111111111111111111/kplr007419318-2009131105131_lpd-targ.fits.gz']
[27]:
# we can also filter the results by observing quarter
kep_quarters = kep.filter_table(quarter=[7,17])
kep_quarters
[27]:
target_name | pipeline | mission | quarter | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Lightcurve Short Cadence (CSC) - Q7 |
1 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Lightcurve Short Cadence (CSC) - Q7 |
2 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Target Pixel Short Cadence (TPS) - Q7 |
3 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Target Pixel Short Cadence (TPS) - Q7 |
4 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Target Pixel Short Cadence (TPS) - Q7 |
5 | kplr007419318 | Kepler | Kepler | 7 | 60.0 | 0.0 | 2010 | Lightcurve Short Cadence (CSC) - Q7 |
6 | kplr007419318 | Kepler | Kepler | 7 | 1800.0 | 0.0 | 2010 | Target Pixel Long Cadence (TPL) - Q7 |
7 | kplr007419318 | Kepler | Kepler | 7 | 1800.0 | 0.0 | 2010 | Lightcurve Long Cadence (CLC) - Q7 |
8 | kplr007419318 | Kepler | Kepler | 17 | 1800.0 | 0.0 | 2013 | Lightcurve Long Cadence (CLC) - Q17 |
9 | kplr007419318 | Kepler | Kepler | 17 | 1800.0 | 0.0 | 2013 | Target Pixel Long Cadence (TPL) - Q17 |
K2 Search#
K2Search behaves in much the same way as Kepler. As with Kepler, both mission products and HLSPs are returned by default. Note that instead of quarters, the K2 mission was separated by campaign.
[28]:
K2 = K2Search("K2-18")
K2
[28]:
target_name | pipeline | mission | campaign | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | ktwo201912552 | K2 | K2 | 1 | 1800.0 | 0.0 | 2014 | Target Pixel Long Cadence (KTL) - C01 |
1 | ktwo201912552 | K2 | K2 | 1 | 1800.0 | 0.0 | 2014 | Lightcurve Long Cadence (KLC) - C01 |
2 | ktwo201912552 | EVEREST | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
3 | ktwo201912552 | EVEREST | HLSP | 1 | 1800.0 | 0.0 | 2014 | |
4 | ktwo201912552 | K2SFF | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
5 | ktwo201912552 | K2VARCAT | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
[29]:
# Download all lightcurves produced by HLSPs
K2_HLSPs = K2.HLSPs
K2_HLSPs
[29]:
target_name | pipeline | mission | campaign | exptime | distance | year | description | |
---|---|---|---|---|---|---|---|---|
0 | ktwo201912552 | EVEREST | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
1 | ktwo201912552 | EVEREST | HLSP | 1 | 1800.0 | 0.0 | 2014 | |
2 | ktwo201912552 | K2SFF | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
3 | ktwo201912552 | K2VARCAT | HLSP | 1 | 1800.0 | 0.0 | 2014 | FITS |
[30]:
manifest = K2_HLSPs.timeseries.download()
manifest
pipeline products: 100%|████████████████████████████████████████████| 3/3 [00:01<00:00, 2.02it/s]
[30]:
Local Path | Status | Message | URL | |
---|---|---|---|---|
0 | /Users/tapritc2/.lksearch/cache/mastDownload/H... | COMPLETE | None | None |
1 | /Users/tapritc2/.lksearch/cache/mastDownload/H... | COMPLETE | None | None |
2 | /Users/tapritc2/.lksearch/cache/mastDownload/H... | COMPLETE | None | None |
Configuration and Caching#
lksearch
has a default file download location that serves as the file cache, and an optional configuration file that can be created and used to overwrite the default values
lksearch File Download and Cache#
The lksearch
file cache is a directory where files are downloaded to. This directory also serves as a cache directory, and if a file matching the name of the file to be downloaded exists we treat this as a cached file and by default do not overwrite the current file on disk.
The default file download and cache directory is located at: ~/.lksearch/cache
This can be verified using the get_cache_dir convenience function in the config sub-module, e.g.:
[31]:
from lksearch import config as lkconfig
lkconfig.get_cache_dir()
[31]:
'/Users/tapritc2/.lksearch/cache'
Clearing the Cache & Corrupted Files#
If you wish to delete an individual file that you downloaded (for example, if you are concerned that a previously downloaded file is corrupted), the easiest way to do that is using the Local Path
information in the manifest returned by the .download()
function.
[32]:
import os
# The manifest returned by download() is a pandas DataFrame
# We will access the first local path using iloc as so
os.remove(manifest.iloc[0]["Local Path"])
If you want to clear everything from your cache, you can use the config.clearcache()
function to completely empty your cache of downloaded files. by default this will run in “test” mode and print what you will be deleting. To confirm deletion, run with test=False
optional parameter.
[33]:
lkconfig.clearcache()
Running in test mode, rerun with test=False to clear cache
removing /Users/tapritc2/.lksearch/cache/mastDownload/TESS
removing /Users/tapritc2/.lksearch/cache/mastDownload/K2
removing /Users/tapritc2/.lksearch/cache/mastDownload/Kepler
removing /Users/tapritc2/.lksearch/cache/mastDownload/TESSCut
removing /Users/tapritc2/.lksearch/cache/mastDownload/HLSP
Passing ``test=False`` will then fully delete the above directories
e.g. lkconfig.clearcache(test=False)
lksearch Configuration and Configuration File#
lksearch has a number of configuration parameters, these are contained in the ~lksearch.Conf
class. One can modify these parameters for a given python session by updating the values in the Conf class. To modify these configuration parameters default values, lksearch also has an optional configuration file that is built on-top of ~astropy.config
using ~astropy.config.ConfigNamespace
. This file does not exist by
default, but a default version can be created using the config.create_config_file
helper function. Modifications to the values in this file will then update the default ~lksearch.Conf
values.
[34]:
lkconfig.create_config_file(overwrite = True)
This file can be found in the below location. To edit this, please see the astropy.config documentation.
[35]:
lkconfig.get_config_dir()
[35]:
'/Users/tapritc2/.lksearch/config'
[36]:
lkconfig.get_config_file()
[36]:
'/Users/tapritc2/.lksearch/config/lksearch.cfg'
lksearch Cloud Configuration#
lksearch has three configuration parameters that are particularly relevant to cloud-based science platforms. These are: - CLOUD_ONLY: Only Download cloud based data. If False, will download all data. If True, will only download data located on a cloud (Amazon S3) bucket - PREFER_CLOUD: Prefer Cloud-based data product retrieval where available - DDOWNLOAD_CLOUD: Download cloud based data.If False, download() will return a pointer to the cloud based datainstead of downloading it - intended usage for cloud-based science platforms (e.g. TIKE)
CLOUD_ONLY governs whether or not non-cloud based data will be possible to be downloaded. Many science files have both a cloud-based location (typically on Amazon S3) and a MAST archive location. By default this is False, and all products will be downloaded regardless of whether the file is available via cloud-hosting or MAST archive hosting. If CLOUD_ONLY is True, only files available for download on a cloud-based platform will be retrieved. This configuration parameter is passed through to the
~astroquery.mast
parameter of the same name.
PREFER_CLOUD governs the default download behaviour in the event that a data product is available from both a cloud-based location and a MAST-hosted archive location. If True (default), then lksearch will preferentially download files from the cloud-host rather than the MAST-hosted Archive. This configuration parameter is passed through to the ~astroquery.mast
parameter of the same name.
DOWNLOAD_CLOUD governs whether files that are hosted on the cloud are downloaded locally. If this value is True (default), cloud-hosted files are downloaded normally. If False, then files hosted on a cloud based platform are not downloaded, and a URI containing the path to the desired file on the cloud-host is returned instead of the local path to the file. This path can then be used to read the file remotely (see ~astropy.io.fits
working with remote and cloud hosted
files for more information). This ability may be most relevant when using lksearch on a cloud-based science platform where the remote read is very rapid and short-term local storage comparatively expensive.
Using this DOWNLOAD_CLOUD functionality, we can find a cloud-hosted file and read it directly into memory like so:
[37]:
#First, lets update our configuration to not download a cloud-hosted file
from lksearch import Conf
Conf.DOWNLOAD_CLOUD=False
# Now, lets find some data. We use this target earlier in the tutorial.
toi = TESSSearch('TOI 1161')
#What happens when we try to download it in our updated configuration?
cloud_result = toi.timeseries.mission_products[0].download()
cloud_result
pipeline products: 100%|███████████████████████████████████████████| 1/1 [00:00<00:00, 395.88it/s]
[37]:
Local Path | Status | Message | URL | |
---|---|---|---|---|
0 | s3://stpubdata/tess/public/tid/s0014/0000/0001... | COMPLETE | Link to S3 bucket for remote read | None |
As we can see above, instead of downloading the above file we have instead returned an amazon S3 URI for its cloud hosted location. If we want to access the file, we can do it using the remote-read capabilities of ~astropy.io.fits
.
[38]:
import astropy.io.fits as fits
with fits.open(cloud_result["Local Path"].values[0], use_fsspec=True, fsspec_kwargs={"anon": True}) as hdu:
for item in hdu:
print(item.fileinfo())
{'file': <astropy.io.fits.file._File <File-like object S3FileSystem, stpubdata/tess/public/tid/s0014/0000/0001/5832/4245/tess2019198215352-s0014-0000000158324245-0150-s_lc.fits>>, 'filemode': 'readonly', 'hdrLoc': 0, 'datLoc': 5760, 'datSpan': 0}
{'file': <astropy.io.fits.file._File <File-like object S3FileSystem, stpubdata/tess/public/tid/s0014/0000/0001/5832/4245/tess2019198215352-s0014-0000000158324245-0150-s_lc.fits>>, 'filemode': 'readonly', 'hdrLoc': 5760, 'datLoc': 20160, 'datSpan': 1935360}
{'file': <astropy.io.fits.file._File <File-like object S3FileSystem, stpubdata/tess/public/tid/s0014/0000/0001/5832/4245/tess2019198215352-s0014-0000000158324245-0150-s_lc.fits>>, 'filemode': 'readonly', 'hdrLoc': 1955520, 'datLoc': 1961280, 'datSpan': 2880}