RAMjET

ramjet.data_interface.tess_data_interface

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

Module Contents

Classes

TessFluxType An enum to represent the types of available fluxes in TESS two minute data.
ColumnName An enum for the names of the columns produced by the data interface class.
TessDataInterface A class for common interfacing with TESS data, such as downloading, sorting, and manipulating.

Functions

is_common_mast_connection_error(exception: Exception) → bool Returns if the passed exception is a common MAST connection error. Made for deciding whether to retry a function.
class TessFluxType[source]

Bases: enum.Enum

An enum to represent the types of available fluxes in TESS two minute data.

SAP = SAP_FLUX
PDCSAP = PDCSAP_FLUX
class ColumnName[source]

Bases: enum.StrEnum

An enum for the names of the columns produced by the data interface class.

TIC_ID = TIC ID
SECTOR = Sector
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.
exception NoDataProductsFoundException[source]

Bases: Exception

An exception when no data products are found from MAST.

class TessDataInterface[source]

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

__init__(self)[source]

Initialize self. See help(type(self)) for accurate signature.

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_out_twenty_second_cadence_observations(time_series_observations: pd.DataFrame)[source]

Removes 20-second cadence data from the observation data frame.

Parameters:time_series_observations – A data frame of observations to filtered.
Returns:The data frame without 20-second cadence data.
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.
load_lightcurve_from_fits_file(self, lightcurve_path: Union[str, Path])[source]

Loads a lightcurve from a FITS file in a dictionary form with the structure of the FITS arrays.

Parameters:lightcurve_path – The path to the FITS file.
Returns:The lightcurve.
load_fluxes_and_times_from_fits_file(self, lightcurve_path: Union[str, Path], flux_type: TessFluxType = TessFluxType.PDCSAP, remove_nans: bool = True)[source]

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

Parameters:
  • lightcurve_path – The path to the FITS file.
  • flux_type – The flux type to extract from the FITS file.
  • remove_nans – Whether or not to remove nans.
Returns:

The flux and times values from the FITS file.

load_fluxes_flux_errors_and_times_from_fits_file(self, lightcurve_path: Union[str, Path], flux_type: TessFluxType = TessFluxType.PDCSAP, remove_nans: bool = True)[source]

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

Parameters:
  • lightcurve_path – The path to the FITS file.
  • flux_type – The flux type to extract from the FITS file.
  • remove_nans – Whether or not to remove nans.
Returns:

The flux and times values from the FITS file.

download_two_minute_cadence_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).
create_pdcsap_and_sap_comparison_figure_from_mast(self, tic_id: int, sector: int = None)[source]

Creates a comparison figure containing both the PDCSAP and SAP signals.

Parameters:
  • tic_id – The TIC ID of the lightcurve to plot.
  • sector – The sector of the lightcurve to plot.
Returns:

The generated figure.

show_pdcsap_and_sap_comparison_from_mast(self, tic_id: int, sector: int = None)[source]

Shows a comparison figure containing both the PDCSAP and SAP signals.

Parameters:
  • tic_id – The TIC ID of the lightcurve to plot.
  • sector – The sector of the lightcurve to plot.
show_lightcurve(self, lightcurve_path: Path)[source]

Shows a figure of the lightcurve at the passed path.

Parameters:lightcurve_path – The path of the lightcurve.
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_tess_input_catalog_row(tic_id: int)[source]

Get the TIC row for a TIC ID.

Parameters:tic_id – The target’s TIC ID.
Returns:The row of a the TIC corresponding to the TIC ID.
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.
download_two_minute_cadence_lightcurves(self, save_directory: Path, limit: Union[None, int] = None)[source]

Downloads all two minute cadence lightcurves from TESS.

Parameters:
  • save_directory – The directory to save the lightcurves to.
  • limit – Limits the number of lightcurves downloaded. Default of None will download all lightcurves.
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.
get_all_two_minute_single_sector_observations(self, tic_ids: List[int] = None)[source]

Gets the data frame containing all the single sector observations, with TIC ID and sector columns.

Parameters:tic_ids – The TIC IDs to get observations for.
Returns:The data frame containing the observation information.
verify_lightcurve(self, lightcurve_path: Path)[source]

The lightcurve is checked if it’s malformed, and if it is, it is re-downloaded.

Parameters:lightcurve_path – The path of the lightcurve.
static get_tic_id_and_sector_from_file_path(file_path: Union[Path, str])[source]

Gets 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