ramjet.data_interface.tess_data_interface

Code for a class for common interfacing with TESS data, such as downloading, sorting, and manipulating.

Module Contents

class TessFluxType[source]

Bases: enum.Enum

SAP = SAP_FLUX
PDCSAP = PDCSAP_FLUX
is_common_mast_connection_error(exception: Exception) → bool[source]

Returns if the passed exception is a common MAST connection error. Made for deciding whether to retry a function.

Parameters:exception – The exception to check.
Returns:A boolean stating if the exception is a common MAST connection error.
class TessDataInterface[source]

A class for common interfacing with TESS data, such as downloading, sorting, and manipulating.

__init__(self)[source]
get_all_tess_time_series_observations(self, tic_id: Union[int, List[int]] = None)[source]

Gets all TESS time-series observations, limited to science data product level. Breaks large queries up to make the communication with MAST smoother.

Parameters:tic_id – An optional TIC ID or list of TIC IDs to limit the query to.
Returns:The list of time series observations as rows in a Pandas data frame.
static get_all_tess_time_series_observations_chunk(tic_id: Union[int, List[int]] = None)[source]

Gets all TESS time-series observations, limited to science data product level. Repeats download attempt on error.

Parameters:tic_id – An optional TIC ID or list of TIC IDs to limit the query to.
Returns:The list of time series observations as rows in a Pandas data frame.
get_product_list(self, observations: pd.DataFrame)[source]

A wrapper for MAST’s get_product_list, allowing the use of Pandas DataFrames instead of AstroPy Tables. Breaks large queries up to make the communication with MAST smoother.

Parameters:observations – The data frame of observations to get. Will be converted from DataFrame to Table for query.
Returns:The data frame of the product list. Will be converted from Table to DataFrame for use.
static get_product_list_chunk(observations: pd.DataFrame)[source]

A wrapper for MAST’s get_product_list, allowing the use of Pandas DataFrames instead of AstroPy Tables. Retries on error when communicating with the MAST server.

Parameters:observations – The data frame of observations to get. Will be converted from DataFrame to Table for query.
Returns:The data frame of the product list. Will be converted from Table to DataFrame for use.
static download_products(data_products: pd.DataFrame, data_directory: Path)[source]

A wrapper for MAST’s download_products, allowing the use of Pandas DataFrames instead of AstroPy Tables. Retries on error when communicating with the MAST server.

Parameters:
  • data_products – The data frame of data products to download. Will be converted from DataFrame to Table for sending the request to MAST.
  • data_directory – The path to download the data to.
Returns:

The manifest of the download. Will be converted from Table to DataFrame for use.

static filter_for_single_sector_observations(time_series_observations: pd.DataFrame)[source]

Filters a data frame of observations to get only the single sector observations.

Parameters:time_series_observations – A data frame of observations to filter for single sector observations.
Returns:The data frame of single sector observations.
static filter_for_multi_sector_observations(time_series_observations: pd.DataFrame)[source]

Filters a data frame of observations to get only the multi sector observations.

Parameters:time_series_observations – A data frame of observations to filter for multi sector observations.
Returns:The data frame of multi sector observations.
static get_tic_id_from_single_sector_obs_id(obs_id: str)[source]

Extracts the TIC ID from a single-sector obs_id string.

Parameters:obs_id – The obs_id to extract from.
Returns:The extracted TIC ID.
static get_sector_from_single_sector_obs_id(obs_id: str)[source]

Extracts the sector from a single-sector obs_id string.

Parameters:obs_id – The obs_id to extract from.
Returns:The extracted sector number.
add_tic_id_column_to_single_sector_observations(self, data_frame: pd.DataFrame)[source]

Adds a column with the TIC ID the row is related to.

Parameters:data_frame – The data frame of single-sector entries.
Returns:The table with the added TIC ID column.
add_sector_column_to_single_sector_observations(self, observations: pd.DataFrame)[source]

