Skip to content

Commit ce03e94

Browse files
committed
Implement SPICE (bsp) for planet ephemeris
1 parent d450571 commit ce03e94

File tree

51 files changed

+1074
-741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1074
-741
lines changed

.github/workflows/c.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ASSIST Unit Tests (C)
33
on: [push, pull_request]
44

55
env:
6-
JPL_PLANET_EPHEM: ../../data/linux_p1550p2650.440
6+
JPL_PLANET_EPHEM: ../../data/de440.bsp
77

88
jobs:
99
build:
@@ -17,19 +17,11 @@ jobs:
1717
run: |
1818
pwd
1919
git clone https://github.com/hannorein/rebound.git
20-
#- name: Compile REBOUND
21-
# working-directory: ../rebound
22-
# run: |
23-
# pwd
24-
# make
25-
#- name: Compile ASSIST
26-
# run: |
27-
# make
2820
- name: Download DE441 dataset
2921
working-directory: ./data/
3022
run: |
31-
#wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de441/linux_m13000p17000.441
32-
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440
23+
#wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de441.bsp
24+
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp
3325
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp
3426
- name: Reproduce Holman trajectory
3527
working-directory: ./unit_tests/holman/
@@ -91,3 +83,18 @@ jobs:
9183
run: |
9284
make
9385
LD_LIBRARY_PATH=../../../rebound/src/ ./rebound
86+
- name: Test Loading Spice Kernels
87+
working-directory: ./unit_tests/spk_init/
88+
run: |
89+
make
90+
LD_LIBRARY_PATH=../../../rebound/src/ ./rebound
91+
- name: Test Loading Constants from Planet SPK
92+
working-directory: ./unit_tests/spk_load_constants/
93+
run: |
94+
make
95+
LD_LIBRARY_PATH=../../../rebound/src/ ./rebound
96+
- name: Test Joining Mass Data from SPK
97+
working-directory: ./unit_tests/spk_join_masses/
98+
run: |
99+
make
100+
LD_LIBRARY_PATH=../../../rebound/src/ ./rebound

.github/workflows/python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- name: Download DE441 dataset
2525
working-directory: ./data/
2626
run: |
27-
#wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de441/linux_m13000p17000.441
28-
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440
27+
#wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de441.bsp
28+
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp
2929
wget --no-verbose https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp
3030
- name: Build package
3131
run: pip install -e .

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assist

MANIFEST.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
include src/assist.c
22
include src/forces.c
3-
include src/planets.c
43
include src/spk.c
54
include src/assist.h
65
include src/forces.h
7-
include src/planets.h
86
include src/spk.h
97
include README.md
108
include LICENSE

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,25 @@ doc:
1818
cd doc/doxygen && doxygen
1919
$(MAKE) -C doc html
2020

