harv 0.0.1__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.
Files changed (74) hide show
  1. harv-0.0.1/.gitignore +252 -0
  2. harv-0.0.1/LICENSE +21 -0
  3. harv-0.0.1/PKG-INFO +206 -0
  4. harv-0.0.1/README.md +168 -0
  5. harv-0.0.1/pyproject.toml +359 -0
  6. harv-0.0.1/src/harv/__init__.py +64 -0
  7. harv-0.0.1/src/harv/_version.py +24 -0
  8. harv-0.0.1/src/harv/custom_types.py +91 -0
  9. harv-0.0.1/src/harv/data/__init__.py +28 -0
  10. harv-0.0.1/src/harv/data/containers.py +351 -0
  11. harv-0.0.1/src/harv/data/datasets.py +334 -0
  12. harv-0.0.1/src/harv/data/helpers.py +182 -0
  13. harv-0.0.1/src/harv/distributions.py +81 -0
  14. harv-0.0.1/src/harv/io.py +70 -0
  15. harv-0.0.1/src/harv/kepler/__init__.py +38 -0
  16. harv-0.0.1/src/harv/kepler/body.py +267 -0
  17. harv-0.0.1/src/harv/kepler/constants.py +8 -0
  18. harv-0.0.1/src/harv/kepler/masses.py +197 -0
  19. harv-0.0.1/src/harv/kepler/nbody_system.py +156 -0
  20. harv-0.0.1/src/harv/kepler/orbits.py +505 -0
  21. harv-0.0.1/src/harv/kepler/orientation.py +283 -0
  22. harv-0.0.1/src/harv/models/__init__.py +40 -0
  23. harv-0.0.1/src/harv/models/_helpers.py +121 -0
  24. harv-0.0.1/src/harv/models/astrometry.py +162 -0
  25. harv-0.0.1/src/harv/models/component.py +980 -0
  26. harv-0.0.1/src/harv/models/extensions/__init__.py +16 -0
  27. harv-0.0.1/src/harv/models/extensions/base.py +142 -0
  28. harv-0.0.1/src/harv/models/extensions/gp.py +136 -0
  29. harv-0.0.1/src/harv/models/extensions/jitter.py +65 -0
  30. harv-0.0.1/src/harv/models/extensions/multi_survey.py +76 -0
  31. harv-0.0.1/src/harv/models/extensions/trend.py +107 -0
  32. harv-0.0.1/src/harv/models/joint.py +1408 -0
  33. harv-0.0.1/src/harv/models/parameterizations/__init__.py +19 -0
  34. harv-0.0.1/src/harv/models/parameterizations/_base.py +103 -0
  35. harv-0.0.1/src/harv/models/parameterizations/gaia.py +702 -0
  36. harv-0.0.1/src/harv/models/parameterizations/rv.py +309 -0
  37. harv-0.0.1/src/harv/models/priors/__init__.py +15 -0
  38. harv-0.0.1/src/harv/models/priors/custom_priors.py +255 -0
  39. harv-0.0.1/src/harv/models/priors/defaults.py +131 -0
  40. harv-0.0.1/src/harv/models/priors/helpers.py +169 -0
  41. harv-0.0.1/src/harv/models/priors/prior.py +178 -0
  42. harv-0.0.1/src/harv/models/rv.py +135 -0
  43. harv-0.0.1/src/harv/plot.py +1265 -0
  44. harv-0.0.1/src/harv/samplers/__init__.py +24 -0
  45. harv-0.0.1/src/harv/samplers/base.py +81 -0
  46. harv-0.0.1/src/harv/samplers/conversion.py +209 -0
  47. harv-0.0.1/src/harv/samplers/numpyro.py +1076 -0
  48. harv-0.0.1/src/harv/samplers/rejection.py +691 -0
  49. harv-0.0.1/src/harv/samplers/samples.py +1583 -0
  50. harv-0.0.1/src/harv/simulate/__init__.py +14 -0
  51. harv-0.0.1/src/harv/simulate/astrometry.py +332 -0
  52. harv-0.0.1/src/harv/simulate/rv.py +311 -0
  53. harv-0.0.1/src/harv/simulate/scanlaw.py +124 -0
  54. harv-0.0.1/tests/functional/__init__.py +1 -0
  55. harv-0.0.1/tests/functional/test_api.py +314 -0
  56. harv-0.0.1/tests/functional/test_kepler.py +78 -0
  57. harv-0.0.1/tests/unit/extensions/__init__.py +0 -0
  58. harv-0.0.1/tests/unit/extensions/test_base.py +67 -0
  59. harv-0.0.1/tests/unit/extensions/test_extensions.py +455 -0
  60. harv-0.0.1/tests/unit/extensions/test_gp.py +321 -0
  61. harv-0.0.1/tests/unit/kepler/__init__.py +0 -0
  62. harv-0.0.1/tests/unit/kepler/test_body.py +310 -0
  63. harv-0.0.1/tests/unit/kepler/test_helpers.py +51 -0
  64. harv-0.0.1/tests/unit/kepler/test_masses.py +113 -0
  65. harv-0.0.1/tests/unit/kepler/test_nbody_system.py +195 -0
  66. harv-0.0.1/tests/unit/kepler/test_orbit_math.py +354 -0
  67. harv-0.0.1/tests/unit/kepler/test_orientation.py +299 -0
  68. harv-0.0.1/tests/unit/models/__init__.py +0 -0
  69. harv-0.0.1/tests/unit/models/test_astrometry_model.py +258 -0
  70. harv-0.0.1/tests/unit/models/test_ecosw_esinw.py +285 -0
  71. harv-0.0.1/tests/unit/models/test_joint_model.py +384 -0
  72. harv-0.0.1/tests/unit/models/test_numpyro_model.py +194 -0
  73. harv-0.0.1/tests/unit/models/test_parameterizations.py +481 -0
  74. harv-0.0.1/tests/unit/models/test_rv_model.py +194 -0
harv-0.0.1/.gitignore ADDED
@@ -0,0 +1,252 @@
1
+ ### Linux template
2
+ *~
3
+
4
+ # temporary files which can be created if a process still has a handle open of a deleted file
5
+ .fuse_hidden*
6
+
7
+ # KDE directory preferences
8
+ .directory
9
+
10
+ # Linux trash folder which might appear on any partition or disk
11
+ .Trash-*
12
+
13
+ # .nfs files are created when an open file is removed but is still being accessed
14
+ .nfs*
15
+
16
+ ### Windows template
17
+ # Windows thumbnail cache files
18
+ Thumbs.db
19
+ Thumbs.db:encryptable
20
+ ehthumbs.db
21
+ ehthumbs_vista.db
22
+
23
+ # Dump file
24
+ *.stackdump
25
+
26
+ # Folder config file
27
+ [Dd]esktop.ini
28
+
29
+ # Recycle Bin used on file shares
30
+ $RECYCLE.BIN/
31
+
32
+ # Windows Installer files
33
+ *.cab
34
+ *.msi
35
+ *.msix
36
+ *.msm
37
+ *.msp
38
+
39
+ # Windows shortcuts
40
+ *.lnk
41
+
42
+ ### JupyterNotebooks template
43
+ # gitignore template for Jupyter Notebooks
44
+ # website: http://jupyter.org/
45
+
46
+ .ipynb_checkpoints
47
+ */.ipynb_checkpoints/*
48
+
49
+ # IPython
50
+ profile_default/
51
+ ipython_config.py
52
+
53
+ # Remove previous ipynb_checkpoints
54
+ # git rm -r .ipynb_checkpoints/
55
+
56
+ ### macOS template
57
+ # General
58
+ .DS_Store
59
+ .AppleDouble
60
+ .LSOverride
61
+
62
+ # Icon must end with two \r
63
+ Icon
64
+
65
+ # Thumbnails
66
+ ._*
67
+
68
+ # Files that might appear in the root of a volume
69
+ .DocumentRevisions-V100
70
+ .fseventsd
71
+ .Spotlight-V100
72
+ .TemporaryItems
73
+ .Trashes
74
+ .VolumeIcon.icns
75
+ .com.apple.timemachine.donotpresent
76
+
77
+ # Directories potentially created on remote AFP share
78
+ .AppleDB
79
+ .AppleDesktop
80
+ Network Trash Folder
81
+ Temporary Items
82
+ .apdisk
83
+
84
+ ### Python template
85
+ # Byte-compiled / optimized / DLL files
86
+ __pycache__/
87
+ *.py[cod]
88
+ *$py.class
89
+
90
+ # C extensions
91
+ *.so
92
+
93
+ # Distribution / packaging
94
+ .Python
95
+ build/
96
+ develop-eggs/
97
+ dist/
98
+ downloads/
99
+ eggs/
100
+ .eggs/
101
+ lib/
102
+ lib64/
103
+ parts/
104
+ sdist/
105
+ var/
106
+ wheels/
107
+ share/python-wheels/
108
+ *.egg-info/
109
+ .installed.cfg
110
+ *.egg
111
+ MANIFEST
112
+
113
+ # PyInstaller
114
+ # Usually these files are written by a python script from a template
115
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
116
+ *.manifest
117
+ *.spec
118
+
119
+ # Installer logs
120
+ pip-log.txt
121
+ pip-delete-this-directory.txt
122
+
123
+ # Unit test / coverage reports
124
+ htmlcov/
125
+ .tox/
126
+ .nox/
127
+ .coverage
128
+ .coverage.*
129
+ .cache
130
+ nosetests.xml
131
+ coverage.xml
132
+ *.cover
133
+ *.py,cover
134
+ .hypothesis/
135
+ .pytest_cache/
136
+ cover/
137
+
138
+ # Translations
139
+ *.mo
140
+ *.pot
141
+
142
+ # Django stuff:
143
+ *.log
144
+ local_settings.py
145
+ db.sqlite3
146
+ db.sqlite3-journal
147
+
148
+ # Flask stuff:
149
+ instance/
150
+ .webassets-cache
151
+
152
+ # Scrapy stuff:
153
+ .scrapy
154
+
155
+ # Sphinx documentation
156
+ docs/_build/
157
+ docs/api
158
+
159
+ # PyBuilder
160
+ .pybuilder/
161
+ target/
162
+
163
+ # Jupyter Notebook
164
+
165
+ # IPython
166
+
167
+ # pyenv
168
+ # For a library or package, you might want to ignore these files since the code is
169
+ # intended to run in multiple environments; otherwise, check them in:
170
+ # .python-version
171
+
172
+ # pipenv
173
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
174
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
175
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
176
+ # install all needed dependencies.
177
+ #Pipfile.lock
178
+
179
+ # poetry
180
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
181
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
182
+ # commonly ignored for libraries.
183
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
184
+ #poetry.lock
185
+
186
+ # pdm
187
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
188
+ #pdm.lock
189
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
190
+ # in version control.
191
+ # https://pdm.fming.dev/#use-with-ide
192
+ .pdm.toml
193
+
194
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
195
+ __pypackages__/
196
+
197
+ # Celery stuff
198
+ celerybeat-schedule
199
+ celerybeat.pid
200
+
201
+ # SageMath parsed files
202
+ *.sage.py
203
+
204
+ # Environments
205
+ .env
206
+ .venv
207
+ env/
208
+ venv/
209
+ ENV/
210
+ env.bak/
211
+ venv.bak/
212
+
213
+ # Spyder project settings
214
+ .spyderproject
215
+ .spyproject
216
+
217
+ # Rope project settings
218
+ .ropeproject
219
+
220
+ # mkdocs documentation
221
+ /site
222
+
223
+ # mypy
224
+ .mypy_cache/
225
+ .dmypy.json
226
+ dmypy.json
227
+
228
+ # Pyre type checker
229
+ .pyre/
230
+
231
+ # pytype static type analyzer
232
+ .pytype/
233
+
234
+ # ty
235
+ .ty_cache/
236
+
237
+ # Cython debug symbols
238
+ cython_debug/
239
+
240
+ # PyCharm
241
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
242
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
243
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
244
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
245
+ #.idea/
246
+
247
+ # Hatch-VCS
248
+ _version.py
249
+
250
+ /data
251
+ notebooks
252
+ docs/_static/logo*
harv-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 adrn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice (including the next
13
+ paragraph) shall be included in all copies or substantial portions of the
14
+ Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
harv-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: harv
3
+ Version: 0.0.1
4
+ Summary: Tools for modeling Keplerian systems in astrometric and/or radial velocity data.
5
+ Project-URL: Homepage, https://github.com/adrn/harv
6
+ Project-URL: Source Code, https://github.com/adrn/harv
7
+ Project-URL: Bug Tracker, https://github.com/adrn/harv/issues
8
+ Project-URL: Documentation, https://harv.readthedocs.io
9
+ Project-URL: Download, https://pypi.org/project/harv/#files
10
+ Author-email: adrn <583379+adrn@users.noreply.github.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Classifier: Development Status :: 2 - Pre-Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Requires-Python: >=3.12
19
+ Requires-Dist: equinox>=0.13.2
20
+ Requires-Dist: h5py>=3.15.1
21
+ Requires-Dist: jax==0.8.1
22
+ Requires-Dist: jaxoplanet>=0.1.0
23
+ Requires-Dist: jaxtyping>=0.3.3
24
+ Requires-Dist: numpyro-ext>=0.0.4
25
+ Requires-Dist: numpyro>=0.15.0
26
+ Requires-Dist: quaxed>=0.10.4
27
+ Requires-Dist: unxt>=1.7.2
28
+ Provides-Extra: extra
29
+ Requires-Dist: arviz>=1.0.0; extra == 'extra'
30
+ Requires-Dist: gaiaunlimited>=0.3.2; extra == 'extra'
31
+ Requires-Dist: healpy>=1.18.1; extra == 'extra'
32
+ Requires-Dist: matplotlib>=3.10.7; extra == 'extra'
33
+ Requires-Dist: pooch>=1.8.2; extra == 'extra'
34
+ Requires-Dist: scikit-learn>=1.5; extra == 'extra'
35
+ Requires-Dist: setuptools; extra == 'extra'
36
+ Requires-Dist: tinygp>=0.3.1; extra == 'extra'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # harv
40
+
41
+ [![Tests](https://github.com/adrn/harv/actions/workflows/test.yml/badge.svg)](https://github.com/adrn/harv/actions/workflows/test.yml)
42
+ [![Docs](https://readthedocs.org/projects/harv/badge/?version=latest)](https://harv.readthedocs.io/en/latest/)
43
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
44
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://python.org)
45
+
46
+ <br/>
47
+ <div align="center">
48
+ <img
49
+ src="https://raw.githubusercontent.com/adrn/harv/refs/heads/main/docs/_static/logo-text-only.png"
50
+ alt="harv logo"
51
+ width="300"
52
+ >
53
+ </div>
54
+ <br/>
55
+
56
+ **harv** is a Python package for inferring Keplerian orbital parameters of binary-star
57
+ and star–exoplanet systems from time series data. Built on
58
+ [JAX](https://github.com/google/jax), [NumPyro](https://github.com/pyro-ppl/numpyro),
59
+ and [unxt](https://github.com/GalacticDynamics/unxt) for units-aware computation.
60
+
61
+ It's pronounced _harvey_.
62
+
63
+ ## ⚠️ Warning! ⚠️
64
+
65
+ `harv` is in rapid development and is pre-alpha. Meaning the API is not stable or
66
+ guaranteed! Once the first version is released, we will have some guarantees about
67
+ backwards compatibility, but there are no guarantees for API stability with the current
68
+ development versions of this package. Sorry!
69
+
70
+ <!-- ### Key features
71
+
72
+ - **JAX-native** — JIT-compiled likelihoods and samplers; runs on CPU or GPU.
73
+ - **Units throughout** — all physical quantities carry explicit units via
74
+ [unxt](https://github.com/GalacticDynamics/unxt), reducing unit-conversion errors
75
+ - **Analytical marginalization** — linear parameters (semi-amplitude, systemic velocity,
76
+ astrometric offsets) are marginalized analytically for fast rejection sampling
77
+ - **Multi-instrument support** — fit RV data from multiple spectrographs with
78
+ per-instrument offsets
79
+ - **Gaia DR4 ready** — native support for Gaia epoch astrometry (along-scan
80
+ measurements) using the local plane coordinate convention
81
+ - **SB1 and SB2** — supports single- and double-lined spectroscopic binaries
82
+ - **Polynomial trends** — optional polynomial velocity trends for long-period companions -->
83
+
84
+ ## Installation
85
+
86
+ Requires Python 3.12+. Install from GitHub:
87
+
88
+ ```bash
89
+ pip install git+https://github.com/adrn/harv
90
+ ```
91
+
92
+ Or, if using [uv](https://docs.astral.sh/uv/):
93
+
94
+ ```bash
95
+ uv add git+https://github.com/adrn/harv
96
+ ```
97
+
98
+ ## Quickstart
99
+
100
+ TODO: move to a quickstart page in documentation and link here.
101
+
102
+ ### Radial velocity modeling
103
+
104
+ ```python
105
+ from unxt import Q
106
+ import harv
107
+ import harv.models as hm
108
+
109
+ # Load or create RV data with explicit units - some sample RV data:
110
+ data = harv.RVData(
111
+ time=Q([56000.0, 56100.0, 56250.0, 56400.0, 56600.0], "day"),
112
+ rv=Q([12.3, -8.7, 5.1, -14.2, 10.8], "km/s"),
113
+ rv_err=Q([1.2, 0.9, 1.1, 0.8, 1.0], "km/s"),
114
+ )
115
+
116
+ # Set up a prior with default structure (log-uniform in period, etc.)
117
+ prior = hm.StandardRV().default_prior(
118
+ period_min=Q(10, "day"),
119
+ period_max=Q(1000, "day"),
120
+ sigma_K0=Q(30, "km/s"), # RV semi-amplitude scale
121
+ sigma_v0=Q(10, "km/s"), # systemic velocity prior width
122
+ )
123
+
124
+ # Run the rejection sampler
125
+ sampler = harv.RejectionSampler(prior, harv.RVModel())
126
+ samples = sampler.run(data, n_prior_samples=1_000_000, seed=42)
127
+
128
+ # Inspect results — quantities carry units:
129
+ print(f"Accepted {samples.n_samples} posterior samples")
130
+ print(f"Period: {samples['period']}")
131
+ print(f"Eccentricity: {samples['eccentricity']}")
132
+ ```
133
+
134
+ ### Gaia epoch astrometry
135
+
136
+ <!-- TODO: custom parallax prior parallax=harv.QD(dist.TruncatedNormal(0.5, 0.5, low=0.0), "mas"), # parallax prior -->
137
+
138
+ ```python
139
+ import numpyro.distributions as dist
140
+ import quaxed.numpy as jnp
141
+
142
+ astro_data = harv.GaiaAstrometryData(
143
+ time=Q([958.110978, 994.910525, 995.086642, 1010.091395, 1076.918577], "day"),
144
+ al_position=Q([147.066, 379.996, 378.656, 74.666, -293.923], "mas"),
145
+ al_position_err=Q([0.370, 0.446, 0.428, 0.270, 0.247], "mas"),
146
+ scan_angle=Q([-59.047, -5.114, -5.783, -68.579, -134.155], "deg"),
147
+ parallax_factor=jnp.array([0.70828, -0.46657, -0.45946, 0.19659, -0.21379])
148
+ )
149
+
150
+ prior = hm.StandardGaiaAstrometry().default_prior(
151
+ period_min=Q(50, "day"),
152
+ period_max=Q(3000, "day"),
153
+ sigma_a0=Q(1, "au"), # astrometric semi-major axis prior scale
154
+ sigma_parallax=Q(1.0, "mas"), # parallax prior width
155
+ sigma_pos=Q(1, "mas"), # position offset prior width
156
+ sigma_vtan=Q(30, "km/s"), # tangential velocity prior width
157
+ )
158
+
159
+ sampler = harv.RejectionSampler(prior, harv.GaiaAstrometryModel())
160
+ samples = sampler.run(astro_data, n_prior_samples=1_000_000, seed=42)
161
+ ```
162
+
163
+ ### MCMC continuation
164
+
165
+ When the rejection sampler returns a small number of samples, you can refine with
166
+ NumPyro MCMC, started from the posterior samples:
167
+
168
+ ```py
169
+ from harv.samplers import NumpyroSampler
170
+
171
+ samples = sampler.run(n_prior_samples=1_000_000, max_posterior_samples=128)
172
+ mcmc_sampler = NumpyroSampler(model=model, prior=prior)
173
+ mcmc_samples = mcmc_sampler.run(samples, seed=0)
174
+ ```
175
+
176
+ ## How it works
177
+
178
+ **harv** is built on the same tricks as [The Joker](https://github.com/adrn/thejoker)
179
+ (Price-Whelan et al. 2017) to make rejection sampling practical for Keplerian orbit
180
+ inference. It uses a two-level parameterization that separates orbital parameters into:
181
+
182
+ 1. **Nonlinear parameters** (period, eccentricity, argument of pericenter, phase) —
183
+ sampled directly from the prior via rejection sampling, and
184
+ 1. **Linear parameters** (RV semi-amplitude, systemic velocity, astrometric offsets) —
185
+ these can be analytically marginalized given each set of nonlinear parameters.
186
+
187
+ This approach makes rejection sampling possible for high-dimensional parameter spaces by
188
+ reducing the effective dimensionality of the sampling problem. The main utility of the
189
+ rejection sampler is to map out the multi-modal posterior distribution of orbital
190
+ parameters in the low signal-to-noise or low number of observations regime, which is
191
+ challenging or impossible for MCMC methods. The samples returned by the rejection
192
+ sampler are exact draws from the posterior distribution, and can be used to initialize
193
+ MCMC samplers for further refinement, if necessary.
194
+
195
+ All objects are [Equinox](https://github.com/patrick-kidger/equinox) modules (valid JAX
196
+ pytrees), so they work seamlessly with `jax.jit`, `jax.vmap`, and `jax.grad`.
197
+
198
+ ## Documentation
199
+
200
+ TODO: Full documentation will be available at
201
+ [harv.readthedocs.io](https://harv.readthedocs.io).
202
+
203
+ ## License
204
+
205
+ **harv** is free software released under the MIT License. See [LICENSE](LICENSE) for
206
+ details.
harv-0.0.1/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # harv
2
+
3
+ [![Tests](https://github.com/adrn/harv/actions/workflows/test.yml/badge.svg)](https://github.com/adrn/harv/actions/workflows/test.yml)
4
+ [![Docs](https://readthedocs.org/projects/harv/badge/?version=latest)](https://harv.readthedocs.io/en/latest/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://python.org)
7
+
8
+ <br/>
9
+ <div align="center">
10
+ <img
11
+ src="https://raw.githubusercontent.com/adrn/harv/refs/heads/main/docs/_static/logo-text-only.png"
12
+ alt="harv logo"
13
+ width="300"
14
+ >
15
+ </div>
16
+ <br/>
17
+
18
+ **harv** is a Python package for inferring Keplerian orbital parameters of binary-star
19
+ and star–exoplanet systems from time series data. Built on
20
+ [JAX](https://github.com/google/jax), [NumPyro](https://github.com/pyro-ppl/numpyro),
21
+ and [unxt](https://github.com/GalacticDynamics/unxt) for units-aware computation.
22
+
23
+ It's pronounced _harvey_.
24
+
25
+ ## ⚠️ Warning! ⚠️
26
+
27
+ `harv` is in rapid development and is pre-alpha. Meaning the API is not stable or
28
+ guaranteed! Once the first version is released, we will have some guarantees about
29
+ backwards compatibility, but there are no guarantees for API stability with the current
30
+ development versions of this package. Sorry!
31
+
32
+ <!-- ### Key features
33
+
34
+ - **JAX-native** — JIT-compiled likelihoods and samplers; runs on CPU or GPU.
35
+ - **Units throughout** — all physical quantities carry explicit units via
36
+ [unxt](https://github.com/GalacticDynamics/unxt), reducing unit-conversion errors
37
+ - **Analytical marginalization** — linear parameters (semi-amplitude, systemic velocity,
38
+ astrometric offsets) are marginalized analytically for fast rejection sampling
39
+ - **Multi-instrument support** — fit RV data from multiple spectrographs with
40
+ per-instrument offsets
41
+ - **Gaia DR4 ready** — native support for Gaia epoch astrometry (along-scan
42
+ measurements) using the local plane coordinate convention
43
+ - **SB1 and SB2** — supports single- and double-lined spectroscopic binaries
44
+ - **Polynomial trends** — optional polynomial velocity trends for long-period companions -->
45
+
46
+ ## Installation
47
+
48
+ Requires Python 3.12+. Install from GitHub:
49
+
50
+ ```bash
51
+ pip install git+https://github.com/adrn/harv
52
+ ```
53
+
54
+ Or, if using [uv](https://docs.astral.sh/uv/):
55
+
56
+ ```bash
57
+ uv add git+https://github.com/adrn/harv
58
+ ```
59
+
60
+ ## Quickstart
61
+
62
+ TODO: move to a quickstart page in documentation and link here.
63
+
64
+ ### Radial velocity modeling
65
+
66
+ ```python
67
+ from unxt import Q
68
+ import harv
69
+ import harv.models as hm
70
+
71
+ # Load or create RV data with explicit units - some sample RV data:
72
+ data = harv.RVData(
73
+ time=Q([56000.0, 56100.0, 56250.0, 56400.0, 56600.0], "day"),
74
+ rv=Q([12.3, -8.7, 5.1, -14.2, 10.8], "km/s"),
75
+ rv_err=Q([1.2, 0.9, 1.1, 0.8, 1.0], "km/s"),
76
+ )
77
+
78
+ # Set up a prior with default structure (log-uniform in period, etc.)
79
+ prior = hm.StandardRV().default_prior(
80
+ period_min=Q(10, "day"),
81
+ period_max=Q(1000, "day"),
82
+ sigma_K0=Q(30, "km/s"), # RV semi-amplitude scale
83
+ sigma_v0=Q(10, "km/s"), # systemic velocity prior width
84
+ )
85
+
86
+ # Run the rejection sampler
87
+ sampler = harv.RejectionSampler(prior, harv.RVModel())
88
+ samples = sampler.run(data, n_prior_samples=1_000_000, seed=42)
89
+
90
+ # Inspect results — quantities carry units:
91
+ print(f"Accepted {samples.n_samples} posterior samples")
92
+ print(f"Period: {samples['period']}")
93
+ print(f"Eccentricity: {samples['eccentricity']}")
94
+ ```
95
+
96
+ ### Gaia epoch astrometry
97
+
98
+ <!-- TODO: custom parallax prior parallax=harv.QD(dist.TruncatedNormal(0.5, 0.5, low=0.0), "mas"), # parallax prior -->
99
+
100
+ ```python
101
+ import numpyro.distributions as dist
102
+ import quaxed.numpy as jnp
103
+
104
+ astro_data = harv.GaiaAstrometryData(
105
+ time=Q([958.110978, 994.910525, 995.086642, 1010.091395, 1076.918577], "day"),
106
+ al_position=Q([147.066, 379.996, 378.656, 74.666, -293.923], "mas"),
107
+ al_position_err=Q([0.370, 0.446, 0.428, 0.270, 0.247], "mas"),
108
+ scan_angle=Q([-59.047, -5.114, -5.783, -68.579, -134.155], "deg"),
109
+ parallax_factor=jnp.array([0.70828, -0.46657, -0.45946, 0.19659, -0.21379])
110
+ )
111
+
112
+ prior = hm.StandardGaiaAstrometry().default_prior(
113
+ period_min=Q(50, "day"),
114
+ period_max=Q(3000, "day"),
115
+ sigma_a0=Q(1, "au"), # astrometric semi-major axis prior scale
116
+ sigma_parallax=Q(1.0, "mas"), # parallax prior width
117
+ sigma_pos=Q(1, "mas"), # position offset prior width
118
+ sigma_vtan=Q(30, "km/s"), # tangential velocity prior width
119
+ )
120
+
121
+ sampler = harv.RejectionSampler(prior, harv.GaiaAstrometryModel())
122
+ samples = sampler.run(astro_data, n_prior_samples=1_000_000, seed=42)
123
+ ```
124
+
125
+ ### MCMC continuation
126
+
127
+ When the rejection sampler returns a small number of samples, you can refine with
128
+ NumPyro MCMC, started from the posterior samples:
129
+
130
+ ```py
131
+ from harv.samplers import NumpyroSampler
132
+
133
+ samples = sampler.run(n_prior_samples=1_000_000, max_posterior_samples=128)
134
+ mcmc_sampler = NumpyroSampler(model=model, prior=prior)
135
+ mcmc_samples = mcmc_sampler.run(samples, seed=0)
136
+ ```
137
+
138
+ ## How it works
139
+
140
+ **harv** is built on the same tricks as [The Joker](https://github.com/adrn/thejoker)
141
+ (Price-Whelan et al. 2017) to make rejection sampling practical for Keplerian orbit
142
+ inference. It uses a two-level parameterization that separates orbital parameters into:
143
+
144
+ 1. **Nonlinear parameters** (period, eccentricity, argument of pericenter, phase) —
145
+ sampled directly from the prior via rejection sampling, and
146
+ 1. **Linear parameters** (RV semi-amplitude, systemic velocity, astrometric offsets) —
147
+ these can be analytically marginalized given each set of nonlinear parameters.
148
+
149
+ This approach makes rejection sampling possible for high-dimensional parameter spaces by
150
+ reducing the effective dimensionality of the sampling problem. The main utility of the
151
+ rejection sampler is to map out the multi-modal posterior distribution of orbital
152
+ parameters in the low signal-to-noise or low number of observations regime, which is
153
+ challenging or impossible for MCMC methods. The samples returned by the rejection
154
+ sampler are exact draws from the posterior distribution, and can be used to initialize
155
+ MCMC samplers for further refinement, if necessary.
156
+
157
+ All objects are [Equinox](https://github.com/patrick-kidger/equinox) modules (valid JAX
158
+ pytrees), so they work seamlessly with `jax.jit`, `jax.vmap`, and `jax.grad`.
159
+
160
+ ## Documentation
161
+
162
+ TODO: Full documentation will be available at
163
+ [harv.readthedocs.io](https://harv.readthedocs.io).
164
+
165
+ ## License
166
+
167
+ **harv** is free software released under the MIT License. See [LICENSE](LICENSE) for
168
+ details.