eph package

eph.eph module

Define base class Eph. Eph class is fundamental to this package because it represents an ephemeris, allowing manipulation of this kind of data structures.

class eph.eph.Eph(*args, **kwargs)

Bases: list

Base class for manipulating and combining ephemerides.

  • An Eph object is a list of rows containing data.
  • Rows are expected to be list of data cells.
  • Data cells can be either strings or any type.

Eph objects can be created with some class methods:

  • from a list of strings interpreted as rows containing strings of data.
  • from a raw string containing all rows of data.
  • from a csv-like data file.

An Eph object is considered valid if all rows have the same length or, said otherwise, if all rows of data have the same number of columns. An Eph is considered clean if does not contain useless spaces in data cells, empty rows or empty columns.

A new Eph object can be obtained selecting columns from one Eph object or combining specific columns of many Eph objects.

clean()

Cleans the ephemeris.

An Eph is considered clean if does not contain useless spaces in data cells, empty rows or empty columns.

Returns:the object itself.
Return type:Eph
classmethod from_file(filename, **kwargs)

Creates an Eph object from a ephemeris text file.

Parameters:
  • filename (str) – the file containing the ephemeris data.
  • kwargs – use delimiter key to set delimiter character between columns.
classmethod from_raw(raw, **kwargs)

Creates an Eph object from a raw text ephemeris.

Parameters:
  • raw (str) – the string to be interpreted as an ephemeris.
  • kwargs – use delimiter key to set delimiter character between columns.
classmethod from_rows(rows, **kwargs)

Creates an Eph object from a list of string type rows.

Parameters:
  • rows (list) – the list of rows.
  • kwargs – use delimiter key to set delimiter character between columns.
is_empty()

Tells if the ephemeris has zero rows or not.

is_valid()

Check if Eph object can be considered a valid representation of an ephemeris.

An Eph object is considered valid if all rows have the same length or, said otherwise, if all rows of data have the same number of columns.

static join(*ephs, cols=None, ids=())

Combines many Eph objects.

Parameters:
  • ephs (Eph) – Eph objects to join.
  • cols (list) – a list of columns to select for each Eph object.
  • ids (tuple) – a tuple of indices that identify columns that will be treated as ids. A column is considered an id if values are equal for all ephemerides to join and it will present only once in the resulting ephemeris.
Returns:

The Eph object obtained combining multiple Eph objects.

Return type:

Eph

n_cols()

Gives the number of columns for each row.

Returns:a list of integers representing the number of columns for all rows.
Return type:list
rows()

Gives a list of string type formatted rows.

Returns:the list of rows.
Return type:list
select_cols(*cols)

Creates an Eph object from the columns specified with their indices.

Parameters:cols (list) – indices of columns to be selected.
Returns:the Eph object built from the columns specified.
Return type:Eph

eph.jpl module

Define classes used to retrive a desired ephemris from JPL Horizon’s service.

  • JPLReq represents a request to JPL Horizon’s service. JPLReq is a dict where key-values pairs are parameters accepted by JPL Horizon’s interface (a complete description of the interface can be found at ftp://ssd.jpl.nasa.gov/pub/ssd/horizons_batch_example.long).
  • JPLRes represents a response by JPL Horizon’s service. It gives a structure to http response by separating raw data in header, ephemeris and footer. JPLRes.eph is parsed from http response as an Eph object. JPLRes.header and JPLRes.footer are raw strings.
  • BadRequestError is a exception raised if the JPL Horizon’s response is not formatted as expected, indicating that something went wrong (for example if JPLReq parameters are not accepted by JPL Horizon’s interface).
exception eph.jpl.BadRequestError(jpl_msg)

Bases: Exception

Exception raised when JPL output is not formatted as expected, indicating that something went wrong (probably because of an invalid param passed to the request).

class eph.jpl.JPLReq(filename=None, params=None)

Bases: dict

JPLReq represents a request to JPL Horizons service. JPLReq is a dict where key-values pairs are parameters accepted by JPL Horizons interface (a complete description of the interface can be found at ftp://ssd.jpl.nasa.gov/pub/ssd/horizons_batch_example.long).

BASE_URL = 'http://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=1'
read(filename, section)

Reads key-value pairs from file.

Parameters:
  • filename (str) – the filename to be parsed.
  • section (str) – section of the ini file to be read.
Returns:

the object itself.

Return type:

JPLReq

request()

Make a request to JPL Horizons service server from the parameters assigned to it.

Returns:a JPLRes object representing a structured version of raw http JPL response.
Return type:JPLRes
set(params)

Wrapper for dict.update() allowing chaining.

Parameters:params (dict) – key-value pairs of JPL parameters.
Returns:the object itself.
Return type:JPLReq
url()

Builds a url addressing JPL Horizons service with query string specifying JPL params.

Returns:the url.
Return type:str
class eph.jpl.JPLRes(res=None)

Bases: object

JPLRes represents a response by JPL Horizon’s service. It structures the raw http JPL response by separating data in header, ephemeris and footer. JPLRes.ephemeris is parsed from http response as an Eph object. JPLRes.header and JPLRes.footer are raw strings instead.

parsejpl(res)

Parses a JPL response and extracts three sections:

  • header: the header containing info about the requested celestial objects and the formatting of the ephemeris,
  • ephemeris: the actual data parsed as an Eph object,
  • footer: the footer containing info about how things are to be intended, JPL Horizons service and the request’s parameters used.
Parameters:res (requests.models.Response) – the JPL Horizons response.
Returns:the object itself.
Return type:JPLRes