21+
22+
# Iterate through each directory in the unit_tests directory and compile the test files
23+
# then run them
24+
test:
25+
@echo "Running tests ..."
26+
@set -e; \
27+
for dir in $(wildcard unit_tests/*); do \
28+
if [ -d $$dir ]; then \
29+
echo "Entering directory $$dir"; \
30+
if $(MAKE) -C $$dir; then \
31+
if [ -f "$$dir/rebound" ]; then \
32+
(cd $$dir && LD_LIBRARY_PATH=$(REB_DIR):. ./rebound); \
33+
else \
34+
echo "No rebound executable found in $$dir"; \
35+
exit 1; \
36+
fi \
37+
else \
38+
echo "Make failed in $$dir"; \
39+
exit 1; \
40+
fi \
41+
fi \
42+
done

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,36 @@ Now we can install numpy, REBOUND, and ASSIST:
2525
pip install rebound
2626
pip install assist
2727

28-
To use use ASSIST, you also need to download ephemeris data files. One file for planet ephemeris and another suplementary file for asteroid ephemeris. The following commands download these files with curl. You can also manually download them using your browser. Note that these are large files, almost 1GB in size.
28+
To use use ASSIST, you also need to download ephemeris data files. One file for planet ephemeris and another suplementary file for asteroid ephemeris. You can do this with Python packages or by downloading files directly. Note that these are large files, almost 1GB in size.
29+
30+
pip install naif-de440
31+
pip install jpl-small-bodies-de441-n16
32+
33+
34+
You can initialize the ephemeris data from the packages like so:
35+
36+
python3
37+
38+
>>> import assist
39+
>>> from naif_de440 import de440
40+
>>> from jpl_small_bodies_de441_n16 import de441_n16
41+
>>> ephem = assist.Ephem(de440, de441_n16)
42+
43+
The variables to the ephemeris files are simply path strings to the files. Alternatively, you can download these files with curl or your browser.
2944

3045
mkdir data
31-
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440 -o data/linux_p1550p2650.440
46+
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp -o data/de440.bsp
3247
curl https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp -o data/sb441-n16.bsp
3348

34-
Now you can try out if assist works.
49+
Now you can point assist to those files directly, like so:
3550

3651
python3
3752

3853
>>> import assist
39-
>>> ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
54+
>>> ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
55+
56+
Once you've initialized the ephemeris data, you can test that assist is working by running the following commands:
57+
4058
>>> print(ephem.jd_ref)
4159
>>> ephem.get_particle("Earth", 0)
4260

@@ -51,12 +69,12 @@ To install the C version of ASSIST, first clone the REBOUND and then the ASSIST
5169

5270
To use use ASSIST, you also need to download ephemeris data files. One file for planet ephemeris and another suplementary file for asteroid ephemeris. The following commands download these files with curl. You can also manually download them using your browser. Note that these are large files, almost 1GB in size.
5371

54-
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440 -o assist/data/linux_p1550p2650.440
72+
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp -o assist/data/de440.bsp
5573
curl https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp -o assist/data/sb441-n16.bsp
5674

5775
For some of the examples, you will also need the planet ephemeris file with an extended coverage. Note that this file is 2.6GB in size.
5876

59-
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de441/linux_m13000p17000.441 -o assist/data/linux_m13000p17000.441
77+
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de441.bsp -o assist/data/de441.bsp
6078

6179
Next, go to one of the example directories and compile the problem file. This will also trigger the installation of the REBOUND and ASSIST shared libraries.
6280

@@ -81,5 +99,6 @@ ASSIST is open source, freely distributed under the [GNU General Public license,
8199
* Robert Weryk, University of Western Ontario
82100
* Dan Tamayo, Harvey Mudd College, <[email protected]>
83101
* David M. Hernandez, Center for Astrophysics | Harvard & Smithsonian
102+
* Alec Koumjian, Asteroid Institute | B612 Foundation, <[email protected]>
84103

85104

assist/ephem.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import warnings
2+
from ctypes import (CFUNCTYPE, POINTER, Structure, byref, c_char, c_char_p,
3+
c_double, c_int, c_long, c_uint, c_uint32, c_ulong,
4+
c_void_p, cast)
15
from typing import Optional, Union
26

3-
from . import clibassist, assist_error_messages
4-
from ctypes import Structure, c_double, POINTER, c_int, c_uint, c_long, c_ulong, c_void_p, c_char_p, CFUNCTYPE, byref, c_uint32, c_uint, cast, c_char
57
import rebound
8+
69
import assist
7-
import warnings
10+
11+
from . import assist_error_messages, clibassist
812

913
ASSIST_BODY_IDS = {
1014
0: "Sun",
@@ -82,8 +86,10 @@ def get_particle(self, body: Union[int, str], t: float) -> rebound.Particle:
8286
def __del__(self) -> None:
8387
clibassist.assist_ephem_free_pointers(byref(self))
8488

85-
_fields_ = [("jd_ref", c_double),
86-
("_pl", c_void_p),
87-
("_spl", c_void_p),
88-
]
89+
_fields_ = [
90+
("jd_ref", c_double),
91+
("spk_global", c_void_p),
92+
("spk_planets", c_void_p),
93+
("spk_asteroids", c_void_p),
94+
]
8995

assist/extras.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
from typing import NoReturn, List
2-
3-
from . import clibassist
4-
from ctypes import Structure, c_double, POINTER, c_int, c_uint, c_long, c_ulong, c_void_p, c_char_p, CFUNCTYPE, byref, c_uint32, c_uint, cast, c_char
5-
import rebound
61
import warnings
7-
from .ephem import Ephem
2+
from ctypes import (CFUNCTYPE, POINTER, Structure, byref, c_char, c_char_p,
3+
c_double, c_int, c_long, c_uint, c_uint32, c_ulong,
4+
c_void_p, cast)
5+
from typing import List, NoReturn
6+
87
import numpy as np
98
import numpy.typing as npt
109

10+
import rebound
11+
12+
from . import clibassist
13+
from .ephem import Ephem
14+
1115
ASSIST_FORCES = {
1216
"SUN" : 0x01,
1317
"PLANETS" : 0x02,

assist/test/test_apophis.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import rebound
2-
import assist
3-
import unittest
41
import math
2+
import unittest
3+
54
import numpy as np
5+
import rebound
6+
7+
import assist
8+
69

710
class TestAssist(unittest.TestCase):
811
def test_apophis(self):
912

10-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
13+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
1114

1215
t_initial = 2.4621385359989386E+06 - ephem.jd_ref # Julian Days relative to jd_ref
1316

assist/test/test_basic.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import math
2+
import unittest
3+
14
import rebound
5+
26
import assist
3-
import unittest
4-
import math
7+
58

69
class TestAssist(unittest.TestCase):
710
def test_rebound(self):
@@ -12,18 +15,18 @@ def test_rebound(self):
1215
self.assertEqual(sim.t,1.0)
1316

1417
def test_ephem(self):
15-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
18+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
1619
self.assertEqual(ephem.jd_ref, 2451545.0)
1720
p = ephem.get_particle(0,0) # Sun
18-
self.assertEqual(p.x, -0.007137179161607906)
21+
self.assertEqual(p.x, -0.0071371791616079054)
1922
p = ephem.get_particle(1,100) # planet
2023
self.assertEqual(p.x, 0.12906301685045435)
2124
p = ephem.get_particle(20,200) #asteroid
2225
self.assertEqual(p.x, -2.62956381075119)
2326
del ephem
2427

2528
def test_ephem_names(self):
26-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
29+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
2730
p1 = ephem.get_particle(0,0) # Sun
2831
p2 = ephem.get_particle("Sun",0) # Also Sun
2932
self.assertEqual(p1.x, p2.x)
@@ -32,7 +35,7 @@ def test_ephem_names(self):
3235
ephem.get_particle("Planet 9",0) # Does not exist
3336

3437
def test_holman(self):
35-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
38+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
3639

3740
sim = rebound.Simulation()
3841
extras = assist.Extras(sim, ephem)

assist/test/test_forces.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import math
2+
import unittest
3+
14
import rebound
5+
26
import assist
3-
import unittest
4-
import math
7+
58

69
class TestForces(unittest.TestCase):
710
def test_errors(self):
811
sim = rebound.Simulation()
9-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
12+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
1013
extras = assist.Extras(sim, ephem)
1114

1215
with self.assertRaises(AttributeError) as context:
@@ -33,7 +36,7 @@ def test_forces(self):
3336

3437
sim2 = sim.copy()
3538

36-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
39+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
3740
extras = assist.Extras(sim, ephem)
3841
extras2 = assist.Extras(sim2, ephem)
3942

assist/test/test_interpolate.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import math
2+
import unittest
3+
14
import rebound
5+
26
import assist
3-
import unittest
4-
import math
7+
58

69
class TestInterpolate(unittest.TestCase):
710
def test_interpolate(self):
@@ -18,7 +21,7 @@ def test_interpolate(self):
1821

1922
sim2 = sim.copy()
2023

21-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
24+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
2225
extras = assist.Extras(sim, ephem)
2326
extras2 = assist.Extras(sim2, ephem)
2427

@@ -30,7 +33,7 @@ def test_interpolate(self):
3033
d = sim.particles[0] - sim2.particles[0]
3134
au2meter = 149597870700
3235

33-
self.assertLess(math.fabs(d.x*au2meter), 0.01) # 1cm accurary
36+
self.assertLess(math.fabs(d.x*au2meter), 0.02) # 1cm accurary
3437
self.assertLess(math.fabs(d.y*au2meter), 0.01) # 1cm accurary
3538
self.assertLess(math.fabs(d.z*au2meter), 0.01) # 1cm accurary
3639

data/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
This is the standard location for the ephemeris files, i.e.:
2-
linux_m13000p17000.441 & sb441-n16.bsp
2+
de441.bsp & sb441-n16.bsp
33

44
You can download them from:
55

6-
https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440
6+
https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp
77
https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp

docs/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ To use ASSIST, you also need to download ephemeris data files. One file for plan
3131

3232
```bash
3333
mkdir data
34-
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de440/linux_p1550p2650.440 -o data/linux_p1550p2650.440
34+
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de440.bsp -o data/de440.bsp
3535
curl https://ssd.jpl.nasa.gov/ftp/eph/small_bodies/asteroids_de441/sb441-n16.bsp -o data/sb441-n16.bsp
3636
```
3737

3838
For some of the examples, you will also need the planet ephemeris file with an extended coverage.
3939

4040
```bash
41-
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/Linux/de441/linux_m13000p17000.441 -o assist/data/linux_m13000p17000.441
41+
curl https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de441.bsp -o assist/data/de441.bsp
4242
```
4343

4444
!!! Info
@@ -62,7 +62,7 @@ You can now verify that your installation of assist works.
6262
Then run the following code:
6363
```python
6464
import assist
65-
ephem = assist.Ephem("data/linux_p1550p2650.440", "data/sb441-n16.bsp")
65+
ephem = assist.Ephem("data/de440.bsp", "data/sb441-n16.bsp")
6666
print(ephem.jd_ref)
6767
ephem.get_particle("Earth", 0)
6868
```

examples/asteroid/problem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int argc, char* argv[]){
1717

1818
// Load the ephemeris data
1919
struct assist_ephem* ephem = assist_ephem_create(
20-
"../../data/linux_p1550p2650.440",
20+
"../../data/de440.bsp",
2121
"../../data/sb441-n16.bsp");
2222
if (!ephem){
2323
printf("Cannot create ephemeris structure.\n");

examples/ephemeris/problem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int argc, char* argv[]){
1717
// download the files.
1818

1919
struct assist_ephem* ephem = assist_ephem_create(
20-
"../../data/linux_p1550p2650.440",
20+
"../../data/de440.bsp",
2121
"../../data/sb441-n16.bsp");
2222
if (!ephem){
2323
printf("Cannot create ephemeris structure.\n");

0 commit comments

Comments
 (0)