curryer.tle

TLE related logic.

@author: Brandon Stone

Attributes

Classes

TLERemoteAccessor

Access TLE data from SpaceTrack.org.

Module Contents

curryer.tle.logger
class curryer.tle.TLERemoteAccessor(user, pswd, keep_duplicates=False)

Access TLE data from SpaceTrack.org.

URL_BASE = 'https://www.space-track.org'
URL_AUTH = 'https://www.space-track.org/ajaxauth/login'
MAIN_COLUMNS = ('object_name', 'norad_cat_id', 'epoch', 'creation_date', 'file', 'tle_line1', 'tle_line2')
__prev_request_time = 0
__spacetrack_user
__spacetrack_pswd
keep_duplicates = False
__cookies = None
limiter()

Check API limits and sleep if necessary.

Must self limit API requests or risk server-side errors (to limit). Limits: 30 per minute, 300 per hour.

Returns:

Number of seconds that it paused for (0=not API limited).

Return type:

float

authenticate()

Authenticate, storing cookie for later queries.

is_authenticated()

Check if queries are authenticated.

static _as_str(value)

Convert misc. data types to a string.

render_query(norad_cat_id, columns=None, query_args=None)

Render a query string.

Parameters:
  • norad_cat_id (int) – NORAD catalog ID.

  • columns (list[str], optional) – Columns to request. Default is MAIN_COLUMNS.

  • query_args (list[tuple[str, str, any]], optional) – List of query arguments (field, comparison, value). Default is to get latest TLE entry.

Returns:

URL to query data from.

Return type:

str

query(query_url)

Query for TLE data using a pre-rendered URL.

Parameters:

query_url (str) – URL to query data from. Expected to be generated using render_query, otherwise it set JSON and metadata args.

Returns:

Dictionary response. If empty, the dict will be:

{‘request_metadata’: {‘ReturnedRows’: 0}, ‘data’: []}

Return type:

dict

read(norad_cat_id, columns=None, query_args=None, index_col=None)

Get TLE data and format it into a table.

Parameters:
  • norad_cat_id (int) – NORAD catalog ID.

  • columns (list[str], optional) – Columns to request. Default is MAIN_COLUMNS.

  • query_args (list[tuple], optional) – List of query arguments (field, comparison, value). Default is to get the latest TLE entry.

  • index_col (str, optional) – Column to set as the table’s index.

Returns:

Table of data. Will always contain the columns, even if no data was returned.

Return type:

pd.DataFrame

static write(tle_table, filename, overwrite=False, append=False, header=True)

Write TLE data to a file.

Parameters:
  • tle_table (pd.DataFrame) – TLE data in table form. Must contain the columns “tle_line1” and “tle_line2”. An empty table will cause a warning log.

  • filename (str or Path or func, optional) – File path to write to or function to send the text. If None, returns the text.

  • overwrite (bool, optional) – Option to overwrite an existing file. Can not use with append.

  • append (bool, optional) – Option to append to an existing file. It will create a new file if one does not already exist. Can not use with overwrite.

  • header (bool, optional) – Option to include a header in the file as the table name.

Returns:

TLE file text if filename was None, otherwise None is returned.

Return type:

str or None