From 7dae84d506edeccf81899ff5417448f4e4895161 Mon Sep 17 00:00:00 2001 From: Brandon Rhodes Date: Thu, 3 Jan 2019 23:34:10 -0500 Subject: [PATCH] Version 2.9: add load_array() --- jplephem/__init__.py | 12 +++++++++++- jplephem/spk.py | 6 ++++++ jplephem/test.py | 5 +++++ setup.py | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/jplephem/__init__.py b/jplephem/__init__.py index e4c9f08..5101e4d 100644 --- a/jplephem/__init__.py +++ b/jplephem/__init__.py @@ -195,6 +195,13 @@ provided above and read through the code to learn more. | segment.end_i - index where segment ends ... +* If you want to access the raw coefficients, use the segment + ``load_array()`` method. It returns two floats and a NumPy array: + + >>> initial_epoch, interval_length, coefficients = segment.load_array() + >>> print(coefficients.shape) + (3, 100448, 13) + * The square-bracket lookup mechanism ``kernel[3,399]`` is a non-standard convenience that returns only the last matching segment in the file. While the SPK standard does say that the last segment @@ -212,7 +219,6 @@ provided above and read through the code to learn more. the position, and then only proceed to the velocity once you are sure that the light-time error is now small enough. - High-Precision Dates -------------------- @@ -298,6 +304,10 @@ https://github.com/brandon-rhodes/python-jplephem/ Changelog --------- +**2019 January 3 — Version 2.9** + +* Added the ``load_array()`` method to the segment class. + **2018 July 22 — Version 2.8** * Switched to a making a single memory map of the entire file, to avoid diff --git a/jplephem/spk.py b/jplephem/spk.py index e8819ac..131cbd9 100644 --- a/jplephem/spk.py +++ b/jplephem/spk.py @@ -149,6 +149,12 @@ class Segment(object): coefficients = rollaxis(coefficients, 1) return initial_epoch, interval_length, coefficients + def load_array(self): + data = self._data + if data is None: + self._data = data = self._load() + return data + def generate(self, tdb, tdb2): """Generate components and differentials for time `tdb` plus `tdb2`. diff --git a/jplephem/test.py b/jplephem/test.py index b9827f5..644ed10 100644 --- a/jplephem/test.py +++ b/jplephem/test.py @@ -322,6 +322,11 @@ class SPKTests(_CommonTests, TestCase): '2414864.50..2471184.50 Solar System Barycenter (0) -> Mars Barycenter (4)' '\n frame=1 data_type=2 source=DE-0421LE-0421') + def test_loading_array(self): + segment = self.spk[0,4] + initial_epoch, interval_length, coefficients = segment.load_array() + self.assertEqual(coefficients.shape, (3, 1760, 11)) + class LegacyTests(_CommonTests, TestCase): diff --git a/setup.py b/setup.py index e475b64..f6d513d 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ import jplephem description, long_description = jplephem.__doc__.split('\n', 1) setup(name = 'jplephem', - version = '2.8', + version = '2.9', description = description, long_description = long_description, license = 'MIT',