Adds a column with the sector the data was taken from.

Parameters:observations – The table of single-sector observations.
Returns:The table with the added sector column.
static load_fluxes_and_times_from_fits_file(example_path: Union[str, Path], flux_type: TessFluxType = TessFluxType.PDCSAP)[source]

Extract the flux and time values from a TESS FITS file.

Parameters:
  • example_path – The path to the FITS file.
  • flux_type – The flux type to extract from the FITS file.
Returns:

The flux and times values from the FITS file.

download_lightcurve(self, tic_id: int, sector: int = None, save_directory: Union[Path, str] = None)[source]

Downloads a lightcurve from MAST.

Parameters:
  • tic_id – The TIC ID of the lightcurve target to download.
  • sector – The sector to download. If not specified, downloads first available sector.
  • save_directory – The directory to save the FITS file to. If not specified, uses the system temporary directory.
Returns:

The path to the downloaded file.

plot_lightcurve_from_mast(self, tic_id: int, sector: int = None, exclude_flux_outliers: bool = False, base_data_point_size=3)[source]

Downloads and plots a lightcurve from MAST.

Parameters:
  • tic_id – The TIC ID of the lightcurve target to download.
  • sector – The sector to download. If not specified, downloads first available sector.
  • exclude_flux_outliers – Whether or not to exclude flux outlier data points when plotting.
  • base_data_point_size – The size of the data points to use when plotting (and related sizes).
static get_target_coordinates(tic_id: int)[source]

Get the sky coordinates of the target by a TIC ID.

Parameters:tic_id – The target’s TIC ID.
Returns:The coordinates of the target.
static get_variable_data_frame_for_coordinates(coordinates, radius='21s')[source]

Gets a data frame containing all known variables within a radius of the given coordinates.

Parameters:
  • coordinates – The coordinates to search.
  • radius – The radius to search. TESS has a pixel size of 21 arcseconds across.
Returns:

The data frame of the variables. Returns an empty data frame if none exist.

get_variable_data_frame_for_tic_id(self, tic_id)[source]

Gets a data frame containing all known variables near a TIC target (including the target if applicable).

Parameters:tic_id – The TIC target to search for variables near.
Returns:A data frame of the variables near the target (including the target if applicable).
print_variables_near_tess_target(self, tic_id)[source]

Prints all variable stars near a given TESS target (including the target if applicable).

Parameters:tic_id – The TIC target to search for variables near.
retrieve_exofop_planet_disposition_for_tic_id(self, tic_id: int)[source]

Retrieves the ExoFOP disposition information for a given TIC ID from <https://exofop.ipac.caltech.edu/tess/download_toi.php?sort=toi&output=csv>`_.

Parameters:tic_id – The TIC ID to get available data for.
Returns:The disposition data frame.
print_exofop_planet_dispositions_for_tic_target(self, tic_id)[source]

Prints all ExoFOP disposition information for a given TESS target.

Parameters:tic_id – The TIC target to for.
download_all_two_minute_cadence_lightcurves(self, save_directory: Path)[source]

Downloads all two minute cadence lightcurves from TESS.

Parameters:save_directory – The directory to save the lightcurves to.
get_sectors_target_appears_in(self, tic_id: int)[source]

Gets the list of sectors a TESS target appears in.

Parameters:tic_id – The TIC ID of the target.
Returns:The list of sectors.
download_exofop_toi_lightcurves_to_directory(self, directory: Union[Path, str] = None)[source]

Downloads the ExoFOP database lightcurve files to the given directory.

Parameters:directory – The directory to download the lightcurves to. Defaults to the data interface directory.
static get_tic_id_and_sector_from_file_path(file_path: Union[Path, str])[source]

Add general purpose function to get the TIC ID and sector from commonly encountered file name patterns.

Parameters:file_path – The path of the file to extract the TIC ID and sector.
Returns:The TIC ID and sector. The sector might be omitted (as None).
tess_data_interface