pyorbiter 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .venv/
6
+ dist/
7
+ build/
8
+ *.gif
9
+ rsconnect-python/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dave Rosenman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyorbiter
3
+ Version: 0.1.0
4
+ Summary: A tidy N-body physics engine for building and visualizing orbital simulations.
5
+ Project-URL: Homepage, https://pyorbiter.com
6
+ Project-URL: Documentation, https://pyorbiter.com
7
+ Project-URL: Repository, https://github.com/DRosenman/pyorbiter
8
+ Project-URL: Issues, https://github.com/DRosenman/pyorbiter/issues
9
+ Project-URL: R package, https://github.com/DRosenman/orbitr
10
+ Author: Dave Rosenman
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: astronomy,n-body,orbital mechanics,physics,simulation
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
26
+ Classifier: Topic :: Scientific/Engineering :: Physics
27
+ Requires-Python: >=3.10
28
+ Requires-Dist: matplotlib>=3.7
29
+ Requires-Dist: numpy>=1.24
30
+ Requires-Dist: pandas>=2.0
31
+ Provides-Extra: app
32
+ Requires-Dist: shiny>=1.0; extra == 'app'
33
+ Provides-Extra: dev
34
+ Requires-Dist: pillow>=9.0; extra == 'dev'
35
+ Requires-Dist: plotly>=5.0; extra == 'dev'
36
+ Requires-Dist: polars>=1.0; extra == 'dev'
37
+ Requires-Dist: pytest>=7.0; extra == 'dev'
38
+ Provides-Extra: docs
39
+ Requires-Dist: griffe<2; extra == 'docs'
40
+ Requires-Dist: jupyter; extra == 'docs'
41
+ Requires-Dist: pillow>=9.0; extra == 'docs'
42
+ Requires-Dist: plotly>=5.0; extra == 'docs'
43
+ Requires-Dist: polars>=1.0; extra == 'docs'
44
+ Requires-Dist: quartodoc>=0.11; extra == 'docs'
45
+ Provides-Extra: gif
46
+ Requires-Dist: pillow>=9.0; extra == 'gif'
47
+ Provides-Extra: plotly
48
+ Requires-Dist: plotly>=5.0; extra == 'plotly'
49
+ Provides-Extra: polars
50
+ Requires-Dist: polars>=1.0; extra == 'polars'
51
+ Description-Content-Type: text/markdown
52
+
53
+ # pyorbiter
54
+
55
+ A tidy N-body physics engine for building and visualizing orbital simulations in Python.
56
+
57
+ Build a system of bodies, integrate it forward in time, and get back a tidy DataFrame with one row per body per time step, ready for pandas or polars, matplotlib, or plotly. `pyorbiter` is the Python sibling of the [orbitr](https://orbit-r.com) R package.
58
+
59
+ Full documentation, with a function reference and articles: <https://pyorbiter.com>.
60
+
61
+ ```python
62
+ import pyorbiter as orb
63
+
64
+ sim = (
65
+ orb.create_system()
66
+ .add_sun()
67
+ .add_planet("Earth", parent="Sun")
68
+ .simulate(time_step=orb.seconds_per_day, duration=orb.seconds_per_year)
69
+ )
70
+
71
+ orb.plot_orbits(sim)
72
+ ```
73
+
74
+ ## Installation
75
+
76
+ ```bash
77
+ pip install pyorbiter # the package
78
+ pip install "pyorbiter[plotly]" # plus interactive 3D plots
79
+ pip install "pyorbiter[polars]" # plus polars DataFrames
80
+ pip install "pyorbiter[gif]" # plus saving animations as GIFs
81
+ ```
82
+
83
+ To work on the package itself, clone the repository and install it in editable mode with the development tools:
84
+
85
+ ```bash
86
+ pip install -e ".[dev]"
87
+ ```
88
+
89
+ Requires Python 3.10+, numpy, pandas, and matplotlib. polars is optional.
90
+
91
+ ## A tour
92
+
93
+ Units are SI throughout (meters, kilograms, seconds); angles are in degrees.
94
+
95
+ ### Build
96
+
97
+ Every `add_*` method returns a new system, so calls chain the way the R pipe does.
98
+
99
+ ```python
100
+ system = (
101
+ orb.create_system()
102
+ .add_body("Sun", mass=orb.mass_sun)
103
+ .add_body("Earth", mass=orb.mass_earth, x=orb.distance_earth_sun, vy=orb.speed_earth)
104
+ # by orbital elements; e > 1 with a < 0 gives a hyperbola
105
+ .add_body_keplerian("Comet", mass=1e14, a=3e11, e=0.7, i=30, parent="Sun")
106
+ )
107
+
108
+ solar = orb.load_solar_system() # Sun, 8 planets, Moon, Pluto
109
+ inner = solar.remove_body(["Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"])
110
+ ```
111
+
112
+ ### Simulate
113
+
114
+ ```python
115
+ sim = solar.simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_year)
116
+ sim = orb.continue_simulation(sim, time_step=orb.seconds_per_hour, duration=orb.seconds_per_year)
117
+ ```
118
+
119
+ `method` is `"verlet"` (velocity Verlet, the default), `"euler_cromer"`, or `"euler"`. `softening` tames close encounters. The result has columns `id, mass, x, y, z, vx, vy, vz, time`, and the run's `G`, `softening`, `method`, and `time_step` are kept in `sim.attrs` (or, for either kind of DataFrame, `orb.run_settings(sim)`).
120
+
121
+ ### pandas or polars
122
+
123
+ Results are pandas DataFrames by default. To get polars DataFrames instead, install the extra (`pip install "pyorbiter[polars]"`) and switch the backend once:
124
+
125
+ ```python
126
+ orb.set_backend("polars")
127
+
128
+ sim = solar.simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_year) # a polars DataFrame
129
+ energy = orb.get_energy(sim) # also polars
130
+ ```
131
+
132
+ Or ask for it in a single call with `backend="polars"` on `simulate()`, `simulate_system()`, or `get_bodies()`. Every function that takes a simulation (analysis, plotting, `continue_simulation()`) accepts either kind and returns the kind it was given, so the two can be mixed freely. A polars `LazyFrame` is accepted too; it is collected, and a polars `DataFrame` comes back. Columns of your own that you add to a polars simulation are carried through untouched.
133
+
134
+ A polars DataFrame has no `.attrs`, so pyorbiter remembers the run's settings for the exact DataFrame it returned; `orb.run_settings(sim)` shows them. A frame you derive yourself (`sim.filter(...)`, `sort`, `with_columns`, a join, a file you read back) no longer carries them. If the run did not use the defaults, pass `G` and `softening` to the analysis functions, and `G`, `softening`, and `method` to `continue_simulation()`, explicitly. (pandas keeps `.attrs` through most of those operations, so this only matters for polars.)
135
+
136
+ ### Analyze
137
+
138
+ ```python
139
+ orb.shift_reference_frame(sim, "Earth") # or "barycenter"
140
+ orb.get_orbital_elements(sim, "Moon", "Earth") # a, e, i, lan, arg_pe, nu, period at every step
141
+ orb.conserved_quantities(sim) # energy, momentum, angular momentum, and their errors
142
+ ```
143
+
144
+ These take and return DataFrames, so they compose with `DataFrame.pipe`:
145
+
146
+ ```python
147
+ sim.pipe(orb.shift_reference_frame, "Earth").pipe(orb.plot_orbits)
148
+ ```
149
+
150
+ ### Plot
151
+
152
+ ```python
153
+ orb.plot_orbits(sim) # full trajectories
154
+ orb.plot_system(sim, time=30 * orb.seconds_per_day, trails=True) # a snapshot
155
+ orb.animate_system(sim, path="orbit.gif")
156
+ ```
157
+
158
+ 2D plots are matplotlib (and return the `Axes`). If there is any motion in `z` you get an interactive plotly figure instead; force either with `three_d=True/False`.
159
+
160
+ ## Coming from R
161
+
162
+ | orbitr (R) | pyorbiter (Python) |
163
+ |:--|:--|
164
+ | `create_system() \|> add_body(...)` | `orb.create_system().add_body(...)` (or `orb.add_body(system, ...)`) |
165
+ | `simulate_system(system, ...)` | `system.simulate(...)` or `orb.simulate_system(system, ...)` |
166
+ | `sim \|> shift_reference_frame("Earth")` | `orb.shift_reference_frame(sim, "Earth")` or `sim.pipe(...)` |
167
+ | a tibble with attributes | a pandas DataFrame with `.attrs`, or a polars DataFrame |
168
+ | `save_system()` writes `.rds` | `save_system()` writes JSON |
169
+ | ggplot2 / gganimate | matplotlib |
170
+ | the C++ kernel (`use_cpp`) | a vectorized numpy kernel |
171
+
172
+ Function names, argument names, constants, and defaults are otherwise the same. The test suite checks pyorbiter against numbers produced by orbitr 1.0.0 (`tests/reference/`); the two agree to about 8 significant figures or better.
173
+
174
+ ## The simulator app
175
+
176
+ `app/` holds a [Shiny for Python](https://shiny.posit.co/py/) simulator with preset scenarios, a snapshot slider, conservation diagnostics, orbital elements, and the code to reproduce each run.
177
+
178
+ ```bash
179
+ pip install -e ".[app]"
180
+ shiny run app/app.py
181
+ ```
182
+
183
+ ## Tests
184
+
185
+ ```bash
186
+ pytest
187
+ ```
188
+
189
+ ## License
190
+
191
+ MIT
@@ -0,0 +1,139 @@
1
+ # pyorbiter
2
+
3
+ A tidy N-body physics engine for building and visualizing orbital simulations in Python.
4
+
5
+ Build a system of bodies, integrate it forward in time, and get back a tidy DataFrame with one row per body per time step, ready for pandas or polars, matplotlib, or plotly. `pyorbiter` is the Python sibling of the [orbitr](https://orbit-r.com) R package.
6
+
7
+ Full documentation, with a function reference and articles: <https://pyorbiter.com>.
8
+
9
+ ```python
10
+ import pyorbiter as orb
11
+
12
+ sim = (
13
+ orb.create_system()
14
+ .add_sun()
15
+ .add_planet("Earth", parent="Sun")
16
+ .simulate(time_step=orb.seconds_per_day, duration=orb.seconds_per_year)
17
+ )
18
+
19
+ orb.plot_orbits(sim)
20
+ ```
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install pyorbiter # the package
26
+ pip install "pyorbiter[plotly]" # plus interactive 3D plots
27
+ pip install "pyorbiter[polars]" # plus polars DataFrames
28
+ pip install "pyorbiter[gif]" # plus saving animations as GIFs
29
+ ```
30
+
31
+ To work on the package itself, clone the repository and install it in editable mode with the development tools:
32
+
33
+ ```bash
34
+ pip install -e ".[dev]"
35
+ ```
36
+
37
+ Requires Python 3.10+, numpy, pandas, and matplotlib. polars is optional.
38
+
39
+ ## A tour
40
+
41
+ Units are SI throughout (meters, kilograms, seconds); angles are in degrees.
42
+
43
+ ### Build
44
+
45
+ Every `add_*` method returns a new system, so calls chain the way the R pipe does.
46
+
47
+ ```python
48
+ system = (
49
+ orb.create_system()
50
+ .add_body("Sun", mass=orb.mass_sun)
51
+ .add_body("Earth", mass=orb.mass_earth, x=orb.distance_earth_sun, vy=orb.speed_earth)
52
+ # by orbital elements; e > 1 with a < 0 gives a hyperbola
53
+ .add_body_keplerian("Comet", mass=1e14, a=3e11, e=0.7, i=30, parent="Sun")
54
+ )
55
+
56
+ solar = orb.load_solar_system() # Sun, 8 planets, Moon, Pluto
57
+ inner = solar.remove_body(["Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"])
58
+ ```
59
+
60
+ ### Simulate
61
+
62
+ ```python
63
+ sim = solar.simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_year)
64
+ sim = orb.continue_simulation(sim, time_step=orb.seconds_per_hour, duration=orb.seconds_per_year)
65
+ ```
66
+
67
+ `method` is `"verlet"` (velocity Verlet, the default), `"euler_cromer"`, or `"euler"`. `softening` tames close encounters. The result has columns `id, mass, x, y, z, vx, vy, vz, time`, and the run's `G`, `softening`, `method`, and `time_step` are kept in `sim.attrs` (or, for either kind of DataFrame, `orb.run_settings(sim)`).
68
+
69
+ ### pandas or polars
70
+
71
+ Results are pandas DataFrames by default. To get polars DataFrames instead, install the extra (`pip install "pyorbiter[polars]"`) and switch the backend once:
72
+
73
+ ```python
74
+ orb.set_backend("polars")
75
+
76
+ sim = solar.simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_year) # a polars DataFrame
77
+ energy = orb.get_energy(sim) # also polars
78
+ ```
79
+
80
+ Or ask for it in a single call with `backend="polars"` on `simulate()`, `simulate_system()`, or `get_bodies()`. Every function that takes a simulation (analysis, plotting, `continue_simulation()`) accepts either kind and returns the kind it was given, so the two can be mixed freely. A polars `LazyFrame` is accepted too; it is collected, and a polars `DataFrame` comes back. Columns of your own that you add to a polars simulation are carried through untouched.
81
+
82
+ A polars DataFrame has no `.attrs`, so pyorbiter remembers the run's settings for the exact DataFrame it returned; `orb.run_settings(sim)` shows them. A frame you derive yourself (`sim.filter(...)`, `sort`, `with_columns`, a join, a file you read back) no longer carries them. If the run did not use the defaults, pass `G` and `softening` to the analysis functions, and `G`, `softening`, and `method` to `continue_simulation()`, explicitly. (pandas keeps `.attrs` through most of those operations, so this only matters for polars.)
83
+
84
+ ### Analyze
85
+
86
+ ```python
87
+ orb.shift_reference_frame(sim, "Earth") # or "barycenter"
88
+ orb.get_orbital_elements(sim, "Moon", "Earth") # a, e, i, lan, arg_pe, nu, period at every step
89
+ orb.conserved_quantities(sim) # energy, momentum, angular momentum, and their errors
90
+ ```
91
+
92
+ These take and return DataFrames, so they compose with `DataFrame.pipe`:
93
+
94
+ ```python
95
+ sim.pipe(orb.shift_reference_frame, "Earth").pipe(orb.plot_orbits)
96
+ ```
97
+
98
+ ### Plot
99
+
100
+ ```python
101
+ orb.plot_orbits(sim) # full trajectories
102
+ orb.plot_system(sim, time=30 * orb.seconds_per_day, trails=True) # a snapshot
103
+ orb.animate_system(sim, path="orbit.gif")
104
+ ```
105
+
106
+ 2D plots are matplotlib (and return the `Axes`). If there is any motion in `z` you get an interactive plotly figure instead; force either with `three_d=True/False`.
107
+
108
+ ## Coming from R
109
+
110
+ | orbitr (R) | pyorbiter (Python) |
111
+ |:--|:--|
112
+ | `create_system() \|> add_body(...)` | `orb.create_system().add_body(...)` (or `orb.add_body(system, ...)`) |
113
+ | `simulate_system(system, ...)` | `system.simulate(...)` or `orb.simulate_system(system, ...)` |
114
+ | `sim \|> shift_reference_frame("Earth")` | `orb.shift_reference_frame(sim, "Earth")` or `sim.pipe(...)` |
115
+ | a tibble with attributes | a pandas DataFrame with `.attrs`, or a polars DataFrame |
116
+ | `save_system()` writes `.rds` | `save_system()` writes JSON |
117
+ | ggplot2 / gganimate | matplotlib |
118
+ | the C++ kernel (`use_cpp`) | a vectorized numpy kernel |
119
+
120
+ Function names, argument names, constants, and defaults are otherwise the same. The test suite checks pyorbiter against numbers produced by orbitr 1.0.0 (`tests/reference/`); the two agree to about 8 significant figures or better.
121
+
122
+ ## The simulator app
123
+
124
+ `app/` holds a [Shiny for Python](https://shiny.posit.co/py/) simulator with preset scenarios, a snapshot slider, conservation diagnostics, orbital elements, and the code to reproduce each run.
125
+
126
+ ```bash
127
+ pip install -e ".[app]"
128
+ shiny run app/app.py
129
+ ```
130
+
131
+ ## Tests
132
+
133
+ ```bash
134
+ pytest
135
+ ```
136
+
137
+ ## License
138
+
139
+ MIT