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:
listBase class for manipulating and combining ephemerides.
- An
Ephobject is alistof rows containing data. - Rows are expected to be
listof data cells. - Data cells can be either strings or any type.
Ephobjects can be created with some class methods:- from a
listof strings interpreted as rows containing strings of data. - from a raw string containing all rows of data.
- from a csv-like data file.
An
Ephobject is considered valid if all rows have the same length or, said otherwise, if all rows of data have the same number of columns. AnEphis considered clean if does not contain useless spaces in data cells, empty rows or empty columns.A new
Ephobject can be obtained selecting columns from oneEphobject or combining specific columns of manyEphobjects.-
clean()¶ Cleans the ephemeris.
An
Ephis 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
Ephobject from a ephemeris text file.Parameters: - filename (
str) – the file containing the ephemeris data. - kwargs – use
delimiterkey to set delimiter character between columns.
- filename (
-
classmethod
from_raw(raw, **kwargs)¶ Creates an
Ephobject from a raw text ephemeris.Parameters: - raw (
str) – the string to be interpreted as an ephemeris. - kwargs – use
delimiterkey to set delimiter character between columns.
- raw (
-
classmethod
from_rows(rows, **kwargs)¶ Creates an
Ephobject from alistof string type rows.Parameters: - rows (
list) – thelistof rows. - kwargs – use
delimiterkey to set delimiter character between columns.
- rows (
-
is_empty()¶ Tells if the ephemeris has zero rows or not.
-
is_valid()¶ Check if
Ephobject can be considered a valid representation of an ephemeris.An
Ephobject 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
Ephobjects.Parameters: - ephs (
Eph) –Ephobjects to join. - cols (
list) – alistof columns to select for eachEphobject. - ids (
tuple) – atupleof 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: Return type: - ephs (
-
n_cols()¶ Gives the number of columns for each row.
Returns: a listof integers representing the number of columns for all rows.Return type: list
-
rows()¶ Gives a
listof string type formatted rows.Returns: the listof rows.Return type: list
- An
eph.jpl module¶
Define classes used to retrive a desired ephemris from JPL Horizon’s service.
JPLReqrepresents a request to JPL Horizon’s service.JPLReqis adictwhere 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).JPLResrepresents a response by JPL Horizon’s service. It gives a structure tohttpresponse by separating raw data in header, ephemeris and footer.JPLRes.eph is parsed fromhttpresponse as anEphobject.JPLRes.header andJPLRes.footer are raw strings.BadRequestErroris a exception raised if the JPL Horizon’s response is not formatted as expected, indicating that something went wrong (for example ifJPLReqparameters are not accepted by JPL Horizon’s interface).
-
exception
eph.jpl.BadRequestError(jpl_msg)¶ Bases:
ExceptionException 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:
dictJPLReqrepresents a request to JPL Horizons service.JPLReqis adictwhere 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: - filename (
-
request()¶ Make a request to JPL Horizons service server from the parameters assigned to it.
Returns: a JPLResobject representing a structured version of rawhttpJPL 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:
objectJPLResrepresents a response by JPL Horizon’s service. It structures the rawhttpJPL response by separating data in header, ephemeris and footer.JPLRes.ephemerisis parsed fromhttpresponse as anEphobject.JPLRes.headerandJPLRes.footerare 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
Ephobject, - 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
-