Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 beta! #270

Merged
merged 114 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
cb0daa1
some initial code & notes on fully integrated HippIAD API
sblunt Feb 10, 2021
7831faf
almost working separation of compute_model and multiplanet
sblunt Feb 17, 2021
e4fac1f
Merge branch 'main' into hip-iad
sblunt Feb 17, 2021
a0ef67d
multiplanet tests still failing but split compute_model code intact
sblunt Feb 17, 2021
c162843
documented & tests passing compute_model split!
sblunt Feb 17, 2021
1aa843e
running but untested implementation of Hip IAD module
sblunt Apr 1, 2021
ee6bc7d
small updates to beta pic test
sblunt Apr 1, 2021
1b7f86c
change MCMC sampling in beta pic test
sblunt Apr 1, 2021
17c9c5b
all tests passing except rebound which I didn't test yet
sblunt Apr 1, 2021
d6a23bb
rebound tests passing now too
sblunt Apr 2, 2021
9006e29
add some nuisance files created during testing
sblunt Apr 2, 2021
80a6f74
add simple stellar astrom unit test
sblunt Apr 2, 2021
cc1ad04
fewer MCMC # steps for beta pic end-to-end
sblunt Apr 2, 2021
164dd48
more files that should be ignored
sblunt Apr 2, 2021
169b0ed
cleanup
sblunt Apr 2, 2021
4321480
Merge branch 'main' into hip-iad
sblunt Apr 2, 2021
1630b74
Revert "cleanup"
sblunt Apr 2, 2021
e21f707
cleanup of hopefully the right nuisance files
sblunt Apr 2, 2021
5d95ea5
more cleanup
sblunt Apr 2, 2021
834efc5
added all changes
rferrerc May 26, 2021
5e19213
Merge branch 'changebasis' into hip-iad
rferrerc May 27, 2021
235e60b
Merge pull request #2 from sblunt/hip-iad
rferrerc May 27, 2021
5034163
Revert "more cleanup"
sblunt Jun 9, 2021
b550f71
fits in XYZ basis and its tutorial
rferrerc Jun 21, 2021
376cf18
done
rferrerc Jun 21, 2021
2f22df0
Update results.py
rferrerc Jun 21, 2021
d51fda2
Update system.py
rferrerc Jun 21, 2021
dc2f885
Merge pull request #237 from rferrerc/changebasis
sblunt Jul 20, 2021
3e24897
Merge branch 'develop' into hip-iad
sblunt Jul 20, 2021
5d0b5d1
Merge pull request #226 from sblunt/hip-iad
sblunt Jul 20, 2021
40e38bd
implemented basis api for standard, period, semi-amp, and XYZ sets an…
TirthDS Aug 2, 2021
06fb7c3
Comparisons with current orbit approximator
sofiacovarrubias Aug 3, 2021
16a300c
Bug fixes to improve accuracy
sofiacovarrubias Aug 3, 2021
2722cfe
fixed a bug in kepler.py (!) that was causing very very small offsets…
sblunt Aug 4, 2021
9f7ca6c
fixed a bug in the RA offset calculation when we're tracking planet p…
sblunt Aug 4, 2021
af74066
Merge branch 'develop' into rebound_develop
sblunt Aug 4, 2021
2029a00
fixed tau_to_manom function
sblunt Aug 4, 2021
0022d28
Merge branch 'develop' into rebound_develop
sblunt Aug 4, 2021
5db6759
Cleaned up to prepare for implementation
sofiacovarrubias Aug 4, 2021
b9e468a
add todos for rebound API implementation
sblunt Aug 4, 2021
bc9ad75
Merge branch 'rebound_develop' of https://github.com/sblunt/orbitize …
sofiacovarrubias Aug 4, 2021
24708ba
Basis objects now work with plotting and saving/loading data
TirthDS Aug 5, 2021
4c114e6
Merge branch 'develop' into multiplebasis
sblunt Aug 6, 2021
90de67d
Created calling capability and edited for clarity
sofiacovarrubias Aug 9, 2021
6665676
Updated basis API to work with OFTI
TirthDS Aug 11, 2021
a6b51f6
Merge branch 'multiplebasis' of https://github.com/sblunt/orbitize in…
TirthDS Aug 11, 2021
0d77d69
removed pdb trace
TirthDS Aug 11, 2021
e302c64
XYZ basis now works with supplied rv data, and added system test for …
TirthDS Aug 12, 2021
3826cd3
fixed xyz initial positions validator
TirthDS Aug 12, 2021
91e04a8
validate xyz works with conversion method in basis.py and now make co…
TirthDS Aug 13, 2021
db5dd9d
added conversion tests for period basis
TirthDS Aug 13, 2021
09ae418
added conversion back to semi-amp basis from standard
TirthDS Aug 13, 2021
edbc448
added parameter checking for basis sets, and various comments
TirthDS Aug 16, 2021
0755541
added system optionals for Rebound
sofiacovarrubias Aug 16, 2021
81ac3ab
tests for xyz basis
TirthDS Aug 17, 2021
137e908
revised tests, validate_xyz based on each companion ecc
TirthDS Aug 17, 2021
26e51fd
passes results test now
TirthDS Aug 17, 2021
a5d665e
added temporary fix to xyz conversion that makes the conversions to a…
TirthDS Aug 17, 2021
d519209
Fixed subtle differences, created test file
sofiacovarrubias Aug 18, 2021
8254adc
forgot to push this
sofiacovarrubias Aug 18, 2021
3f97a9d
removed import pdb statements, using max likelihood for rv plotting r…
TirthDS Aug 19, 2021
ac0f332
basis conversion happens in compute_model now
TirthDS Aug 20, 2021
c499162
topped up test file and added optionals to nbody to match output formats
sofiacovarrubias Aug 24, 2021
ba9d7a8
catch Sn !=5 exception
sblunt Aug 24, 2021
741a10b
allow arbitrary epoch for alpha0, dec0
sblunt Aug 24, 2021
3ca3ff3
pass in the HipparcosLogProb object to system directly
sblunt Aug 24, 2021
d540e54
fixed mo/mtot bug in test_abs_astro test; now works to machine precision
sblunt Aug 25, 2021
f682b6a
Make copy of the selected posteriors before converting in plot_orbits()
TirthDS Aug 25, 2021
659e5ae
add preliminary nielsen iad test
sblunt Aug 26, 2021
64a472c
gitignore vscode config files
sblunt Aug 26, 2021
7dba71d
working Nielsen test
sblunt Aug 26, 2021
c91635f
remove references to my own path lol
sblunt Aug 26, 2021
b3b05b9
unit-test-ified the Nielsen test
sblunt Aug 26, 2021
c21c416
fixed corner plot labels for Hip IAD params
sblunt Aug 26, 2021
ce8f23c
bug fixes for beta pic end-to-end IAD test
sblunt Aug 26, 2021
e949cd9
finishing touches to Hip API code
sblunt Aug 26, 2021
1c0c79f
Merge pull request #249 from sblunt/multiplebasis
sblunt Aug 26, 2021
545d581
grabbing latest changes from main
sblunt Aug 26, 2021
9d72db1
Grab new basis code for hip-api branch
sblunt Aug 26, 2021
04ecbfc
Hip IAD module now fully documented
sblunt Aug 27, 2021
9b5dd68
removed hard-coded indices in system
sblunt Aug 28, 2021
afe237f
typeo
sblunt Aug 31, 2021
6f2cd27
5-param exception-> valueerror
sblunt Aug 31, 2021
1aa4cf3
Merge pull request #258 from sblunt/hipparcos-api
sblunt Aug 31, 2021
6097fd8
not implemented exceptions for OFTI+non-astrometric data types; indic…
sblunt Sep 1, 2021
e01c28f
Merge branch 'develop' into indices-to-param_idx
sblunt Sep 1, 2021
74fbed3
tests not passing yet but all code for this branch in
sblunt Sep 1, 2021
421c64b
more tests passing but still not all
sblunt Sep 1, 2021
c2cd594
more tests passing; transform_errors now handles case of x12_corr=nan
sblunt Sep 1, 2021
739ce6b
tests passed!
sblunt Sep 1, 2021
66fac91
remove sampler_str from system; not implemented OFTI error from syste…
sblunt Sep 1, 2021
8a93533
update driver and tests to remove system sampler_str attr
sblunt Sep 2, 2021
970f3e6
deleting rogue import statements
sblunt Sep 2, 2021
b0e7fe9
as -> mas
sblunt Sep 2, 2021
4ebc754
unused import
sblunt Sep 2, 2021
b59846e
body_num self consistent in OFTI
sblunt Sep 2, 2021
4741e3b
binary file removed
sblunt Sep 2, 2021
2ff279a
more comments for beta pic end->end
sblunt Sep 2, 2021
890648e
Merge pull request #266 from sblunt/indices-to-param_idx
sblunt Sep 2, 2021
833c5f2
improved comments on beta pic end-to-end test
sblunt Sep 2, 2021
d00393e
add full hipparcos tutorial
sblunt Sep 2, 2021
8ddde0b
Merge branch 'develop' into rebound_develop
sblunt Sep 3, 2021
d5c236b
nbody tests agreeing with orbitize stellar abs astrometry
sblunt Sep 3, 2021
4f05fd0
Merge pull request #254 from sblunt/rebound_develop
sblunt Sep 3, 2021
8a3b7c9
increase # of steps in two tests that occasionally fail
sblunt Sep 3, 2021
153a7bd
Merge branch 'main' into develop
sblunt Sep 3, 2021
7ef8e2e
running OFTI pan prior test for fewer steps to avoid travis timeout
sblunt Sep 3, 2021
86e7178
delete an unused import
semaphoreP Sep 3, 2021
e3d3d6f
fixed a stellar RV dimension bug in system
sblunt Sep 3, 2021
2525a2c
and add in Tirth's RV plotting fix to make tests pass
sblunt Sep 3, 2021
00b0575
up # of hipparcos test MCMC steps to hopefully make test always pass
sblunt Sep 3, 2021
144ef58
added note on no Gaia data.
semaphoreP Sep 3, 2021
a65c69d
Merge pull request #268 from sblunt/hipparcos-tutorial
semaphoreP Sep 3, 2021
c7f5d87
address Jason's comments; cleaning up
sblunt Sep 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Added by orbitize! Developers
orbitize/example_data/rebound*.csv
orbitize/example_data/*test.hdf5
.vscode/launch.json
.vscode/settings.json

# images & storage files generated by tutorials
*.hdf5
*.fits
*.png
tests/test_results.h5
tests/multiplanet*test.csv

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -106,11 +119,3 @@ ENV/

# utility scripts
build.sh

# images & storage files generated by tutorials
*.hdf5
*.fits
*.png
.vscode/settings.json
tests/test_results.h5
tests/multiplanet*test.csv
8 changes: 8 additions & 0 deletions docs/basis.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _basis:

Basis
=====
.. module:: orbitize

.. automodule:: orbitize.basis
:members:
8 changes: 8 additions & 0 deletions docs/conversions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _conversions:

Basis Conversions
=================
.. module:: orbitize

.. automodule:: orbitize.conversions
:members:
8 changes: 8 additions & 0 deletions docs/hipparcos.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _hipparcos:

Hipparcos API Module
====================
.. module:: orbitize

.. automodule:: orbitize.hipparcos
:members:
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Attribution:
* If you use the OFTI algorithm, please also cite `Blunt et al (2017) <https://ui.adsabs.harvard.edu/#abs/2017AJ....153..229B/abstract>`_.
* If you use the Affine-invariant MCMC algorithm from ``emcee``, please also cite `Foreman-Mackey et al (2013) <https://ui.adsabs.harvard.edu/abs/2013PASP..125..306F/abstract>`_.
* If you use the parallel-tempered Affine-invariant MCMC algorithm from ``ptemcee``, please also cite `Vousden et al (2016) <https://ui.adsabs.harvard.edu/abs/2016MNRAS.455.1919V/abstract>`_.

* If you use the Hipparcos intermediate astrometric data (IAD) fitting capability, please also cite `Nielsen et al (2020) <https://ui.adsabs.harvard.edu/abs/2020AJ....159...71N/abstract>`_.


User Guide:
Expand Down
228 changes: 228 additions & 0 deletions docs/tutorials/Changing_bases_tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fitting in different orbital bases\n",
"\n",
"In this tutorial, we show how one can perform orbit-fits in different coordinate bases amongst the ones supported by `orbitize`. Currently fitting in different bases is only supported in MCMC, so we will use MCMC to perform an orbit-fit in an orbital basis distinct from the default one. For a general introduction to MCMC, be sure to check out the [MCMC Introduction tutorial](https://orbitize.readthedocs.io/en/latest/tutorials/MCMC_tutorial.html) first!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The \"standard\" and \"XYZ\" bases"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The default way to define an orbit in `orbitize` is through what we call the 'standard basis', which consists of eight parameters: semi-major axis (sma), eccentricity (ecc), inclination (inc), argument of periastron (aop), position angle of the nodes (pan), epoch of periastron expressed as a fraction of the period past a reference epoch (tau), parallax (plx) and total system mass (mtot). Each orbital element has an associated default prior; to see how to explore and modify these priors check out the [Modifying priors tutorial](http://orbitize.info/en/latest/tutorials/Modifying_Priors.html).\n",
"\n",
"An alternative way to define an orbit is through its position and velocity components in XYZ space for a given epoch; we will call this the 'XYZ basis'. The orbit is thus defined with the array ($x$, $y$, $z$, $\\dot{x}$, $\\dot{y}$,$\\dot{z}$, plx, mtot), with position coordinates measured in AU and velocity components in $\\text{km s}^{-1}$. In this basis, the sky-plane coordinates ($x,y$) are the separations of the planet relative to the primary, with the positive $x$ and $y$ directions coinciding with the positive RA and Dec directions, respectively. The $z$ direction is the line-of-sight coordinate, such that movement in the positive $z$ direction causes a redshift. The default priors are uniform all uniform."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up Sampler in the XYZ basis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The easiest way to run an orbit-fit in an alternative orbital basis in `orbitize` is through the `orbitize.driver.Driver` interface. The process is exactly like initializing a regular `Driver` object, but setting the `fitting_basis` keyword to 'XYZ':"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import orbitize\n",
"from orbitize import driver\n",
"import multiprocessing as mp\n",
"\n",
"filename = \"{}/ \".format(orbitize.DATADIR) # a file with input in radec since rn it only works for that\n",
"\n",
"# system parameters\n",
"num_secondary_bodies = 1\n",
"system_mass = 1.75 # [Msol]\n",
"plx = 51.44 # [mas]\n",
"mass_err = 0.05 # [Msol]\n",
"plx_err = 0.12 # [mas]\n",
"\n",
"# MCMC parameters\n",
"num_temps = 5\n",
"num_walkers = 20\n",
"num_threads = mp.cpu_count() # or a different number if you prefer\n",
"\n",
"\n",
"my_driver = driver.Driver(\n",
" filename, 'MCMC', num_secondary_bodies, system_mass, plx, mass_err=mass_err, plx_err=plx_err, fitting_basis='XYZ',\n",
" mcmc_kwargs={'num_temps': num_temps, 'num_walkers': num_walkers, 'num_threads': num_threads}\n",
")\n",
"\n",
"s = my_driver.sampler"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Properly) initializing walkers in the XYZ basis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the standard basis at this point we would be ready to use the `s.run_sampler` method to start the sampling, but with the XYZ basis we have to make sure that all our walkers are initialized in a valid region of parameter space. This is because randomly generated values of ($x$, $y$, $z$, $\\dot{x}$, $\\dot{y}$, $\\dot{z}$) can result in unbound, invalid orbits with, for example, negative eccentricities (which is not cool). This can be easily corrected with the `s.validate_xyz_positions` method:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s.validate_xyz_positions()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___________________"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After this is done, the sampler can be run and the results saved normally:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"total_orbits = 6000 # number of steps x number of walkers (at lowest temperature)\n",
"burn_steps = 10 # steps to burn in per walker\n",
"thin = 2 # only save every 2nd step\n",
"\n",
"s.run_sampler(total_orbits, burn_steps=burn_steps, thin=thin)\n",
"s.results.save_results('my_posterior.hdf5')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading and converting results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can load the results as you normally would. The orbit posteriors are saved in the `results.post` attribute, and the basis you used for the fit in the `results.fitting_basis` attribute:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from orbitize import results \n",
"\n",
"myResults = orbitize.results.Results() # create empty Results object\n",
"myResults.load_results('my_posterior.hdf5') \n",
"print('The used basis for the fit was ', myResults.fitting_basis)\n",
"print('The posteriors are ', myResults.post)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is important to note that, as you can probably see, the results will be saved in the XYZ basis, so we might want to convert those back to the standard basis to work with them. For this we can use the `orbitize.conversions` module, which can convert from the standard basis to the XYZ basis and back. To do this, remember that the XYZ basis gives the position and velocity of the planet at a given epoch; so before converting back to standard we need to check the epoch that was used for the fit through the `results.xyz_epochs` attribute:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(myResults.xyz_epochs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since we only fit for one planet, we only have one epoch. Now, we can use that epoch to convert back to the good old standard basis:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from orbitize import conversions\n",
"xyz_posterior = myResults.post\n",
"xyz_epoch = myResults.xyz_epochs\n",
"\n",
"standard_posterior = conversions.xyz_to_standard(xyz_epoch, xyz_posterior)\n",
"\n",
"print('My posterior in standard basis is ', standard_posterior)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And we're done! Enjoy the XYZ basis."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "cbafa42b6ff5e39c327df57f5a3bbaee7fd2ec257998acb6b9d49a010b26573d"
},
"kernelspec": {
"display_name": "Python 3.8.3 ('base': conda)",
"name": "python3"
},
"language_info": {
"name": "python",
"version": ""
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading